Subversion Repositories eFlore/Applications.coel

Rev

Rev 1417 | Rev 1516 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1417 Rev 1513
1
package org.tela_botanica.client.modeles.publication;
1
package org.tela_botanica.client.modeles.publication;
-
 
2
 
-
 
3
import java.util.ArrayList;
-
 
4
import java.util.Iterator;
-
 
5
import java.util.Map;
-
 
6
import java.util.Set;
2
 
7
 
-
 
8
import org.tela_botanica.client.modeles.aDonnee;
3
import org.tela_botanica.client.modeles.aDonnee;
9
import org.tela_botanica.client.modeles.collection.CollectionAPublication;
-
 
10
import org.tela_botanica.client.modeles.structure.Structure;
4
import org.tela_botanica.client.modeles.structure.Structure;
11
import org.tela_botanica.client.util.Debug;
-
 
12
import org.tela_botanica.client.util.UtilString;
5
import org.tela_botanica.client.util.UtilString;
13
 
6
 
14
import com.extjs.gxt.ui.client.data.ModelData;
7
import com.google.gwt.json.client.JSONObject;
15
import com.google.gwt.json.client.JSONObject;
8
 
16
 
9
public class Publication extends aDonnee {
17
public class Publication extends aDonnee {
10
 
18
 
11
	private static final long serialVersionUID = 4142843068041690126L;
19
	private static final long serialVersionUID = 4142843068041690126L;
12
 
20
 
-
 
21
	public static final String PREFIXE = "cpu";
13
	private static final String PREFIXE = "cpu";
22
	private boolean removePrefix = true;
14
	private Structure editeur = null;
23
	private Structure editeur = null;
-
 
24
	public static String[] champsObligatoires = {"cpu_id_publication"};
-
 
25
	public ArrayList<String> cles = null;
-
 
26
	
-
 
27
	public Publication() {
15
	public static String[] champsObligatoires = {"cpu_id_publication"};
28
	}
-
 
29
	
-
 
30
	public Publication(boolean removePrefix) {
-
 
31
		this.removePrefix = removePrefix;
16
	
32
		cles = new ArrayList<String>();
17
	public Publication() {	
33
		cles.add("id_publication");
18
	}
34
	}
19
	
35
	
20
	public Publication(JSONObject publication) {
36
	public Publication(JSONObject publication) {
21
		initialiserModele(publication);
37
		initialiserModele(publication);
22
		editeur = new Structure(publication);
38
		editeur = new Structure(publication);
-
 
39
		cles = new ArrayList<String>();
-
 
40
		cles.add("id_publication");
-
 
41
	}
-
 
42
	
-
 
43
	public Publication(ModelData model, boolean removePrefix)
-
 
44
	{
-
 
45
		this.removePrefix = removePrefix;
-
 
46
		cles = new ArrayList<String>();
-
 
47
		cles.add("id_publication");
-
 
48
		
-
 
49
		Map<String, Object> a = model.getProperties();
-
 
50
 
-
 
51
		Set<String> cles = a.keySet();
-
 
52
		Iterator<String> it = cles.iterator();
-
 
53
		while (it.hasNext()) {
-
 
54
			String cle = it.next();			
-
 
55
			if (a.get(cle) != null) {
-
 
56
				String cleObjet = "";
-
 
57
				if (removePrefix) {
-
 
58
					cleObjet = cle.replaceFirst("^"+getPrefixe()+"_", "");
-
 
59
				}
-
 
60
				else {
-
 
61
					cleObjet=cle;
-
 
62
					String valeur = "";
-
 
63
					if (a.get(cle) instanceof Integer) valeur = String.valueOf(a.get(cle));
-
 
64
					else if (a.get(cle) instanceof String) valeur = (String)a.get(cle);
-
 
65
					traiterClesEtrangeres(cle, valeur);
-
 
66
				}
-
 
67
				this.set(cleObjet, a.get(cle));
-
 
68
			}
-
 
69
		}
-
 
70
	}
-
 
71
	
-
 
72
	// Action
-
 
73
	//--------
-
 
74
	// cette méthode sert dans le cas suivant : le contructeur reçoit un object ModelData
-
 
75
	// qui contient cpuap_id_publication mais pas cpu_id_publication ou id_publication. Sans
-
 
76
	// la méthode ci-dessous, on aurait des problèmes. Celle-ci affecte à id_publication la
-
 
77
	// valeur des clés étrangères rencontrées (cpuap_id_publication, cpuac_id_publication, etc.)
-
 
78
	private void traiterClesEtrangeres(String cle, String valeur) {
-
 
79
		// on recupere le nom de la clé de la propriété (sans son prefixe)
-
 
80
		String nomSansPrefixe = cle.replaceFirst("^[a-zA-Z]+_", "");
-
 
81
		// on regarde si cette clé est une clé primaire de la table Publication
-
 
82
		if (cles.contains(nomSansPrefixe)) {
-
 
83
			// si c'est le cas et que la valeur est non nulle
-
 
84
			if (valeur != null && !UtilString.isEmpty(valeur)) {
-
 
85
				// on affecte la valeur de la clés étrangère à la clé primaire
-
 
86
				if (removePrefix) this.set(nomSansPrefixe, valeur);
-
 
87
				else this.set(PREFIXE+"_"+nomSansPrefixe, valeur);
-
 
88
			}
-
 
89
		}
23
	}
90
	}
24
	
-
 
25
	@Override
91
	
26
	protected String getPrefixe() {
92
	protected String getPrefixe() {
27
		return PREFIXE;
93
		return PREFIXE;
28
	}
94
	}
29
		
95
		
30
	protected String[] getChampsObligatoires()	{
96
	protected String[] getChampsObligatoires()	{
31
		return champsObligatoires;
97
		return champsObligatoires;
32
	}
98
	}
33
	
99
	
34
	public void setStructureEditeur(Structure structure) {
100
	public void setStructureEditeur(Structure structure) {
35
		editeur = structure;
101
		editeur = structure;
36
	}
102
	}
37
	
103
	
38
	public String getId() {
104
	public String getId() {
-
 
105
		if (removePrefix) return renvoyerValeurCorrecte("id_publication");
39
		return renvoyerValeurCorrecte("id_publication");
106
		else return renvoyerValeurCorrecte(PREFIXE+"_id_publication");
40
	}
107
	}
41
	public void setId(String idPublication) {
108
	public void setId(String idPublication) {
-
 
109
		if (removePrefix) this.set("id_publication", idPublication);
42
		this.set("id_publication", idPublication);
110
		else this.set(PREFIXE+"_id_publication", idPublication);
43
	}
111
	}
44
	
112
	
45
	public String getIdProjet() {
113
	public String getIdProjet() {
-
 
114
		if (removePrefix) return renvoyerValeurCorrecte("ce_projet");
46
		return renvoyerValeurCorrecte("ce_projet");
115
		else return renvoyerValeurCorrecte(PREFIXE+"_ce_projet");
47
	}
116
	}
48
	public void setIdProjet(String idProjet) {
117
	public void setIdProjet(String idProjet) {
-
 
118
		if (removePrefix) this.set("ce_projet", idProjet);
49
		this.set("ce_projet", idProjet);
119
		else this.set(PREFIXE+"_ce_projet", idProjet);
50
	}
120
	}
51
	
121
	
52
	public String getNomComplet() {
122
	public String getNomComplet() {
-
 
123
		if (removePrefix) return renvoyerValeurCorrecte("fmt_nom_complet");
53
		return renvoyerValeurCorrecte("fmt_nom_complet");
124
		else return renvoyerValeurCorrecte(PREFIXE+"_fmt_nom_complet");
54
	}
125
	}
55
	public void setNomComplet(String nomComplet) {
126
	public void setNomComplet(String nomComplet) {
-
 
127
		if (removePrefix) this.set("fmt_nom_complet", nomComplet);
56
		this.set("fmt_nom_complet", nomComplet);
128
		else this.set(PREFIXE+"_fmt_nom_complet", nomComplet);
57
	}
129
	}
58
	
130
	
59
	public String getURI() {
131
	public String getURI() {
-
 
132
		if (removePrefix) return renvoyerValeurCorrecte("uri");
60
		return renvoyerValeurCorrecte("uri");
133
		else return renvoyerValeurCorrecte(PREFIXE+"_uri");
61
	}
134
	}
62
	public void setUri(String uri) {
135
	public void setUri(String uri) {
-
 
136
		if (removePrefix) this.set("uri", uri);
63
		this.set("uri", uri);
137
		else this.set(PREFIXE+"_uri", uri);
64
	}
138
	}
65
 
139
 
66
	public String getAuteur() {
140
	public String getAuteur() {
-
 
141
		if (removePrefix) return renvoyerValeurCorrecte("fmt_auteur");
67
		return renvoyerValeurCorrecte("fmt_auteur");
142
		else return renvoyerValeurCorrecte(PREFIXE+"_fmt_auteur");
68
	}
143
	}
69
	public void setAuteur(String auteurFormate) {
144
	public void setAuteur(String auteurFormate) {
-
 
145
		if (removePrefix) this.set("fmt_auteur", auteurFormate);
70
		this.set("fmt_auteur", auteurFormate);
146
		else this.set(PREFIXE+"_fmt_auteur", auteurFormate);
71
	}
147
	}
72
 
148
 
73
	public String getCollection() {
149
	public String getCollection() {
-
 
150
		if (removePrefix) return renvoyerValeurCorrecte("collection");
74
		return renvoyerValeurCorrecte("collection");
151
		else return renvoyerValeurCorrecte(PREFIXE+"_collection");
75
	}
152
	}
76
	public void setCollection(String collection) {
153
	public void setCollection(String collection) {
-
 
154
		if (removePrefix) this.set("collection", collection);
77
		this.set("collection", collection);
155
		else this.set(PREFIXE+"_collection", collection);
78
	}
156
	}
79
	
157
	
80
	public String getTitre() {
158
	public String getTitre() {
-
 
159
		if (removePrefix) return renvoyerValeurCorrecte("titre");
81
		return renvoyerValeurCorrecte("titre");
160
		else return renvoyerValeurCorrecte(PREFIXE+"_titre");
82
	}
161
	}
83
	public void setTitre(String titre) {
162
	public void setTitre(String titre) {
-
 
163
		if (removePrefix) this.set("titre", UtilString.ucFirst(titre));
84
		this.set("titre", UtilString.ucFirst(titre));
164
		else this.set(PREFIXE+"_titre", UtilString.ucFirst(titre));
85
	}
165
	}
86
 
166
 
87
	public String getNomEditeur() {
167
	public String getNomEditeur() {
88
		String editeurNom = getEditeur();
168
		String editeurNom = getEditeur();
89
		if (editeurNom.matches("[0-9]+")) {
169
		if (editeurNom.matches("[0-9]+")) {
90
			editeurNom = editeur.getNom();
170
			editeurNom = editeur.getNom();
91
		}
171
		}
92
		return editeurNom;
172
		return editeurNom;
93
	}
173
	}
94
	public String getEditeur() {
174
	public String getEditeur() {
-
 
175
		if (removePrefix) return getChaineDenormaliseUnique("ce_truk_editeur");
95
		return getChaineDenormaliseUnique("ce_truk_editeur");
176
		else return getChaineDenormaliseUnique(PREFIXE+"_ce_truk_editeur");
96
	}
177
	}
97
	public void setEditeur(String editeur) {
178
	public void setEditeur(String editeur) {
-
 
179
		if (removePrefix) setChaineDenormaliseUnique("ce_truk_editeur", "AUTRE", editeur);
98
		setChaineDenormaliseUnique("ce_truk_editeur", "AUTRE", editeur);
180
		else setChaineDenormaliseUnique(PREFIXE+"_ce_truk_editeur", "AUTRE", editeur);
99
	}
181
	}
100
 
182
 
101
	public String getAnneeParution() {
183
	public String getAnneeParution() {
-
 
184
		String date;
-
 
185
		if (removePrefix) date = renvoyerValeurCorrecte("date_parution");
102
		return renvoyerValeurCorrecte("date_parution").substring(0, 4);
186
		else date = renvoyerValeurCorrecte(PREFIXE+"_date_parution");
-
 
187
		if (date != null && !UtilString.isEmpty(date))
-
 
188
			return date.substring(0, 4);
-
 
189
		else
-
 
190
			return null;	
103
	}
191
	}
104
	public String getDateParution() {
192
	public String getDateParution() {
-
 
193
		if (removePrefix) return renvoyerValeurCorrecte("date_parution");
105
		return renvoyerValeurCorrecte("date_parution");
194
		else return renvoyerValeurCorrecte(PREFIXE+"_date_parution");
106
	}
195
	}
107
	public void setDateParution(String date) {
196
	public void setDateParution(String date) {
-
 
197
		if (removePrefix) this.set("date_parution", date);
108
		this.set("date_parution", date);
198
		else this.set(PREFIXE+"_date_parution", date);
109
	}
199
	}
110
 
200
 
111
	public String getIndicationNvt() {
201
	public String getIndicationNvt() {
-
 
202
		if (removePrefix) return renvoyerValeurCorrecte("indication_nvt");
112
		return renvoyerValeurCorrecte("indication_nvt");
203
		else return renvoyerValeurCorrecte(PREFIXE+"_indication_nvt");
113
	}
204
	}
114
	public void setIndicationNvt(String nvt) {
205
	public void setIndicationNvt(String nvt) {
-
 
206
		if (removePrefix) this.set("indication_nvt", nvt);
115
		this.set("indication_nvt", nvt);
207
		else this.set(PREFIXE+"_indication_nvt", nvt);
116
	}
208
	}
117
	
209
	
118
	public String getFascicule() {
210
	public String getFascicule() {
-
 
211
		if (removePrefix) return renvoyerValeurCorrecte("fascicule");
119
		return renvoyerValeurCorrecte("fascicule");
212
		else return renvoyerValeurCorrecte(PREFIXE+"_fascicule");
120
	}
213
	}
121
	public void setFascicule(String fascicule) {
214
	public void setFascicule(String fascicule) {
-
 
215
		if (removePrefix) this.set("fascicule", fascicule);
122
		this.set("fascicule", fascicule);
216
		else this.set(PREFIXE+"_fascicule", fascicule);
123
	}
217
	}
124
	
218
	
125
	public String getPages() {
219
	public String getPages() {
-
 
220
		if (removePrefix) return renvoyerValeurCorrecte("truk_pages");
126
		return renvoyerValeurCorrecte("truk_pages");
221
		else return renvoyerValeurCorrecte(PREFIXE+"_truk_pages");
127
	}
222
	}
128
	public void setPages(String pages) {
223
	public void setPages(String pages) {
-
 
224
		if (removePrefix) this.set("truk_pages", pages);
129
		this.set("truk_pages", pages);
225
		else this.set(PREFIXE+"_truk_pages", pages);
130
	}
226
	}
131
	
227
	
132
}
228
}