Subversion Repositories eFlore/Applications.coel

Rev

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

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