Subversion Repositories eFlore/Applications.coel

Rev

Rev 1270 | Rev 1303 | 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
		}
1295 cyprien 219
		String s = DateTimeFormat.getFormat("dddd/MM/yyyy").format(new Date(dateNaiss));
875 jpm 220
		return dateNaiss;
181 gduche 221
	}
1270 jpm 222
 
223
	public String getAnneeOuDateNaiss()	{
224
		 String valeurDateNaissance = get("naissance_date");
1295 cyprien 225
 
1270 jpm 226
		 if (!UtilString.isEmpty(valeurDateNaissance) && valeurDateNaissance.endsWith("00-00")) {
227
				valeurDateNaissance = valeurDateNaissance.substring(0, 4);
228
		 } else if (UtilString.isEmpty(valeurDateNaissance) && valeurDateNaissance.equals("0000-00-00")) {
229
			 valeurDateNaissance  = "";
230
		 }
1295 cyprien 231
 
232
		 if (valeurDateNaissance != null && valeurDateNaissance != "") {
233
			if (valeurDateNaissance.matches("\\d{4}-\\d{2}-\\d{2}")) {
234
				Date naissanceDate = DateTimeFormat.getFormat("yyyy-MM-dd").parse(valeurDateNaissance);
235
				DateTimeFormat fmt = DateTimeFormat.getFormat("dd/MM/yyyy");
236
				valeurDateNaissance = fmt.format(naissanceDate);
237
			}
238
		 }
239
 
1270 jpm 240
		 return valeurDateNaissance;
241
	}
242
 
455 gduche 243
	public void setNaissanceDate(Date naissanceDate) {
244
		if (naissanceDate != null) {
245
			this.set("naissance_date", DateTimeFormat.getFormat("yyyy-MM-dd").format(naissanceDate));
1188 gduche 246
		} else {
247
			this.set("naissance_date", null);
455 gduche 248
		}
249
	}
250
 
875 jpm 251
	// NAISSANCE LIEU
252
	public String getNaissanceLieu() {
253
		return renvoyerValeurCorrecte("naissance_lieu");
827 gduche 254
	}
875 jpm 255
	public void setNaissanceLieu(String naissanceLieu) {
256
		this.set("naissance_lieu", naissanceLieu);
827 gduche 257
	}
258
 
875 jpm 259
	// DÉCÉS
827 gduche 260
	public boolean estDecedee()	{
875 jpm 261
		String ceDeces = getDeces();
262
		if (ceDeces.isEmpty() || ceDeces.equals(ETRE_DECEDE))	{
1185 gduche 263
			return true;
264
		} else {
827 gduche 265
			return false;
266
		}
267
	}
1270 jpm 268
 
875 jpm 269
	public String getDeces()	{
270
		return renvoyerValeurCorrecte("ce_deces");
455 gduche 271
	}
1270 jpm 272
 
273
	public String getAnneeOuDateDeces()	{
274
		 String valeurDateDeces = get("deces_date");
275
		 if (!UtilString.isEmpty(valeurDateDeces) && valeurDateDeces.endsWith("00-00")) {
276
			 valeurDateDeces = valeurDateDeces.substring(0, 4);
277
		 } else if (UtilString.isEmpty(valeurDateDeces) && valeurDateDeces.equals("0000-00-00")) {
278
			 valeurDateDeces  = "";
279
		 }
1295 cyprien 280
 
281
		 if (valeurDateDeces != null && valeurDateDeces != "") {
282
			if (valeurDateDeces.matches("\\d{4}-\\d{2}-\\d{2}")) {
283
				Date naissanceDate = DateTimeFormat.getFormat("yyyy-MM-dd").parse(valeurDateDeces);
284
				DateTimeFormat fmt = DateTimeFormat.getFormat("dd/MM/yyyy");
285
				valeurDateDeces = fmt.format(naissanceDate);
286
			}
287
		 }
288
 
1270 jpm 289
		 return valeurDateDeces;
290
	}
291
 
875 jpm 292
	public void setDeces(String deces)	{
293
		set("ce_deces", deces);
294
	}
1270 jpm 295
 
875 jpm 296
	public void setDeces(Date decesDate, String lieuDeces)	{
297
		set("ce_deces", ETRE_DECEDE);
298
		setDecesDate(decesDate);
299
		setDecesLieu(lieuDeces);
300
	}
301
	public void setNonDecedee()	{
302
		set("ce_deces", ETRE_VIVANT);
303
		setDecesDate(null);
304
		setDecesLieu("");
305
	}
455 gduche 306
 
875 jpm 307
	// DÉCÉS DATE
827 gduche 308
	public String getDecesDate()	{
875 jpm 309
		String dateDeces = renvoyerValeurCorrecte("deces_date");
310
		if (UtilString.isEmpty(dateDeces) || dateDeces.equals("0000-00-00"))	{
827 gduche 311
			dateDeces = Mediateur.i18nC.inconnue();
312
		}
313
		return dateDeces;
314
	}
1270 jpm 315
 
875 jpm 316
	public void setDecesDate(Date decesDate) {
317
		if (decesDate != null)	{
318
			this.set("deces_date", DateTimeFormat.getFormat("yyyy-MM-dd").format(decesDate));
319
		}	else	{
320
			this.set("deces_date", "");
827 gduche 321
		}
322
	}
323
 
875 jpm 324
	// DÉCÉS LIEU
325
	public String getDecesLieu() {
326
		return renvoyerValeurCorrecte("deces_lieu");
455 gduche 327
	}
875 jpm 328
	public void setDecesLieu(String decesLieu) {
329
		this.set("deces_lieu", decesLieu);
818 gduche 330
	}
912 jpm 331
 
332
	// PARAMÊTRE
333
	public String getParametre() {
334
		return renvoyerValeurCorrecte("parametre");
335
	}
336
	public void setParametre(String parametre) {
337
		this.set("parametre", parametre);
338
	}
947 gduche 339
 
340
	public void setCourrielPrinc(String courriel)	{
341
		this.set("_courriel_princ_", courriel);
342
	}
343
 
344
	public String getCourrielPrinc()	{
345
		return (String) this.get("_courriel_princ_");
346
	}
993 gduche 347
 
348
	// PUBLICATIONS LIÉES
349
	public PublicationAPersonneListe getPublicationsLiees() {
350
		return publicationsLiees;
351
	}
352
 
353
	public void setPublicationsLiees(PublicationAPersonneListe relationsCollectionAPublication) {
354
		publicationsLiees = relationsCollectionAPublication;
355
	}
947 gduche 356
}
357