Subversion Repositories eFlore/Applications.coel

Rev

Rev 818 | Rev 875 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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