Subversion Repositories eFlore/Applications.del

Rev

Rev 1496 | Go to most recent revision | 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) {
445 benjamin 26
 
1496 aurelien 27
		// RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET,
445 benjamin 28
		// serverUrl+"ImagesEflore");
29
		// adresse ajoutee temporairement le temps de faire fonctionner le
30
		// service d'images eflore
1496 aurelien 31
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "images?nom_taxon=" + taxon);
939 benjamin 32
		callback.setMode(ModeRequete.LECTURE);
346 aurelien 33
		try {
382 aurelien 34
			rb.sendRequest(null, callback);
346 aurelien 35
		} catch (Exception e) {
36
			// TODO: handle exception
37
		}
38
	}
39
 
40
	@Override
41
	public void getImagesParTaxon(InformationsRecherche infos, int debut, int fin, ImagesParTaxonCallback callback) {
1496 aurelien 42
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "images" + assemblerChaineRequete(infos, debut, fin));
939 benjamin 43
		callback.setMode(ModeRequete.LECTURE);
346 aurelien 44
		try {
382 aurelien 45
			rb.sendRequest(null, callback);
346 aurelien 46
		} catch (Exception e) {
47
			// TODO: handle exception
48
		}
49
	}
445 benjamin 50
 
51
	public void getImagesParObservation(String observationId, ImagesParTaxonCallback callback) {
52
		// TODO implementer avec une methode realiste
1496 aurelien 53
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "observations/"+observationId);
939 benjamin 54
		callback.setMode(ModeRequete.LECTURE);
466 aurelien 55
		try {
56
			rb.sendRequest(null, callback);
57
		} catch (Exception e) {
58
			// TODO: handle exception
59
		}
445 benjamin 60
	}
61
 
346 aurelien 62
	private String assemblerChaineRequete(InformationsRecherche infos, int debut, int fin) {
445 benjamin 63
 
765 aurelien 64
		String chaineRequete = "?navigation.depart=" + debut + "&navigation.limite=" + (fin - debut);
474 aurelien 65
		chaineRequete+= infos.versChaineRequete();
445 benjamin 66
 
346 aurelien 67
		return chaineRequete;
68
	}
1672 jpm 69
 
70
	public void supprimer(Image image, SuppressionImageCallback callback) {
71
		String urlService = baseUrl+"images/"+image.getIdImage();
72
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.DELETE, urlService);
73
 
74
		callback.setMode(ModeRequete.SUPPRESSION);
75
		try {
76
			rb.sendRequest(null, callback);
77
		} catch (Exception e) {
78
			//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
79
		}
80
	}
346 aurelien 81
}