Subversion Repositories eFlore/Applications.del

Rev

Rev 1862 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
346 aurelien 1
package org.tela_botanica.del.client.services.rest;
2
 
530 jpm 3
import org.tela_botanica.del.client.config.Config;
1672 jpm 4
import org.tela_botanica.del.client.modeles.Image;
346 aurelien 5
import org.tela_botanica.del.client.modeles.InformationsRecherche;
6
import org.tela_botanica.del.client.services.rest.async.ImagesParTaxonCallback;
1672 jpm 7
import org.tela_botanica.del.client.services.rest.async.SuppressionImageCallback;
939 benjamin 8
import org.tela_botanica.del.client.services.rest.async.PHPCallback.ModeRequete;
1496 aurelien 9
import org.tela_botanica.del.client.services.RequestBuilderWithCredentials;
346 aurelien 10
 
11
public class ImageServiceConcret implements ImageService {
445 benjamin 12
 
530 jpm 13
	private String baseUrl;
14
 
15
	public ImageServiceConcret() {
16
		Config config = new Config();
17
		this.baseUrl = config.getServiceBaseUrl();
18
	}
19
 
20
	public ImageServiceConcret(Config config) {
21
		this.baseUrl = config.getServiceBaseUrl();
22
	}
23
 
346 aurelien 24
	@Override
25
	public void getImagesEfloreParTaxon(String taxon, ImagesParTaxonCallback callback) {
1496 aurelien 26
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "images?nom_taxon=" + taxon);
939 benjamin 27
		callback.setMode(ModeRequete.LECTURE);
346 aurelien 28
		try {
382 aurelien 29
			rb.sendRequest(null, callback);
346 aurelien 30
		} catch (Exception e) {
31
			// TODO: handle exception
32
		}
33
	}
34
 
35
	@Override
36
	public void getImagesParTaxon(InformationsRecherche infos, int debut, int fin, ImagesParTaxonCallback callback) {
1496 aurelien 37
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "images" + assemblerChaineRequete(infos, debut, fin));
939 benjamin 38
		callback.setMode(ModeRequete.LECTURE);
346 aurelien 39
		try {
382 aurelien 40
			rb.sendRequest(null, callback);
346 aurelien 41
		} catch (Exception e) {
42
			// TODO: handle exception
43
		}
44
	}
445 benjamin 45
 
46
	public void getImagesParObservation(String observationId, ImagesParTaxonCallback callback) {
47
		// TODO implementer avec une methode realiste
1496 aurelien 48
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "observations/"+observationId);
939 benjamin 49
		callback.setMode(ModeRequete.LECTURE);
466 aurelien 50
		try {
51
			rb.sendRequest(null, callback);
52
		} catch (Exception e) {
53
			// TODO: handle exception
54
		}
445 benjamin 55
	}
56
 
346 aurelien 57
	private String assemblerChaineRequete(InformationsRecherche infos, int debut, int fin) {
765 aurelien 58
		String chaineRequete = "?navigation.depart=" + debut + "&navigation.limite=" + (fin - debut);
1862 jpm 59
		chaineRequete += infos.versChaineRequete();
445 benjamin 60
 
346 aurelien 61
		return chaineRequete;
62
	}
1672 jpm 63
 
64
	public void supprimer(Image image, SuppressionImageCallback callback) {
65
		String urlService = baseUrl+"images/"+image.getIdImage();
66
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.DELETE, urlService);
67
 
68
		callback.setMode(ModeRequete.SUPPRESSION);
69
		try {
70
			rb.sendRequest(null, callback);
71
		} catch (Exception e) {
72
			//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
73
		}
74
	}
1862 jpm 75
}