Subversion Repositories eFlore/Applications.coel

Rev

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