12 |
david |
1 |
package org.tela_botanica.client.modeles;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.client.Util;
|
|
|
4 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
|
|
5 |
import org.tela_botanica.client.observation.ObservationModele;
|
|
|
6 |
|
341 |
aurelien |
7 |
import com.google.gwt.core.client.GWT;
|
32 |
jpm |
8 |
import com.google.gwt.http.client.Request;
|
|
|
9 |
import com.google.gwt.http.client.RequestBuilder;
|
|
|
10 |
import com.google.gwt.http.client.RequestCallback;
|
|
|
11 |
import com.google.gwt.http.client.RequestException;
|
|
|
12 |
import com.google.gwt.http.client.Response;
|
203 |
david |
13 |
import com.google.gwt.http.client.URL;
|
12 |
david |
14 |
import com.google.gwt.json.client.JSONArray;
|
|
|
15 |
import com.google.gwt.json.client.JSONParser;
|
|
|
16 |
import com.google.gwt.json.client.JSONString;
|
|
|
17 |
import com.google.gwt.json.client.JSONValue;
|
61 |
jpm |
18 |
import com.google.gwt.user.client.Window;
|
12 |
david |
19 |
|
|
|
20 |
/**
|
54 |
david |
21 |
* DAO la liste des observations attachées a un observateur.
|
12 |
david |
22 |
* @author David Delon
|
20 |
david |
23 |
* TODO : se servir de ObservationDAO pour la lecture unitaire
|
12 |
david |
24 |
*
|
|
|
25 |
*/
|
|
|
26 |
public class ListeObservationAsynchroneDAO {
|
|
|
27 |
|
54 |
david |
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Le modèle associé au DAO.
|
|
|
31 |
*/
|
|
|
32 |
private ObservationModele observationModele = null;
|
|
|
33 |
|
|
|
34 |
public ListeObservationAsynchroneDAO(final ObservationModele obs) {
|
|
|
35 |
this.observationModele=obs;
|
|
|
36 |
}
|
12 |
david |
37 |
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Envoie une requete au serveur jrest pour obtenir le nombre d'observation correspondant
|
|
|
41 |
* à des critères données en paramètres
|
|
|
42 |
* @param r le rafraichissable qui demande la mise à jour
|
|
|
43 |
* @param criteres un tableau nom/valeur des critères pour les observations
|
|
|
44 |
*/
|
54 |
david |
45 |
public final void obtenirListeObservation(final Rafraichissable r, final String utilisateur, final String[][] criteres)
|
12 |
david |
46 |
{
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
String requete = "" ;
|
|
|
50 |
|
|
|
51 |
if(criteres != null)
|
|
|
52 |
{
|
|
|
53 |
// on construit les paramètres du get avec les critères (&critere1=valeur1&critere2=valeur2 etc...)
|
203 |
david |
54 |
// ils contiennent limite et taille page et autres filtres (communes , lieu dit etc ...)S
|
12 |
david |
55 |
|
|
|
56 |
for (int i = 0; i < criteres.length; i++) {
|
|
|
57 |
|
318 |
aurelien |
58 |
if(criteres[i][1] != null && !criteres[i][1].equals(""))
|
12 |
david |
59 |
{
|
|
|
60 |
if(i!= 0)
|
|
|
61 |
{
|
|
|
62 |
requete += "&";
|
|
|
63 |
}
|
203 |
david |
64 |
requete += criteres[i][0]+"="+URL.encodeComponent(criteres[i][1]) ;
|
12 |
david |
65 |
}
|
|
|
66 |
}
|
157 |
aurelien |
67 |
}
|
12 |
david |
68 |
|
32 |
jpm |
69 |
// on envoie le get asynchrone
|
116 |
aurelien |
70 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,Configuration.getServiceBaseUrl()
|
32 |
jpm |
71 |
+"/InventoryObservationList/"+utilisateur+"/"+requete) ;
|
12 |
david |
72 |
|
32 |
jpm |
73 |
try {
|
|
|
74 |
rb.sendRequest(null, new RequestCallback() {
|
|
|
75 |
|
54 |
david |
76 |
public void onError(final Request request, final Throwable exception) {
|
32 |
jpm |
77 |
// TODO Auto-generated method stub
|
12 |
david |
78 |
|
32 |
jpm |
79 |
}
|
|
|
80 |
|
54 |
david |
81 |
public void onResponseReceived(final Request request,
|
|
|
82 |
final Response response) {
|
12 |
david |
83 |
|
32 |
jpm |
84 |
final ListeObservation observationData ;
|
|
|
85 |
final JSONValue responseValue = JSONParser.parse(response.getText());
|
|
|
86 |
|
|
|
87 |
JSONArray reponse=null;
|
12 |
david |
88 |
|
32 |
jpm |
89 |
// si c'est un tableau
|
|
|
90 |
if ((reponse=responseValue.isArray()) != null) {
|
12 |
david |
91 |
|
32 |
jpm |
92 |
JSONArray observation;
|
|
|
93 |
final int taillemax = reponse.size();
|
|
|
94 |
|
|
|
95 |
observationData = new ListeObservation(taillemax);
|
|
|
96 |
|
|
|
97 |
for (int i = 0; i < taillemax; i++) {
|
20 |
david |
98 |
|
32 |
jpm |
99 |
if ((observation=reponse.get(i).isArray()) != null) {
|
|
|
100 |
|
|
|
101 |
String transmis=((JSONString) observation.get(13)).stringValue();
|
|
|
102 |
String identifiantLocalite=((JSONString) observation.get(14)).toString();
|
|
|
103 |
String nomSaisi=Util.toCelString(((JSONString) observation.get(0)).toString());
|
|
|
104 |
String nomRetenu=Util.toCelString(((JSONString) observation.get(2)).toString());
|
|
|
105 |
String numeroNomenclaturalSaisi=((JSONString) observation.get(1)).stringValue();
|
|
|
106 |
String numeroNomenclaturalRetenu=((JSONString) observation.get(3)).stringValue();
|
|
|
107 |
String numeroTaxonomique=((JSONString) observation.get(4)).stringValue();
|
|
|
108 |
String famille=Util.toCelString(((JSONString) observation .get(5)).toString());
|
|
|
109 |
String localite=Util.toCelString(((JSONString) observation .get(6)).toString());
|
|
|
110 |
String lieudit=Util.toCelString(((JSONString) observation .get(9)).toString());
|
|
|
111 |
String station=Util.toCelString(((JSONString) observation .get(10)).toString());
|
|
|
112 |
String milieu=Util.toCelString(((JSONString) observation .get(11)).toString());
|
|
|
113 |
String commentaire=Util.toCelString(((JSONString) observation .get(12)).toString());
|
|
|
114 |
String date=((JSONString) observation .get(8)).stringValue();
|
|
|
115 |
String numeroOrdre=((JSONString) observation.get(7)).stringValue();
|
266 |
aurelien |
116 |
String coordX=((JSONString) observation.get(15)).stringValue();
|
|
|
117 |
String coordY=((JSONString) observation.get(16)).stringValue();
|
341 |
aurelien |
118 |
String motsCles=((JSONString) observation.get(17)).stringValue();
|
32 |
jpm |
119 |
|
157 |
aurelien |
120 |
Observation obs=new Observation(transmis, nomSaisi, nomRetenu, numeroNomenclaturalSaisi, numeroNomenclaturalRetenu ,numeroTaxonomique, famille, localite, identifiantLocalite, lieudit, station, milieu, commentaire, date, numeroOrdre/*, motsCles*/);
|
266 |
aurelien |
121 |
obs.setCoordonneeX(coordX);
|
|
|
122 |
obs.setCoordonneeY(coordY);
|
341 |
aurelien |
123 |
obs.setMotsCles(motsCles);
|
32 |
jpm |
124 |
observationData.put(obs.getNumeroOrdre(),obs);
|
44 |
david |
125 |
|
|
|
126 |
|
32 |
jpm |
127 |
}
|
12 |
david |
128 |
}
|
32 |
jpm |
129 |
} else {
|
|
|
130 |
|
|
|
131 |
observationData = new ListeObservation(0) ;
|
12 |
david |
132 |
}
|
32 |
jpm |
133 |
|
|
|
134 |
// dans tous les cas on transmet la liste crée au rafraichissable en lui demandant de répandre les données car il est
|
|
|
135 |
// le premier à les recevoir
|
65 |
david |
136 |
|
|
|
137 |
// TODO : ce n'est pas ici qu'on devrait le decider ..
|
|
|
138 |
r.rafraichir(observationData,true);
|
32 |
jpm |
139 |
}
|
|
|
140 |
}) ;
|
|
|
141 |
|
|
|
142 |
} catch (RequestException e) {
|
|
|
143 |
// TODO Auto-generated catch block
|
|
|
144 |
e.printStackTrace();
|
|
|
145 |
}
|
12 |
david |
146 |
}
|
217 |
aurelien |
147 |
|
|
|
148 |
public void modifierEnMasse(final Rafraichissable r, String identifiant,
|
|
|
149 |
final Observation obs) {
|
107 |
aurelien |
150 |
|
217 |
aurelien |
151 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,Configuration.getServiceBaseUrl()+ "/InventoryObservationList/" + identifiant + "/" + obs.getNumeroOrdre()+ "/") ;
|
|
|
152 |
|
|
|
153 |
String postData = "identifiant="
|
|
|
154 |
+ identifiant ;
|
|
|
155 |
if(obs.getNomSaisi() != null) {
|
|
|
156 |
postData += "&nom_sel=" + URL.encodeComponent(obs.getNomSaisi());
|
|
|
157 |
}
|
220 |
aurelien |
158 |
if(obs.getNumeroNomenclaturalSaisi() != null) {
|
|
|
159 |
postData += "&num_nom_sel=" + obs.getNumeroNomenclaturalSaisi();
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
if(obs.getIdentifiantLocalite() != null) {
|
|
|
163 |
postData += "&id_location=" + obs.getIdentifiantLocalite();
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
if(obs.getLocalite() != null) {
|
|
|
167 |
postData += "&location=" + URL.encodeComponent(obs.getLocalite());
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
if(obs.getDate() != null) {
|
|
|
171 |
postData += "&date_observation=" + obs.getDate();
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
if(obs.getLieudit() != null) {
|
|
|
175 |
postData += "&lieudit="+ URL.encodeComponent(obs.getLieudit());
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
if(obs.getStation() != null) {
|
|
|
179 |
postData += "&station="+ URL.encodeComponent(obs.getStation());
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
if(obs.getMilieu() != null) {
|
|
|
183 |
postData += "&milieu="+ URL.encodeComponent(obs.getMilieu());
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
if(obs.getCommentaire() != null) {
|
|
|
187 |
postData += "&commentaire="+URL.encodeComponent(""+obs.getCommentaire());
|
|
|
188 |
}
|
266 |
aurelien |
189 |
|
272 |
aurelien |
190 |
if(obs.getCoordonneeX() != null ) {
|
266 |
aurelien |
191 |
postData += "&coord_x="+URL.encodeComponent(""+obs.getCoordonneeX());
|
272 |
aurelien |
192 |
}
|
|
|
193 |
|
|
|
194 |
if(obs.getCoordonneeY() != null) {
|
266 |
aurelien |
195 |
postData += "&coord_y="+URL.encodeComponent(""+obs.getCoordonneeY());
|
|
|
196 |
}
|
|
|
197 |
|
358 |
aurelien |
198 |
if(obs.getMotsCles() != null) {
|
|
|
199 |
postData += "&mots_cles="+URL.encodeComponent(obs.getMotsCles()) ;
|
|
|
200 |
}
|
|
|
201 |
|
217 |
aurelien |
202 |
try {
|
|
|
203 |
|
|
|
204 |
rb.sendRequest(postData, new RequestCallback() {
|
|
|
205 |
|
|
|
206 |
public void onError(Request request, Throwable exception) {
|
|
|
207 |
// TODO Auto-generated method stub
|
|
|
208 |
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
public void onResponseReceived(Request request,
|
|
|
212 |
Response response) {
|
|
|
213 |
|
|
|
214 |
observationModele.obtenirListeObservation(r);
|
|
|
215 |
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
}) ;
|
|
|
220 |
|
|
|
221 |
} catch (RequestException e) {
|
|
|
222 |
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
}
|
|
|
226 |
|
107 |
aurelien |
227 |
/**
|
|
|
228 |
* Supprime les observations possédant les identifiants données
|
|
|
229 |
* @param r le rafraichissable à avertir de la mise à jour
|
|
|
230 |
* @param identifiant l'identifiant utilisateur
|
|
|
231 |
* @param numerosOrdre les numéros d'ordre des observations séparés par des virgules
|
|
|
232 |
*/
|
|
|
233 |
public void supprimerListeObservation(Rafraichissable r, String identifiant, String numerosOrdre) {
|
|
|
234 |
|
|
|
235 |
String postData = "";
|
|
|
236 |
postData += "&action=DELETE";
|
|
|
237 |
|
|
|
238 |
// on envoie un post avec l'id de l'image à supprimer
|
|
|
239 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,
|
|
|
240 |
Configuration.getServiceBaseUrl()
|
|
|
241 |
+ "/inventoryObservationList/"
|
|
|
242 |
+ identifiant
|
|
|
243 |
+ "/"
|
|
|
244 |
+ numerosOrdre);
|
|
|
245 |
|
|
|
246 |
try {
|
|
|
247 |
rb.sendRequest(postData, new RequestCallback() {
|
|
|
248 |
|
|
|
249 |
public void onError(Request request, Throwable exception) {
|
|
|
250 |
// TODO Auto-generated method stub
|
|
|
251 |
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
public void onResponseReceived(Request request,
|
|
|
255 |
Response response) {
|
|
|
256 |
|
|
|
257 |
if (response.getText().equals("OK")) {
|
|
|
258 |
|
|
|
259 |
|
|
|
260 |
} else {
|
|
|
261 |
com.google.gwt.user.client.Window
|
|
|
262 |
.alert("Problème lors de la mise à jour des données");
|
|
|
263 |
return ;
|
|
|
264 |
}
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
});
|
|
|
268 |
|
|
|
269 |
r.rafraichir("OK", true) ;
|
|
|
270 |
|
|
|
271 |
} catch (RequestException e) {
|
|
|
272 |
// TODO Auto-generated catch block
|
|
|
273 |
e.printStackTrace();
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
}
|
12 |
david |
277 |
|
|
|
278 |
}
|