Subversion Repositories eFlore/Applications.coel

Rev

Rev 1197 | Rev 1369 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1197 Rev 1329
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))	{
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
	
162
 
-
 
163
	public boolean avoirLicenceAcceptee() {
-
 
164
		if (getLicence().equals("1"))	{
-
 
165
			return true;
-
 
166
		}	else	{
-
 
167
			return false;
-
 
168
		}
-
 
169
	}
-
 
170
 
163
	// LICENCE ACCEPTÉE
171
	// LICENCE ACCEPTÉE
164
	public void setLicence(String licence)	{
172
	public void setLicence(String licence)	{
165
		this.set("licenceAcceptee", licence);
173
		this.set("licenceAcceptee", licence);
166
	}
174
	}
167
	
175
	
168
	public String getLicence()	{
176
	public String getLicence()	{
169
		if (this.get("licenceAcceptee") != null)	{
177
		if (this.get("licenceAcceptee") != null)	{
170
			return this.get("licenceAcceptee");
178
			return this.get("licenceAcceptee");
171
		} else {
179
		} else {
172
			return "";
180
			return "";
173
		}
181
		}
174
	}
182
	}
175
}
183
}