Subversion Repositories eFlore/Applications.coel

Rev

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