Subversion Repositories eFlore/Applications.coel

Rev

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

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