Subversion Repositories eFlore/Applications.del

Rev

Rev 1467 | Rev 1689 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
392 aurelien 1
package org.tela_botanica.del.client.services.rest;
2
 
530 jpm 3
import org.tela_botanica.del.client.config.Config;
392 aurelien 4
import org.tela_botanica.del.client.modeles.InformationsRecherche;
5
import org.tela_botanica.del.client.services.rest.async.ObservationsCallback;
939 benjamin 6
import org.tela_botanica.del.client.services.rest.async.PHPCallback.ModeRequete;
392 aurelien 7
 
1496 aurelien 8
import org.tela_botanica.del.client.services.RequestBuilderWithCredentials;
392 aurelien 9
 
10
public class ObservationServiceConcret implements ObservationService {
445 benjamin 11
 
530 jpm 12
	private String baseUrl;
392 aurelien 13
 
530 jpm 14
	public ObservationServiceConcret() {
15
		Config config = new Config();
16
		this.baseUrl = config.getServiceBaseUrl();
17
	}
18
 
19
	public ObservationServiceConcret(Config config) {
20
		this.baseUrl = config.getServiceBaseUrl();
21
	}
22
 
392 aurelien 23
	@Override
1101 gduche 24
	public void getObservations(InformationsRecherche infos, int debut, int fin, String statut, ObservationsCallback callback) {
1496 aurelien 25
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "observations" + assemblerChaineRequete(infos, debut, fin, statut));
939 benjamin 26
		callback.setMode(ModeRequete.LECTURE);
392 aurelien 27
		try {
28
			rb.sendRequest(null, callback);
29
		} catch (Exception e) {
30
			// TODO: handle exception
31
		}
32
	}
445 benjamin 33
 
1101 gduche 34
	private String assemblerChaineRequete(InformationsRecherche infos, int debut, int fin, String statut) {
445 benjamin 35
 
768 aurelien 36
		String chaineRequete = "?navigation.depart=" + debut + "&navigation.limite=" + (fin - debut);
1467 aurelien 37
		if (statut != null && !statut.equals("tous")) {
1101 gduche 38
			chaineRequete += "&masque.type=" + statut;
39
		}
474 aurelien 40
		chaineRequete+= infos.versChaineRequete();
445 benjamin 41
 
392 aurelien 42
		return chaineRequete;
43
	}
845 aurelien 44
 
45
	@Override
46
	public void getObservation(String idObservation,
47
			ObservationsCallback callback) {
1496 aurelien 48
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "observations/"+idObservation);
939 benjamin 49
		callback.setMode(ModeRequete.LECTURE);
845 aurelien 50
		try {
51
			rb.sendRequest(null, callback);
52
		} catch (Exception e) {
53
			// TODO: handle exception
54
		}
55
	}
392 aurelien 56
}