Subversion Repositories eFlore/Applications.coel

Rev

Rev 602 | Rev 620 | 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
 
431 gduche 3
import java.util.Collection;
350 gduche 4
import java.util.Date;
431 gduche 5
import java.util.HashMap;
102 jpm 6
import java.util.Iterator;
7
import java.util.Set;
8
 
350 gduche 9
import com.google.gwt.core.client.GWT;
431 gduche 10
import com.google.gwt.http.client.URL;
350 gduche 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
 
16
	public static final String PREFIXE = "cp";
245 jp_milcent 17
	public static final String TELEPHONE_FIXE = "FIX";
18
	public static final String TELEPHONE_GSM = "GSM";
602 jp_milcent 19
	public static final String TELEPHONE_FAX = "FAX";
208 jp_milcent 20
 
102 jpm 21
	/**
103 jpm 22
	 * Constructeur vide
23
	 */
24
	public Personne() {
208 jp_milcent 25
 
103 jpm 26
	}
27
 
28
	/**
102 jpm 29
	 * Constructeur avec un objet JSON
30
	 *
31
	 * @param image
32
	 */
33
	public Personne(JSONObject liste) {
34
		// l'objet JSON est une table de hachage
35
		Set<String> im = liste.keySet();
36
 
37
		// Parcourt pour chaque clé
38
		for (Iterator<String> it = im.iterator(); it.hasNext();) {
431 gduche 39
 
102 jpm 40
			// Si elle est associée à une valeur, nous l'ajoutons
41
			String cle = it.next();
431 gduche 42
			if (cle.startsWith(PREFIXE+"_")) {
43
 
44
				// Suppression de l'abréviation du champ. Inutile dans le contexte d'un objet
45
				String cleObjet = cle.replaceFirst("^" + PREFIXE + "_", "");
46
				if (liste.get(cle).isString() != null) {
47
					String valeur = liste.get(cle).isString().stringValue();
48
					this.set(cleObjet, valeur);
49
				} else {
50
					// Sinon, nous ajoutons la clé avec une valeur vide
51
					String valeur = " ";
52
					this.set(cleObjet, valeur);
53
				}
102 jpm 54
			}
55
		}
261 gduche 56
 
57
		//Ajout du champ courriel principal
58
		this.set("courriel_princ", this.getInfoDenormaliseParPosition(this.renvoyerValeurCorrecte("truk_courriel"), 1));
102 jpm 59
	}
60
 
240 jp_milcent 61
	// ID PERSONNE
102 jpm 62
	public String getId() {
240 jp_milcent 63
		return renvoyerValeurCorrecte("id_personne");
102 jpm 64
	}
65
 
609 jp_milcent 66
	// ID PROJET
67
	public String getIdProjet() {
68
		return renvoyerValeurCorrecte("ce_projet");
69
	}
70
 
240 jp_milcent 71
	// NOM COMPLET
72
	public String getNomComplet() {
73
		return renvoyerValeurCorrecte("fmt_nom_complet");
181 gduche 74
	}
75
 
240 jp_milcent 76
	// NOM
77
	public String getNom() {
78
		return renvoyerValeurCorrecte("nom");
181 gduche 79
	}
80
 
240 jp_milcent 81
	// PRÉNOM
82
	public String getPrenom() {
83
		return renvoyerValeurCorrecte("prenom");
238 aurelien 84
	}
85
 
350 gduche 86
	public Date getDate(String nomChamp)	{
87
 
88
		String strDate = renvoyerValeurCorrecte(nomChamp);
89
 
90
		Date dateRetour = null;
91
		try
92
		{
93
			if ((strDate != null) && (!strDate.equals("0000-00-00"))) {
94
				dateRetour = DateTimeFormat.getFormat("yyyy-MM-dd").parseStrict(strDate);
95
			}
96
		} catch (StringIndexOutOfBoundsException e)	{
97
			GWT.log("Impossible de parser la date " + strDate, e);
98
		}
99
		return dateRetour;
100
	}
101
 
240 jp_milcent 102
	// TÉLÉPHONE
103
	public String getTelephone() {
104
		return renvoyerValeurCorrecte("truk_telephone");
105
	}
106
	public void setTelephone(String t) {
107
		this.set("truk_telephone", t);
108
	}
245 jp_milcent 109
	public void ajouterTelephone(String type, Object valeur) {
240 jp_milcent 110
		ajouterChaineDenormaliseAvecType("truk_telephone", type, valeur);
111
	}
245 jp_milcent 112
	public String selectionnerTelephone(String type) {
113
		return getInfoDenormaliseParType(renvoyerValeurCorrecte("truk_telephone"), type);
114
	}
240 jp_milcent 115
 
116
	// FAX
117
	public String getFax() {
118
		return renvoyerValeurCorrecte("truk_fax");
119
	}
120
	public void setFax(String f) {
121
		this.set("truk_fax", f);
122
	}
245 jp_milcent 123
	public void ajouterFax(Object valeur) {
240 jp_milcent 124
		ajouterChaineDenormalise("truk_fax", valeur);
125
	}
245 jp_milcent 126
	public String selectionnerFax(int position) {
127
		return getInfoDenormaliseParPosition(renvoyerValeurCorrecte("truk_fax"), position);
128
	}
240 jp_milcent 129
 
130
	// COURRIEL
131
	public String getCourriel() {
132
		return renvoyerValeurCorrecte("truk_courriel");
133
	}
134
	public void setCourriel(String c) {
135
		this.set("truk_courriel", c);
136
	}
245 jp_milcent 137
	public void ajouterCourriel(String c) {
240 jp_milcent 138
		ajouterChaineDenormalise("truk_courriel", c);
139
	}
245 jp_milcent 140
	public String selectionnerCourriel(int position) {
141
		return getInfoDenormaliseParPosition(renvoyerValeurCorrecte("truk_courriel"), position);
142
	}
240 jp_milcent 143
 
144
	// SPÉCIALITÉ
145
	public String getSpecialite() {
146
		return renvoyerValeurCorrecte("ce_truk_specialite");
147
	}
148
	public void setSpecialite(String s) {
149
		// Pas de liste pour l'instant, donc tout passe dans "Autre".
150
		setChaineDenormaliseUnique("ce_truk_specialite", "AUTRE", s);
151
	}
245 jp_milcent 152
	public String afficherSpecialite() {
153
		return getChaineDenormaliseUnique("ce_truk_specialite");
154
	}
240 jp_milcent 155
 
181 gduche 156
	public Object obtenirValeurChamp(String nomChamp)	{
157
		return renvoyerValeurCorrecte(nomChamp);
158
	}
431 gduche 159
 
160
 
161
	public String getString(String champ)	{
162
 
163
		return String.valueOf(renvoyerValeurCorrecte(champ));
164
 
165
	}
455 gduche 166
 
167
	public void setNaissanceDate(Date naissanceDate) {
168
		if (naissanceDate != null) {
169
			this.set("naissance_date", DateTimeFormat.getFormat("yyyy-MM-dd").format(naissanceDate));
170
		}
171
	}
172
 
173
	public void setDecesDate(Date decesDate) {
174
		if (decesDate != null) {
175
			this.set("deces_date", DateTimeFormat.getFormat("yyyy-MM-dd").format(decesDate));
176
		}
177
	}
178
 
179
	public void setFmtNomComplet(String prefixe, String suffixe)	{
180
		String fmtNomComplet = "";
181
		if ((prefixe != null)&&(!prefixe.trim().equals("")))	{
182
			fmtNomComplet += prefixe + " ";
183
		}
184
 
185
		if ((this.getPrenom()!=null)&&(!this.getPrenom().trim().equals("")))	{
186
			fmtNomComplet += this.getPrenom() + " ";
187
		}
188
 
189
		if ((this.getNom()!=null)&&(!this.getNom().trim().equals("")))	{
190
			fmtNomComplet += this.getNom() + " ";
191
		}
192
 
193
		if ((suffixe!=null)&&(!suffixe.trim().equals("")))	{
194
			fmtNomComplet += suffixe;
195
		}
196
 
197
		this.set("fmt_nom_complet", fmtNomComplet);
198
	}
199
 
200
 
181 gduche 201
 
102 jpm 202
}