Subversion Repositories eFlore/Applications.coel

Rev

Rev 1513 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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