Subversion Repositories eFlore/Applications.del

Rev

Go to most recent revision | Details | 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;
1689 jpm 5
import org.tela_botanica.del.client.modeles.Observation;
6
import org.tela_botanica.del.client.modeles.VoteDetermination;
7
import org.tela_botanica.del.client.services.rest.async.DepublicationObservationCallBack;
392 aurelien 8
import org.tela_botanica.del.client.services.rest.async.ObservationsCallback;
939 benjamin 9
import org.tela_botanica.del.client.services.rest.async.PHPCallback.ModeRequete;
1496 aurelien 10
import org.tela_botanica.del.client.services.RequestBuilderWithCredentials;
392 aurelien 11
 
12
public class ObservationServiceConcret implements ObservationService {
445 benjamin 13
 
530 jpm 14
	private String baseUrl;
392 aurelien 15
 
530 jpm 16
	public ObservationServiceConcret() {
17
		Config config = new Config();
18
		this.baseUrl = config.getServiceBaseUrl();
19
	}
20
 
21
	public ObservationServiceConcret(Config config) {
22
		this.baseUrl = config.getServiceBaseUrl();
23
	}
24
 
392 aurelien 25
	@Override
1101 gduche 26
	public void getObservations(InformationsRecherche infos, int debut, int fin, String statut, ObservationsCallback callback) {
1496 aurelien 27
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "observations" + assemblerChaineRequete(infos, debut, fin, statut));
939 benjamin 28
		callback.setMode(ModeRequete.LECTURE);
392 aurelien 29
		try {
30
			rb.sendRequest(null, callback);
31
		} catch (Exception e) {
32
			// TODO: handle exception
33
		}
34
	}
445 benjamin 35
 
1101 gduche 36
	private String assemblerChaineRequete(InformationsRecherche infos, int debut, int fin, String statut) {
768 aurelien 37
		String chaineRequete = "?navigation.depart=" + debut + "&navigation.limite=" + (fin - debut);
1467 aurelien 38
		if (statut != null && !statut.equals("tous")) {
1101 gduche 39
			chaineRequete += "&masque.type=" + statut;
40
		}
474 aurelien 41
		chaineRequete+= infos.versChaineRequete();
445 benjamin 42
 
392 aurelien 43
		return chaineRequete;
44
	}
845 aurelien 45
 
46
	@Override
1689 jpm 47
	public void getObservation(String idObservation, 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
	}
1689 jpm 56
 
57
	public void depublier(Observation observation, DepublicationObservationCallBack callback) {
58
		String urlService = baseUrl+"observations/"+observation.getId();
59
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.POST, urlService);
60
 
61
		callback.setMode(ModeRequete.MODIFICATION);
62
		String chainePost = "transmission=0";
63
		try {
64
			rb.sendRequest(chainePost, callback);
65
		} catch (Exception e) {
66
			//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
67
		}
68
	}
392 aurelien 69
}