Subversion Repositories eFlore/Applications.coel

Rev

Rev 1426 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
935 jpm 1
package org.tela_botanica.client.modeles.publication;
741 aurelien 2
 
3
import java.util.Iterator;
1426 cyprien 4
import java.util.Map;
741 aurelien 5
import java.util.Set;
6
 
935 jpm 7
import org.tela_botanica.client.modeles.aDonnee;
1485 cyprien 8
import org.tela_botanica.client.modeles.collection.CollectionAPublication;
935 jpm 9
import org.tela_botanica.client.modeles.personne.Personne;
1426 cyprien 10
import org.tela_botanica.client.util.Debug;
935 jpm 11
 
1485 cyprien 12
import com.extjs.gxt.ui.client.data.ModelData;
741 aurelien 13
import com.google.gwt.json.client.JSONObject;
14
 
15
public class PublicationAPersonne extends aDonnee {
16
 
17
	private static final long serialVersionUID = 7769105365939978129L;
748 jpm 18
 
751 jpm 19
	public static final String PREFIXE = "cpuap";
1485 cyprien 20
	private boolean removePrefix = true;
751 jpm 21
	public static final String ROLE_AUTEUR = "2360";
992 gduche 22
	//FIXME: insérer en base de données une valeur cohérente pour l'identifiant ci-dessous
23
	public static final String ROLE_SUJET = "30762";
24
 
775 jpm 25
	private Personne personneLiee = null;
992 gduche 26
	private Publication publicationLiee = null;
1173 jpm 27
	public static String[] champsObligatoires = {"cpuap_id_personne", "cpuap_id_publication", "cpuap_id_role"};
775 jpm 28
 
992 gduche 29
	public PublicationAPersonne() {
30
		new PublicationAPersonne(new JSONObject());
31
	}
901 jpm 32
 
1485 cyprien 33
	public PublicationAPersonne(boolean removePrefix) {
34
		this.removePrefix = removePrefix;
35
		new PublicationAPersonne(new JSONObject());
36
	}
37
 
741 aurelien 38
	public PublicationAPersonne(JSONObject pubAPersListe) {
1426 cyprien 39
		Personne personne = new Personne(pubAPersListe);
40
		setPersonne(personne);
992 gduche 41
		publicationLiee = new Publication(pubAPersListe);
775 jpm 42
 
741 aurelien 43
		// l'objet JSON est une table de hachage
44
		Set<String> im = pubAPersListe.keySet();
45
 
46
		// Parcourt pour chaque clé
47
		for (Iterator<String> it = im.iterator(); it.hasNext();) {
48
			// Si elle est associée à une valeur, nous l'ajoutons
49
			String cle = it.next();
1485 cyprien 50
			String cleObjet = "";
51
			if (removePrefix) cleObjet = cle.replaceFirst("^"+getPrefixe()+"_", "");
52
			else cleObjet=cle;
748 jpm 53
			// Valeur vide par défaut
54
			String valeur = "";
741 aurelien 55
			if (pubAPersListe.get(cle).isString() != null) {
748 jpm 56
				valeur = pubAPersListe.get(cle).isString().stringValue();
1485 cyprien 57
			}
58
			this.set(cleObjet, valeur);
741 aurelien 59
		}
992 gduche 60
 
61
		initialiserChampsPourGrille();
741 aurelien 62
	}
63
 
1485 cyprien 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_"));
92
	}
992 gduche 93
 
94
	private void initialiserChampsPourGrille() {
1485 cyprien 95
		if (removePrefix) {
96
			set("fmt_auteur", publicationLiee.getAuteur());
97
			set("titre", publicationLiee.getTitre());
98
			set("collection", publicationLiee.getCollection());
99
			set("_editeur_", "");
100
			set("_annee_", "");
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());
113
			set("cpu_fascicule", publicationLiee.getFascicule());
114
			set("cpu_truk_pages", publicationLiee.getPages());
115
			set("_etat_", "");
116
			set("_role_", this.get("id_role"));
117
		}
992 gduche 118
	}
119
 
120
 
748 jpm 121
	@Override
122
	protected String getPrefixe() {
123
		return PREFIXE;
124
	}
125
 
1173 jpm 126
	protected String[] getChampsObligatoires()	{
127
		return champsObligatoires;
128
	}
129
 
775 jpm 130
	public Personne getPersonne() {
131
		return personneLiee;
748 jpm 132
	}
775 jpm 133
	public void setPersonne(Personne personne) {
134
		personneLiee = personne;
901 jpm 135
		if (personne != null) {
136
			setIdPersonne(personne.getId());
137
		}
1485 cyprien 138
		/*
1426 cyprien 139
		Map<String, Object> a = personne.getProperties();
140
 
141
		Set<String> cles = a.keySet();
142
		Iterator<String> it = cles.iterator();
143
		while (it.hasNext()) {
144
			String cle = it.next();
145
			if (a.get(cle) != null) {
1485 cyprien 146
				String cleObjet = "";
147
				if (removePrefix) {
148
					cleObjet = cle.replaceFirst("^"+Personne.PREFIXE+"_", "");
149
				}
150
				else {
151
					cleObjet = cle;
152
				}
1426 cyprien 153
				this.set(cleObjet, a.get(cle));
154
			}
1485 cyprien 155
		}*/
741 aurelien 156
	}
157
 
901 jpm 158
	// ID
159
	public String getId() {
160
		String idPublication = getIdPublication();
161
		String idPersonne = getIdPersonne();
162
		String idRole = getIdRole();
163
		if (idPublication.equals("") && idPersonne.equals("") && idRole.equals("")) {
164
			return null;
165
		} else {
166
			return (idPublication+"-"+idPersonne+"-"+idRole);
167
		}
168
	}
169
 
170
	// ID PUBLICATION
171
	public String getIdPublication() {
1485 cyprien 172
		if (removePrefix) return renvoyerValeurCorrecte("id_publication");
173
		else return renvoyerValeurCorrecte("cpuap_id_publication");
901 jpm 174
	}
175
	public void setIdPublication(String id) {
1485 cyprien 176
		if (removePrefix) set("id_publication", id);
177
		else set("cpuap_id_publication", id);
901 jpm 178
	}
179
 
992 gduche 180
	// PUBLICATION LIEE
181
	public Publication getPublicationLiee()	{
182
		return this.publicationLiee;
183
	}
184
 
185
	// LIER PUBLICATION
186
	public void setPublicationLiee(Publication publication)	{
187
		this.publicationLiee = publication;
188
		initialiserChampsPourGrille();
189
	}
190
 
1004 gduche 191
	// ROLE
192
	public String getRole() {
193
		String role = this.get("_role_");
194
		if (role != null)	{
195
			return role;
196
		} else 	{
197
			return "";
198
		}
199
	}
200
 
901 jpm 201
	// ID PERSONNE
202
	public String getIdPersonne() {
1485 cyprien 203
		if (removePrefix) return renvoyerValeurCorrecte("id_personne");
204
		else return renvoyerValeurCorrecte("cpuap_id_personne");
901 jpm 205
	}
206
	public void setIdPersonne(String id) {
1485 cyprien 207
		if (removePrefix) set("id_personne", id);
208
		else set(PREFIXE+"_id_personne", id);
901 jpm 209
	}
210
 
211
	// ID RôLE
212
	public String getIdRole() {
213
		return renvoyerValeurCorrecte("id_role");
214
	}
215
	public void setIdRole(String id) {
216
		set("id_role", id);
217
	}
218
 
219
	// TYPE
220
	public String getType() {
221
		return renvoyerValeurCorrecte("ce_truk_type");
222
	}
223
	public void setType(String type) {
224
		set("ce_truk_type", type);
225
	}
226
	public void setFonction(String type, String valeur) {
227
		setChaineDenormaliseUnique("ce_truk_type", type, valeur);
228
	}
1426 cyprien 229
 
230
	// ORDRE DES AUTEURS
231
	public String getOrdreAuteurs() {
232
		return renvoyerValeurCorrecte("ordre");
233
	}
234
	public void setOrdreAuteurs(String ordre) {
235
		if (ordre.matches("[0-9]+")) {
236
			this.set("ordre", ordre);
237
		}
238
	}
775 jpm 239
}