Subversion Repositories eFlore/Applications.coel

Rev

Rev 214 | Rev 242 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
208 jp_milcent 1
package org.tela_botanica.client.modeles;
2
 
3
import java.util.Iterator;
4
import java.util.List;
5
import java.util.Set;
6
 
231 jp_milcent 7
import org.apache.commons.digester.SetRootRule;
8
 
208 jp_milcent 9
import com.extjs.gxt.ui.client.widget.form.CheckBox;
10
import com.google.gwt.json.client.JSONObject;
11
 
12
public class StructureAPersonne extends aDonnee {
13
 
14
	public static final String ROLE_ADMIN = "2026";
15
	public static final String ROLE_EQUIPE = "2027";
16
	public static final String PREFIXE = "csap";
17
 
18
	/**
19
	 * Constructeur vide
20
	 *
21
	 */
22
	public StructureAPersonne() {
23
		// Définition des valeurs par défaut de variables obligatoires vis à vis de l'utilisation de l'objet
24
		this.set("contact", false);
214 jp_milcent 25
		this.set("fonction", "");
26
		this.set("statut", "");
231 jp_milcent 27
		this.set("travail", 0);
208 jp_milcent 28
	}
29
 
30
	/**
31
	 * Constructeur avec un objet JSON
32
	 *
33
	 * @param
34
	 */
35
	public StructureAPersonne(JSONObject personnel) {
36
		// Définition des valeurs par défaut de variables obligatoires vis à vis de l'utilisation de l'objet
37
		this.set("contact", false);
214 jp_milcent 38
		this.set("fonction", "");
39
		this.set("statut", "");
231 jp_milcent 40
		this.set("travail", 0);
208 jp_milcent 41
 
42
		// L'objet JSON est une table de hachage
43
		Set<String> im = personnel.keySet();
44
 
45
		// Parcourt pour chaque clé
46
		for (Iterator<String> it = im.iterator(); it.hasNext();) {
47
			// Si elle est associée à une valeur, nous l'ajoutons
48
			String cle = it.next();
49
			if (cle.startsWith(PREFIXE+"_")) {
50
				// Suppression de l'abréviation du champ. Inutile dans le contexte d'un objet
51
				String cleObjet = cle.replaceFirst("^"+PREFIXE+"_", "");
52
				// Sinon, nous ajoutons la clé avec une valeur vide
53
				String valeur = "";
54
				if (personnel.get(cle).isString() != null) {
55
					valeur = personnel.get(cle).isString().stringValue();
56
				}
57
				this.set(cleObjet, valeur);
58
				if (cle.equals("mark_contact")) {
59
					this.set("contact", (valeur.equals("1") ? true : false));
60
				} else if (cle.equals("bota_travail_hebdo_tps")) {
61
					this.set("travail", Integer.parseInt(valeur));
62
				}
63
			}
64
			if (cle.startsWith(Personne.PREFIXE+"_")) {
65
				// Suppression de l'abréviation du champ. Inutile dans le contexte d'un objet
66
				String cleObjet = cle.replaceFirst("^"+Personne.PREFIXE+"_", "");
67
				// Sinon, nous ajoutons la clé avec une valeur vide
68
				String valeur = "";
69
				if (personnel.get(cle).isString() != null) {
70
					valeur = personnel.get(cle).isString().stringValue();
71
				}
72
 
73
				if (cleObjet.equals("truk_telephone")) {
74
					this.set("telephone", getInfoDenormaliseParType(valeur, "FIX"));
75
				} else if (cleObjet.equals("truk_fax")) {
76
					this.set("fax", getInfoDenormaliseParPosition(valeur, 1));
77
				} else if (cleObjet.equals("truk_courriel")) {
78
					this.set("courriel", getInfoDenormaliseParPosition(valeur, 1));
79
				} else if (cleObjet.equals("ce_truk_specialite")) {
80
					this.set("specialite", getInfoDenormaliseParPosition(valeur, 1));
81
				} else {
82
					this.set(cleObjet, valeur);
83
				}
84
			}
85
		}
86
	}
87
 
88
	/**
89
	 * Constructeur avec la fonction à passer en paramètre
90
	 *
231 jp_milcent 91
	 * @param fonction fonction de la personne dans la structure.
92
	 * @param role identifiant du rôle de la personne vis à vis de la structure.
208 jp_milcent 93
	 */
231 jp_milcent 94
	public StructureAPersonne(String fonction, String roleId) {
208 jp_milcent 95
		setFonction(fonction);
231 jp_milcent 96
		setIdRole(roleId);
97
 
208 jp_milcent 98
		// Définition des valeurs par défaut de variables obligatoires vis à vis de l'utilisation de l'objet
99
		this.set("contact", false);
214 jp_milcent 100
		this.set("fonction", "");
101
		this.set("statut", "");
231 jp_milcent 102
		this.set("travail", 0);
208 jp_milcent 103
	}
104
 
105
	// ID
106
	/** Génère un identifiant de StructureAPersonne.
107
	 *
108
	 * C'est une concaténation des clés primaires de la table coel_structure_a_personne séparées par un tiret "-".
109
	 *
110
	 * @return identifiant unique d'une relation "structure à personne".
111
	 */
112
	public String getId() {
231 jp_milcent 113
		String idStructure = renvoyerValeurCorrecte("id_structure");
114
		String idPersonne = renvoyerValeurCorrecte("id_personne");
115
		String idRole = renvoyerValeurCorrecte("id_role");
116
		if (idStructure.equals("") && idPersonne.equals("") && idRole.equals("")) {
117
			return null;
118
		} else {
119
			return (idStructure+"-"+idPersonne+"-"+idRole);
120
		}
208 jp_milcent 121
	}
122
 
123
	//+---------------------------------------------------------------------------------------------------------------+
124
	// CHAMPS PROVENANT de la TABLE COEL_STRUCTURE_A_PERSONNE
125
 
126
	// ID STRUCTURE
127
	public String getIdStructure() {
128
		return renvoyerValeurCorrecte("id_structure");
129
	}
130
	public void setIdStructure(String is) {
131
		this.set("id_structure", is);
132
	}
133
 
134
	// ID PERSONNE
135
	public String getIdPersonne() {
136
		return renvoyerValeurCorrecte("id_personne");
137
	}
138
	public void setIdPersonne(String ip) {
139
		this.set("id_personne", ip);
140
	}
141
 
142
	// ID RôLE
143
	public String getIdRole() {
144
		return renvoyerValeurCorrecte("id_role");
145
	}
146
	public void setIdRole(String ir) {
147
		this.set("id_role", ir);
148
	}
149
 
150
	// FONCTION
151
	public String getFonction() {
212 jp_milcent 152
		return renvoyerValeurCorrecte("ce_truk_fonction");
208 jp_milcent 153
	}
154
	public void setFonction(String ctf) {
155
		this.set("ce_truk_fonction", ctf);
156
	}
157
	public void setFonction(String type, Object valeur) {
231 jp_milcent 158
		setChaineDenormaliseUnique("ce_truk_fonction", type, valeur);
208 jp_milcent 159
	}
160
 
161
 
162
	// SERVICE
163
	public String getService() {
164
		return renvoyerValeurCorrecte("service");
165
	}
166
	public void setService(String s) {
167
		this.set("service", s);
168
	}
169
 
170
	// STATUT
171
	public String getStatut() {
172
		return renvoyerValeurCorrecte("ce_truk_statut");
173
	}
174
	public void setStatut(String cts) {
175
		this.set("ce_truk_statut", cts);
176
	}
231 jp_milcent 177
	public void setStatut(String type, Object valeur) {
178
		setChaineDenormaliseUnique("ce_truk_statut", type, valeur);
208 jp_milcent 179
	}
180
 
181
	// CONTACT
182
	public String getContact() {
183
		return renvoyerValeurCorrecte("mark_contact");
184
	}
185
	public void setContact(String c) {
231 jp_milcent 186
		//this.set("contact", (c.equals("1") ? true : false));
208 jp_milcent 187
		this.set("mark_contact", c);
188
	}
189
	public void setContact(Boolean c) {
190
		setContact((c.equals(Boolean.TRUE) ? "1" : "0"));
191
	}
192
 
193
	// BOTA TRAVAIL HEBDO TPS
194
	public String getBotaTravailHebdoTps() {
195
		return renvoyerValeurCorrecte("bota_travail_hebdo_tps");
196
	}
197
	public void setBotaTravailHebdoTps(String btht) {
198
		this.set("bota_travail_hebdo_tps", btht);
199
	}
200
 
201
	//+---------------------------------------------------------------------------------------------------------------+
202
	// CHAMPS PROVENANT de la TABLE COEL_PERSONNE
203
 
204
	// PRÉNOM
205
	public String getPrenom() {
206
		return renvoyerValeurCorrecte("prenom");
207
	}
208
	public void setPrenom(String p) {
209
		this.set("prenom", p);
210
	}
211
 
212
	// NOM
213
	public String getNom() {
214
		return renvoyerValeurCorrecte("nom");
215
	}
216
	public void setNom(String n) {
217
		this.set("nom", n);
218
	}
219
 
220
	// TÉLÉPHONE
221
	public String getTelephone() {
222
		return renvoyerValeurCorrecte("telephone");
223
	}
224
	public void setTelephone(String t) {
231 jp_milcent 225
		// Nous remplaçons le premier numéro de Téléphone FIX de la personne
226
		this.setChaineDenormaliseParType("telephone", "FIX", t);
208 jp_milcent 227
	}
228
 
229
	// FAX
230
	public String getFax() {
231
		return renvoyerValeurCorrecte("fax");
232
	}
233
	public void setFax(String f) {
231 jp_milcent 234
		// Nous remplaçons le numéro de Fax en position 1 (principal)
235
		this.setChaineDenormaliseParPosition("fax", 1, f);
208 jp_milcent 236
	}
237
 
238
	// COURRIEL
239
	public String getCourriel() {
240
		return renvoyerValeurCorrecte("courriel");
241
	}
242
	public void setCourriel(String c) {
231 jp_milcent 243
		// Nous remplaçons le courriel en position 1 (principal)
244
		this.setChaineDenormaliseParPosition("courriel", 1, c);
208 jp_milcent 245
	}
246
 
247
	// SPÉCIALITÉ
248
	public String getSpecialite() {
249
		return renvoyerValeurCorrecte("specialite");
250
	}
251
	public void setSpecialite(String s) {
231 jp_milcent 252
		// Nous remplaçons le premier numéro de Téléphone FIX de la personne
253
		this.setChaineDenormaliseUnique("specialite", "AUTRE", s);
208 jp_milcent 254
	}
255
}