Subversion Repositories eFlore/Applications.del

Rev

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

package org.tela_botanica.del.client.services.rest;

import org.tela_botanica.del.client.config.Config;
import org.tela_botanica.del.client.modeles.InformationsRecherche;
import org.tela_botanica.del.client.services.rest.async.ObservationsCallback;

import com.google.gwt.http.client.RequestBuilder;

public class ObservationServiceConcret implements ObservationService {

        private String baseUrl;

        public ObservationServiceConcret() {
                Config config = new Config();
                this.baseUrl = config.getServiceBaseUrl();
        }
        
        public ObservationServiceConcret(Config config) {
                this.baseUrl = config.getServiceBaseUrl();
        }
        
        @Override
        public void getObservations(InformationsRecherche infos, int debut, int fin, ObservationsCallback callback) {
                RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, baseUrl + "observations" + assemblerChaineRequete(infos, debut, fin));
                try {
                        rb.sendRequest(null, callback);
                } catch (Exception e) {
                        // TODO: handle exception
                }
        }

        private String assemblerChaineRequete(InformationsRecherche infos, int debut, int fin) {

                String chaineRequete = "?navigation.depart=" + debut + "&navigation.limite=" + (fin - debut);
                chaineRequete+= infos.versChaineRequete();

                return chaineRequete;
        }

        @Override
        public void getObservation(String idObservation,
                        ObservationsCallback callback) {
                RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, baseUrl + "observations/"+idObservation);
                try {
                        rb.sendRequest(null, callback);
                } catch (Exception e) {
                        // TODO: handle exception
                }
        }
}