| 935 |
jpm |
1 |
package org.tela_botanica.client.modeles.publication;
|
| 741 |
aurelien |
2 |
|
|
|
3 |
import java.util.Iterator;
|
| 1428 |
cyprien |
4 |
import java.util.Map;
|
| 741 |
aurelien |
5 |
import java.util.Set;
|
|
|
6 |
|
| 935 |
jpm |
7 |
import org.tela_botanica.client.modeles.aDonnee;
|
| 1513 |
jpm |
8 |
import org.tela_botanica.client.modeles.collection.CollectionAPublication;
|
| 935 |
jpm |
9 |
import org.tela_botanica.client.modeles.personne.Personne;
|
| 1428 |
cyprien |
10 |
import org.tela_botanica.client.util.Debug;
|
| 935 |
jpm |
11 |
|
| 1513 |
jpm |
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";
|
| 1513 |
jpm |
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 |
|
| 1513 |
jpm |
33 |
public PublicationAPersonne(boolean removePrefix) {
|
|
|
34 |
this.removePrefix = removePrefix;
|
|
|
35 |
new PublicationAPersonne(new JSONObject());
|
|
|
36 |
}
|
|
|
37 |
|
| 741 |
aurelien |
38 |
public PublicationAPersonne(JSONObject pubAPersListe) {
|
| 1428 |
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();
|
| 1513 |
jpm |
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();
|
| 1513 |
jpm |
57 |
}
|
|
|
58 |
this.set(cleObjet, valeur);
|
| 741 |
aurelien |
59 |
}
|
| 992 |
gduche |
60 |
|
|
|
61 |
initialiserChampsPourGrille();
|
| 741 |
aurelien |
62 |
}
|
|
|
63 |
|
| 1513 |
jpm |
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() {
|
| 1513 |
jpm |
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 |
}
|
| 1513 |
jpm |
133 |
|
| 775 |
jpm |
134 |
public void setPersonne(Personne personne) {
|
| 1513 |
jpm |
135 |
setPersonne(personne, false);
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
public void setPersonne(Personne personne, boolean integrerProprietes) {
|
| 775 |
jpm |
139 |
personneLiee = personne;
|
| 901 |
jpm |
140 |
if (personne != null) {
|
|
|
141 |
setIdPersonne(personne.getId());
|
|
|
142 |
}
|
| 1428 |
cyprien |
143 |
|
| 1513 |
jpm |
144 |
if (integrerProprietes) {
|
|
|
145 |
Map<String, Object> a = personne.getProperties();
|
|
|
146 |
|
|
|
147 |
Set<String> cles = a.keySet();
|
|
|
148 |
Iterator<String> it = cles.iterator();
|
|
|
149 |
while (it.hasNext()) {
|
|
|
150 |
String cle = it.next();
|
|
|
151 |
if (a.get(cle) != null) {
|
|
|
152 |
String cleObjet = "";
|
|
|
153 |
if (removePrefix) {
|
|
|
154 |
cleObjet = cle.replaceFirst("^"+Personne.PREFIXE+"_", "");
|
|
|
155 |
}
|
|
|
156 |
else {
|
|
|
157 |
cleObjet = cle;
|
|
|
158 |
}
|
|
|
159 |
this.set(cleObjet, a.get(cle));
|
|
|
160 |
}
|
| 1428 |
cyprien |
161 |
}
|
|
|
162 |
}
|
| 741 |
aurelien |
163 |
}
|
|
|
164 |
|
| 901 |
jpm |
165 |
// ID
|
|
|
166 |
public String getId() {
|
|
|
167 |
String idPublication = getIdPublication();
|
|
|
168 |
String idPersonne = getIdPersonne();
|
|
|
169 |
String idRole = getIdRole();
|
|
|
170 |
if (idPublication.equals("") && idPersonne.equals("") && idRole.equals("")) {
|
|
|
171 |
return null;
|
|
|
172 |
} else {
|
|
|
173 |
return (idPublication+"-"+idPersonne+"-"+idRole);
|
|
|
174 |
}
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
// ID PUBLICATION
|
|
|
178 |
public String getIdPublication() {
|
| 1513 |
jpm |
179 |
if (removePrefix) return renvoyerValeurCorrecte("id_publication");
|
|
|
180 |
else return renvoyerValeurCorrecte("cpuap_id_publication");
|
| 901 |
jpm |
181 |
}
|
|
|
182 |
public void setIdPublication(String id) {
|
| 1513 |
jpm |
183 |
if (removePrefix) set("id_publication", id);
|
|
|
184 |
else set("cpuap_id_publication", id);
|
| 901 |
jpm |
185 |
}
|
|
|
186 |
|
| 992 |
gduche |
187 |
// PUBLICATION LIEE
|
|
|
188 |
public Publication getPublicationLiee() {
|
|
|
189 |
return this.publicationLiee;
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
// LIER PUBLICATION
|
|
|
193 |
public void setPublicationLiee(Publication publication) {
|
|
|
194 |
this.publicationLiee = publication;
|
|
|
195 |
initialiserChampsPourGrille();
|
|
|
196 |
}
|
|
|
197 |
|
| 1004 |
gduche |
198 |
// ROLE
|
|
|
199 |
public String getRole() {
|
|
|
200 |
String role = this.get("_role_");
|
|
|
201 |
if (role != null) {
|
|
|
202 |
return role;
|
|
|
203 |
} else {
|
|
|
204 |
return "";
|
|
|
205 |
}
|
|
|
206 |
}
|
|
|
207 |
|
| 901 |
jpm |
208 |
// ID PERSONNE
|
|
|
209 |
public String getIdPersonne() {
|
| 1513 |
jpm |
210 |
if (removePrefix) return renvoyerValeurCorrecte("id_personne");
|
|
|
211 |
else return renvoyerValeurCorrecte("cpuap_id_personne");
|
| 901 |
jpm |
212 |
}
|
|
|
213 |
public void setIdPersonne(String id) {
|
| 1513 |
jpm |
214 |
if (removePrefix) set("id_personne", id);
|
|
|
215 |
else set(PREFIXE+"_id_personne", id);
|
| 901 |
jpm |
216 |
}
|
|
|
217 |
|
|
|
218 |
// ID RôLE
|
|
|
219 |
public String getIdRole() {
|
|
|
220 |
return renvoyerValeurCorrecte("id_role");
|
|
|
221 |
}
|
|
|
222 |
public void setIdRole(String id) {
|
|
|
223 |
set("id_role", id);
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
// TYPE
|
|
|
227 |
public String getType() {
|
|
|
228 |
return renvoyerValeurCorrecte("ce_truk_type");
|
|
|
229 |
}
|
|
|
230 |
public void setType(String type) {
|
|
|
231 |
set("ce_truk_type", type);
|
|
|
232 |
}
|
|
|
233 |
public void setFonction(String type, String valeur) {
|
|
|
234 |
setChaineDenormaliseUnique("ce_truk_type", type, valeur);
|
|
|
235 |
}
|
| 1428 |
cyprien |
236 |
|
|
|
237 |
// ORDRE DES AUTEURS
|
|
|
238 |
public String getOrdreAuteurs() {
|
| 1513 |
jpm |
239 |
if (removePrefix) return renvoyerValeurCorrecte("ordre");
|
|
|
240 |
else return renvoyerValeurCorrecte(PREFIXE+"_ordre");
|
| 1428 |
cyprien |
241 |
}
|
|
|
242 |
public void setOrdreAuteurs(String ordre) {
|
|
|
243 |
if (ordre.matches("[0-9]+")) {
|
| 1513 |
jpm |
244 |
if (removePrefix) this.set("ordre", ordre);
|
|
|
245 |
else this.set(PREFIXE+"_ordre", ordre);
|
|
|
246 |
|
|
|
247 |
this.set("_ordre_", ordre);
|
| 1428 |
cyprien |
248 |
}
|
|
|
249 |
}
|
| 775 |
jpm |
250 |
}
|