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 |
import com.google.gwt.user.client.HTTPRequest;
|
|
|
13 |
import com.google.gwt.user.client.ResponseTextHandler;
|
|
|
14 |
import com.google.gwt.user.client.Window;
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* DAO d'accès a une observation
|
|
|
18 |
*
|
|
|
19 |
* @author aurelien
|
|
|
20 |
*
|
|
|
21 |
*/
|
|
|
22 |
public class ObservationAsynchroneDAO {
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* Le modele associé au DAO
|
|
|
26 |
*/
|
|
|
27 |
private ObservationModele oModele = null;
|
|
|
28 |
|
|
|
29 |
public ObservationAsynchroneDAO(ObservationModele obs) {
|
|
|
30 |
oModele = obs;
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Setteur pour le modèle
|
|
|
35 |
*
|
|
|
36 |
* @param obs
|
|
|
37 |
* le modèle à associer
|
|
|
38 |
*/
|
|
|
39 |
public void setoModele(ObservationModele obs) {
|
|
|
40 |
oModele = obs;
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Envoie requete au serveur pour ajouter une observations
|
|
|
45 |
*
|
|
|
46 |
* @param motcle
|
|
|
47 |
* le mots clés à ajouter avec son parent et son identifiant
|
|
|
48 |
*/
|
|
|
49 |
|
|
|
50 |
public void ajouter(final Rafraichissable r, String utilisateur, final Observation obs) {
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
// private void addElement(String nom_sel, String num_nom_sel, String nom_ret,
|
|
|
55 |
// 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) {
|
|
|
56 |
|
32 |
jpm |
57 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,oModele.getConfig().getServiceBaseUrl()+ "/Inventory/") ;
|
39 |
david |
58 |
|
32 |
jpm |
59 |
String postData = "identifiant="
|
|
|
60 |
+ utilisateur + "&nom_sel=" + URL.encodeComponent(obs.getNomSaisi()) + "&num_nom_sel=" + obs.getNumeroNomenclaturalSaisi()
|
|
|
61 |
+ "&nom_ret=" + URL.encodeComponent(obs.getNomRetenu()) + "&num_nom_ret=" + obs.getNumeroNomenclaturalRetenu()
|
|
|
62 |
+ "&num_taxon=" + obs.getNumeroTaxonomique() + "&famille=" + URL.encodeComponent(obs.getFamille()) + "&location=" + URL.encodeComponent(obs.getLocalite()) + "&id_location=" + obs.getIdentifiantLocalite() + "&date_observation=" + obs.getDate()
|
|
|
63 |
+ "&lieudit="+ URL.encodeComponent(obs.getLieudit()) + "&station="+ URL.encodeComponent(obs.getLieudit()) +"&milieu="+ URL.encodeComponent(obs.getMilieu()) + "&commentaire="+ URL.encodeComponent(obs.getCommentaire()) ;
|
21 |
david |
64 |
|
32 |
jpm |
65 |
try {
|
|
|
66 |
|
|
|
67 |
rb.sendRequest(postData, new RequestCallback() {
|
21 |
david |
68 |
|
32 |
jpm |
69 |
public void onError(Request request, Throwable exception) {
|
|
|
70 |
// TODO Auto-generated method stub
|
|
|
71 |
|
|
|
72 |
}
|
21 |
david |
73 |
|
32 |
jpm |
74 |
public void onResponseReceived(Request request,
|
|
|
75 |
Response response) {
|
|
|
76 |
|
21 |
david |
77 |
r.rafraichir(obs,true);
|
32 |
jpm |
78 |
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
}) ;
|
|
|
83 |
|
|
|
84 |
} catch (RequestException e) {
|
|
|
85 |
|
21 |
david |
86 |
}
|
32 |
jpm |
87 |
}
|
21 |
david |
88 |
|
|
|
89 |
}
|