Subversion Repositories eFlore/Applications.coel

Rev

Rev 182 | Rev 296 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.client.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;

import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.modeles.Configuration;
import org.tela_botanica.client.modeles.PersonneListe;

import com.extjs.gxt.ui.client.Registry;
import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONException;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.Window;

public class UtilDAO {
        
        /**
         * @author greg
         * @description La classe utilDAO fournit des méthodes communes pour les outils DAO
         * */
        
        private static String baseUrl = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl(); 
        
        /**
         * @author greg
         * @description La classe construireRequete permet de revonyer un object RequestBuilder pour le service JREST
         * @param nomService String le nom du service JREST
         * @param strParametres String le paramètre pour le service  
         */
        
        public static RequestBuilder construireRequete(String nomService, String strParametres) {
                
                String[] arrParametres = {strParametres};               
                return construireRequete(nomService, arrParametres);
        }
        
        /**
         * 
         * @param nomService
         * @param arrParametres
         * @return
         */
        public static RequestBuilder construireRequete(String nomService, String[] arrParametres)       {
                
                HashMap<String, String> hmRestrictions = null;
                return construireRequete(nomService, arrParametres, hmRestrictions);
                
        }
        
        public static RequestBuilder construireRequete(String nomService, HashMap<String, String> hmRestrictions)       {
                
                String[] arrParametres = null;
                return construireRequete( nomService, arrParametres, hmRestrictions);
                
        }
        
        public static RequestBuilder construireRequete(String nomService, String[] arrParametres, HashMap<String, String> hmRestrictions)       {
                
                
                String restrictions = "";
                
                //Les restrictions sont ajoutées en paramètres GET
                if ((hmRestrictions!=null)&&(hmRestrictions.size() > 0))        {
                        
                        Iterator<String> itRestrictions = hmRestrictions.keySet().iterator();
                        while (itRestrictions.hasNext())        {
                                String cle = itRestrictions.next();
                                restrictions += cle + "=" + hmRestrictions.get(cle);
                                
                                if (itRestrictions.hasNext())   {
                                        restrictions = restrictions + "&";
                                }
                        }
                        
                        restrictions = "?" + restrictions;
                }
                
                String strParametres = "/";
                if (arrParametres != null) {
                        
                        for (int i=0; i < arrParametres.length; i++)    {
                                strParametres += arrParametres[i]+ "/";
                        }
                }
                
                System.out.println(baseUrl + nomService + strParametres + restrictions);
                
                RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, baseUrl + nomService + strParametres + restrictions);
                return rb;
        }
        
        /**
         * 
         * @param nomService String le nom du service
         * @return un objet RB
         */
        public static RequestBuilder construireRequete(String nomService)       {
                        
                String[] arrParametres = null;
                return construireRequete(nomService, arrParametres);
        }

}