69 |
jpm |
1 |
package org.tela_botanica.client.modeles;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.client.RegistreId;
|
|
|
4 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
299 |
gduche |
5 |
import org.tela_botanica.client.util.UtilDAO;
|
69 |
jpm |
6 |
|
|
|
7 |
import com.google.gwt.http.client.Request;
|
|
|
8 |
import com.google.gwt.http.client.RequestBuilder;
|
|
|
9 |
import com.google.gwt.http.client.RequestCallback;
|
|
|
10 |
import com.google.gwt.http.client.RequestException;
|
|
|
11 |
import com.google.gwt.http.client.Response;
|
|
|
12 |
import com.google.gwt.json.client.JSONArray;
|
91 |
jpm |
13 |
import com.google.gwt.json.client.JSONObject;
|
69 |
jpm |
14 |
import com.google.gwt.json.client.JSONParser;
|
91 |
jpm |
15 |
import com.google.gwt.json.client.JSONString;
|
69 |
jpm |
16 |
import com.google.gwt.json.client.JSONValue;
|
|
|
17 |
|
|
|
18 |
public class ValeurListeAsyncDao {
|
268 |
jp_milcent |
19 |
private static final String SERVICE_NOM = "CoelValeurListe";
|
69 |
jpm |
20 |
|
268 |
jp_milcent |
21 |
private Rafraichissable vue = null;
|
69 |
jpm |
22 |
|
268 |
jp_milcent |
23 |
public ValeurListeAsyncDao() {
|
|
|
24 |
// TODO Auto-generated constructor stub
|
69 |
jpm |
25 |
}
|
|
|
26 |
|
268 |
jp_milcent |
27 |
public ValeurListeAsyncDao(Rafraichissable vueARafraichir) {
|
|
|
28 |
vue = vueARafraichir;
|
|
|
29 |
}
|
|
|
30 |
|
299 |
gduche |
31 |
public void obtenirListe(Integer cle) {
|
|
|
32 |
selectionner("id", cle, "*");
|
292 |
gduche |
33 |
}
|
|
|
34 |
|
299 |
gduche |
35 |
public void selectionner(String type, Integer cle, String abv) {
|
91 |
jpm |
36 |
// Demande de toutes les structures
|
299 |
gduche |
37 |
//String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
|
|
|
38 |
|
|
|
39 |
// Ajout des paramètres et données à selectionner dans l'URL
|
|
|
40 |
String[] parametres = new String[3];
|
|
|
41 |
parametres[0] = type;
|
|
|
42 |
|
|
|
43 |
if (type.equals("id")) {
|
|
|
44 |
parametres[1] = cle.toString();
|
|
|
45 |
} else {
|
|
|
46 |
parametres[1] = abv;
|
|
|
47 |
parametres[2] = cle.toString();
|
292 |
gduche |
48 |
}
|
299 |
gduche |
49 |
|
|
|
50 |
RequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
|
|
|
51 |
|
|
|
52 |
//RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
|
113 |
jpm |
53 |
//GWT.log(url, null);
|
69 |
jpm |
54 |
try {
|
|
|
55 |
rb.sendRequest(null, new RequestCallback() {
|
|
|
56 |
|
|
|
57 |
public void onError(Request request, Throwable exception) {
|
|
|
58 |
// TODO Auto-generated method stub
|
|
|
59 |
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
public void onResponseReceived(Request request, Response response) {
|
91 |
jpm |
63 |
|
69 |
jpm |
64 |
final JSONValue responseValue = JSONParser.parse(response.getText());
|
|
|
65 |
|
|
|
66 |
// Si la requête est un succès, reception d'un tableau
|
91 |
jpm |
67 |
if (responseValue.isObject() != null) {
|
|
|
68 |
try {
|
|
|
69 |
final JSONObject reponse = responseValue.isObject();
|
|
|
70 |
JSONString listeId = reponse.get("id").isString();
|
|
|
71 |
JSONArray listeValeurs = reponse.get("valeurs").isArray();
|
|
|
72 |
// Transformation du tableau JSON réponse en Liste
|
|
|
73 |
ValeurListe liste = new ValeurListe(listeId, listeValeurs);
|
|
|
74 |
// et on met à jour le demandeur des données
|
268 |
jp_milcent |
75 |
vue.rafraichir(liste);
|
91 |
jpm |
76 |
} catch (NullPointerException e) {
|
|
|
77 |
e.printStackTrace();
|
|
|
78 |
}
|
69 |
jpm |
79 |
}
|
|
|
80 |
|
|
|
81 |
}
|
|
|
82 |
});
|
|
|
83 |
} catch (RequestException e) {
|
|
|
84 |
e.printStackTrace();
|
|
|
85 |
}
|
|
|
86 |
}
|
292 |
gduche |
87 |
|
|
|
88 |
|
69 |
jpm |
89 |
}
|