Subversion Repositories eFlore/Applications.coel

Rev

Rev 277 | Rev 300 | 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
 
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++)	{
184 gduche 81
				strParametres += arrParametres[i]+ "/";
148 gduche 82
			}
83
		}
84
 
296 gduche 85
		String wholeUrl = baseUrl + nomService + strParametres + restrictions;
86
		wholeUrl = URL.encode(wholeUrl);
184 gduche 87
 
296 gduche 88
		GWT.log("Envoi d'une requête: " + wholeUrl, null);
89
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, wholeUrl);
90
 
148 gduche 91
		return rb;
92
	}
93
 
94
	/**
95
	 *
96
	 * @param nomService String le nom du service
97
	 * @return un objet RB
98
	 */
99
	public static RequestBuilder construireRequete(String nomService)	{
100
 
101
		String[] arrParametres = null;
102
		return construireRequete(nomService, arrParametres);
103
	}
104
 
105
}