Subversion Repositories eFlore/Applications.coel

Rev

Rev 378 | Rev 752 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 378 Rev 748
Line 2... Line 2...
2
 
2
 
3
import java.util.HashMap;
3
import java.util.HashMap;
Line 4... Line 4...
4
import java.util.Iterator;
4
import java.util.Iterator;
-
 
5
 
5
 
6
import org.tela_botanica.client.RegistreId;
Line 6... Line 7...
6
import org.tela_botanica.client.RegistreId;
7
import org.tela_botanica.client.http.JsonRestRequestBuilder;
7
import org.tela_botanica.client.modeles.Configuration;
-
 
8
 
-
 
9
import com.extjs.gxt.ui.client.Registry;
8
import org.tela_botanica.client.modeles.Configuration;
Line -... Line 9...
-
 
9
 
-
 
10
import com.extjs.gxt.ui.client.Registry;
-
 
11
import com.google.gwt.http.client.URL;
-
 
12
 
-
 
13
/**
10
import com.google.gwt.core.client.GWT;
14
 * @author Gréguoire DUCHÉ <greguoire@tela-botanica.org>
Line 11... Line -...
11
import com.google.gwt.http.client.RequestBuilder;
-
 
12
import com.google.gwt.http.client.URL;
-
 
13
 
-
 
14
public class UtilDAO {
-
 
15
	
-
 
16
	/**
15
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
-
 
16
 * @description La classe utilDAO fournit des méthodes communes pour les outils DAO
-
 
17
 * */
-
 
18
public class UtilDAO {
-
 
19
	
Line 17... Line -...
17
	 * @author greg
-
 
18
	 * @description La classe utilDAO fournit des méthodes communes pour les outils DAO
-
 
19
	 * */
20
	private static String baseUrl = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl(); 
20
	
21
 
21
	private static String baseUrl = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl(); 
-
 
22
	
22
	public static JsonRestRequestBuilder construireRequete(String nomService)	{
Line 23... Line 23...
23
	/**
23
		return construireRequete(nomService, null, null, "GET");
24
	 * @author greg
-
 
25
	 * @description La classe construireRequete permet de revonyer un object RequestBuilder pour le service JREST
24
	}
26
	 * @param nomService String le nom du service JREST
25
	
27
	 * @param strParametres String le paramètre pour le service  
26
	public static JsonRestRequestBuilder construireRequetePost(String nomService)	{
Line 28... Line -...
28
	 */
-
 
29
	
-
 
30
	public static RequestBuilder construireRequete(String nomService, String strParametres)	{
-
 
31
		
-
 
32
		String[] arrParametres = {strParametres};		
-
 
33
		return construireRequete(nomService, arrParametres);
-
 
34
	}
27
		return construireRequete(nomService, null, null, "POST");
35
	
28
	}
36
	/**
29
	
Line 37... Line 30...
37
	 * 
30
	public static JsonRestRequestBuilder construireRequete(String nomService, String parametre)	{
38
	 * @param nomService
-
 
39
	 * @param arrParametres
-
 
40
	 * @return
31
		String[] parametres = {parametre};		
41
	 */
-
 
42
	public static RequestBuilder construireRequete(String nomService, String[] arrParametres)	{
32
		return construireRequete(nomService, parametres);
Line 43... Line 33...
43
		return construireRequete(nomService, arrParametres, "GET");
33
	}
44
	}
34
	
45
	
35
	public static JsonRestRequestBuilder construireRequete(String nomService, String[] parametres)	{
46
	public static RequestBuilder construireRequete(String nomService, String[] arrParametres, String typeRequete)	{
-
 
47
		
36
		return construireRequete(nomService, parametres, "GET");
48
		HashMap<String, String> hmRestrictions = null;
37
	}
49
		return construireRequete(nomService, arrParametres, hmRestrictions, typeRequete);
38
	
50
		
-
 
51
	}
39
	public static JsonRestRequestBuilder construireRequete(String nomService, String[] parametres, String typeRequete)	{
Line 52... Line 40...
52
	
40
		return construireRequete(nomService, parametres, null, typeRequete);
53
	public static RequestBuilder construireRequete(String nomService, HashMap<String, String> hmRestrictions)	{
-
 
-
 
41
	}
-
 
42
	
Line -... Line 43...
-
 
43
	public static JsonRestRequestBuilder construireRequete(String nomService, HashMap<String, String> restrictions)	{
54
		return construireRequete(nomService, hmRestrictions, "GET");
44
		return construireRequete(nomService, restrictions, "GET");
Line 55... Line 45...
55
	}
45
	}
56
		public static RequestBuilder construireRequete(String nomService, HashMap<String, String> hmRestrictions, String typeRequete)	{
46
 
-
 
47
	public static JsonRestRequestBuilder construireRequete(String nomService, HashMap<String, String> restrictions, String typeRequete)	{
-
 
48
		return construireRequete( nomService, null, restrictions, typeRequete);
-
 
49
	}
-
 
50
	
-
 
51
	public static JsonRestRequestBuilder construireRequete(String nomService, String[] parametres, HashMap<String, String> restrictions, String typeRequete)	{
-
 
52
		String restrictionsUrl = construireUrlParametres(restrictions);
57
		
53
		String parametresUrl = construireUrlChemin(parametres);
-
 
54
		
-
 
55
		String urlComplete = baseUrl + nomService + parametresUrl + restrictionsUrl;
-
 
56
		String urlCompleteEncodee = URL.encode(urlComplete);
-
 
57
		
58
		String[] arrParametres = null;
58
		JsonRestRequestBuilder jrrb;
59
		return construireRequete( nomService, arrParametres, hmRestrictions, typeRequete);
59
		if (typeRequete.equals("GET"))	{
60
		
60
			jrrb = new JsonRestRequestBuilder(JsonRestRequestBuilder.GET, urlCompleteEncodee);
61
	}
61
		} else	{
Line 62... Line 62...
62
	
62
			jrrb = new JsonRestRequestBuilder(JsonRestRequestBuilder.POST, urlCompleteEncodee);
63
	public static RequestBuilder construireRequete(String nomService, String[] arrParametres, HashMap<String, String> hmRestrictions, String typeRequete)	{
63
		}
64
		
64
		return jrrb;
65
		
65
	}
66
		String restrictions = "";
-
 
67
		
-
 
68
		//Les restrictions sont ajoutées en paramètres GET
66
	
-
 
67
	private static String construireUrlParametres(HashMap<String, String> parametres) {
-
 
68
		String parametresUrl = "";
69
		if ((hmRestrictions!=null)&&(hmRestrictions.size() > 0))	{
69
		if (parametres != null && parametres.size() > 0)	{
-
 
70
			parametresUrl = "?";
70
			
71
			Iterator<String> iterateur = parametres.keySet().iterator();
-
 
72
			while (iterateur.hasNext())	{
71
			Iterator<String> itRestrictions = hmRestrictions.keySet().iterator();
73
				String cle = iterateur.next();
72
			while (itRestrictions.hasNext())	{
-
 
73
				String cle = itRestrictions.next();
74
				parametresUrl += cle + "=" + parametres.get(cle);
74
				restrictions += cle + "=" + hmRestrictions.get(cle);
-
 
75
				
75
				
76
				if (itRestrictions.hasNext())	{
-
 
77
					restrictions = restrictions + "&";
76
				if (iterateur.hasNext())	{
78
				}
77
					parametresUrl = parametresUrl + "&";
79
			}
-
 
80
			
-
 
81
			restrictions = "?" + restrictions;
-
 
82
		}
-
 
83
		
-
 
84
		String strParametres = "/";
-
 
85
		if (arrParametres != null) {
-
 
86
			
-
 
87
			for (int i=0; i < arrParametres.length; i++)	{
-
 
88
				if (arrParametres[i] != null)	{
-
 
89
					strParametres += arrParametres[i]+ "/";
-
 
90
				}
78
				}
91
			}
79
			}
Line 92... Line -...
92
		}
-
 
93
		
-
 
94
		String wholeUrl = baseUrl + nomService + strParametres + restrictions;
-
 
95
		wholeUrl = URL.encode(wholeUrl);
-
 
96
		
-
 
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
		}
-
 
103
		
80
		}
104
		return rb;
81
		return parametresUrl;