Subversion Repositories eFlore/Applications.coel

Rev

Go to most recent revision | Details | 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)	{
348 gduche 43
		return construireRequete(nomService, arrParametres, "GET");
44
	}
45
 
46
	public static RequestBuilder construireRequete(String nomService, String[] arrParametres, String typeRequete)	{
148 gduche 47
 
182 gduche 48
		HashMap<String, String> hmRestrictions = null;
348 gduche 49
		return construireRequete(nomService, arrParametres, hmRestrictions, typeRequete);
182 gduche 50
 
51
	}
52
 
53
	public static RequestBuilder construireRequete(String nomService, HashMap<String, String> hmRestrictions)	{
348 gduche 54
		return construireRequete(nomService, hmRestrictions, "GET");
55
	}
56
		public static RequestBuilder construireRequete(String nomService, HashMap<String, String> hmRestrictions, String typeRequete)	{
182 gduche 57
 
58
		String[] arrParametres = null;
348 gduche 59
		return construireRequete( nomService, arrParametres, hmRestrictions, typeRequete);
182 gduche 60
 
61
	}
62
 
348 gduche 63
	public static RequestBuilder construireRequete(String nomService, String[] arrParametres, HashMap<String, String> hmRestrictions, String typeRequete)	{
182 gduche 64
 
65
 
66
		String restrictions = "";
67
 
68
		//Les restrictions sont ajoutées en paramètres GET
69
		if ((hmRestrictions!=null)&&(hmRestrictions.size() > 0))	{
70
 
71
			Iterator<String> itRestrictions = hmRestrictions.keySet().iterator();
72
			while (itRestrictions.hasNext())	{
73
				String cle = itRestrictions.next();
74
				restrictions += cle + "=" + hmRestrictions.get(cle);
75
 
76
				if (itRestrictions.hasNext())	{
77
					restrictions = restrictions + "&";
78
				}
79
			}
80
 
81
			restrictions = "?" + restrictions;
82
		}
83
 
148 gduche 84
		String strParametres = "/";
85
		if (arrParametres != null) {
86
 
87
			for (int i=0; i < arrParametres.length; i++)	{
300 gduche 88
				if (arrParametres[i] != null)	{
89
					strParametres += arrParametres[i]+ "/";
90
				}
148 gduche 91
			}
92
		}
93
 
296 gduche 94
		String wholeUrl = baseUrl + nomService + strParametres + restrictions;
95
		wholeUrl = URL.encode(wholeUrl);
184 gduche 96
 
348 gduche 97
		RequestBuilder rb;
98
		if (typeRequete.equals("GET"))	{
99
			rb = new RequestBuilder(RequestBuilder.GET, wholeUrl);
100
		} else	{
101
			rb = new RequestBuilder(RequestBuilder.POST, wholeUrl);
102
		}
296 gduche 103
 
148 gduche 104
		return rb;
105
	}
106
 
107
	/**
108
	 *
109
	 * @param nomService String le nom du service
110
	 * @return un objet RB
111
	 */
112
	public static RequestBuilder construireRequete(String nomService)	{
113
 
114
		String[] arrParametres = null;
115
		return construireRequete(nomService, arrParametres);
116
	}
117
 
118
}