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