148 |
gduche |
1 |
package org.tela_botanica.client.util;
|
|
|
2 |
|
182 |
gduche |
3 |
import java.util.HashMap;
|
|
|
4 |
import java.util.Iterator;
|
148 |
gduche |
5 |
|
|
|
6 |
import org.tela_botanica.client.RegistreId;
|
|
|
7 |
import org.tela_botanica.client.modeles.Configuration;
|
|
|
8 |
|
|
|
9 |
import com.extjs.gxt.ui.client.Registry;
|
296 |
gduche |
10 |
import com.google.gwt.core.client.GWT;
|
148 |
gduche |
11 |
import com.google.gwt.http.client.RequestBuilder;
|
296 |
gduche |
12 |
import com.google.gwt.http.client.URL;
|
148 |
gduche |
13 |
|
|
|
14 |
public class UtilDAO {
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* @author greg
|
|
|
18 |
* @description La classe utilDAO fournit des méthodes communes pour les outils DAO
|
|
|
19 |
* */
|
|
|
20 |
|
|
|
21 |
private static String baseUrl = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* @author greg
|
|
|
25 |
* @description La classe construireRequete permet de revonyer un object RequestBuilder pour le service JREST
|
|
|
26 |
* @param nomService String le nom du service JREST
|
|
|
27 |
* @param strParametres String le paramètre pour le service
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
public static RequestBuilder construireRequete(String nomService, String strParametres) {
|
|
|
31 |
|
|
|
32 |
String[] arrParametres = {strParametres};
|
|
|
33 |
return construireRequete(nomService, arrParametres);
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
*
|
|
|
38 |
* @param nomService
|
|
|
39 |
* @param arrParametres
|
|
|
40 |
* @return
|
|
|
41 |
*/
|
|
|
42 |
public static RequestBuilder construireRequete(String nomService, String[] arrParametres) {
|
|
|
43 |
|
182 |
gduche |
44 |
HashMap<String, String> hmRestrictions = null;
|
|
|
45 |
return construireRequete(nomService, arrParametres, hmRestrictions);
|
|
|
46 |
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public static RequestBuilder construireRequete(String nomService, HashMap<String, String> hmRestrictions) {
|
|
|
50 |
|
|
|
51 |
String[] arrParametres = null;
|
|
|
52 |
return construireRequete( nomService, arrParametres, hmRestrictions);
|
|
|
53 |
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
public static RequestBuilder construireRequete(String nomService, String[] arrParametres, HashMap<String, String> hmRestrictions) {
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
String restrictions = "";
|
|
|
60 |
|
|
|
61 |
//Les restrictions sont ajoutées en paramètres GET
|
|
|
62 |
if ((hmRestrictions!=null)&&(hmRestrictions.size() > 0)) {
|
|
|
63 |
|
|
|
64 |
Iterator<String> itRestrictions = hmRestrictions.keySet().iterator();
|
|
|
65 |
while (itRestrictions.hasNext()) {
|
|
|
66 |
String cle = itRestrictions.next();
|
|
|
67 |
restrictions += cle + "=" + hmRestrictions.get(cle);
|
|
|
68 |
|
|
|
69 |
if (itRestrictions.hasNext()) {
|
|
|
70 |
restrictions = restrictions + "&";
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
restrictions = "?" + restrictions;
|
|
|
75 |
}
|
|
|
76 |
|
148 |
gduche |
77 |
String strParametres = "/";
|
|
|
78 |
if (arrParametres != null) {
|
|
|
79 |
|
|
|
80 |
for (int i=0; i < arrParametres.length; i++) {
|
300 |
gduche |
81 |
if (arrParametres[i] != null) {
|
|
|
82 |
strParametres += arrParametres[i]+ "/";
|
|
|
83 |
}
|
148 |
gduche |
84 |
}
|
|
|
85 |
}
|
|
|
86 |
|
296 |
gduche |
87 |
String wholeUrl = baseUrl + nomService + strParametres + restrictions;
|
|
|
88 |
wholeUrl = URL.encode(wholeUrl);
|
184 |
gduche |
89 |
|
296 |
gduche |
90 |
GWT.log("Envoi d'une requête: " + wholeUrl, null);
|
|
|
91 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, wholeUrl);
|
|
|
92 |
|
148 |
gduche |
93 |
return rb;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
/**
|
|
|
97 |
*
|
|
|
98 |
* @param nomService String le nom du service
|
|
|
99 |
* @return un objet RB
|
|
|
100 |
*/
|
|
|
101 |
public static RequestBuilder construireRequete(String nomService) {
|
|
|
102 |
|
|
|
103 |
String[] arrParametres = null;
|
|
|
104 |
return construireRequete(nomService, arrParametres);
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
}
|