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