Subversion Repositories eFlore/Applications.coel

Rev

Rev 1568 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1568 Rev 1573
1
package org.tela_botanica.client.modeles.publication;
1
package org.tela_botanica.client.modeles.publication;
2
 
2
 
3
import java.util.Iterator;
3
import java.util.Iterator;
4
import java.util.Map;
4
import java.util.Map;
5
import java.util.Set;
5
import java.util.Set;
6
 
6
 
7
import org.tela_botanica.client.modeles.aDonnee;
7
import org.tela_botanica.client.modeles.aDonnee;
8
import org.tela_botanica.client.modeles.personne.Personne;
8
import org.tela_botanica.client.modeles.personne.Personne;
9
import org.tela_botanica.client.util.Log;
9
import org.tela_botanica.client.util.Log;
-
 
10
import org.tela_botanica.client.util.UtilString;
10
 
11
 
11
import com.extjs.gxt.ui.client.data.ModelData;
12
import com.extjs.gxt.ui.client.data.ModelData;
12
import com.google.gwt.json.client.JSONObject;
13
import com.google.gwt.json.client.JSONObject;
13
 
14
 
14
public class PublicationAPersonne extends aDonnee {
15
public class PublicationAPersonne extends aDonnee {
15
 
16
 
16
	private static final long serialVersionUID = 7769105365939978129L;
17
	private static final long serialVersionUID = 7769105365939978129L;
17
	
18
	
18
	public static final String PREFIXE = "cpuap";
19
	public static final String PREFIXE = "cpuap";
19
	public static final String ROLE_AUTEUR = "2360";
20
	public static final String ROLE_AUTEUR = "2360";
20
	//FIXME: insérer en base de données une valeur cohérente pour l'identifiant ci-dessous
21
	//FIXME: insérer en base de données une valeur cohérente pour l'identifiant ci-dessous
21
	public static final String ROLE_SUJET = "30762";
22
	public static final String ROLE_SUJET = "30762";
22
	
23
	
23
	private Personne personneLiee = null;
24
	private Personne personneLiee = null;
24
	private Publication publicationLiee = null;
25
	private Publication publicationLiee = null;
25
	public static String[] champsObligatoires = {"cpuap_id_personne", "cpuap_id_publication", "cpuap_id_role"};
26
	public static String[] champsObligatoires = {"cpuap_id_personne", "cpuap_id_publication", "cpuap_id_role"};
26
	
27
	
27
	public PublicationAPersonne() {
28
	public PublicationAPersonne() {
28
		new PublicationAPersonne(new JSONObject());
29
		new PublicationAPersonne(new JSONObject());
29
	}
30
	}
30
	
31
	
31
	public PublicationAPersonne(boolean removePrefix) {
32
	public PublicationAPersonne(boolean removePrefix) {
32
		this.removePrefix = removePrefix;
33
		this.removePrefix = removePrefix;
33
		new PublicationAPersonne(new JSONObject());
34
		new PublicationAPersonne(new JSONObject());
34
	}
35
	}
35
	
36
	
36
	public PublicationAPersonne(JSONObject pubAPersListe) {
37
	public PublicationAPersonne(JSONObject pubAPersListe) {
37
		Personne personne = new Personne(pubAPersListe);
38
		Personne personne = new Personne(pubAPersListe);
38
		setPersonne(personne);
39
		setPersonne(personne);
39
		publicationLiee = new Publication(pubAPersListe);
40
		publicationLiee = new Publication(pubAPersListe);
40
		
41
		
41
		// l'objet JSON est une table de hachage
42
		// l'objet JSON est une table de hachage
42
		Set<String> im = pubAPersListe.keySet();
43
		Set<String> im = pubAPersListe.keySet();
43
 
44
 
44
		// Parcourt pour chaque clé
45
		// Parcourt pour chaque clé
45
		for (Iterator<String> it = im.iterator(); it.hasNext();) {
46
		for (Iterator<String> it = im.iterator(); it.hasNext();) {
46
			// Si elle est associée à une valeur, nous l'ajoutons
47
			// Si elle est associée à une valeur, nous l'ajoutons
47
			String cle = it.next();
48
			String cle = it.next();
48
			String cleObjet = "";
49
			String cleObjet = "";
49
			if (removePrefix) {
50
			if (removePrefix) {
50
				cleObjet = cle.replaceFirst("^"+getPrefixe()+"_", "");
51
				cleObjet = cle.replaceFirst("^"+getPrefixe()+"_", "");
51
			} else {
52
			} else {
52
				cleObjet = cle;
53
				cleObjet = cle;
53
			}
54
			}
54
			// Valeur vide par défaut
55
			// Valeur vide par défaut
55
			String valeur = "";
56
			String valeur = "";
56
			if (pubAPersListe.get(cle).isString() != null) {
57
			if (pubAPersListe.get(cle).isString() != null) {
57
				valeur = pubAPersListe.get(cle).isString().stringValue();
58
				valeur = pubAPersListe.get(cle).isString().stringValue();
58
			}			
59
			}			
59
			this.set(cleObjet, valeur);
60
			this.set(cleObjet, valeur);
60
		}
61
		}
61
		
62
		
62
		initialiserChampsPourGrille();
63
		initialiserChampsPourGrille();
63
	}
64
	}
64
	
65
	
65
	public PublicationAPersonne(ModelData modele, boolean removePrefix) {
66
	public PublicationAPersonne(ModelData modele, boolean removePrefix) {
66
		this.removePrefix = removePrefix;
67
		this.removePrefix = removePrefix;
67
		if (modele != null) {
68
		if (modele != null) {
68
			Map<String, Object> modeleProprietes = modele.getProperties();
69
			Map<String, Object> modeleProprietes = modele.getProperties();
69
			
70
			
70
			Set<String> cles = modeleProprietes.keySet();
71
			Set<String> cles = modeleProprietes.keySet();
71
			Iterator<String> it = cles.iterator();
72
			Iterator<String> it = cles.iterator();
72
			while (it.hasNext()) {
73
			while (it.hasNext()) {
73
				String cle = it.next();
74
				String cle = it.next();
-
 
75
				Object valeur = modeleProprietes.get(cle);
74
				if (modeleProprietes.get(cle) != null) {
76
				if (modeleProprietes.get(cle) != null) {
75
					String cleObjet = "";
77
					String cleObjet = "";
76
					if (removePrefix) {
78
					if (removePrefix) {
77
						cleObjet = cle.replaceFirst("^"+Personne.PREFIXE+"_", "");
-
 
78
						cleObjet = cle.replaceFirst("^"+Publication.PREFIXE+"_", "");
-
 
79
						cleObjet = cleObjet.replaceFirst("^"+getPrefixe()+"_", "");
79
						cleObjet = cleObjet.replaceFirst("^"+getPrefixe()+"_", "");
80
					} else {
80
					} else {
81
						cleObjet = cle;
81
						cleObjet = cle;
82
					}
82
					}
83
					this.set(cleObjet, modeleProprietes.get(cle));
83
					this.set(cleObjet, valeur);
84
				}
84
				}
85
			}
85
			}
86
	
-
 
87
			setPersonne(new Personne(modele, removePrefix));
86
			setPersonne(new Personne(modele, removePrefix));
88
			setPublicationLiee(new Publication(modele, removePrefix));
87
			setPublicationLiee(new Publication(modele, removePrefix));
-
 
88
			initialiserChampsPourGrille();
89
			this.set("_role_", modeleProprietes.get("_role_"));
89
			this.set("_role_", modeleProprietes.get("_role_"));
90
			this.set("_etat_", modeleProprietes.get("_etat_"));
90
			this.set("_etat_", modeleProprietes.get("_etat_"));
91
		} else {
91
		} else {
92
			Log.debug("Le modèle passé en paramètre ne doit pas être vide");
92
			Log.debug("Le modèle passé en paramètre ne doit pas être vide");
93
		}
93
		}
94
	}
94
	}
95
	
95
	
96
	private void initialiserChampsPourGrille() {
96
	private void initialiserChampsPourGrille() {
97
		if (removePrefix) {
97
		if (removePrefix) {
98
			set("fmt_auteur", publicationLiee.getAuteur());
98
			set("fmt_auteur", publicationLiee.getAuteur());
99
			set("titre", publicationLiee.getTitre());
99
			set("titre", publicationLiee.getTitre());
100
			set("collection", publicationLiee.getCollection());
100
			set("collection", publicationLiee.getCollection());
101
			set("_editeur_", "");
101
			set("_editeur_", "");
102
			set("_annee_", "");
102
			set("_annee_", "");
103
			set("indication_nvt", publicationLiee.getIndicationNvt());
103
			set("indication_nvt", publicationLiee.getIndicationNvt());
104
			set("fascicule", publicationLiee.getFascicule());
104
			set("fascicule", publicationLiee.getFascicule());
105
			set("truk_pages", publicationLiee.getPages());
105
			set("truk_pages", publicationLiee.getPages());
106
			set("_etat_", "");
106
			set("_etat_", "");
107
			set("_role_", this.getIdRole());
107
			set("_role_", this.getIdRole());
108
		} else {
108
		} else {
109
			set("cpu_fmt_auteur", publicationLiee.getAuteur());
109
			set("cpu_fmt_auteur", publicationLiee.getAuteur());
110
			set("cpu_titre", publicationLiee.getTitre());
110
			set("cpu_titre", publicationLiee.getTitre());
111
			set("cpu_collection", publicationLiee.getCollection());
111
			set("cpu_collection", publicationLiee.getCollection());
112
			set("_editeur_", "");
112
			set("_editeur_", "");
113
			set("_annee_", "");
113
			set("_annee_", "");
114
			set("cpu_indication_nvt", publicationLiee.getIndicationNvt());
114
			set("cpu_indication_nvt", publicationLiee.getIndicationNvt());
115
			set("cpu_fascicule", publicationLiee.getFascicule());
115
			set("cpu_fascicule", publicationLiee.getFascicule());
116
			set("cpu_truk_pages", publicationLiee.getPages());
116
			set("cpu_truk_pages", publicationLiee.getPages());
117
			set("_etat_", "");
117
			set("_etat_", "");
118
			set("_role_", this.getIdRole());
118
			set("_role_", this.getIdRole());
119
		}
119
		}
120
	}
120
	}
121
	
121
	
122
	@Override
122
	@Override
123
	protected String getPrefixe() {
123
	protected String getPrefixe() {
124
		return PREFIXE;
124
		return PREFIXE;
125
	}
125
	}
126
 
126
 
127
	protected String[] getChampsObligatoires()	{
127
	protected String[] getChampsObligatoires()	{
128
		return champsObligatoires;
128
		return champsObligatoires;
129
	}
129
	}
130
	
130
	
131
	public Personne getPersonne() {
131
	public Personne getPersonne() {
132
		return personneLiee;
132
		return personneLiee;
133
	}
133
	}
134
	
134
	
135
	public void setPersonne(Personne personne) {
135
	public void setPersonne(Personne personne) {
136
		setPersonne(personne, false);
136
		setPersonne(personne, false);
137
	}
137
	}
138
	
138
	
139
	public void setPersonne(Personne personne, boolean integrerProprietes) {
139
	public void setPersonne(Personne personne, boolean integrerProprietes) {
140
		personneLiee = personne;
140
		personneLiee = personne;
141
		if (personne != null) {
141
		if (personne != null) {
-
 
142
			Log.debug("Tentative ajout id personne : "+personne.getId());
142
			setIdPersonne(personne.getId());
143
			setIdPersonne(personne.getId());
143
		}
144
		}
144
		
145
		
145
		if (integrerProprietes) {
146
		if (integrerProprietes) {
146
			Map<String, Object> a = personne.getProperties();
147
			Map<String, Object> a = personne.getProperties();
147
	
148
	
148
			Set<String> cles = a.keySet();
149
			Set<String> cles = a.keySet();
149
			Iterator<String> it = cles.iterator();
150
			Iterator<String> it = cles.iterator();
150
			while (it.hasNext()) {
151
			while (it.hasNext()) {
151
				String cle = it.next();			
152
				String cle = it.next();			
152
				if (a.get(cle) != null) {
153
				if (a.get(cle) != null) {
153
					String cleObjet = "";
154
					String cleObjet = "";
154
					if (removePrefix) {
155
					if (removePrefix) {
155
						cleObjet = cle.replaceFirst("^"+Personne.PREFIXE+"_", "");
156
						cleObjet = cle.replaceFirst("^"+Personne.PREFIXE+"_", "");
156
					} else {
157
					} else {
157
						cleObjet = cle;
158
						cleObjet = cle;
158
					}
159
					}
159
					this.set(cleObjet, a.get(cle));
160
					this.set(cleObjet, a.get(cle));
160
				}
161
				}
161
			}
162
			}
162
		}
163
		}
163
	}
164
	}
164
	
165
	
165
	// ID
166
	// ID
166
	public String getId() {
167
	public String getId() {
167
		String idPublication = getIdPublication();
168
		String idPublication = getIdPublication();
168
		String idPersonne = getIdPersonne();
169
		String idPersonne = getIdPersonne();
169
		String idRole = getIdRole();
170
		String idRole = getIdRole();
170
		if (idPublication.equals("") && idPersonne.equals("") && idRole.equals("")) {
171
		if (idPublication.equals("") && idPersonne.equals("") && idRole.equals("")) {
171
			return null;
172
			return null;
172
		} else {
173
		} else {
173
			return (idPublication+"-"+idPersonne+"-"+idRole);
174
			return (idPublication+"-"+idPersonne+"-"+idRole);
174
		}
175
		}
175
	}
176
	}
176
	
177
	
177
	// ID PUBLICATION
178
	// ID PUBLICATION
178
	public String getIdPublication() {
179
	public String getIdPublication() {
179
		return renvoyerValeurCorrecte("id_publication");
180
		String valeur =  renvoyerValeurCorrecte("id_publication");
-
 
181
		return UtilString.isEmpty(valeur) ? "0" : valeur; 
180
	}
182
	}
181
	public void setIdPublication(String id) {
183
	public void setIdPublication(String id) {
182
		setValeurCorrecte("id_publication", id);
184
		setValeurCorrecte("id_publication", id);
183
	}
185
	}
184
	
186
	
185
	// PUBLICATION LIEE
187
	// PUBLICATION LIEE
186
	public Publication getPublicationLiee() {
188
	public Publication getPublicationLiee() {
187
		return this.publicationLiee;
189
		return this.publicationLiee;
188
	}
190
	}
189
	
191
	
190
	// LIER PUBLICATION
192
	// LIER PUBLICATION
191
	public void setPublicationLiee(Publication publication)	{
193
	public void setPublicationLiee(Publication publication)	{
192
		this.publicationLiee = publication;
194
		this.publicationLiee = publication;
193
		initialiserChampsPourGrille();
195
		initialiserChampsPourGrille();
194
	}
196
	}
195
	
197
	
196
	// ID PERSONNE
198
	// ID PERSONNE
197
	public String getIdPersonne() {
199
	public String getIdPersonne() {
198
		return renvoyerValeurCorrecte("id_personne");
200
		String valeur = renvoyerValeurCorrecte("id_personne");
-
 
201
		return UtilString.isEmpty(valeur) ? "0" : valeur;
199
	}
202
	}
200
	public void setIdPersonne(String id) {
203
	public void setIdPersonne(String id) {
201
		setValeurCorrecte("id_personne", id);
204
		setValeurCorrecte("id_personne", id);
202
	}
205
	}
203
	
206
	
204
	// ID RôLE
207
	// ID RôLE
205
	public String getIdRole() {
208
	public String getIdRole() {
206
		return renvoyerValeurCorrecte("id_role");
209
		String valeur = renvoyerValeurCorrecte("id_role");
-
 
210
		return UtilString.isEmpty(valeur) ? "0" : valeur;
207
	}
211
	}
208
	public void setIdRole(String id) {
212
	public void setIdRole(String id) {
209
		setValeurCorrecte("id_role", id);
213
		setValeurCorrecte("id_role", id);
210
		this.set("_role_", id);
214
		this.set("_role_", id);
211
	}
215
	}
212
	
216
	
213
	// ROLE
217
	// ROLE
214
	public String getRole() {
218
	public String getRole() {
215
		String role = this.get("_role_");
219
		String role = this.get("_role_");
216
		if (role != null)	{
220
		if (role != null)	{
217
			return role;
221
			return role;
218
		} else 	{
222
		} else 	{
219
			return "";
223
			return "";
220
		}
224
		}
221
	}
225
	}
222
		
226
		
223
	// TYPE
227
	// TYPE
224
	public String getType() {
228
	public String getType() {
225
		return renvoyerValeurCorrecte("ce_truk_type");
229
		return renvoyerValeurCorrecte("ce_truk_type");
226
	}
230
	}
227
	public void setType(String type) {
231
	public void setType(String type) {
228
		setValeurCorrecte("ce_truk_type", type);
232
		setValeurCorrecte("ce_truk_type", type);
229
	}
233
	}
230
	public void setFonction(String type, String valeur) {
234
	public void setFonction(String type, String valeur) {
231
		setChaineDenormaliseUnique("ce_truk_type", type, valeur);
235
		setChaineDenormaliseUnique("ce_truk_type", type, valeur);
232
	}
236
	}
233
	
237
	
234
	// ORDRE DES AUTEURS
238
	// ORDRE DES AUTEURS
235
	public String getOrdreAuteurs() {
239
	public String getOrdreAuteurs() {
236
		return renvoyerValeurCorrecte("ordre");
240
		return renvoyerValeurCorrecte("ordre");
237
	}
241
	}
238
	public void setOrdreAuteurs(String ordre) {
242
	public void setOrdreAuteurs(String ordre) {
239
		if (ordre.matches("[0-9]+")) {
243
		if (ordre.matches("[0-9]+")) {
240
			setValeurCorrecte("ordre", ordre);
244
			setValeurCorrecte("ordre", ordre);
241
			this.set("_ordre_", ordre);
245
			this.set("_ordre_", ordre);
242
		}
246
		}
243
	}
247
	}
244
}
248
}