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