121 |
jpm |
1 |
package org.tela_botanica.client.modeles;
|
|
|
2 |
|
770 |
jpm |
3 |
import org.tela_botanica.client.Mediateur;
|
121 |
jpm |
4 |
import org.tela_botanica.client.RegistreId;
|
770 |
jpm |
5 |
import org.tela_botanica.client.http.JsonRestRequestBuilder;
|
|
|
6 |
import org.tela_botanica.client.http.JsonRestRequestCallback;
|
121 |
jpm |
7 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
770 |
jpm |
8 |
import org.tela_botanica.client.util.UtilDAO;
|
121 |
jpm |
9 |
|
|
|
10 |
import com.extjs.gxt.ui.client.Registry;
|
133 |
jpm |
11 |
import com.google.gwt.core.client.GWT;
|
121 |
jpm |
12 |
import com.google.gwt.http.client.URL;
|
|
|
13 |
import com.google.gwt.json.client.JSONArray;
|
156 |
jp_milcent |
14 |
import com.google.gwt.json.client.JSONObject;
|
121 |
jpm |
15 |
import com.google.gwt.json.client.JSONValue;
|
|
|
16 |
|
|
|
17 |
public class StructureAsyncDao {
|
268 |
jp_milcent |
18 |
private static final String SERVICE_NOM = "CoelStructure";
|
264 |
jp_milcent |
19 |
|
770 |
jpm |
20 |
private String utilisateurId = null;
|
|
|
21 |
private Rafraichissable vueARafraichir = null;
|
|
|
22 |
|
|
|
23 |
public StructureAsyncDao(Rafraichissable vue) {
|
|
|
24 |
vueARafraichir = vue;
|
|
|
25 |
utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
public void selectionner(final String projetId, final String structureId) {
|
|
|
29 |
String[] parametres = {projetId, structureId};
|
|
|
30 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
|
|
|
31 |
rb.envoyerRequete(null, new JsonRestRequestCallback() {
|
|
|
32 |
@Override
|
|
|
33 |
public void surReponse(JSONValue responseValue) {
|
|
|
34 |
if (responseValue != null) {
|
|
|
35 |
Information info = new Information("selection_structure");
|
|
|
36 |
// Si la requête est un succès, reception d'un objet ou d'un tableau
|
|
|
37 |
if (responseValue.isObject() != null) {
|
|
|
38 |
final JSONObject reponse = responseValue.isObject();
|
|
|
39 |
Structure structure = new Structure(reponse);
|
|
|
40 |
StructureConservation structureConservation = new StructureConservation(reponse);
|
|
|
41 |
StructureValorisation structureValorisation = new StructureValorisation(reponse);
|
|
|
42 |
info.setDonnee(0, structure);
|
|
|
43 |
info.setDonnee(1, structureConservation);
|
|
|
44 |
info.setDonnee(2, structureValorisation);
|
|
|
45 |
vueARafraichir.rafraichir(info);
|
|
|
46 |
} else if (responseValue.isArray() != null) {
|
|
|
47 |
final JSONArray reponse = responseValue.isArray();
|
|
|
48 |
StructureListe structures = new StructureListe(reponse);
|
|
|
49 |
vueARafraichir.rafraichir(structures);
|
|
|
50 |
} else {
|
|
|
51 |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un objet ou un talbeau JSON et vaut : "+responseValue.toString(), null);
|
|
|
52 |
}
|
|
|
53 |
} else {
|
|
|
54 |
if (structureId == null) {
|
|
|
55 |
// Dans le cas, où nous demandons toutes les institutions et qu'il n'y en a pas, nous retournons un objet vide
|
|
|
56 |
StructureListe structures = new StructureListe(0);
|
|
|
57 |
vueARafraichir.rafraichir(structures);
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
}
|
|
|
61 |
});
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
public void ajouter(final Structure str, StructureConservation conservation, StructureValorisation valorisation) {
|
|
|
65 |
String postDonneesEncodees = construirePost(null, str, conservation, valorisation);
|
156 |
jp_milcent |
66 |
|
770 |
jpm |
67 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM);
|
|
|
68 |
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
|
|
|
69 |
@Override
|
|
|
70 |
public void surReponse(JSONValue responseValue) {
|
|
|
71 |
if (responseValue.isString() != null) {
|
|
|
72 |
Information info = new Information("ajout_structure");
|
|
|
73 |
String structureIdOuMessage = responseValue.isString().stringValue();
|
|
|
74 |
if (structureIdOuMessage.matches("^[0-9]+$")) {
|
|
|
75 |
info.setDonnee(structureIdOuMessage);
|
156 |
jp_milcent |
76 |
} else {
|
770 |
jpm |
77 |
info.setMessage(structureIdOuMessage);
|
156 |
jp_milcent |
78 |
}
|
770 |
jpm |
79 |
vueARafraichir.rafraichir(info);
|
|
|
80 |
} else {
|
|
|
81 |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
|
156 |
jp_milcent |
82 |
}
|
770 |
jpm |
83 |
}
|
|
|
84 |
});
|
156 |
jp_milcent |
85 |
}
|
770 |
jpm |
86 |
|
|
|
87 |
public void modifier(String structureId, Structure str, StructureConservation conservation, StructureValorisation valorisation) {
|
|
|
88 |
String postDonneesEncodees = construirePost(structureId, str, conservation, valorisation);
|
|
|
89 |
|
772 |
jpm |
90 |
String[] parametres = {structureId};
|
|
|
91 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
|
|
|
92 |
rb.envoyerRequete(postDonneesEncodees, new JsonRestRequestCallback() {
|
|
|
93 |
@Override
|
|
|
94 |
public void surReponse(JSONValue responseValue) {
|
|
|
95 |
// Si la requête est un succès, reception d'une chaine
|
|
|
96 |
if (responseValue.isString() != null) {
|
|
|
97 |
Information info = new Information("modif_structure");
|
|
|
98 |
info.setMessage(responseValue.isString().stringValue());
|
|
|
99 |
vueARafraichir.rafraichir(info);
|
|
|
100 |
} else {
|
|
|
101 |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
|
121 |
jpm |
102 |
}
|
772 |
jpm |
103 |
}
|
|
|
104 |
});
|
121 |
jpm |
105 |
}
|
770 |
jpm |
106 |
|
772 |
jpm |
107 |
public void supprimer(String structuresId) {
|
|
|
108 |
String[] parametres = {utilisateurId, structuresId};
|
|
|
109 |
final JsonRestRequestBuilder rb = UtilDAO.construireRequetePost(SERVICE_NOM, parametres);
|
|
|
110 |
rb.envoyerRequeteSuppression(new JsonRestRequestCallback() {
|
|
|
111 |
@Override
|
|
|
112 |
public void surReponse(JSONValue responseValue) {
|
|
|
113 |
if (responseValue.isString() != null) {
|
|
|
114 |
Information info = new Information("suppression_structure");
|
|
|
115 |
info.setMessage(responseValue.isString().stringValue());
|
|
|
116 |
vueARafraichir.rafraichir(info);
|
|
|
117 |
} else {
|
|
|
118 |
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas une chaine JSON.", null);
|
133 |
jpm |
119 |
}
|
772 |
jpm |
120 |
}
|
|
|
121 |
});
|
133 |
jpm |
122 |
}
|
169 |
jp_milcent |
123 |
|
770 |
jpm |
124 |
private String construirePost(String structureId, Structure str, StructureConservation conservation, StructureValorisation valorisation) {
|
602 |
jp_milcent |
125 |
String postDonnees = "cmhl_ce_modifier_par=" + URL.encodeComponent(utilisateurId);
|
|
|
126 |
if (str != null) {
|
612 |
jp_milcent |
127 |
if (structureId != null) {
|
|
|
128 |
postDonnees += "&cs_id_structure=" + URL.encodeComponent(structureId);
|
|
|
129 |
}
|
602 |
jp_milcent |
130 |
postDonnees += "&cs_ce_projet=" + URL.encodeComponent(str.getIdProjet()) +
|
|
|
131 |
"&cs_ce_mere=" + URL.encodeComponent(str.getIdMere()) +
|
|
|
132 |
"&cs_guid=" + URL.encodeComponent(str.getGuid()) +
|
|
|
133 |
"&cs_truk_identifiant_alternatif=" + URL.encodeComponent(str.getIdAlternatif()) +
|
|
|
134 |
"&cs_nom=" + URL.encodeComponent(str.getNom()) +
|
|
|
135 |
"&cs_truk_nom_alternatif=" + URL.encodeComponent(str.getNomAlternatif()) +
|
|
|
136 |
"&cs_ce_type=" + URL.encodeComponent(str.getType()) +
|
|
|
137 |
"&cs_ce_truk_type_prive=" + URL.encodeComponent(str.getTypePrive()) +
|
|
|
138 |
"&cs_ce_truk_type_public=" + URL.encodeComponent(str.getTypePublic()) +
|
|
|
139 |
"&cs_adresse_01=" + URL.encodeComponent(str.getAdresse()) +
|
|
|
140 |
"&cs_adresse_02=" + URL.encodeComponent(str.getAdresseComplement()) +
|
|
|
141 |
"&cs_date_fondation=" + URL.encodeComponent(str.getDateFondationFormatMysql()) +
|
|
|
142 |
"&cs_code_postal=" + URL.encodeComponent(str.getCodePostal()) +
|
|
|
143 |
"&cs_ville=" + URL.encodeComponent(str.getVille()) +
|
|
|
144 |
"&cs_ce_truk_region=" + URL.encodeComponent(str.getRegion()) +
|
|
|
145 |
"&cs_ce_truk_pays=" + URL.encodeComponent(str.getPays()) +
|
|
|
146 |
"&cs_truk_telephone=" + URL.encodeComponent(str.getTelephone()) +
|
|
|
147 |
"&cs_truk_url=" + URL.encodeComponent(str.getUrl()) +
|
|
|
148 |
"&cs_nbre_personne=" + URL.encodeComponent(Integer.toString(str.getNbrePersonne()));
|
|
|
149 |
}
|
|
|
150 |
if (conservation != null) {
|
612 |
jp_milcent |
151 |
if (structureId != null) {
|
|
|
152 |
postDonnees += "&csc_id_structure=" + URL.encodeComponent(structureId);
|
|
|
153 |
}
|
602 |
jp_milcent |
154 |
postDonnees += "&csc_mark_formation=" + URL.encodeComponent(conservation.getFormation()) +
|
|
|
155 |
"&csc_formation=" + URL.encodeComponent(conservation.getFormationInfo()) +
|
|
|
156 |
"&csc_mark_formation_interet=" + URL.encodeComponent(conservation.getFormationInteret()) +
|
|
|
157 |
"&csc_truk_stockage_local=" + URL.encodeComponent(conservation.getStockageLocal()) +
|
|
|
158 |
"&csc_truk_stockage_meuble=" + URL.encodeComponent(conservation.getStockageMeuble()) +
|
|
|
159 |
"&csc_truk_stockage_parametre=" + URL.encodeComponent(conservation.getStockageParametre()) +
|
|
|
160 |
"&csc_mark_collection_commune=" + URL.encodeComponent(conservation.getCollectionCommune()) +
|
|
|
161 |
"&csc_truk_collection_autre=" + URL.encodeComponent(conservation.getCollectionAutre()) +
|
|
|
162 |
"&csc_mark_acces_controle=" + URL.encodeComponent(conservation.getAccesControle()) +
|
|
|
163 |
"&csc_mark_restauration=" + URL.encodeComponent(conservation.getRestauration()) +
|
|
|
164 |
"&csc_truk_restauration_operation=" + URL.encodeComponent(conservation.getRestaurationOperation()) +
|
|
|
165 |
"&csc_ce_materiel_conservation=" + URL.encodeComponent(conservation.getMaterielConservation()) +
|
|
|
166 |
"&csc_truk_materiel_autre=" + URL.encodeComponent(conservation.getMaterielAutre()) +
|
|
|
167 |
"&csc_mark_traitement=" + URL.encodeComponent(conservation.getTraitement()) +
|
|
|
168 |
"&csc_truk_traitement=" + URL.encodeComponent(conservation.getTraitements()) +
|
|
|
169 |
"&csc_mark_acquisition_collection=" + URL.encodeComponent(conservation.getAcquisitionCollection()) +
|
|
|
170 |
"&csc_mark_acquisition_echantillon=" + URL.encodeComponent(conservation.getAcquisitionEchantillon()) +
|
|
|
171 |
"&csc_mark_acquisition_traitement=" + URL.encodeComponent(conservation.getAcquisitionTraitement()) +
|
|
|
172 |
"&csc_truk_acquisition_traitement_poison=" + URL.encodeComponent(conservation.getAcquisitionTraitementPoison()) +
|
|
|
173 |
"&csc_truk_acquisition_traitement_insecte=" + URL.encodeComponent(conservation.getAcquisitionTraitementInsecte());
|
|
|
174 |
}
|
|
|
175 |
if (valorisation != null) {
|
612 |
jp_milcent |
176 |
if (structureId != null) {
|
632 |
jp_milcent |
177 |
postDonnees += "&csv_id_structure=" + URL.encodeComponent(structureId);
|
612 |
jp_milcent |
178 |
}
|
602 |
jp_milcent |
179 |
postDonnees += "&csv_mark_action=" + URL.encodeComponent(valorisation.getAction()) +
|
|
|
180 |
"&csv_truk_action=" + URL.encodeComponent(valorisation.getActionInfo()) +
|
|
|
181 |
"&csv_publication=" + URL.encodeComponent(valorisation.getPublication()) +
|
|
|
182 |
"&csv_collection_autre=" + URL.encodeComponent(valorisation.getCollectionAutre()) +
|
|
|
183 |
"&csv_mark_action_future=" + URL.encodeComponent(valorisation.getActionFuture()) +
|
|
|
184 |
"&csv_action_future=" + URL.encodeComponent(valorisation.getActionFutureInfo()) +
|
|
|
185 |
"&csv_mark_recherche=" + URL.encodeComponent(valorisation.getRecherche()) +
|
|
|
186 |
"&csv_truk_recherche_provenance=" + URL.encodeComponent(valorisation.getRechercheProvenance()) +
|
|
|
187 |
"&csv_truk_recherche_type=" + URL.encodeComponent(valorisation.getRechercheType()) +
|
|
|
188 |
"&csv_mark_acces_ss_motif=" + URL.encodeComponent(valorisation.getAccesSansMotif()) +
|
|
|
189 |
"&csv_acces_ss_motif=" + URL.encodeComponent(valorisation.getAccesSansMotifInfo()) +
|
|
|
190 |
"&csv_mark_visite_avec_motif=" + URL.encodeComponent(valorisation.getVisiteAvecMotif()) +
|
|
|
191 |
"&csv_visite_avec_motif=" + URL.encodeComponent(valorisation.getVisiteAvecMotifInfo());
|
|
|
192 |
}
|
|
|
193 |
return postDonnees;
|
|
|
194 |
}
|
121 |
jpm |
195 |
}
|