Subversion Repositories eFlore/Applications.coel

Rev

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