Subversion Repositories eFlore/Applications.coel

Rev

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