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