Subversion Repositories eFlore/Applications.coel

Rev

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