Subversion Repositories eFlore/Applications.coel

Rev

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