Subversion Repositories eFlore/Applications.coel

Rev

Rev 1415 | Rev 1513 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
61 jpm 1
package org.tela_botanica.client.modeles;
2
 
896 gduche 3
import java.util.HashMap;
61 jpm 4
import java.util.Iterator;
5
import java.util.Set;
6
 
7
import com.google.gwt.json.client.JSONObject;
8
 
69 jpm 9
public class Utilisateur extends aDonnee {
61 jpm 10
 
748 jpm 11
	private static final long serialVersionUID = -4016615552202089985L;
12
 
13
	public static final String PREFIXE = "cp";
1173 jpm 14
	public static String[] champsObligatoires = {"cp_id_personne"};
748 jpm 15
 
766 jpm 16
	public Utilisateur() {
769 jpm 17
		initialiserUtilisateur(null, false);
766 jpm 18
	}
769 jpm 19
 
132 jpm 20
	public Utilisateur(String id, boolean identifie) {
769 jpm 21
		initialiserUtilisateur(id, identifie);
61 jpm 22
	}
769 jpm 23
 
61 jpm 24
	public Utilisateur(JSONObject utilisateur) {
25
		// l'objet JSON est une table de hachage
26
		Set<String> im = utilisateur.keySet();
27
 
28
		// Parcourt pour chaque clé
29
		for (Iterator<String> it = im.iterator(); it.hasNext();) {
30
			// Si elle est associée à une valeur, nous l'ajoutons
31
			String cle = it.next();
32
			// Suppression de l'abréviation du champ. Inutile dans le contexte d'un objet
748 jpm 33
			String cleObjet = cle.replaceFirst("^"+PREFIXE+"_", "");
34
			// Valeur est vide par défaut
35
			String valeur = "";
61 jpm 36
			if (utilisateur.get(cle).isString() != null) {
748 jpm 37
				valeur = utilisateur.get(cle).isString().stringValue();
61 jpm 38
				this.set(cleObjet, valeur);
39
			} else {
40
				this.set(cleObjet, valeur);
41
			}
42
		}
43
	}
44
 
748 jpm 45
	@Override
46
	protected String getPrefixe() {
47
		return PREFIXE;
48
	}
1173 jpm 49
 
50
	protected String[] getChampsObligatoires()	{
51
		return champsObligatoires;
52
	}
132 jpm 53
 
769 jpm 54
	private void initialiserUtilisateur(String id, boolean etreIdentifie) {
55
		setId(id);
56
		setIdentification(etreIdentifie);
61 jpm 57
	}
58
 
132 jpm 59
 
912 jpm 60
	// ID
61 jpm 61
	/**
119 jpm 62
	 * Retourne l'id de l'utilisateur ou l'identifiant de session si la personne n'est pas identifiée.
63
	 * @return String id de l'utilisateur
64
	 */
65
	public String getId() {
769 jpm 66
		return renvoyerValeurCorrecte("id_personne");
119 jpm 67
	}
769 jpm 68
	public void setId(String id) {
69
		set("id_personne", id);
70
	}
71
 
912 jpm 72
	// NOM COMPLET
132 jpm 73
	/**
74
	 * Retourne le nom complet et formaté de l'utilisateur
75
	 * @return String nom complet
76
	 */
77
	public String getNomComplet() {
769 jpm 78
		return renvoyerValeurCorrecte("fmt_nom_complet");
132 jpm 79
	}
896 gduche 80
 
769 jpm 81
	public void setNomComplet(String nom_complet) {
82
		set("fmt_nom_complet", nom_complet);
83
	}
132 jpm 84
 
912 jpm 85
	// PRÉNOM
132 jpm 86
	/**
87
	 * Retourne le prénom de l'utilisateur
88
	 * @return String prénom
89
	 */
90
	public String getPrenom() {
769 jpm 91
		return renvoyerValeurCorrecte("prenom");
132 jpm 92
	}
769 jpm 93
	public void setPrenom(String prenom) {
94
		set("prenom", prenom);
95
	}
119 jpm 96
 
912 jpm 97
	// NOM
119 jpm 98
	/**
132 jpm 99
	 * Retourne le nom de l'utilisateur
100
	 * @return String nom
101
	 */
102
	public String getNom() {
769 jpm 103
		return renvoyerValeurCorrecte("nom");
132 jpm 104
	}
769 jpm 105
	public void setNom(String nom) {
106
		set("nom", nom);
107
	}
132 jpm 108
 
912 jpm 109
	// LOGIN
132 jpm 110
	/**
66 jpm 111
	 * Retourne le login de l'utilisateur ou l'identifiant de session si la personne n'est pas identifiée.
64 jpm 112
	 * @return String login
113
	 */
114
	public String getLogin() {
769 jpm 115
		return renvoyerValeurCorrecte("login");
64 jpm 116
	}
769 jpm 117
	public void setLogin(String l) {
118
		set("login", l);
119
	}
120
 
912 jpm 121
	// MOT DE PASSE
64 jpm 122
	/**
123
	 * Retourne le mot de passe de l'utilisateur
124
	 * @return String mot de passe
125
	 */
126
	public String getMotDePasse() {
769 jpm 127
		return renvoyerValeurCorrecte("mot_de_passe");
64 jpm 128
	}
769 jpm 129
	public void setMotDePasse(String mdp) {
130
		set("mot_de_passe", mdp);
131
	}
64 jpm 132
 
912 jpm 133
	// PARAMÈTRE
134
	public String getParametre() {
135
		String xml = renvoyerValeurCorrecte("parametre");
136
		if (xml.equals("")) {
137
			xml = "<?xml version='1.0' encoding='UTF-8'?>\n<parametres>\n</parametres>";
138
		}
139
		return xml;
140
	}
141
	public void setParametre(String param) {
142
		set("parametre", param);
143
	}
144
 
145
	// +---------------------------------------------------------------------------------------------------------------+
146
	// IDENTIFIÉ
64 jpm 147
	/**
61 jpm 148
	 * Retourne vrai si utilisateur est identifié.
149
	 * @return boolean
150
	 */
151
	public boolean isIdentifie() {
1329 cyprien 152
		if (get("identifie").equals(true))	{
896 gduche 153
			return true;
154
		}	else	{
155
			return false;
156
		}
61 jpm 157
	}
896 gduche 158
 
769 jpm 159
	public void setIdentification(Boolean bool) {
160
		set("identifie", bool);
161
	}
1369 cyprien 162
 
1329 cyprien 163
	public boolean avoirLicenceAcceptee() {
164
		if (getLicence().equals("1"))	{
165
			return true;
166
		}	else	{
167
			return false;
168
		}
169
	}
170
 
912 jpm 171
	// LICENCE ACCEPTÉE
896 gduche 172
	public void setLicence(String licence)	{
173
		this.set("licenceAcceptee", licence);
174
	}
175
 
176
	public String getLicence()	{
177
		if (this.get("licenceAcceptee") != null)	{
178
			return this.get("licenceAcceptee");
179
		} else {
180
			return "";
181
		}
182
	}
769 jpm 183
}