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