5 |
aperonnet |
1 |
package org.tela_botanica.client.modeles;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.client.image.ImageModele;
|
|
|
4 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
94 |
jpm |
5 |
import org.tela_botanica.client.observation.ObservationModele;
|
730 |
aurelien |
6 |
import org.tela_botanica.client.util.Util;
|
5 |
aperonnet |
7 |
|
596 |
aurelien |
8 |
import com.google.gwt.core.client.GWT;
|
5 |
aperonnet |
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;
|
94 |
jpm |
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;
|
5 |
aperonnet |
18 |
import com.google.gwt.user.client.Window;
|
|
|
19 |
|
|
|
20 |
public class LienImageAsynchroneDAO {
|
|
|
21 |
|
|
|
22 |
private ImageModele iModele = null ;
|
|
|
23 |
|
94 |
jpm |
24 |
private ObservationModele oModele = null ;
|
|
|
25 |
|
|
|
26 |
private Rafraichissable raf = null ;
|
|
|
27 |
|
5 |
aperonnet |
28 |
public LienImageAsynchroneDAO(ImageModele im) {
|
|
|
29 |
iModele = im;
|
|
|
30 |
}
|
94 |
jpm |
31 |
|
|
|
32 |
public LienImageAsynchroneDAO(ObservationModele om) {
|
|
|
33 |
oModele = om;
|
|
|
34 |
}
|
5 |
aperonnet |
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Setteur pour le modèle
|
|
|
38 |
*
|
|
|
39 |
* @param im
|
|
|
40 |
* le modèle à associer
|
|
|
41 |
*/
|
|
|
42 |
public void setIModele(ImageModele im) {
|
|
|
43 |
iModele = im;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
public void obtenirLiaisonsImagesObservations(Rafraichissable r,String id)
|
|
|
47 |
{
|
|
|
48 |
String paramGet = "&coi_ce_image="+id ;
|
99 |
jpm |
49 |
|
|
|
50 |
raf = r ;
|
|
|
51 |
|
5 |
aperonnet |
52 |
// et on envoie ça au serveur
|
104 |
jpm |
53 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl()
|
5 |
aperonnet |
54 |
+ "/inventoryImageLink/" + iModele.getIdentifiant() + "/" + paramGet);
|
62 |
jpm |
55 |
try {
|
|
|
56 |
rb.sendRequest(null, new RequestCallback() {
|
|
|
57 |
|
|
|
58 |
public void onError(Request request, Throwable exception) {
|
|
|
59 |
// TODO Auto-generated method stub
|
|
|
60 |
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
public void onResponseReceived(Request request,
|
|
|
64 |
Response response) {
|
|
|
65 |
|
99 |
jpm |
66 |
final ListeObservation observationData ;
|
|
|
67 |
final JSONValue responseValue = JSONParser.parse(response.getText());
|
|
|
68 |
|
|
|
69 |
JSONArray reponse=null;
|
|
|
70 |
|
|
|
71 |
// si c'est un tableau
|
|
|
72 |
if ((reponse=responseValue.isArray()) != null) {
|
|
|
73 |
|
|
|
74 |
JSONArray observation;
|
|
|
75 |
final int taillemax = reponse.size();
|
|
|
76 |
|
|
|
77 |
observationData = new ListeObservation(taillemax);
|
|
|
78 |
|
|
|
79 |
for (int i = 0; i < taillemax; i++) {
|
|
|
80 |
|
|
|
81 |
if ((observation=reponse.get(i).isArray()) != null) {
|
|
|
82 |
|
|
|
83 |
String transmis=((JSONString) observation.get(13)).stringValue();
|
|
|
84 |
String identifiantLocalite=((JSONString) observation.get(14)).toString();
|
|
|
85 |
String nomSaisi=Util.toCelString(((JSONString) observation.get(0)).toString());
|
|
|
86 |
String nomRetenu=Util.toCelString(((JSONString) observation.get(2)).toString());
|
|
|
87 |
String numeroNomenclaturalSaisi=((JSONString) observation.get(1)).stringValue();
|
|
|
88 |
String numeroNomenclaturalRetenu=((JSONString) observation.get(3)).stringValue();
|
|
|
89 |
String numeroTaxonomique=((JSONString) observation.get(4)).stringValue();
|
|
|
90 |
String famille=Util.toCelString(((JSONString) observation .get(5)).toString());
|
|
|
91 |
String localite=Util.toCelString(((JSONString) observation .get(6)).toString());
|
|
|
92 |
String lieudit=Util.toCelString(((JSONString) observation .get(9)).toString());
|
|
|
93 |
String station=Util.toCelString(((JSONString) observation .get(10)).toString());
|
|
|
94 |
String milieu=Util.toCelString(((JSONString) observation .get(11)).toString());
|
|
|
95 |
String commentaire=Util.toCelString(((JSONString) observation .get(12)).toString());
|
|
|
96 |
String date=((JSONString) observation .get(8)).stringValue();
|
|
|
97 |
String numeroOrdre=((JSONString) observation.get(7)).stringValue();
|
|
|
98 |
|
127 |
aurelien |
99 |
Observation obs=new Observation(transmis, nomSaisi, nomRetenu, numeroNomenclaturalSaisi, numeroNomenclaturalRetenu ,numeroTaxonomique, famille, localite, identifiantLocalite, lieudit, station, milieu, commentaire, date, numeroOrdre);
|
99 |
jpm |
100 |
|
107 |
aurelien |
101 |
observationData.put(obs.getNumeroOrdre(),obs);
|
|
|
102 |
}
|
99 |
jpm |
103 |
}
|
|
|
104 |
} else {
|
|
|
105 |
|
|
|
106 |
observationData = new ListeObservation(0) ;
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
// dans tous les cas on transmet la liste crée au rafraichissable en lui demandant de répandre les données car il est
|
|
|
110 |
// le premier à les recevoir
|
|
|
111 |
|
|
|
112 |
// TODO : ce n'est pas ici qu'on devrait le decider ..
|
|
|
113 |
raf.rafraichir(observationData,true);
|
62 |
jpm |
114 |
}
|
|
|
115 |
});
|
|
|
116 |
|
|
|
117 |
} catch (RequestException e) {
|
|
|
118 |
// TODO Auto-generated catch block
|
|
|
119 |
e.printStackTrace();
|
|
|
120 |
}
|
5 |
aperonnet |
121 |
}
|
|
|
122 |
|
94 |
jpm |
123 |
public void obtenirLiaisonsObservationsImages(Rafraichissable r,String idObs, String utilisateur)
|
|
|
124 |
{
|
|
|
125 |
String paramGet = "&coi_ce_observation="+idObs ;
|
|
|
126 |
raf = r ;
|
|
|
127 |
|
|
|
128 |
// et on envoie ça au serveur
|
104 |
jpm |
129 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl()
|
94 |
jpm |
130 |
+ "/inventoryImageLink/" + utilisateur + "/" + paramGet);
|
|
|
131 |
try {
|
|
|
132 |
rb.sendRequest(null, new RequestCallback() {
|
|
|
133 |
|
|
|
134 |
public void onError(Request request, Throwable exception) {
|
|
|
135 |
// TODO Auto-generated method stub
|
|
|
136 |
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
public void onResponseReceived(Request request,
|
|
|
140 |
Response response) {
|
|
|
141 |
|
104 |
jpm |
142 |
String baseUrl = Configuration.getImageBaseUrl() ;
|
94 |
jpm |
143 |
|
|
|
144 |
final JSONValue responseValue = JSONParser.parse(response
|
|
|
145 |
.getText());
|
|
|
146 |
// si c'est un tableau
|
|
|
147 |
if (responseValue.isArray() != null) {
|
|
|
148 |
|
|
|
149 |
final JSONArray reponse = responseValue.isArray();
|
|
|
150 |
|
|
|
151 |
final int taillemax = reponse.size();
|
|
|
152 |
|
210 |
aurelien |
153 |
String imgTab[][] = new String[taillemax][3] ;
|
94 |
jpm |
154 |
|
|
|
155 |
for(int i = 0 ;i<taillemax ;i++)
|
|
|
156 |
{
|
|
|
157 |
|
|
|
158 |
final JSONArray reponseInt = reponse.get(i).isArray();
|
|
|
159 |
String idImg = ((JSONString)reponseInt.get(0)).stringValue() ;
|
210 |
aurelien |
160 |
String X = ((JSONString)reponseInt.get(1)).stringValue() ;
|
|
|
161 |
String Y = ((JSONString)reponseInt.get(2)).stringValue() ;
|
|
|
162 |
imgTab[i][0] = idImg ;
|
|
|
163 |
imgTab[i][1] = X ;
|
|
|
164 |
imgTab[i][2] = Y ;
|
94 |
jpm |
165 |
|
|
|
166 |
}
|
|
|
167 |
|
104 |
jpm |
168 |
raf.rafraichir(imgTab, false) ;
|
94 |
jpm |
169 |
}
|
|
|
170 |
else
|
|
|
171 |
{
|
104 |
jpm |
172 |
String imgTab[] = new String[0] ;
|
|
|
173 |
raf.rafraichir(imgTab, false) ;
|
94 |
jpm |
174 |
}
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
});
|
|
|
178 |
|
|
|
179 |
} catch (RequestException e) {
|
|
|
180 |
// TODO Auto-generated catch block
|
|
|
181 |
e.printStackTrace();
|
|
|
182 |
}
|
|
|
183 |
}
|
|
|
184 |
|
5 |
aperonnet |
185 |
public void lierImageBaseDeDonnees(String idsImages, String idsObs) {
|
|
|
186 |
|
|
|
187 |
String postData = "";
|
|
|
188 |
|
|
|
189 |
postData += "&coi_ce_image="+idsImages ;
|
|
|
190 |
postData += "&coi_ce_observation="+idsObs ;
|
|
|
191 |
postData += "&identifiant="+iModele.getIdentifiant() ;
|
|
|
192 |
|
|
|
193 |
// et on envoie ça au serveur
|
104 |
jpm |
194 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, Configuration.getServiceBaseUrl()
|
5 |
aperonnet |
195 |
+ "/inventoryImageLink/");
|
210 |
aurelien |
196 |
try {
|
|
|
197 |
rb.sendRequest(postData, new RequestCallback() {
|
|
|
198 |
|
|
|
199 |
public void onError(Request request, Throwable exception) {
|
|
|
200 |
// TODO Auto-generated method stub
|
|
|
201 |
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
public void onResponseReceived(Request request,
|
|
|
205 |
Response response) {
|
|
|
206 |
|
398 |
aurelien |
207 |
iModele.requeteTerminee();
|
210 |
aurelien |
208 |
|
|
|
209 |
}
|
|
|
210 |
});
|
|
|
211 |
|
|
|
212 |
} catch (RequestException e) {
|
|
|
213 |
// TODO Auto-generated catch block
|
|
|
214 |
e.printStackTrace();
|
5 |
aperonnet |
215 |
}
|
|
|
216 |
}
|
104 |
jpm |
217 |
|
|
|
218 |
public void supprimerLienImageObservation(String idImg, String idObs) {
|
|
|
219 |
|
|
|
220 |
String postData = "";
|
|
|
221 |
|
|
|
222 |
postData += "&action=DELETE" ;
|
|
|
223 |
String identifiant = "" ;
|
|
|
224 |
|
|
|
225 |
if(iModele == null) {
|
|
|
226 |
identifiant = oModele.getIdentifiant() ; ;
|
|
|
227 |
}
|
|
|
228 |
else
|
|
|
229 |
{
|
|
|
230 |
identifiant = iModele.getIdentifiant() ;
|
|
|
231 |
}
|
596 |
aurelien |
232 |
|
104 |
jpm |
233 |
// et on envoie ça au serveur
|
|
|
234 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, Configuration.getServiceBaseUrl()
|
|
|
235 |
+ "/inventoryImageLink/"+identifiant+"/"+idImg+"/"+idObs);
|
|
|
236 |
|
|
|
237 |
try {
|
|
|
238 |
rb.sendRequest(postData, new RequestCallback() {
|
|
|
239 |
|
|
|
240 |
public void onError(Request request, Throwable exception) {
|
|
|
241 |
// TODO Auto-generated method stub
|
|
|
242 |
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
public void onResponseReceived(Request request,
|
|
|
246 |
Response response) {
|
|
|
247 |
|
|
|
248 |
// quand la requête est éxecutée on le signale au modèle
|
|
|
249 |
// poru qu'il mette à jour les données
|
|
|
250 |
// et en notifie le médiateur
|
411 |
aurelien |
251 |
iModele.requeteTerminee();
|
104 |
jpm |
252 |
|
|
|
253 |
}
|
|
|
254 |
});
|
|
|
255 |
|
|
|
256 |
} catch (RequestException e) {
|
|
|
257 |
// TODO Auto-generated catch block
|
|
|
258 |
e.printStackTrace();
|
|
|
259 |
}
|
|
|
260 |
}
|
5 |
aperonnet |
261 |
}
|