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()
|
32 |
jpm |
59 |
+ "&lieudit="+ URL.encodeComponent(obs.getLieudit()) + "&station="+ URL.encodeComponent(obs.getLieudit()) +"&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 |
}
|
21 |
david |
85 |
|
|
|
86 |
}
|