Subversion Repositories eFlore/Applications.coel

Rev

Rev 1474 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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