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