985 |
jpm |
1 |
package org.tela_botanica.client.modeles.collection;
|
|
|
2 |
|
1484 |
cyprien |
3 |
import java.util.Iterator;
|
|
|
4 |
import java.util.Map;
|
|
|
5 |
import java.util.Set;
|
|
|
6 |
|
985 |
jpm |
7 |
import org.tela_botanica.client.modeles.aDonnee;
|
|
|
8 |
import org.tela_botanica.client.modeles.commentaire.Commentaire;
|
1484 |
cyprien |
9 |
import org.tela_botanica.client.modeles.personne.Personne;
|
|
|
10 |
import org.tela_botanica.client.modeles.publication.Publication;
|
985 |
jpm |
11 |
|
1484 |
cyprien |
12 |
import com.extjs.gxt.ui.client.data.ModelData;
|
985 |
jpm |
13 |
import com.google.gwt.json.client.JSONObject;
|
|
|
14 |
|
|
|
15 |
public class CollectionACommentaire extends aDonnee {
|
|
|
16 |
|
|
|
17 |
private static final long serialVersionUID = 8751553802444398035L;
|
|
|
18 |
public static final String PREFIXE = "ccac";
|
1484 |
cyprien |
19 |
private boolean removePrefix = true;
|
985 |
jpm |
20 |
private Commentaire commentaireLiee = null;
|
1173 |
jpm |
21 |
public static String[] champsObligatoires = {"cc_id_collection", "ccac_id_commentaire"};
|
985 |
jpm |
22 |
|
|
|
23 |
public CollectionACommentaire() {
|
|
|
24 |
initialiser(new JSONObject(), false);
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
public CollectionACommentaire(JSONObject collectionACommentaireListe) {
|
997 |
jpm |
28 |
initialiser(collectionACommentaireListe, true);
|
985 |
jpm |
29 |
}
|
|
|
30 |
|
|
|
31 |
public CollectionACommentaire(JSONObject collectionACommentaireListe, boolean chargerCommentaire) {
|
|
|
32 |
initialiser(collectionACommentaireListe, chargerCommentaire);
|
|
|
33 |
}
|
|
|
34 |
|
1484 |
cyprien |
35 |
public CollectionACommentaire(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("^"+CollectionACommentaire.PREFIXE+"_", "");
|
|
|
49 |
cleObjet = cleObjet.replaceFirst("^"+Commentaire.PREFIXE+"_", "");
|
|
|
50 |
}
|
|
|
51 |
else {
|
|
|
52 |
cleObjet = cle;
|
|
|
53 |
}
|
|
|
54 |
this.set(cleObjet, a.get(cle));
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
setCommentaire(new Commentaire(model));
|
|
|
59 |
this.set("_etat_", a.get("_etat_"));
|
|
|
60 |
this.set("_type_", a.get("_type_"));
|
|
|
61 |
}
|
|
|
62 |
|
985 |
jpm |
63 |
@Override
|
|
|
64 |
protected String getPrefixe() {
|
|
|
65 |
return PREFIXE;
|
|
|
66 |
}
|
|
|
67 |
|
1173 |
jpm |
68 |
protected String[] getChampsObligatoires() {
|
|
|
69 |
return champsObligatoires;
|
|
|
70 |
}
|
|
|
71 |
|
985 |
jpm |
72 |
private void initialiser(JSONObject collectionACommentaireListe, boolean chargerCommentaire) {
|
|
|
73 |
if (chargerCommentaire) {
|
|
|
74 |
setCommentaire(new Commentaire(collectionACommentaireListe, false));
|
|
|
75 |
} else {
|
|
|
76 |
setCommentaire(new Commentaire());
|
|
|
77 |
}
|
|
|
78 |
initialiserModele(collectionACommentaireListe);
|
|
|
79 |
initialiserChampsPourGrille();
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
// COMMENTAIRE
|
|
|
83 |
public Commentaire getCommentaire() {
|
|
|
84 |
return commentaireLiee;
|
|
|
85 |
}
|
|
|
86 |
public void setCommentaire(Commentaire commentaire) {
|
|
|
87 |
commentaireLiee = commentaire;
|
|
|
88 |
initialiserChampsPourGrille();
|
|
|
89 |
if (commentaire != null) {
|
|
|
90 |
setIdCommentaire(commentaire.getId());
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
private void initialiserChampsPourGrille() {
|
|
|
95 |
set("_type_", getType());
|
|
|
96 |
set("_titre_", getCommentaire().getTitre());
|
|
|
97 |
set("_texte_", getCommentaire().getTexte());
|
|
|
98 |
set("_ponderation_", getCommentaire().getPonderation());
|
|
|
99 |
set("_public_", getCommentaire().getPublic());
|
|
|
100 |
set("_etat_", "");
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
// ID
|
|
|
104 |
/** Génère un identifiant de CollectionACommentaire.
|
|
|
105 |
*
|
|
|
106 |
* C'est une concaténation des clés primaires de la table coel_collection_a_commentaire séparées par un tiret "-".
|
|
|
107 |
*
|
|
|
108 |
* @return identifiant unique d'une relation "collection à commentaire".
|
|
|
109 |
*/
|
|
|
110 |
public String getId() {
|
|
|
111 |
String idCollection = getIdCollection();
|
|
|
112 |
String idCommentaire = getIdCommentaire();
|
|
|
113 |
if (idCollection.equals("") && idCommentaire.equals("")) {
|
|
|
114 |
return null;
|
|
|
115 |
} else {
|
|
|
116 |
return (idCollection+"-"+idCommentaire);
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
//+---------------------------------------------------------------------------------------------------------------+
|
|
|
121 |
// CHAMPS PROVENANT de la TABLE COEL_COLLECTION_A_COMMENTAIRE
|
|
|
122 |
|
|
|
123 |
// ID COLLECTION
|
|
|
124 |
public String getIdCollection() {
|
|
|
125 |
return renvoyerValeurCorrecte("id_collection");
|
|
|
126 |
}
|
|
|
127 |
public void setIdCollection(String idCollection) {
|
|
|
128 |
set("id_collection", idCollection);
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
// ID COMENTAIRE
|
|
|
132 |
public String getIdCommentaire() {
|
|
|
133 |
return renvoyerValeurCorrecte("id_commentaire");
|
|
|
134 |
}
|
|
|
135 |
public void setIdCommentaire(String ic) {
|
|
|
136 |
set("id_commentaire", ic);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
// TRUCK TYPE
|
|
|
140 |
public String getType() {
|
|
|
141 |
return renvoyerValeurCorrecte("truk_type");
|
|
|
142 |
}
|
|
|
143 |
public void setType(String type) {
|
|
|
144 |
set("truk_type", type);
|
|
|
145 |
}
|
|
|
146 |
}
|