| 935 |
jpm |
1 |
package org.tela_botanica.client.modeles.publication;
|
| 741 |
aurelien |
2 |
|
|
|
3 |
import java.util.Iterator;
|
|
|
4 |
import java.util.Set;
|
|
|
5 |
|
| 935 |
jpm |
6 |
import org.tela_botanica.client.modeles.aDonnee;
|
|
|
7 |
import org.tela_botanica.client.modeles.personne.Personne;
|
|
|
8 |
|
| 741 |
aurelien |
9 |
import com.google.gwt.json.client.JSONObject;
|
|
|
10 |
|
|
|
11 |
public class PublicationAPersonne extends aDonnee {
|
|
|
12 |
|
|
|
13 |
private static final long serialVersionUID = 7769105365939978129L;
|
| 748 |
jpm |
14 |
|
| 751 |
jpm |
15 |
public static final String PREFIXE = "cpuap";
|
|
|
16 |
public static final String ROLE_AUTEUR = "2360";
|
| 992 |
gduche |
17 |
//FIXME: insérer en base de données une valeur cohérente pour l'identifiant ci-dessous
|
|
|
18 |
public static final String ROLE_SUJET = "30762";
|
|
|
19 |
|
| 775 |
jpm |
20 |
private Personne personneLiee = null;
|
| 992 |
gduche |
21 |
private Publication publicationLiee = null;
|
| 1173 |
jpm |
22 |
public static String[] champsObligatoires = {"cpuap_id_personne", "cpuap_id_publication", "cpuap_id_role"};
|
| 775 |
jpm |
23 |
|
| 992 |
gduche |
24 |
public PublicationAPersonne() {
|
|
|
25 |
new PublicationAPersonne(new JSONObject());
|
|
|
26 |
}
|
| 901 |
jpm |
27 |
|
| 741 |
aurelien |
28 |
public PublicationAPersonne(JSONObject pubAPersListe) {
|
| 775 |
jpm |
29 |
personneLiee = new Personne(pubAPersListe);
|
| 992 |
gduche |
30 |
publicationLiee = new Publication(pubAPersListe);
|
| 775 |
jpm |
31 |
|
| 741 |
aurelien |
32 |
// l'objet JSON est une table de hachage
|
|
|
33 |
Set<String> im = pubAPersListe.keySet();
|
|
|
34 |
|
|
|
35 |
// Parcourt pour chaque clé
|
|
|
36 |
for (Iterator<String> it = im.iterator(); it.hasNext();) {
|
|
|
37 |
// Si elle est associée à une valeur, nous l'ajoutons
|
|
|
38 |
String cle = it.next();
|
|
|
39 |
// Suppression de l'abréviation du champ. Inutile dans le contexte d'un objet
|
| 748 |
jpm |
40 |
String cleObjet = cle.replaceFirst("^"+PREFIXE+"_", "");
|
|
|
41 |
// Valeur vide par défaut
|
|
|
42 |
String valeur = "";
|
| 741 |
aurelien |
43 |
if (pubAPersListe.get(cle).isString() != null) {
|
| 748 |
jpm |
44 |
valeur = pubAPersListe.get(cle).isString().stringValue();
|
|
|
45 |
this.set(cleObjet, valeur);
|
| 741 |
aurelien |
46 |
} else {
|
| 748 |
jpm |
47 |
this.set(cleObjet, valeur);
|
| 741 |
aurelien |
48 |
}
|
|
|
49 |
}
|
| 992 |
gduche |
50 |
|
|
|
51 |
initialiserChampsPourGrille();
|
| 741 |
aurelien |
52 |
}
|
|
|
53 |
|
| 992 |
gduche |
54 |
|
|
|
55 |
private void initialiserChampsPourGrille() {
|
|
|
56 |
set("fmt_auteur", publicationLiee.getAuteur());
|
|
|
57 |
set("titre", publicationLiee.getTitre());
|
|
|
58 |
set("collection", publicationLiee.getCollection());
|
|
|
59 |
set("_editeur_", "");
|
|
|
60 |
set("_annee_", "");
|
|
|
61 |
set("indication_nvt", publicationLiee.getIndicationNvt());
|
|
|
62 |
set("fascicule", publicationLiee.getFascicule());
|
|
|
63 |
set("truk_pages", publicationLiee.getPages());
|
|
|
64 |
set("_etat_", "");
|
| 1014 |
gduche |
65 |
set("_role_", this.get("id_role"));
|
| 992 |
gduche |
66 |
}
|
|
|
67 |
|
|
|
68 |
|
| 748 |
jpm |
69 |
@Override
|
|
|
70 |
protected String getPrefixe() {
|
|
|
71 |
return PREFIXE;
|
|
|
72 |
}
|
|
|
73 |
|
| 1173 |
jpm |
74 |
protected String[] getChampsObligatoires() {
|
|
|
75 |
return champsObligatoires;
|
|
|
76 |
}
|
|
|
77 |
|
| 775 |
jpm |
78 |
public Personne getPersonne() {
|
|
|
79 |
return personneLiee;
|
| 748 |
jpm |
80 |
}
|
| 775 |
jpm |
81 |
public void setPersonne(Personne personne) {
|
|
|
82 |
personneLiee = personne;
|
| 901 |
jpm |
83 |
if (personne != null) {
|
|
|
84 |
setIdPersonne(personne.getId());
|
|
|
85 |
}
|
| 741 |
aurelien |
86 |
}
|
|
|
87 |
|
| 901 |
jpm |
88 |
// ID
|
|
|
89 |
public String getId() {
|
|
|
90 |
String idPublication = getIdPublication();
|
|
|
91 |
String idPersonne = getIdPersonne();
|
|
|
92 |
String idRole = getIdRole();
|
|
|
93 |
if (idPublication.equals("") && idPersonne.equals("") && idRole.equals("")) {
|
|
|
94 |
return null;
|
|
|
95 |
} else {
|
|
|
96 |
return (idPublication+"-"+idPersonne+"-"+idRole);
|
|
|
97 |
}
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
// ID PUBLICATION
|
|
|
101 |
public String getIdPublication() {
|
|
|
102 |
return renvoyerValeurCorrecte("id_publication");
|
|
|
103 |
}
|
|
|
104 |
public void setIdPublication(String id) {
|
|
|
105 |
set("id_publication", id);
|
|
|
106 |
}
|
|
|
107 |
|
| 992 |
gduche |
108 |
// PUBLICATION LIEE
|
|
|
109 |
public Publication getPublicationLiee() {
|
|
|
110 |
return this.publicationLiee;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
// LIER PUBLICATION
|
|
|
114 |
public void setPublicationLiee(Publication publication) {
|
|
|
115 |
this.publicationLiee = publication;
|
|
|
116 |
initialiserChampsPourGrille();
|
|
|
117 |
}
|
|
|
118 |
|
| 1004 |
gduche |
119 |
// ROLE
|
|
|
120 |
public String getRole() {
|
|
|
121 |
String role = this.get("_role_");
|
|
|
122 |
if (role != null) {
|
|
|
123 |
return role;
|
|
|
124 |
} else {
|
|
|
125 |
return "";
|
|
|
126 |
}
|
|
|
127 |
}
|
|
|
128 |
|
| 901 |
jpm |
129 |
// ID PERSONNE
|
|
|
130 |
public String getIdPersonne() {
|
|
|
131 |
return renvoyerValeurCorrecte("id_personne");
|
|
|
132 |
}
|
|
|
133 |
public void setIdPersonne(String id) {
|
|
|
134 |
set("id_personne", id);
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
// ID RôLE
|
|
|
138 |
public String getIdRole() {
|
|
|
139 |
return renvoyerValeurCorrecte("id_role");
|
|
|
140 |
}
|
|
|
141 |
public void setIdRole(String id) {
|
|
|
142 |
set("id_role", id);
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
// TYPE
|
|
|
146 |
public String getType() {
|
|
|
147 |
return renvoyerValeurCorrecte("ce_truk_type");
|
|
|
148 |
}
|
|
|
149 |
public void setType(String type) {
|
|
|
150 |
set("ce_truk_type", type);
|
|
|
151 |
}
|
|
|
152 |
public void setFonction(String type, String valeur) {
|
|
|
153 |
setChaineDenormaliseUnique("ce_truk_type", type, valeur);
|
|
|
154 |
}
|
| 775 |
jpm |
155 |
}
|