Subversion Repositories eFlore/Applications.coel

Rev

Rev 1591 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
935 jpm 1
package org.tela_botanica.client.modeles.personne;
102 jpm 2
 
350 gduche 3
import java.util.Date;
102 jpm 4
import java.util.Iterator;
1369 cyprien 5
import java.util.Map;
102 jpm 6
import java.util.Set;
7
 
827 gduche 8
import org.tela_botanica.client.Mediateur;
935 jpm 9
import org.tela_botanica.client.modeles.aDonnee;
1513 jpm 10
import org.tela_botanica.client.modeles.collection.CollectionAPublication;
993 gduche 11
import org.tela_botanica.client.modeles.publication.PublicationAPersonneListe;
1369 cyprien 12
import org.tela_botanica.client.util.Debug;
1573 jpm 13
import org.tela_botanica.client.util.Log;
620 gduche 14
import org.tela_botanica.client.util.UtilString;
15
 
1369 cyprien 16
import com.extjs.gxt.ui.client.data.ModelData;
350 gduche 17
import com.google.gwt.core.client.GWT;
18
import com.google.gwt.i18n.client.DateTimeFormat;
102 jpm 19
import com.google.gwt.json.client.JSONObject;
20
 
21
public class Personne extends aDonnee {
208 jp_milcent 22
 
748 jpm 23
	private static final long serialVersionUID = -6974716696155349332L;
24
 
208 jp_milcent 25
	public static final String PREFIXE = "cp";
245 jp_milcent 26
	public static final String TELEPHONE_FIXE = "FIX";
27
	public static final String TELEPHONE_GSM = "GSM";
602 jp_milcent 28
	public static final String TELEPHONE_FAX = "FAX";
875 jpm 29
	public static final String ETRE_DECEDE = "30745";
30
	public static final String ETRE_VIVANT = "30746";
1173 jpm 31
	public static String[] champsObligatoires = {"cp_id_personne"};
208 jp_milcent 32
 
993 gduche 33
	private PublicationAPersonneListe publicationsLiees= null;
34
 
1573 jpm 35
	public Personne() {}
1369 cyprien 36
 
1513 jpm 37
	public Personne(ModelData model) {
38
		creerPersonne(model, false);
39
	}
40
 
41
	public Personne(ModelData model, boolean removePrefix) {
42
		creerPersonne(model, removePrefix);
43
	}
44
 
45
	private void creerPersonne(ModelData model, boolean removePrefix) {
46
		this.removePrefix = removePrefix;
47
 
1369 cyprien 48
		Map<String, Object> a = model.getProperties();
49
 
50
		Set<String> cles = a.keySet();
51
		Iterator<String> it = cles.iterator();
52
		while (it.hasNext()) {
53
			String cle = it.next();
54
			if (a.get(cle) != null) {
1513 jpm 55
				String cleObjet = "";
56
				if (removePrefix) {
57
					cleObjet = cleObjet.replaceFirst("^"+PREFIXE+"_", "");
58
				}
59
				else {
60
					cleObjet = cle;
61
				}
1369 cyprien 62
				this.set(cleObjet, a.get(cle));
63
			}
64
		}
1513 jpm 65
	}
103 jpm 66
 
775 jpm 67
	public Personne(JSONObject personne) {
68
		initialiserModele(personne);
261 gduche 69
		//Ajout du champ courriel principal
947 gduche 70
		this.setCourrielPrinc(this.getInfoDenormaliseParPosition(this.renvoyerValeurCorrecte("truk_courriel"), 1));
102 jpm 71
	}
72
 
748 jpm 73
	@Override
74
	protected String getPrefixe() {
75
		return PREFIXE;
76
	}
77
 
1173 jpm 78
	protected String[] getChampsObligatoires()	{
79
		return champsObligatoires;
80
	}
81
 
875 jpm 82
	public Object obtenirValeurChamp(String nomChamp)	{
83
		return renvoyerValeurCorrecte(nomChamp);
84
	}
85
 
86
	public Date getDate(String nomChamp)	{
87
		String strDate = renvoyerValeurCorrecte(nomChamp);
88
		Date dateRetour = null;
89
		try {
90
			if ((strDate != null) && (!strDate.equals("0000-00-00"))) {
91
				dateRetour = DateTimeFormat.getFormat("yyyy-MM-dd").parseStrict(strDate);
92
			}
93
		} catch (StringIndexOutOfBoundsException e)	{
94
			GWT.log("Impossible de parser la date " + strDate, e);
95
		}
96
		return dateRetour;
97
	}
98
 
99
	public String getString(String nomChamp)	{
100
		return String.valueOf(renvoyerValeurCorrecte(nomChamp));
101
	}
102
 
103
	//Traitement des truks
104
	protected void remplacerTypeDansChaineDenormalise(String champ, String type, Object valeur) {
105
		if (valeur != null && !valeur.equals("")) {
106
			ajouterChaineDenormaliseAvecType(champ, type, valeur);
107
		} else {
108
			supprimerTypeDansChaineDenormalise(champ, type);
109
		}
110
	}
111
	/**
112
	 * Ajoute un nouvel élément sans type à une chaine dénormalisée.
113
	 * Champ de type "truk" contenant seulement des valeurs séparées par ";;".
114
	 * Si l'élément existe déjà, il ne sera pas ajouté.
115
	 *
116
	 * @param champ le nom du champ dénormalisé
117
	 * @param valeur la valeur à ajouter
118
	 */
119
	protected void ajouterChaineDenormalise(String champ, Object valeur) {
120
		if (valeur instanceof String) {
121
			String chaineExistante = renvoyerValeurCorrecte(champ);
122
			if (chaineExistante.equals("")) {
123
				this.set(champ, valeur);
124
			} else {
125
				// Si la valeur à ajouter n'est pas déjà présente, nous l'ajoutons
126
				if (!chaineExistante.matches("(^|"+SEPARATEUR_VALEURS+")"+valeur+"("+SEPARATEUR_VALEURS+"|$)")) {
127
					this.set(champ, chaineExistante+SEPARATEUR_VALEURS+valeur);
128
				}
129
			}
130
		}
131
	}
132
 
240 jp_milcent 133
	// ID PERSONNE
102 jpm 134
	public String getId() {
1573 jpm 135
		Log.debug("Dans getId() Personne : "+this.toString());
136
		return renvoyerValeurCorrecte("id_personne");
102 jpm 137
	}
875 jpm 138
	public void setId(String personneId) {
1513 jpm 139
		if (removePrefix) this.set("id_personne", personneId);
140
		else this.set(PREFIXE+"_id_personne", personneId);
875 jpm 141
	}
102 jpm 142
 
609 jp_milcent 143
	// ID PROJET
144
	public String getIdProjet() {
145
		return renvoyerValeurCorrecte("ce_projet");
146
	}
147
 
240 jp_milcent 148
	// NOM COMPLET
149
	public String getNomComplet() {
150
		return renvoyerValeurCorrecte("fmt_nom_complet");
181 gduche 151
	}
912 jpm 152
	public void setNomComplet(String nomComplet) {
153
		this.set("fmt_nom_complet", nomComplet);
154
	}
875 jpm 155
	public void setFmtNomComplet(String prefixe, String suffixe)	{
156
		String fmtNomComplet = "";
912 jpm 157
 
875 jpm 158
		if ((prefixe != null)&&(!prefixe.trim().equals("")))	{
159
			fmtNomComplet += prefixe + " ";
160
		}
161
 
162
		if ((this.getPrenom()!=null)&&(!this.getPrenom().trim().equals("")))	{
163
			fmtNomComplet += this.getPrenom() + " ";
164
		}
165
 
166
		if ((this.getNom()!=null)&&(!this.getNom().trim().equals("")))	{
167
			fmtNomComplet += this.getNom() + " ";
168
		}
169
 
170
		if ((suffixe!=null)&&(!suffixe.trim().equals("")))	{
171
			fmtNomComplet += suffixe;
172
		}
912 jpm 173
 
174
		setNomComplet(UtilString.ucFirst(fmtNomComplet));
875 jpm 175
	}
181 gduche 176
 
240 jp_milcent 177
	// NOM
178
	public String getNom() {
1513 jpm 179
		if (removePrefix) return renvoyerValeurCorrecte("nom");
180
		else return renvoyerValeurCorrecte(PREFIXE+"_nom");
181 gduche 181
	}
912 jpm 182
	public void setNom(String nom) {
1513 jpm 183
		if (removePrefix) set("nom", nom);
184
		else set(PREFIXE+"_nom", nom);
912 jpm 185
	}
181 gduche 186
 
240 jp_milcent 187
	// PRÉNOM
188
	public String getPrenom() {
1513 jpm 189
		if (removePrefix) return renvoyerValeurCorrecte("prenom");
190
		else return renvoyerValeurCorrecte(PREFIXE+"_prenom");
238 aurelien 191
	}
912 jpm 192
	public void setPrenom(String prenom) {
1513 jpm 193
		if (removePrefix) set("prenom", prenom);
194
		else set(PREFIXE+"_prenom", prenom);
912 jpm 195
	}
238 aurelien 196
 
240 jp_milcent 197
	// TÉLÉPHONE
198
	public String getTelephone() {
199
		return renvoyerValeurCorrecte("truk_telephone");
200
	}
201
	public void setTelephone(String t) {
202
		this.set("truk_telephone", t);
203
	}
245 jp_milcent 204
	public void ajouterTelephone(String type, Object valeur) {
240 jp_milcent 205
		ajouterChaineDenormaliseAvecType("truk_telephone", type, valeur);
206
	}
245 jp_milcent 207
	public String selectionnerTelephone(String type) {
208
		return getInfoDenormaliseParType(renvoyerValeurCorrecte("truk_telephone"), type);
209
	}
240 jp_milcent 210
 
211
	// FAX
212
	public String getFax() {
213
		return renvoyerValeurCorrecte("truk_fax");
214
	}
215
	public void setFax(String f) {
216
		this.set("truk_fax", f);
217
	}
245 jp_milcent 218
	public void ajouterFax(Object valeur) {
240 jp_milcent 219
		ajouterChaineDenormalise("truk_fax", valeur);
220
	}
245 jp_milcent 221
	public String selectionnerFax(int position) {
222
		return getInfoDenormaliseParPosition(renvoyerValeurCorrecte("truk_fax"), position);
223
	}
240 jp_milcent 224
 
225
	// COURRIEL
226
	public String getCourriel() {
227
		return renvoyerValeurCorrecte("truk_courriel");
228
	}
229
	public void setCourriel(String c) {
230
		this.set("truk_courriel", c);
231
	}
245 jp_milcent 232
	public void ajouterCourriel(String c) {
240 jp_milcent 233
		ajouterChaineDenormalise("truk_courriel", c);
234
	}
245 jp_milcent 235
	public String selectionnerCourriel(int position) {
236
		return getInfoDenormaliseParPosition(renvoyerValeurCorrecte("truk_courriel"), position);
237
	}
240 jp_milcent 238
 
239
	// SPÉCIALITÉ
240
	public String getSpecialite() {
241
		return renvoyerValeurCorrecte("ce_truk_specialite");
242
	}
243
	public void setSpecialite(String s) {
244
		// Pas de liste pour l'instant, donc tout passe dans "Autre".
245
		setChaineDenormaliseUnique("ce_truk_specialite", "AUTRE", s);
246
	}
245 jp_milcent 247
	public String afficherSpecialite() {
248
		return getChaineDenormaliseUnique("ce_truk_specialite");
249
	}
240 jp_milcent 250
 
875 jpm 251
	// NAISSANCE DATE
252
	public String getNaissanceDate()	{
253
		String dateNaiss = "";
254
		dateNaiss = get("naissance_date");
255
		if (UtilString.isEmpty(dateNaiss)||dateNaiss.equals("0000-00-00"))	{
256
			dateNaiss = Mediateur.i18nC.inconnue();
257
		}
258
		return dateNaiss;
181 gduche 259
	}
1284 gduche 260
 
1329 cyprien 261
	public String getDateSouple(String date) {
262
		String valeurDate = date;
263
 
264
		String jour = "";
265
		String mois = "";
266
		String annee = "";
267
 
268
		// pas de date dans la BD
269
		if (UtilString.isEmpty(valeurDate) || valeurDate.equals("0000-00-00")) {
270
			valeurDate  = "";
271
 
272
		// YYYY
273
		} else if (valeurDate.endsWith("00-00")) {
274
			valeurDate = valeurDate.substring(0, 4);
275
			if (valeurDate.matches("\\d{4}")) {
276
				jour = "";
277
				mois = "";
278
				annee = valeurDate.substring(0,4);
279
				valeurDate = annee;
280
			}
281
 
282
		// YYYY-MM
283
		} else if (valeurDate.endsWith("-00")) {
284
			valeurDate = valeurDate.substring(0, 7);
285
			if (valeurDate.matches("\\d{4}-\\d{2}")) {
286
				jour = "";
287
				mois = valeurDate.substring(5,7);
288
				annee = valeurDate.substring(0,4);
289
				valeurDate = mois+"/"+annee;
290
			}
291
		}
292
 
293
		// YYYY-MM-DD
294
		else if (valeurDate.matches("\\d{4}-\\d{2}-\\d{2}")) {
295
			Date objetDate = DateTimeFormat.getFormat("yyyy-MM-dd").parse(valeurDate);
296
			DateTimeFormat fmt = DateTimeFormat.getFormat("dd/MM/yyyy");
297
			valeurDate = fmt.format(objetDate);
298
		}
299
 
300
		 return valeurDate;
301
	}
302
 
1284 gduche 303
	public String getAnneeOuDateNaiss()	{
1329 cyprien 304
		String valeurDateNaissance = get("naissance_date");
305
		return getDateSouple(valeurDateNaissance);
1284 gduche 306
	}
307
 
455 gduche 308
	public void setNaissanceDate(Date naissanceDate) {
309
		if (naissanceDate != null) {
1591 delphine 310
			this.set("naissance_date", naissanceDate);
1189 gduche 311
		} else {
312
			this.set("naissance_date", null);
455 gduche 313
		}
314
	}
315
 
875 jpm 316
	// NAISSANCE LIEU
317
	public String getNaissanceLieu() {
318
		return renvoyerValeurCorrecte("naissance_lieu");
827 gduche 319
	}
875 jpm 320
	public void setNaissanceLieu(String naissanceLieu) {
321
		this.set("naissance_lieu", naissanceLieu);
827 gduche 322
	}
323
 
875 jpm 324
	// DÉCÉS
827 gduche 325
	public boolean estDecedee()	{
875 jpm 326
		String ceDeces = getDeces();
327
		if (ceDeces.isEmpty() || ceDeces.equals(ETRE_DECEDE))	{
1189 gduche 328
			return true;
329
		} else {
827 gduche 330
			return false;
331
		}
332
	}
1284 gduche 333
 
875 jpm 334
	public String getDeces()	{
335
		return renvoyerValeurCorrecte("ce_deces");
455 gduche 336
	}
1284 gduche 337
 
338
	public String getAnneeOuDateDeces()	{
1329 cyprien 339
		String valeurDateDeces = get("deces_date");
340
		return getDateSouple(valeurDateDeces);
1284 gduche 341
	}
342
 
875 jpm 343
	public void setDeces(String deces)	{
344
		set("ce_deces", deces);
345
	}
1284 gduche 346
 
875 jpm 347
	public void setDeces(Date decesDate, String lieuDeces)	{
348
		set("ce_deces", ETRE_DECEDE);
349
		setDecesDate(decesDate);
350
		setDecesLieu(lieuDeces);
351
	}
352
	public void setNonDecedee()	{
353
		set("ce_deces", ETRE_VIVANT);
354
		setDecesDate(null);
355
		setDecesLieu("");
356
	}
455 gduche 357
 
875 jpm 358
	// DÉCÉS DATE
827 gduche 359
	public String getDecesDate()	{
875 jpm 360
		String dateDeces = renvoyerValeurCorrecte("deces_date");
361
		if (UtilString.isEmpty(dateDeces) || dateDeces.equals("0000-00-00"))	{
827 gduche 362
			dateDeces = Mediateur.i18nC.inconnue();
363
		}
364
		return dateDeces;
365
	}
1284 gduche 366
 
875 jpm 367
	public void setDecesDate(Date decesDate) {
368
		if (decesDate != null)	{
369
			this.set("deces_date", DateTimeFormat.getFormat("yyyy-MM-dd").format(decesDate));
370
		}	else	{
371
			this.set("deces_date", "");
827 gduche 372
		}
373
	}
374
 
875 jpm 375
	// DÉCÉS LIEU
376
	public String getDecesLieu() {
377
		return renvoyerValeurCorrecte("deces_lieu");
455 gduche 378
	}
875 jpm 379
	public void setDecesLieu(String decesLieu) {
380
		this.set("deces_lieu", decesLieu);
818 gduche 381
	}
912 jpm 382
 
383
	// PARAMÊTRE
384
	public String getParametre() {
385
		return renvoyerValeurCorrecte("parametre");
386
	}
387
	public void setParametre(String parametre) {
388
		this.set("parametre", parametre);
389
	}
947 gduche 390
 
391
	public void setCourrielPrinc(String courriel)	{
392
		this.set("_courriel_princ_", courriel);
393
	}
394
 
395
	public String getCourrielPrinc()	{
396
		return (String) this.get("_courriel_princ_");
397
	}
993 gduche 398
 
399
	// PUBLICATIONS LIÉES
400
	public PublicationAPersonneListe getPublicationsLiees() {
401
		return publicationsLiees;
402
	}
403
 
404
	public void setPublicationsLiees(PublicationAPersonneListe relationsCollectionAPublication) {
405
		publicationsLiees = relationsCollectionAPublication;
406
	}
947 gduche 407
}
408