Subversion Repositories eFlore/Applications.coel

Rev

Rev 748 | Rev 769 | 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
 
3
import java.util.Iterator;
4
import java.util.Set;
5
 
6
import com.google.gwt.json.client.JSONObject;
7
 
69 jpm 8
public class Utilisateur extends aDonnee {
61 jpm 9
 
748 jpm 10
	private static final long serialVersionUID = -4016615552202089985L;
11
 
12
	public static final String PREFIXE = "cp";
13
 
766 jpm 14
	public Utilisateur() {
15
		set("id_personne", null);
16
		set("identifie", false);
17
	}
18
 
132 jpm 19
	public Utilisateur(String id, boolean identifie) {
20
		set("id_personne", id);
64 jpm 21
		set("identifie", identifie);
61 jpm 22
	}
23
 
24
	public Utilisateur(JSONObject utilisateur) {
25
		// l'objet JSON est une table de hachage
26
		Set<String> im = utilisateur.keySet();
27
 
28
		// Parcourt pour chaque clé
29
		for (Iterator<String> it = im.iterator(); it.hasNext();) {
30
			// Si elle est associée à une valeur, nous l'ajoutons
31
			String cle = it.next();
32
			// Suppression de l'abréviation du champ. Inutile dans le contexte d'un objet
748 jpm 33
			String cleObjet = cle.replaceFirst("^"+PREFIXE+"_", "");
34
			// Valeur est vide par défaut
35
			String valeur = "";
61 jpm 36
			if (utilisateur.get(cle).isString() != null) {
748 jpm 37
				valeur = utilisateur.get(cle).isString().stringValue();
61 jpm 38
				this.set(cleObjet, valeur);
39
			} else {
40
				this.set(cleObjet, valeur);
41
			}
42
		}
43
	}
44
 
748 jpm 45
	@Override
46
	protected String getPrefixe() {
47
		return PREFIXE;
48
	}
49
 
132 jpm 50
	public void setId(String id) {
51
		set("id_personne", id);
61 jpm 52
	}
53
 
132 jpm 54
	public void setNomComplet(String nom_complet) {
55
		set("fmt_nom_complet", nom_complet);
56
	}
57
 
61 jpm 58
	public void setPrenom(String prenom) {
59
		set("prenom", prenom);
60
	}
61
 
132 jpm 62
	public void setNom(String nom) {
63
		set("nom", nom);
64
	}
65
 
64 jpm 66
	public void setIdentifie(Boolean bool) {
67
		set("identifie", bool);
68
	}
65 jpm 69
 
66 jpm 70
	public void setLogin(String l) {
71
		set("login", l);
65 jpm 72
	}
73
 
66 jpm 74
	public void setMotDePasse(String mdp) {
75
		set("mot_de_passe", mdp);
61 jpm 76
	}
132 jpm 77
 
61 jpm 78
	/**
119 jpm 79
	 * Retourne l'id de l'utilisateur ou l'identifiant de session si la personne n'est pas identifiée.
80
	 * @return String id de l'utilisateur
81
	 */
82
	public String getId() {
83
		return get("id_personne");
84
	}
132 jpm 85
 
86
	/**
87
	 * Retourne le nom complet et formaté de l'utilisateur
88
	 * @return String nom complet
89
	 */
90
	public String getNomComplet() {
91
		return get("fmt_nom_complet");
92
	}
93
 
94
	/**
95
	 * Retourne le prénom de l'utilisateur
96
	 * @return String prénom
97
	 */
98
	public String getPrenom() {
99
		return get("prenom");
100
	}
119 jpm 101
 
102
	/**
132 jpm 103
	 * Retourne le nom de l'utilisateur
104
	 * @return String nom
105
	 */
106
	public String getNom() {
107
		return get("nom");
108
	}
109
 
110
	/**
66 jpm 111
	 * Retourne le login de l'utilisateur ou l'identifiant de session si la personne n'est pas identifiée.
64 jpm 112
	 * @return String login
113
	 */
114
	public String getLogin() {
115
		return get("login");
116
	}
117
 
118
	/**
119
	 * Retourne le mot de passe de l'utilisateur
120
	 * @return String mot de passe
121
	 */
122
	public String getMotDePasse() {
123
		return get("mot_de_passe");
124
	}
125
 
126
	/**
61 jpm 127
	 * Retourne vrai si utilisateur est identifié.
128
	 * @return boolean
129
	 */
130
	public boolean isIdentifie() {
64 jpm 131
		return get("identifie");
61 jpm 132
	}
133
 
132 jpm 134
	public String toString() {
135
		String chaine = new String();
136
		for (Iterator<String> it = this.getPropertyNames().iterator(); it.hasNext();) {
137
			// Si elle est associée à une valeur, nous l'ajoutons
138
			String cle = it.next();
139
 
140
			// GXT ne prend pas en compte /n ou /r/n...
141
			chaine += cle+" : "+get(cle)+"\n";
142
		}
143
		return chaine;
144
	}
145
 
61 jpm 146
}