Rev 1672 | 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.Image;
import org.tela_botanica.del.client.modeles.InformationsRecherche;
import org.tela_botanica.del.client.services.rest.async.ImagesParTaxonCallback;
import org.tela_botanica.del.client.services.rest.async.SuppressionImageCallback;
import org.tela_botanica.del.client.services.rest.async.PHPCallback.ModeRequete;
import org.tela_botanica.del.client.services.RequestBuilderWithCredentials;
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) {
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "images?nom_taxon=" + taxon);
callback.setMode(ModeRequete.LECTURE);
try {
rb.sendRequest(null, callback);
} catch (Exception e) {
// TODO: handle exception
}
}
@Override
public void getImagesParTaxon(InformationsRecherche infos, int debut, int fin, ImagesParTaxonCallback callback) {
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "images" + assemblerChaineRequete(infos, debut, fin));
callback.setMode(ModeRequete.LECTURE);
try {
rb.sendRequest(null, callback);
} catch (Exception e) {
// TODO: handle exception
}
}
public void getImagesParObservation(String observationId, ImagesParTaxonCallback callback) {
// TODO implementer avec une methode realiste
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "observations/"+observationId);
callback.setMode(ModeRequete.LECTURE);
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;
}
public void supprimer(Image image, SuppressionImageCallback callback) {
String urlService = baseUrl+"images/"+image.getIdImage();
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.DELETE, urlService);
callback.setMode(ModeRequete.SUPPRESSION);
try {
rb.sendRequest(null, callback);
} catch (Exception e) {
//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
}
}
}