Subversion Repositories eFlore/Applications.del

Rev

Rev 530 | 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.ImagesParTaxonCallback;

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

public class ImageServiceConcret implements ImageService {

        private String baseUrl;
        
        public ImageServiceConcret() {
                Config config = new Config();
                this.baseUrl = config.getServiceBaseUrl();
        }
        
        public ImageServiceConcret(Config config) {
                this.baseUrl = config.getServiceBaseUrl();
        }
        
        @Override
        public void getImagesEfloreParTaxon(String taxon, ImagesParTaxonCallback callback) {

                // RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,
                // serverUrl+"ImagesEflore");
                // adresse ajoutee temporairement le temps de faire fonctionner le
                // service d'images eflore
                RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, baseUrl + "images?nom_taxon=" + taxon);
                try {
                        rb.sendRequest(null, callback);
                } catch (Exception e) {
                        // TODO: handle exception
                }
        }

        @Override
        public void getImagesParTaxon(InformationsRecherche infos, int debut, int fin, ImagesParTaxonCallback callback) {
                RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, baseUrl + "images" + assemblerChaineRequete(infos, debut, fin));
                try {
                        rb.sendRequest(null, callback);
                } catch (Exception e) {
                        // TODO: handle exception
                }
        }

        public void getImagesParObservation(String observationId, ImagesParTaxonCallback callback) {
                // TODO implementer avec une methode realiste
                RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, baseUrl + "observations/"+observationId);
                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;
        }
}