Subversion Repositories eFlore/Applications.coel

Rev

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