935 |
jpm |
1 |
package org.tela_botanica.client.modeles.collection;
|
883 |
jpm |
2 |
|
1513 |
jpm |
3 |
import java.util.Iterator;
|
|
|
4 |
import java.util.Map;
|
|
|
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.personne.Personne;
|
935 |
jpm |
9 |
import org.tela_botanica.client.modeles.publication.Publication;
|
|
|
10 |
|
1513 |
jpm |
11 |
import com.extjs.gxt.ui.client.data.ModelData;
|
883 |
jpm |
12 |
import com.google.gwt.json.client.JSONObject;
|
|
|
13 |
|
|
|
14 |
public class CollectionAPublication extends aDonnee {
|
|
|
15 |
|
|
|
16 |
private static final long serialVersionUID = 1L;
|
|
|
17 |
|
|
|
18 |
public static final String PREFIXE = "ccapu";
|
|
|
19 |
private Publication publicationLiee = null;
|
1173 |
jpm |
20 |
public static String[] champsObligatoires = {"ccapu_id_collection", "ccapu_id_publication"};
|
883 |
jpm |
21 |
|
|
|
22 |
public CollectionAPublication() {
|
|
|
23 |
initialiser(new JSONObject());
|
|
|
24 |
}
|
1513 |
jpm |
25 |
|
|
|
26 |
public CollectionAPublication(boolean removePrefix) {
|
|
|
27 |
this.removePrefix = removePrefix;
|
|
|
28 |
initialiser(new JSONObject());
|
|
|
29 |
}
|
883 |
jpm |
30 |
|
|
|
31 |
public CollectionAPublication(JSONObject collectionAPublicationListe) {
|
|
|
32 |
initialiser(collectionAPublicationListe);
|
|
|
33 |
}
|
|
|
34 |
|
1513 |
jpm |
35 |
public CollectionAPublication(ModelData model, boolean removePrefix)
|
|
|
36 |
{
|
|
|
37 |
this.removePrefix = removePrefix;
|
|
|
38 |
|
|
|
39 |
Map<String, Object> a = model.getProperties();
|
|
|
40 |
|
|
|
41 |
Set<String> cles = a.keySet();
|
|
|
42 |
Iterator<String> it = cles.iterator();
|
|
|
43 |
while (it.hasNext()) {
|
|
|
44 |
String cle = it.next();
|
|
|
45 |
if (a.get(cle) != null) {
|
|
|
46 |
String cleObjet = "";
|
|
|
47 |
if (removePrefix) {
|
|
|
48 |
cleObjet = cle.replaceFirst("^"+Publication.PREFIXE+"_", "");
|
|
|
49 |
cleObjet = cle.replaceFirst("^"+Personne.PREFIXE+"_", "");
|
|
|
50 |
cleObjet = cleObjet.replaceFirst("^"+PREFIXE+"_", "");
|
|
|
51 |
}
|
|
|
52 |
else {
|
|
|
53 |
cleObjet = cle;
|
|
|
54 |
}
|
|
|
55 |
this.set(cleObjet, a.get(cle));
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
setPublication(new Publication(model, removePrefix));
|
|
|
60 |
this.set("_etat_", a.get("_etat_"));
|
|
|
61 |
}
|
|
|
62 |
|
883 |
jpm |
63 |
@Override
|
|
|
64 |
protected String getPrefixe() {
|
|
|
65 |
return PREFIXE;
|
|
|
66 |
}
|
|
|
67 |
|
1173 |
jpm |
68 |
protected String[] getChampsObligatoires() {
|
|
|
69 |
return champsObligatoires;
|
|
|
70 |
}
|
|
|
71 |
|
883 |
jpm |
72 |
private void initialiser(JSONObject collectionAPublicationListe) {
|
|
|
73 |
setPublication(new Publication(collectionAPublicationListe));
|
|
|
74 |
initialiserChampsPourGrille();
|
|
|
75 |
initialiserModele(collectionAPublicationListe);
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
// PUBLICATION
|
|
|
79 |
public Publication getPublication() {
|
|
|
80 |
return publicationLiee;
|
|
|
81 |
}
|
|
|
82 |
public void setPublication(Publication publication) {
|
|
|
83 |
publicationLiee = publication;
|
|
|
84 |
initialiserChampsPourGrille();
|
907 |
jpm |
85 |
if (publication != null) {
|
|
|
86 |
setIdPublication(publication.getId());
|
|
|
87 |
}
|
883 |
jpm |
88 |
}
|
|
|
89 |
|
|
|
90 |
private void initialiserChampsPourGrille() {
|
1513 |
jpm |
91 |
if (removePrefix) {
|
|
|
92 |
set("fmt_auteur", getPublication().getAuteur());
|
|
|
93 |
set("titre", getPublication().getTitre());
|
|
|
94 |
set("collection", getPublication().getCollection());
|
|
|
95 |
set("_editeur_", "");
|
|
|
96 |
set("_annee_", "");
|
|
|
97 |
set("indication_nvt", getPublication().getIndicationNvt());
|
|
|
98 |
set("fascicule", getPublication().getFascicule());
|
|
|
99 |
set("truk_pages", getPublication().getPages());
|
|
|
100 |
set("_etat_", "");
|
|
|
101 |
} else {
|
|
|
102 |
set(Publication.PREFIXE+"_fmt_auteur", getPublication().getAuteur());
|
|
|
103 |
set(Publication.PREFIXE+"_titre", getPublication().getTitre());
|
|
|
104 |
set(Publication.PREFIXE+"_collection", getPublication().getCollection());
|
|
|
105 |
set("_editeur_", "");
|
|
|
106 |
set("_annee_", "");
|
|
|
107 |
set(Publication.PREFIXE+"_indication_nvt", getPublication().getIndicationNvt());
|
|
|
108 |
set(Publication.PREFIXE+"_fascicule", getPublication().getFascicule());
|
|
|
109 |
set(Publication.PREFIXE+"_truk_pages", getPublication().getPages());
|
|
|
110 |
set("_etat_", "");
|
|
|
111 |
}
|
883 |
jpm |
112 |
}
|
|
|
113 |
|
|
|
114 |
// ID
|
|
|
115 |
/** Génère un identifiant de CollectionAPersonne.
|
|
|
116 |
*
|
|
|
117 |
* C'est une concaténation des clés primaires de la table coel_collection_a_personne séparées par un tiret "-".
|
|
|
118 |
*
|
|
|
119 |
* @return identifiant unique d'une relation "collection à personne".
|
|
|
120 |
*/
|
|
|
121 |
public String getId() {
|
|
|
122 |
String idCollection = getIdCollection();
|
|
|
123 |
String idPublication = getIdPublication();
|
|
|
124 |
if (idCollection.equals("") && idPublication.equals("")) {
|
|
|
125 |
return null;
|
|
|
126 |
} else {
|
|
|
127 |
return (idCollection+"-"+idPublication);
|
|
|
128 |
}
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
//+---------------------------------------------------------------------------------------------------------------+
|
|
|
132 |
// CHAMPS PROVENANT de la TABLE COEL_COLLECTION_A_PERSONNE
|
|
|
133 |
|
|
|
134 |
// ID COLLECTION
|
|
|
135 |
public String getIdCollection() {
|
1513 |
jpm |
136 |
if (removePrefix) return renvoyerValeurCorrecte("id_collection");
|
|
|
137 |
else return renvoyerValeurCorrecte(PREFIXE+"_id_collection");
|
883 |
jpm |
138 |
}
|
|
|
139 |
public void setIdCollection(String idCollection) {
|
1513 |
jpm |
140 |
if (removePrefix) set("id_collection", idCollection);
|
|
|
141 |
else set(PREFIXE+"_id_collection", idCollection);
|
883 |
jpm |
142 |
}
|
|
|
143 |
|
|
|
144 |
// ID PUBLICATION
|
|
|
145 |
public String getIdPublication() {
|
1610 |
aurelien |
146 |
String idPublication;
|
|
|
147 |
if (removePrefix) {
|
|
|
148 |
idPublication = renvoyerValeurCorrecte("id_publication");
|
|
|
149 |
} else {
|
|
|
150 |
idPublication = renvoyerValeurCorrecte(PREFIXE+"_id_publication");
|
|
|
151 |
}
|
|
|
152 |
return idPublication;
|
883 |
jpm |
153 |
}
|
|
|
154 |
public void setIdPublication(String ip) {
|
1610 |
aurelien |
155 |
if (removePrefix) {
|
|
|
156 |
set("id_publication", ip);
|
|
|
157 |
} else {
|
|
|
158 |
set(PREFIXE+"_id_publication", ip);
|
|
|
159 |
}
|
883 |
jpm |
160 |
}
|
|
|
161 |
|
|
|
162 |
}
|