Subversion Repositories eFlore/Applications.coel

Rev

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

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