Subversion Repositories eFlore/Applications.coel

Rev

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