Subversion Repositories eFlore/Applications.cel

Rev

Rev 1293 | Blame | Last modification | View Log | RSS feed

package org.tela_botanica.client.modeles.dao;

import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.objets.Configuration;
import org.tela_botanica.client.observation.ObservationModele;

import com.google.gwt.http.client.Request;
import org.tela_botanica.client.util.RequestBuilderWithCredentials;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;

public class NomRetenuAsynchroneDAO {

        private ObservationModele oModele = null ;
        
        public NomRetenuAsynchroneDAO(ObservationModele observationModele) {
                oModele = observationModele ;
        }

        public void obtenirNomRetenu(final Rafraichissable r, final String anum) {
                
                RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET,
                                Configuration.getServiceBaseUrl()
                                + "/name/"+anum);

                try {
                        rb.sendRequest(null, new RequestCallback() {

                                @Override
                                public void onError(Request request, Throwable exception) {
                                        // TODO Auto-generated method stub
                                }

                                @Override
                                public void onResponseReceived(Request request,
                                                Response response) {
                                        
                                        JSONValue jsonValue = JSONParser.parse(response.getText());
                    JSONArray jsonArray;

                    if ((jsonArray = jsonValue.isArray()) != null) {
   
                            String aname = ((JSONString) jsonArray.get(0)).toString();
                           
                            // Nom
                            if (aname.compareTo("null")!=0) {
                                
                                String[] numNom = {aname, anum } ;
                                r.rafraichir(numNom, false);
                            }
                       
                    }
                }
                        });

                } catch (RequestException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        
                
        }

}