1941 |
aurelien |
1 |
package org.tela_botanica.client.modeles.dao;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.HashMap;
|
|
|
5 |
import java.util.Iterator;
|
|
|
6 |
|
|
|
7 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
|
|
8 |
import org.tela_botanica.client.modeles.objets.Configuration;
|
|
|
9 |
import org.tela_botanica.client.modeles.objets.ListeReferentielPerso;
|
|
|
10 |
import org.tela_botanica.client.observation.ObservationModele;
|
|
|
11 |
|
|
|
12 |
import com.google.gwt.http.client.Request;
|
|
|
13 |
import org.tela_botanica.client.util.RequestBuilderWithCredentials;
|
|
|
14 |
import com.google.gwt.http.client.RequestCallback;
|
|
|
15 |
import com.google.gwt.http.client.RequestException;
|
|
|
16 |
import com.google.gwt.http.client.Response;
|
|
|
17 |
import com.google.gwt.http.client.URL;
|
|
|
18 |
import com.google.gwt.json.client.JSONArray;
|
|
|
19 |
import com.google.gwt.json.client.JSONObject;
|
|
|
20 |
import com.google.gwt.json.client.JSONParser;
|
|
|
21 |
import com.google.gwt.json.client.JSONValue;
|
|
|
22 |
|
|
|
23 |
public class ListeReferentielChampsEtendusDAO {
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Cache
|
|
|
27 |
*
|
|
|
28 |
*/
|
|
|
29 |
private HashMap<String,ListeReferentielPerso> cache = new HashMap();
|
|
|
30 |
|
|
|
31 |
public ListeReferentielChampsEtendusDAO(ObservationModele obs) {
|
|
|
32 |
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
public void obtenirListeNomsChampsEtendus(final Rafraichissable r, String recherche) {
|
|
|
36 |
|
|
|
37 |
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, Configuration.getServiceBaseUrl() +
|
|
|
38 |
"/NomsChampsEtendus/cle"+
|
|
|
39 |
"?recherche="+URL.encode(recherche));
|
|
|
40 |
|
|
|
41 |
try {
|
|
|
42 |
|
|
|
43 |
rb.sendRequest(null, new RequestCallback() {
|
|
|
44 |
|
|
|
45 |
@Override
|
|
|
46 |
public void onResponseReceived(final Request request,
|
|
|
47 |
final Response response) {
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
HashMap<String, String> labelCles = new HashMap<String, String>();
|
|
|
51 |
final JSONValue responseValue = JSONParser.parse(response.getText());
|
|
|
52 |
|
|
|
53 |
JSONObject reponse = null;
|
|
|
54 |
|
|
|
55 |
// si c'est un tableau
|
|
|
56 |
if ((reponse = responseValue.isObject()) != null) {
|
|
|
57 |
Iterator<String> it = reponse.keySet().iterator();
|
|
|
58 |
|
|
|
59 |
while(it.hasNext()) {
|
|
|
60 |
String cle = it.next();
|
|
|
61 |
String valeur = reponse.get(cle).isString().stringValue();
|
|
|
62 |
labelCles.put(cle, valeur);
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
r.rafraichir(labelCles, true);
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
@Override
|
|
|
70 |
public void onError(Request request, Throwable exception) {
|
|
|
71 |
// TODO Auto-generated method stub
|
|
|
72 |
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
});
|
|
|
76 |
|
|
|
77 |
} catch (RequestException e) {
|
|
|
78 |
|
|
|
79 |
e.printStackTrace();
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
public void obtenirListeValeursChampEtendu(final Rafraichissable r, String cle, String recherche) {
|
|
|
84 |
|
|
|
85 |
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, Configuration.getServiceBaseUrl() +
|
|
|
86 |
"/NomsChampsEtendus/valeur"+
|
|
|
87 |
"?cle="+URL.encode(cle)+"&recherche="+URL.encode(recherche));
|
|
|
88 |
|
|
|
89 |
try {
|
|
|
90 |
|
|
|
91 |
rb.sendRequest(null, new RequestCallback() {
|
|
|
92 |
|
|
|
93 |
@Override
|
|
|
94 |
public void onResponseReceived(final Request request,
|
|
|
95 |
final Response response) {
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
ArrayList<String> valeurs = new ArrayList<String>();
|
|
|
99 |
final JSONValue responseValue = JSONParser.parse(response.getText());
|
|
|
100 |
|
|
|
101 |
JSONArray reponse = null;
|
|
|
102 |
if ((reponse = responseValue.isArray()) != null) {
|
|
|
103 |
for(int i = 0; i < reponse.size(); i++) {
|
|
|
104 |
valeurs.add(reponse.get(i).isString().stringValue());
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
r.rafraichir(valeurs, true);
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
@Override
|
|
|
112 |
public void onError(Request request, Throwable exception) {
|
|
|
113 |
// TODO Auto-generated method stub
|
|
|
114 |
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
});
|
|
|
118 |
|
|
|
119 |
} catch (RequestException e) {
|
|
|
120 |
|
|
|
121 |
e.printStackTrace();
|
|
|
122 |
}
|
|
|
123 |
}
|
|
|
124 |
}
|