121 |
jpm |
1 |
package org.tela_botanica.client.modeles;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.client.RegistreId;
|
|
|
4 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
|
|
5 |
|
|
|
6 |
import com.extjs.gxt.ui.client.Registry;
|
133 |
jpm |
7 |
import com.google.gwt.core.client.GWT;
|
121 |
jpm |
8 |
import com.google.gwt.http.client.Request;
|
|
|
9 |
import com.google.gwt.http.client.RequestBuilder;
|
|
|
10 |
import com.google.gwt.http.client.RequestCallback;
|
|
|
11 |
import com.google.gwt.http.client.RequestException;
|
|
|
12 |
import com.google.gwt.http.client.Response;
|
|
|
13 |
import com.google.gwt.http.client.URL;
|
|
|
14 |
import com.google.gwt.json.client.JSONArray;
|
|
|
15 |
import com.google.gwt.json.client.JSONParser;
|
|
|
16 |
import com.google.gwt.json.client.JSONValue;
|
|
|
17 |
|
|
|
18 |
public class StructureAsyncDao {
|
|
|
19 |
|
|
|
20 |
public void ajouter(final Rafraichissable r, String utilisateurId, final Structure str) {
|
|
|
21 |
String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
|
|
|
22 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, url+"CoelStructureListe/");
|
|
|
23 |
|
|
|
24 |
String postDonnees = "identifiant=" + utilisateurId +
|
|
|
25 |
"&ce_projet =" + URL.encodeComponent(str.getIdProjet()) +
|
|
|
26 |
"&ce_mere =" + URL.encodeComponent(str.getIdMere()) +
|
|
|
27 |
"&guid =" + URL.encodeComponent(str.getGuid()) +
|
|
|
28 |
"&truk_identifiant_alternatif =" + URL.encodeComponent(str.getIdAlternatif()) +
|
|
|
29 |
"&nom=" + URL.encodeComponent(str.getNom()) +
|
|
|
30 |
"&truk_nom_alternatif =" + URL.encodeComponent(str.getNomAlternatif()) +
|
|
|
31 |
"&ce_type =" + URL.encodeComponent(str.getType()) +
|
|
|
32 |
"&ce_truk_type_prive =" + URL.encodeComponent(str.getTypePrive()) +
|
|
|
33 |
"&ce_truk_type_public =" + URL.encodeComponent(str.getTypePublic()) +
|
|
|
34 |
"&adresse_01 =" + URL.encodeComponent(str.getAdresse()) +
|
|
|
35 |
"&adresse_02 =" + URL.encodeComponent(str.getAdresseComplement()) +
|
|
|
36 |
"&date_fondation =" + URL.encodeComponent(str.getDateFondation()) +
|
|
|
37 |
"&code_postal =" + URL.encodeComponent(str.getCodePostal()) +
|
|
|
38 |
"&ville =" + URL.encodeComponent(str.getVille()) +
|
|
|
39 |
"®ion =" + URL.encodeComponent(str.getRegion()) +
|
|
|
40 |
"&pays =" + URL.encodeComponent(str.getPays()) +
|
|
|
41 |
"&telephone =" + URL.encodeComponent(str.getTelephone()) +
|
|
|
42 |
"&fax =" + URL.encodeComponent(str.getFax()) +
|
|
|
43 |
"&truk_url =" + URL.encodeComponent(str.getUrl()) +
|
|
|
44 |
"&nbre_personne =" + URL.encodeComponent(str.getNbrePersonne()) +
|
|
|
45 |
"";
|
|
|
46 |
|
|
|
47 |
try {
|
|
|
48 |
rb.sendRequest(postDonnees, new RequestCallback() {
|
|
|
49 |
|
|
|
50 |
public void onError(Request request, Throwable exception) {
|
|
|
51 |
// TODO Auto-generated method stub
|
|
|
52 |
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
public void onResponseReceived(Request request, Response response) {
|
|
|
56 |
if (response.getText().length() != 0 && response.getText() != null) {
|
|
|
57 |
final JSONValue responseValue = JSONParser.parse(response.getText());
|
|
|
58 |
|
|
|
59 |
// Si la requête est un succès, reception d'un tableau
|
|
|
60 |
if (responseValue.isString() != null) {
|
|
|
61 |
str.set("messages", responseValue.isString().stringValue());
|
|
|
62 |
r.rafraichir(str);
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
}) ;
|
|
|
68 |
} catch (RequestException e) {
|
|
|
69 |
|
|
|
70 |
}
|
|
|
71 |
}
|
133 |
jpm |
72 |
|
|
|
73 |
public void supprimer(final Rafraichissable r, String idUtilisateur, String idStr) {
|
|
|
74 |
// Ajout des paramètres et données à supprimer dans l'URL
|
|
|
75 |
final String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl() +
|
|
|
76 |
"CoelStructureListe/" +
|
|
|
77 |
idUtilisateur + "/" +
|
|
|
78 |
idStr +
|
|
|
79 |
"";
|
|
|
80 |
|
|
|
81 |
// DELETE n'étant pas disponible comme méthode HTTP, nous utilisons POST avec le paramètre action=DELETE
|
|
|
82 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, url);
|
|
|
83 |
String postDonnees = "action=DELETE";
|
|
|
84 |
|
|
|
85 |
try {
|
|
|
86 |
rb.sendRequest(postDonnees, new RequestCallback() {
|
|
|
87 |
|
|
|
88 |
public void onError(Request request, Throwable exception) {
|
|
|
89 |
// TODO Auto-generated method stub
|
|
|
90 |
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
public void onResponseReceived(Request request, Response response) {
|
|
|
94 |
if (response.getText().length() != 0 && response.getText() != null) {
|
|
|
95 |
final JSONValue responseValue = JSONParser.parse(response.getText());
|
|
|
96 |
|
|
|
97 |
// Si la requête est un succès, reception d'un tableau
|
|
|
98 |
if (responseValue.isString() != null) {
|
|
|
99 |
GWT.log(responseValue.isString().stringValue(), null);
|
|
|
100 |
Information info = new Information("suppression_structure", responseValue.isString().stringValue());
|
|
|
101 |
info.setMessage("ok");
|
|
|
102 |
r.rafraichir(info);
|
|
|
103 |
} else {
|
|
|
104 |
GWT.log(url+"\n\tLa réponse est une chaine valant null", null);
|
|
|
105 |
}
|
|
|
106 |
} else {
|
|
|
107 |
GWT.log(url, null);
|
|
|
108 |
if (response.getText().length() == 0) {
|
|
|
109 |
GWT.log("\tLa réponse a une taille de 0", null);
|
|
|
110 |
}
|
|
|
111 |
if (response.getText() == null) {
|
|
|
112 |
GWT.log("\tLa réponse vaul null", null);
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
}) ;
|
|
|
118 |
} catch (RequestException e) {
|
|
|
119 |
|
|
|
120 |
}
|
|
|
121 |
}
|
121 |
jpm |
122 |
}
|