Subversion Repositories eFlore/Applications.del

Rev

Rev 939 | Rev 1672 | 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;
346 aurelien 4
import org.tela_botanica.del.client.modeles.InformationsRecherche;
5
import org.tela_botanica.del.client.services.rest.async.ImagesParTaxonCallback;
939 benjamin 6
import org.tela_botanica.del.client.services.rest.async.PHPCallback.ModeRequete;
346 aurelien 7
 
1496 aurelien 8
import org.tela_botanica.del.client.services.RequestBuilderWithCredentials;
346 aurelien 9
 
10
public class ImageServiceConcret implements ImageService {
445 benjamin 11
 
530 jpm 12
	private String baseUrl;
13
 
14
	public ImageServiceConcret() {
15
		Config config = new Config();
16
		this.baseUrl = config.getServiceBaseUrl();
17
	}
18
 
19
	public ImageServiceConcret(Config config) {
20
		this.baseUrl = config.getServiceBaseUrl();
21
	}
22
 
346 aurelien 23
	@Override
24
	public void getImagesEfloreParTaxon(String taxon, ImagesParTaxonCallback callback) {
445 benjamin 25
 
1496 aurelien 26
		// RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET,
445 benjamin 27
		// serverUrl+"ImagesEflore");
28
		// adresse ajoutee temporairement le temps de faire fonctionner le
29
		// service d'images eflore
1496 aurelien 30
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "images?nom_taxon=" + taxon);
939 benjamin 31
		callback.setMode(ModeRequete.LECTURE);
346 aurelien 32
		try {
382 aurelien 33
			rb.sendRequest(null, callback);
346 aurelien 34
		} catch (Exception e) {
35
			// TODO: handle exception
36
		}
37
	}
38
 
39
	@Override
40
	public void getImagesParTaxon(InformationsRecherche infos, int debut, int fin, ImagesParTaxonCallback callback) {
1496 aurelien 41
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "images" + assemblerChaineRequete(infos, debut, fin));
939 benjamin 42
		callback.setMode(ModeRequete.LECTURE);
346 aurelien 43
		try {
382 aurelien 44
			rb.sendRequest(null, callback);
346 aurelien 45
		} catch (Exception e) {
46
			// TODO: handle exception
47
		}
48
	}
445 benjamin 49
 
50
	public void getImagesParObservation(String observationId, ImagesParTaxonCallback callback) {
51
		// TODO implementer avec une methode realiste
1496 aurelien 52
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "observations/"+observationId);
939 benjamin 53
		callback.setMode(ModeRequete.LECTURE);
466 aurelien 54
		try {
55
			rb.sendRequest(null, callback);
56
		} catch (Exception e) {
57
			// TODO: handle exception
58
		}
445 benjamin 59
	}
60
 
346 aurelien 61
	private String assemblerChaineRequete(InformationsRecherche infos, int debut, int fin) {
445 benjamin 62
 
765 aurelien 63
		String chaineRequete = "?navigation.depart=" + debut + "&navigation.limite=" + (fin - debut);
474 aurelien 64
		chaineRequete+= infos.versChaineRequete();
445 benjamin 65
 
346 aurelien 66
		return chaineRequete;
67
	}
68
}