116 |
aurelien |
1 |
package org.tela_botanica.client.modeles;
|
|
|
2 |
|
|
|
3 |
import java.util.Iterator;
|
|
|
4 |
import java.util.Set;
|
|
|
5 |
|
|
|
6 |
import org.tela_botanica.client.image.ImageModele;
|
|
|
7 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
|
|
8 |
import org.tela_botanica.client.observation.ObservationModele;
|
|
|
9 |
|
|
|
10 |
import com.google.gwt.http.client.Request;
|
|
|
11 |
import com.google.gwt.http.client.RequestBuilder;
|
|
|
12 |
import com.google.gwt.http.client.RequestCallback;
|
|
|
13 |
import com.google.gwt.http.client.RequestException;
|
|
|
14 |
import com.google.gwt.http.client.Response;
|
|
|
15 |
import com.google.gwt.json.client.JSONArray;
|
|
|
16 |
import com.google.gwt.json.client.JSONObject;
|
|
|
17 |
import com.google.gwt.json.client.JSONParser;
|
|
|
18 |
import com.google.gwt.json.client.JSONValue;
|
|
|
19 |
import com.google.gwt.user.client.Window;
|
|
|
20 |
|
|
|
21 |
public class MotsClesObsAsynchronesDAO {
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* Le modele associé au DAO
|
|
|
25 |
*/
|
|
|
26 |
private ObservationModele oModele = null;
|
|
|
27 |
|
|
|
28 |
public MotsClesObsAsynchronesDAO(ObservationModele om) {
|
|
|
29 |
oModele = om;
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Setteur pour le modèle
|
|
|
34 |
*
|
|
|
35 |
* @param im
|
|
|
36 |
* le modèle à associer
|
|
|
37 |
*/
|
|
|
38 |
public void setIModele(ObservationModele om) {
|
|
|
39 |
oModele = om;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public void obtenirMotsClesObservations(final Rafraichissable r) {
|
|
|
43 |
|
|
|
44 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl()
|
|
|
45 |
+ "/InventoryKeyWordObsList/" + oModele.getIdentifiant());
|
|
|
46 |
|
|
|
47 |
try {
|
|
|
48 |
rb.sendRequest(null, new RequestCallback() {
|
|
|
49 |
|
|
|
50 |
public void onError(Request request, Throwable exception) {
|
|
|
51 |
// TODO Auto-generated method stub
|
|
|
52 |
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
public void onResponseReceived(Request request,
|
|
|
56 |
Response response) {
|
|
|
57 |
|
|
|
58 |
final JSONValue responseValue = JSONParser.parse(response
|
|
|
59 |
.getText());
|
|
|
60 |
// si la requête est un succès on reçoit un tableau
|
|
|
61 |
if (responseValue.isArray() != null) {
|
|
|
62 |
|
|
|
63 |
final JSONArray reponse = responseValue.isArray();
|
|
|
64 |
|
|
|
65 |
int tailleMaxMotCle = (int) reponse.get(0).isNumber().doubleValue() ;
|
|
|
66 |
r.rafraichir(tailleMaxMotCle, false);
|
|
|
67 |
// et on met à jour le demandeur des données
|
|
|
68 |
JSONObject motClesPoids = reponse.get(1).isObject();
|
|
|
69 |
int nbMotsCles = motClesPoids.size();
|
|
|
70 |
Object[][] tabMotsCles = new Object[nbMotsCles][2];
|
|
|
71 |
|
|
|
72 |
Set<String> im = motClesPoids.keySet();
|
|
|
73 |
int i = 0;
|
|
|
74 |
// on la parcourt pour chaque clé
|
|
|
75 |
for (Iterator<String> iterator = im.iterator(); iterator.hasNext();) {
|
|
|
76 |
|
|
|
77 |
String key = iterator.next();
|
|
|
78 |
tabMotsCles[i][0] = key;
|
|
|
79 |
tabMotsCles[i][1] = (int)motClesPoids.get(key).isNumber().doubleValue();
|
|
|
80 |
|
|
|
81 |
i++;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
r.rafraichir(tabMotsCles, false);
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
});
|
|
|
90 |
} catch (RequestException e) {
|
|
|
91 |
// TODO Auto-generated catch block
|
|
|
92 |
e.printStackTrace();
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
public void ajouterMotsCles(final Rafraichissable r, String numObsApl,
|
|
|
97 |
String motsAAjouter) {
|
|
|
98 |
|
|
|
99 |
String post = "motscles="+motsAAjouter+"&idsobs="+numObsApl;
|
|
|
100 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, Configuration.getServiceBaseUrl()
|
|
|
101 |
+ "/InventoryKeyWordObsList/" + oModele.getIdentifiant());
|
|
|
102 |
|
|
|
103 |
try {
|
|
|
104 |
rb.sendRequest(post, new RequestCallback() {
|
|
|
105 |
|
|
|
106 |
public void onError(Request request, Throwable exception) {
|
|
|
107 |
// TODO Auto-generated method stub
|
|
|
108 |
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
public void onResponseReceived(Request request,
|
|
|
112 |
Response response) {
|
|
|
113 |
|
|
|
114 |
if(response.getText().equals("OK")) {
|
|
|
115 |
r.rafraichir("OK", true);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
});
|
|
|
121 |
} catch (RequestException e) {
|
|
|
122 |
// TODO Auto-generated catch block
|
|
|
123 |
e.printStackTrace();
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
}
|
|
|
127 |
}
|