Subversion Repositories eFlore/Applications.coel

Rev

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