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