Subversion Repositories eFlore/Applications.coel

Rev

Rev 1173 | Rev 1329 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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