Subversion Repositories eFlore/Applications.del

Rev

Rev 1689 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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