Subversion Repositories eFlore/Applications.coel

Rev

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

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