Subversion Repositories eFlore/Applications.del

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2211 arthur 1
package org.tela_botanica.del.client.services.rest;
2
 
3
import org.tela_botanica.del.client.config.Config;
4
import org.tela_botanica.del.client.modeles.InformationsRecherche;
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;
8
import org.tela_botanica.del.client.services.rest.async.ObservationsCallback;
9
import org.tela_botanica.del.client.services.rest.async.PHPCallback.ModeRequete;
10
import org.tela_botanica.del.client.utils.Analytics;
11
import org.tela_botanica.del.client.services.RequestBuilderWithCredentials;
12
 
13
public class ObservationServiceConcret implements ObservationService {
14
 
15
	private String baseUrl;
16
 
17
	public ObservationServiceConcret() {
18
		Config config = new Config();
19
		this.baseUrl = config.getServiceBaseUrl();
20
	}
21
 
22
	public ObservationServiceConcret(Config config) {
23
		this.baseUrl = config.getServiceBaseUrl();
24
	}
25
 
26
	@Override
27
	public void getObservations(InformationsRecherche infos, int debut, int fin, String statut, ObservationsCallback callback) {
28
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "observations" + assemblerChaineRequete(infos, debut, fin, statut));
29
		callback.setMode(ModeRequete.LECTURE);
30
		try {
31
			rb.sendRequest(null, callback);
32
		} catch (Exception e) {
33
			// TODO: handle exception
34
		}
35
	}
36
 
37
	private String assemblerChaineRequete(InformationsRecherche infos, int debut, int fin, String statut) {
38
		String chaineRequete = "?navigation.depart=" + debut + "&navigation.limite=" + (fin - debut);
39
		if (statut != null && !statut.equals("tous")) {
40
			chaineRequete += "&masque.type=" + statut;
41
		}
42
		chaineRequete+= infos.versChaineRequete();
43
 
44
		return chaineRequete;
45
	}
46
 
47
	@Override
48
	public void getObservation(String idObservation, ObservationsCallback callback) {
49
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "observations/"+idObservation);
50
		callback.setMode(ModeRequete.LECTURE);
51
		try {
52
			rb.sendRequest(null, callback);
53
		} catch (Exception e) {
54
			// TODO: handle exception
55
		}
56
	}
57
 
58
	public void depublier(Observation observation, DepublicationObservationCallBack callback) {
59
		String urlService = baseUrl+"observations/"+observation.getId();
60
		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.POST, urlService);
61
 
62
		callback.setMode(ModeRequete.MODIFICATION);
63
		String chainePost = "transmission=0";
64
		try {
65
			rb.sendRequest(chainePost, callback);
66
		} catch (Exception e) {
67
			//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
68
		}
69
		// stats
70
		Analytics.evenement("observation", "depublication", "{\"observation\": {\"id\": \"" + observation.getId() + "\", \"auteur\": \"" + observation.getAuteur() + "\"}}");
71
	}
72
}