21 |
david |
1 |
package org.tela_botanica.client.modeles;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
|
|
4 |
import org.tela_botanica.client.observation.ObservationModele;
|
|
|
5 |
|
|
|
6 |
import com.google.gwt.http.client.Request;
|
|
|
7 |
import com.google.gwt.http.client.RequestBuilder;
|
|
|
8 |
import com.google.gwt.http.client.RequestCallback;
|
|
|
9 |
import com.google.gwt.http.client.RequestException;
|
|
|
10 |
import com.google.gwt.http.client.Response;
|
|
|
11 |
import com.google.gwt.http.client.URL;
|
116 |
aurelien |
12 |
import com.google.gwt.user.client.Window;
|
21 |
david |
13 |
|
116 |
aurelien |
14 |
|
21 |
david |
15 |
/**
|
|
|
16 |
* DAO d'accès a une observation
|
|
|
17 |
*
|
|
|
18 |
* @author aurelien
|
|
|
19 |
*
|
|
|
20 |
*/
|
|
|
21 |
public class ObservationAsynchroneDAO {
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* Le modele associé au DAO
|
|
|
25 |
*/
|
|
|
26 |
private ObservationModele oModele = null;
|
|
|
27 |
|
|
|
28 |
public ObservationAsynchroneDAO(ObservationModele obs) {
|
|
|
29 |
oModele = obs;
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Setteur pour le modèle
|
|
|
34 |
*
|
|
|
35 |
* @param obs
|
|
|
36 |
* le modèle à associer
|
|
|
37 |
*/
|
|
|
38 |
public void setoModele(ObservationModele obs) {
|
|
|
39 |
oModele = obs;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* Envoie requete au serveur pour ajouter une observations
|
|
|
44 |
*
|
|
|
45 |
* @param motcle
|
|
|
46 |
* le mots clés à ajouter avec son parent et son identifiant
|
|
|
47 |
*/
|
|
|
48 |
|
|
|
49 |
public void ajouter(final Rafraichissable r, String utilisateur, final Observation obs) {
|
|
|
50 |
|
|
|
51 |
|
116 |
aurelien |
52 |
// private void addElement(String nom_sel, String num_nom_sel, String nom_ret,
|
21 |
david |
53 |
// String num_nom_ret, String num_taxon, String famille,final String loc, String id_location,String dat, String lieu, String sta, String mil, String comment) {
|
122 |
aurelien |
54 |
|
116 |
aurelien |
55 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,Configuration.getServiceBaseUrl()+ "/Inventory/") ;
|
39 |
david |
56 |
|
32 |
jpm |
57 |
String postData = "identifiant="
|
259 |
aurelien |
58 |
+ utilisateur
|
|
|
59 |
+"&nom_sel="+URL.encodeComponent(obs.getNomSaisi())
|
|
|
60 |
+"&num_nom_sel="+obs.getNumeroNomenclaturalSaisi()
|
|
|
61 |
+"&location="+URL.encodeComponent(obs.getLocalite())
|
|
|
62 |
+"&id_location="+obs.getIdentifiantLocalite()
|
|
|
63 |
+"&date_observation=" + obs.getDate()
|
|
|
64 |
+"&lieudit="+ URL.encodeComponent(obs.getLieudit())
|
|
|
65 |
+"&station="+URL.encodeComponent(obs.getStation())
|
|
|
66 |
+"&milieu="+URL.encodeComponent(obs.getMilieu())
|
|
|
67 |
+"&commentaire="+URL.encodeComponent(""+obs.getCommentaire())
|
|
|
68 |
+"&coord_x="+URL.encodeComponent(""+obs.getCoordonneeX())
|
|
|
69 |
+"&coord_y="+URL.encodeComponent(""+obs.getCoordonneeY());;
|
21 |
david |
70 |
|
41 |
jpm |
71 |
|
32 |
jpm |
72 |
try {
|
|
|
73 |
|
|
|
74 |
rb.sendRequest(postData, new RequestCallback() {
|
21 |
david |
75 |
|
32 |
jpm |
76 |
public void onError(Request request, Throwable exception) {
|
|
|
77 |
// TODO Auto-generated method stub
|
|
|
78 |
|
|
|
79 |
}
|
21 |
david |
80 |
|
32 |
jpm |
81 |
public void onResponseReceived(Request request,
|
|
|
82 |
Response response) {
|
|
|
83 |
|
21 |
david |
84 |
r.rafraichir(obs,true);
|
32 |
jpm |
85 |
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
}) ;
|
|
|
90 |
|
|
|
91 |
} catch (RequestException e) {
|
|
|
92 |
|
21 |
david |
93 |
}
|
32 |
jpm |
94 |
}
|
74 |
david |
95 |
|
|
|
96 |
/**
|
|
|
97 |
* Envoie requete au serveur pour modifier une observations
|
|
|
98 |
*
|
|
|
99 |
* @param motcle
|
|
|
100 |
* le mots clés à ajouter avec son parent et son identifiant
|
|
|
101 |
*/
|
|
|
102 |
|
79 |
david |
103 |
public void modifier(final Rafraichissable r, String utilisateur, final Observation obs) {
|
74 |
david |
104 |
|
116 |
aurelien |
105 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,Configuration.getServiceBaseUrl()+ "/Inventory/" + utilisateur + "/" + obs.getNumeroOrdre()+ "/") ;
|
21 |
david |
106 |
|
74 |
david |
107 |
String postData = "identifiant="
|
220 |
aurelien |
108 |
+ utilisateur
|
|
|
109 |
+ "&nom_sel=" + URL.encodeComponent(obs.getNomSaisi())
|
|
|
110 |
+ "&num_nom_sel=" + obs.getNumeroNomenclaturalSaisi()
|
|
|
111 |
+ "&location=" + URL.encodeComponent(obs.getLocalite())
|
|
|
112 |
+ "&id_location=" + obs.getIdentifiantLocalite()
|
|
|
113 |
+ "&date_observation=" + obs.getDate()
|
|
|
114 |
+ "&lieudit="+ URL.encodeComponent(obs.getLieudit())
|
|
|
115 |
+ "&station="+ URL.encodeComponent(obs.getStation())
|
|
|
116 |
+"&milieu="+ URL.encodeComponent(obs.getMilieu())
|
259 |
aurelien |
117 |
+"&commentaire="+URL.encodeComponent(""+obs.getCommentaire())
|
318 |
aurelien |
118 |
+"&mots_cles="+URL.encodeComponent(""+obs.getMotsCles())
|
259 |
aurelien |
119 |
+"&coord_x="+URL.encodeComponent(""+obs.getCoordonneeX())
|
|
|
120 |
+"&coord_y="+URL.encodeComponent(""+obs.getCoordonneeY());
|
74 |
david |
121 |
|
|
|
122 |
try {
|
|
|
123 |
|
|
|
124 |
rb.sendRequest(postData, new RequestCallback() {
|
|
|
125 |
|
|
|
126 |
public void onError(Request request, Throwable exception) {
|
|
|
127 |
// TODO Auto-generated method stub
|
|
|
128 |
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
public void onResponseReceived(Request request,
|
|
|
132 |
Response response) {
|
|
|
133 |
|
79 |
david |
134 |
r.rafraichir(obs,true);
|
74 |
david |
135 |
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
|
|
|
139 |
}) ;
|
|
|
140 |
|
|
|
141 |
} catch (RequestException e) {
|
|
|
142 |
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
}
|
77 |
jpm |
146 |
|
|
|
147 |
public void supprimer(Rafraichissable r, String identifiant, String numeroOrdre) {
|
|
|
148 |
|
|
|
149 |
String postData = "";
|
|
|
150 |
postData += "&action=DELETE";
|
|
|
151 |
|
|
|
152 |
// on envoie un post avec l'id de l'image à supprimer
|
107 |
aurelien |
153 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,
|
|
|
154 |
Configuration.getServiceBaseUrl()
|
77 |
jpm |
155 |
+ "/inventory/"
|
|
|
156 |
+ identifiant
|
|
|
157 |
+ "/"
|
|
|
158 |
+ numeroOrdre);
|
|
|
159 |
|
|
|
160 |
try {
|
|
|
161 |
rb.sendRequest(postData, new RequestCallback() {
|
|
|
162 |
|
|
|
163 |
public void onError(Request request, Throwable exception) {
|
|
|
164 |
// TODO Auto-generated method stub
|
|
|
165 |
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
public void onResponseReceived(Request request,
|
|
|
169 |
Response response) {
|
|
|
170 |
|
|
|
171 |
if (response.getText().equals("OK")) {
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
} else {
|
|
|
175 |
com.google.gwt.user.client.Window
|
|
|
176 |
.alert("Problème lors de la mise à jour des données");
|
|
|
177 |
return ;
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
});
|
|
|
182 |
|
|
|
183 |
r.rafraichir("OK", true) ;
|
|
|
184 |
|
|
|
185 |
} catch (RequestException e) {
|
|
|
186 |
// TODO Auto-generated catch block
|
|
|
187 |
e.printStackTrace();
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
}
|
74 |
david |
191 |
|
21 |
david |
192 |
}
|