Subversion Repositories eFlore/Applications.coel

Rev

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

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