Subversion Repositories eFlore/Applications.coel

Rev

Rev 154 | Rev 184 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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