Subversion Repositories eFlore/Applications.coel

Rev

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