Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 752 Rev 754
Line 15... Line 15...
15
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
15
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
16
 * @description La classe utilDAO fournit des méthodes communes pour les outils DAO
16
 * @description La classe utilDAO fournit des méthodes communes pour les outils DAO
17
 * */
17
 * */
18
public class UtilDAO {
18
public class UtilDAO {
Line 19... Line 19...
19
	
19
	
-
 
20
	private static String baseUrl = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
-
 
21
	public static final String GET = "GET";
-
 
22
	public static final String POST = "POST";
-
 
23
	public static final String DELETE = "DELETE";
-
 
24
	public static final String PUT = "PUT";
-
 
25
	private static final String SEPARATEUR_CHEMIN = "/";
-
 
26
	private static final String SEPARATEUR_CLE_VALEUR = "=";
-
 
27
	private static final String SEPARATEUR_PARAMETRE = "&";
-
 
28
	private static final String SEPARATEUR_CHEMIN_PARAMETRE = "?";
Line 20... Line -...
20
	private static String baseUrl = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl(); 
-
 
21
 
-
 
22
	public static JsonRestRequestBuilder construireRequete(String nomService)	{
-
 
23
		return construireRequete(nomService, null, null, "GET");
-
 
24
	}
29
	private static final String CONTENU_CHEMIN_VIDE = "*";
25
	
30
 
26
	public static JsonRestRequestBuilder construireRequetePost(String nomService)	{
31
	public static JsonRestRequestBuilder construireRequetePost(String nomService)	{
27
		return construireRequete(nomService, null, null, "POST");
32
		return construireRequete(nomService, null, null, POST);
28
	}
-
 
29
	
-
 
30
	public static JsonRestRequestBuilder construireRequete(String nomService, String parametre)	{
-
 
31
		String[] parametres = {parametre};
-
 
32
		return construireRequete(nomService, parametres, null, "GET");
-
 
33
	}
33
	}
34
	
34
 
-
 
35
	public static JsonRestRequestBuilder construireRequetePost(String nomService, String[] parametres)	{
-
 
36
		return construireRequete(nomService, parametres, null, POST);
-
 
37
	}
-
 
38
 
35
	public static JsonRestRequestBuilder construireRequetePost(String nomService, String[] parametres)	{
39
	public static JsonRestRequestBuilder construireRequete(String nomService)	{
Line 36... Line 40...
36
		return construireRequete(nomService, parametres, null, "POST");
40
		return construireRequete(nomService, null, null, GET);
37
	}
41
	}
38
	
42
	
Line 39... Line 43...
39
	public static JsonRestRequestBuilder construireRequete(String nomService, String[] parametres)	{
43
	public static JsonRestRequestBuilder construireRequete(String nomService, String[] parametres)	{
40
		return construireRequete(nomService, parametres, null, "GET");
44
		return construireRequete(nomService, parametres, null, GET);
-
 
45
	}
-
 
46
	
-
 
47
	public static JsonRestRequestBuilder construireRequete(String nomService, HashMap<String, String> restrictions)	{
-
 
48
		return construireRequete(nomService, null, restrictions, GET);
41
	}
49
	}
Line 42... Line 50...
42
	
50
	
43
	public static JsonRestRequestBuilder construireRequete(String nomService, HashMap<String, String> restrictions)	{
51
	public static JsonRestRequestBuilder construireRequete(String nomService, String[] parametres, HashMap<String, String> restrictions)	{
44
		return construireRequete(nomService, null, restrictions, "GET");
52
		return construireRequete(nomService, parametres, restrictions, GET);
Line 45... Line 53...
45
	}
53
	}
46
 
54
 
Line 47... Line 55...
47
	public static JsonRestRequestBuilder construireRequete(String nomService, String[] parametres, HashMap<String, String> restrictions, String typeRequete)	{
55
	private static JsonRestRequestBuilder construireRequete(String nomService, String[] parametres, HashMap<String, String> restrictions, String typeRequete)	{
48
		String restrictionsUrl = construireUrlParametres(restrictions);
56
		String restrictionsUrl = construireUrlParametres(restrictions);
49
		String parametresUrl = construireUrlChemin(parametres);
57
		String parametresUrl = construireUrlChemin(parametres);
50
		
58
		
51
		String urlComplete = baseUrl + nomService + parametresUrl + restrictionsUrl;
59
		String urlComplete = baseUrl + nomService + parametresUrl + restrictionsUrl;
52
		String urlCompleteEncodee = URL.encode(urlComplete);
60
		String urlCompleteEncodee = URL.encode(urlComplete);
53
		
61
		
54
		JsonRestRequestBuilder jrrb;
62
		JsonRestRequestBuilder jrrb;
Line 55... Line 63...
55
		if (typeRequete.equals("GET"))	{
63
		if (typeRequete.equals(GET))	{
56
			jrrb = new JsonRestRequestBuilder(JsonRestRequestBuilder.GET, urlCompleteEncodee);
64
			jrrb = new JsonRestRequestBuilder(JsonRestRequestBuilder.GET, urlCompleteEncodee);
57
		} else	{
65
		} else	{
58
			jrrb = new JsonRestRequestBuilder(JsonRestRequestBuilder.POST, urlCompleteEncodee);
66
			jrrb = new JsonRestRequestBuilder(JsonRestRequestBuilder.POST, urlCompleteEncodee);
59
		}
67
		}
60
		return jrrb;
68
		return jrrb;
61
	}
69
	}
62
	
70
	
Line 63... Line 71...
63
	private static String construireUrlParametres(HashMap<String, String> parametres) {
71
	private static String construireUrlParametres(HashMap<String, String> parametres) {
64
		String parametresUrl = "";
72
		String parametresUrl = "";
65
		if (parametres != null && parametres.size() > 0)	{
73
		if (parametres != null && parametres.size() > 0)	{
66
			parametresUrl = "?";
74
			parametresUrl = SEPARATEUR_CHEMIN_PARAMETRE;
67
			Iterator<String> iterateur = parametres.keySet().iterator();
75
			Iterator<String> iterateur = parametres.keySet().iterator();
68
			while (iterateur.hasNext())	{
76
			while (iterateur.hasNext())	{
69
				String cle = iterateur.next();
77
				String cle = iterateur.next();
Line 70... Line 78...
70
				parametresUrl += cle + "=" + parametres.get(cle);
78
				parametresUrl += cle + SEPARATEUR_CLE_VALEUR + parametres.get(cle);
71
				
79
				
72
				if (iterateur.hasNext())	{
80
				if (iterateur.hasNext())	{
73
					parametresUrl = parametresUrl + "&";
81
					parametresUrl = parametresUrl + SEPARATEUR_PARAMETRE;
74
				}
82
				}
75
			}
83
			}
76
		}
84
		}
77
		return parametresUrl;
85
		return parametresUrl;
78
	}
86
	}
79
	
87