Subversion Repositories eFlore/Applications.coel

Rev

Rev 818 | Rev 875 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
102 jpm 1
package org.tela_botanica.client.modeles;
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;
620 gduche 8
import org.tela_botanica.client.util.UtilString;
9
 
350 gduche 10
import com.google.gwt.core.client.GWT;
11
import com.google.gwt.i18n.client.DateTimeFormat;
102 jpm 12
import com.google.gwt.json.client.JSONObject;
13
 
14
public class Personne extends aDonnee {
208 jp_milcent 15
 
748 jpm 16
	private static final long serialVersionUID = -6974716696155349332L;
17
 
208 jp_milcent 18
	public static final String PREFIXE = "cp";
245 jp_milcent 19
	public static final String TELEPHONE_FIXE = "FIX";
20
	public static final String TELEPHONE_GSM = "GSM";
602 jp_milcent 21
	public static final String TELEPHONE_FAX = "FAX";
208 jp_milcent 22
 
103 jpm 23
	public Personne() {
24
	}
25
 
775 jpm 26
	public Personne(JSONObject personne) {
27
		initialiserModele(personne);
261 gduche 28
		//Ajout du champ courriel principal
29
		this.set("courriel_princ", this.getInfoDenormaliseParPosition(this.renvoyerValeurCorrecte("truk_courriel"), 1));
102 jpm 30
	}
31
 
748 jpm 32
	@Override
33
	protected String getPrefixe() {
34
		return PREFIXE;
35
	}
36
 
240 jp_milcent 37
	// ID PERSONNE
102 jpm 38
	public String getId() {
240 jp_milcent 39
		return renvoyerValeurCorrecte("id_personne");
102 jpm 40
	}
41
 
609 jp_milcent 42
	// ID PROJET
43
	public String getIdProjet() {
44
		return renvoyerValeurCorrecte("ce_projet");
45
	}
46
 
240 jp_milcent 47
	// NOM COMPLET
48
	public String getNomComplet() {
49
		return renvoyerValeurCorrecte("fmt_nom_complet");
181 gduche 50
	}
51
 
240 jp_milcent 52
	// NOM
53
	public String getNom() {
54
		return renvoyerValeurCorrecte("nom");
181 gduche 55
	}
56
 
240 jp_milcent 57
	// PRÉNOM
58
	public String getPrenom() {
59
		return renvoyerValeurCorrecte("prenom");
238 aurelien 60
	}
61
 
350 gduche 62
	public Date getDate(String nomChamp)	{
63
 
64
		String strDate = renvoyerValeurCorrecte(nomChamp);
65
 
66
		Date dateRetour = null;
67
		try
68
		{
69
			if ((strDate != null) && (!strDate.equals("0000-00-00"))) {
70
				dateRetour = DateTimeFormat.getFormat("yyyy-MM-dd").parseStrict(strDate);
71
			}
72
		} catch (StringIndexOutOfBoundsException e)	{
73
			GWT.log("Impossible de parser la date " + strDate, e);
74
		}
75
		return dateRetour;
76
	}
77
 
240 jp_milcent 78
	// TÉLÉPHONE
79
	public String getTelephone() {
80
		return renvoyerValeurCorrecte("truk_telephone");
81
	}
82
	public void setTelephone(String t) {
83
		this.set("truk_telephone", t);
84
	}
245 jp_milcent 85
	public void ajouterTelephone(String type, Object valeur) {
240 jp_milcent 86
		ajouterChaineDenormaliseAvecType("truk_telephone", type, valeur);
87
	}
245 jp_milcent 88
	public String selectionnerTelephone(String type) {
89
		return getInfoDenormaliseParType(renvoyerValeurCorrecte("truk_telephone"), type);
90
	}
240 jp_milcent 91
 
92
	// FAX
93
	public String getFax() {
94
		return renvoyerValeurCorrecte("truk_fax");
95
	}
96
	public void setFax(String f) {
97
		this.set("truk_fax", f);
98
	}
245 jp_milcent 99
	public void ajouterFax(Object valeur) {
240 jp_milcent 100
		ajouterChaineDenormalise("truk_fax", valeur);
101
	}
245 jp_milcent 102
	public String selectionnerFax(int position) {
103
		return getInfoDenormaliseParPosition(renvoyerValeurCorrecte("truk_fax"), position);
104
	}
240 jp_milcent 105
 
106
	// COURRIEL
107
	public String getCourriel() {
108
		return renvoyerValeurCorrecte("truk_courriel");
109
	}
110
	public void setCourriel(String c) {
111
		this.set("truk_courriel", c);
112
	}
245 jp_milcent 113
	public void ajouterCourriel(String c) {
240 jp_milcent 114
		ajouterChaineDenormalise("truk_courriel", c);
115
	}
245 jp_milcent 116
	public String selectionnerCourriel(int position) {
117
		return getInfoDenormaliseParPosition(renvoyerValeurCorrecte("truk_courriel"), position);
118
	}
240 jp_milcent 119
 
120
	// SPÉCIALITÉ
121
	public String getSpecialite() {
122
		return renvoyerValeurCorrecte("ce_truk_specialite");
123
	}
124
	public void setSpecialite(String s) {
125
		// Pas de liste pour l'instant, donc tout passe dans "Autre".
126
		setChaineDenormaliseUnique("ce_truk_specialite", "AUTRE", s);
127
	}
245 jp_milcent 128
	public String afficherSpecialite() {
129
		return getChaineDenormaliseUnique("ce_truk_specialite");
130
	}
240 jp_milcent 131
 
181 gduche 132
	public Object obtenirValeurChamp(String nomChamp)	{
133
		return renvoyerValeurCorrecte(nomChamp);
134
	}
431 gduche 135
 
136
 
137
	public String getString(String champ)	{
138
		return String.valueOf(renvoyerValeurCorrecte(champ));
139
	}
455 gduche 140
 
141
	public void setNaissanceDate(Date naissanceDate) {
142
		if (naissanceDate != null) {
143
			this.set("naissance_date", DateTimeFormat.getFormat("yyyy-MM-dd").format(naissanceDate));
144
		}
145
	}
146
 
827 gduche 147
	public void setDeces(Date decesDate, String lieuDeces)	{
148
		set("ce_deces", "1");
149
		setDecesDate(decesDate);
150
		set("deces_lieu", lieuDeces);
151
	}
152
 
153
	public void setNonDecedee()	{
154
		set("ce_deces", "0");
155
		setDecesDate(null);
156
		set("deces_lieu", "");
157
	}
158
 
159
	public boolean estDecedee()	{
160
		String ceDeces = get("ce_deces");
161
		if ((ceDeces == null)||(ceDeces.equals("0")))	{
162
			return false;
163
		}	else	{
164
			return true;
165
		}
166
	}
167
 
455 gduche 168
	public void setDecesDate(Date decesDate) {
827 gduche 169
		if (decesDate != null)	{
455 gduche 170
			this.set("deces_date", DateTimeFormat.getFormat("yyyy-MM-dd").format(decesDate));
827 gduche 171
		}	else	{
172
			this.set("deces_date", "");
455 gduche 173
		}
174
	}
175
 
827 gduche 176
	public String getDecesDate()	{
177
		String dateDeces = "";
178
		dateDeces = get("deces_date");
179
		if (UtilString.isEmpty(dateDeces)||dateDeces.equals("0000-00-00"))	{
180
			dateDeces = Mediateur.i18nC.inconnue();
181
		}
182
		return dateDeces;
183
	}
184
 
185
	public String getNaissanceDate()	{
186
		String dateNaiss = "";
187
		dateNaiss = get("naissance_date");
188
		if (UtilString.isEmpty(dateNaiss)||dateNaiss.equals("0000-00-00"))	{
189
			dateNaiss = Mediateur.i18nC.inconnue();
190
		}
191
		return dateNaiss;
192
	}
193
 
455 gduche 194
	public void setFmtNomComplet(String prefixe, String suffixe)	{
195
		String fmtNomComplet = "";
196
		if ((prefixe != null)&&(!prefixe.trim().equals("")))	{
197
			fmtNomComplet += prefixe + " ";
198
		}
199
 
200
		if ((this.getPrenom()!=null)&&(!this.getPrenom().trim().equals("")))	{
201
			fmtNomComplet += this.getPrenom() + " ";
202
		}
203
 
204
		if ((this.getNom()!=null)&&(!this.getNom().trim().equals("")))	{
205
			fmtNomComplet += this.getNom() + " ";
206
		}
207
 
208
		if ((suffixe!=null)&&(!suffixe.trim().equals("")))	{
209
			fmtNomComplet += suffixe;
210
		}
211
 
620 gduche 212
		this.set("fmt_nom_complet", UtilString.ucFirst(fmtNomComplet));
455 gduche 213
	}
818 gduche 214
 
215
 
216
	//Traitement des truks
217
	protected void remplacerTypeDansChaineDenormalise(String champ, String type, Object valeur) {
218
		if (valeur != null && !valeur.equals("")) {
219
			ajouterChaineDenormaliseAvecType(champ, type, valeur);
220
		} else {
221
			supprimerTypeDansChaineDenormalise(champ, type);
222
		}
223
	}
224
	/**
225
	 * Ajoute un nouvel élément sans type à une chaine dénormalisée.
226
	 * Champ de type "truk" contenant seulement des valeurs séparées par ";;".
227
	 * Si l'élément existe déjà, il ne sera pas ajouté.
228
	 *
229
	 * @param champ le nom du champ dénormalisé
230
	 * @param valeur la valeur à ajouter
231
	 */
232
	protected void ajouterChaineDenormalise(String champ, Object valeur) {
233
		if (valeur instanceof String) {
234
			String chaineExistante = renvoyerValeurCorrecte(champ);
235
			if (chaineExistante.equals("")) {
236
				this.set(champ, valeur);
237
			} else {
238
				// Si la valeur à ajouter n'est pas déjà présente, nous l'ajoutons
239
				if (!chaineExistante.matches("(^|"+SEPARATEUR_VALEURS+")"+valeur+"("+SEPARATEUR_VALEURS+"|$)")) {
240
					this.set(champ, chaineExistante+SEPARATEUR_VALEURS+valeur);
241
				}
242
			}
243
		}
244
	}
181 gduche 245
 
102 jpm 246
}