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) {
|
|
|
54 |
|
116 |
aurelien |
55 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,Configuration.getServiceBaseUrl()+ "/Inventory/") ;
|
39 |
david |
56 |
|
32 |
jpm |
57 |
String postData = "identifiant="
|
|
|
58 |
+ utilisateur + "&nom_sel=" + URL.encodeComponent(obs.getNomSaisi()) + "&num_nom_sel=" + obs.getNumeroNomenclaturalSaisi()
|
41 |
jpm |
59 |
+ "&location=" + URL.encodeComponent(obs.getLocalite()) + "&id_location=" + obs.getIdentifiantLocalite() + "&date_observation=" + obs.getDate()
|
116 |
aurelien |
60 |
+ "&lieudit="+ URL.encodeComponent(obs.getLieudit()) + "&station="+ URL.encodeComponent(obs.getStation()) +"&milieu="+ URL.encodeComponent(obs.getMilieu()) + "&commentaire="+ URL.encodeComponent(obs.getCommentaire())+ "&motscles="+ URL.encodeComponent(obs.getMotsCles().replace(" ",";")) ;
|
21 |
david |
61 |
|
41 |
jpm |
62 |
|
32 |
jpm |
63 |
try {
|
|
|
64 |
|
|
|
65 |
rb.sendRequest(postData, new RequestCallback() {
|
21 |
david |
66 |
|
32 |
jpm |
67 |
public void onError(Request request, Throwable exception) {
|
|
|
68 |
// TODO Auto-generated method stub
|
|
|
69 |
|
|
|
70 |
}
|
21 |
david |
71 |
|
32 |
jpm |
72 |
public void onResponseReceived(Request request,
|
|
|
73 |
Response response) {
|
|
|
74 |
|
21 |
david |
75 |
r.rafraichir(obs,true);
|
32 |
jpm |
76 |
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
}) ;
|
|
|
81 |
|
|
|
82 |
} catch (RequestException e) {
|
|
|
83 |
|
21 |
david |
84 |
}
|
32 |
jpm |
85 |
}
|
74 |
david |
86 |
|
|
|
87 |
/**
|
|
|
88 |
* Envoie requete au serveur pour modifier une observations
|
|
|
89 |
*
|
|
|
90 |
* @param motcle
|
|
|
91 |
* le mots clés à ajouter avec son parent et son identifiant
|
|
|
92 |
*/
|
|
|
93 |
|
79 |
david |
94 |
public void modifier(final Rafraichissable r, String utilisateur, final Observation obs) {
|
74 |
david |
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
// private void addElement(String nom_sel, String num_nom_sel, String nom_ret,
|
|
|
99 |
// 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) {
|
|
|
100 |
|
116 |
aurelien |
101 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,Configuration.getServiceBaseUrl()+ "/Inventory/" + utilisateur + "/" + obs.getNumeroOrdre()+ "/") ;
|
21 |
david |
102 |
|
74 |
david |
103 |
String postData = "identifiant="
|
|
|
104 |
+ utilisateur + "&nom_sel=" + URL.encodeComponent(obs.getNomSaisi()) + "&num_nom_sel=" + obs.getNumeroNomenclaturalSaisi()
|
|
|
105 |
+ "&location=" + URL.encodeComponent(obs.getLocalite()) + "&id_location=" + obs.getIdentifiantLocalite() + "&date_observation=" + obs.getDate()
|
116 |
aurelien |
106 |
+ "&lieudit="+ URL.encodeComponent(obs.getLieudit()) + "&station="+ URL.encodeComponent(obs.getStation()) +"&milieu="+ URL.encodeComponent(obs.getMilieu()) + "&commentaire="+ URL.encodeComponent(obs.getCommentaire())+ "&motscles="+ URL.encodeComponent(obs.getMotsCles().replace(" ",";")) ;
|
74 |
david |
107 |
|
|
|
108 |
|
|
|
109 |
try {
|
|
|
110 |
|
|
|
111 |
rb.sendRequest(postData, new RequestCallback() {
|
|
|
112 |
|
|
|
113 |
public void onError(Request request, Throwable exception) {
|
|
|
114 |
// TODO Auto-generated method stub
|
|
|
115 |
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
public void onResponseReceived(Request request,
|
|
|
119 |
Response response) {
|
|
|
120 |
|
79 |
david |
121 |
r.rafraichir(obs,true);
|
74 |
david |
122 |
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
}) ;
|
|
|
127 |
|
|
|
128 |
} catch (RequestException e) {
|
|
|
129 |
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
}
|
77 |
jpm |
135 |
|
|
|
136 |
public void supprimer(Rafraichissable r, String identifiant, String numeroOrdre) {
|
|
|
137 |
|
|
|
138 |
String postData = "";
|
|
|
139 |
postData += "&action=DELETE";
|
|
|
140 |
|
|
|
141 |
// on envoie un post avec l'id de l'image à supprimer
|
107 |
aurelien |
142 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,
|
|
|
143 |
Configuration.getServiceBaseUrl()
|
77 |
jpm |
144 |
+ "/inventory/"
|
|
|
145 |
+ identifiant
|
|
|
146 |
+ "/"
|
|
|
147 |
+ numeroOrdre);
|
|
|
148 |
|
|
|
149 |
try {
|
|
|
150 |
rb.sendRequest(postData, new RequestCallback() {
|
|
|
151 |
|
|
|
152 |
public void onError(Request request, Throwable exception) {
|
|
|
153 |
// TODO Auto-generated method stub
|
|
|
154 |
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
public void onResponseReceived(Request request,
|
|
|
158 |
Response response) {
|
|
|
159 |
|
|
|
160 |
if (response.getText().equals("OK")) {
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
} else {
|
|
|
164 |
com.google.gwt.user.client.Window
|
|
|
165 |
.alert("Problème lors de la mise à jour des données");
|
|
|
166 |
return ;
|
|
|
167 |
}
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
});
|
|
|
171 |
|
|
|
172 |
r.rafraichir("OK", true) ;
|
|
|
173 |
|
|
|
174 |
} catch (RequestException e) {
|
|
|
175 |
// TODO Auto-generated catch block
|
|
|
176 |
e.printStackTrace();
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
}
|
74 |
david |
180 |
|
21 |
david |
181 |
}
|