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;
|
2109 |
mathias |
10 |
import org.tela_botanica.del.client.utils.Analytics;
|
1496 |
aurelien |
11 |
import org.tela_botanica.del.client.services.RequestBuilderWithCredentials;
|
392 |
aurelien |
12 |
|
|
|
13 |
public class ObservationServiceConcret implements ObservationService {
|
445 |
benjamin |
14 |
|
530 |
jpm |
15 |
private String baseUrl;
|
392 |
aurelien |
16 |
|
530 |
jpm |
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 |
|
392 |
aurelien |
26 |
@Override
|
1101 |
gduche |
27 |
public void getObservations(InformationsRecherche infos, int debut, int fin, String statut, ObservationsCallback callback) {
|
1496 |
aurelien |
28 |
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "observations" + assemblerChaineRequete(infos, debut, fin, statut));
|
939 |
benjamin |
29 |
callback.setMode(ModeRequete.LECTURE);
|
392 |
aurelien |
30 |
try {
|
|
|
31 |
rb.sendRequest(null, callback);
|
|
|
32 |
} catch (Exception e) {
|
|
|
33 |
// TODO: handle exception
|
|
|
34 |
}
|
|
|
35 |
}
|
445 |
benjamin |
36 |
|
1101 |
gduche |
37 |
private String assemblerChaineRequete(InformationsRecherche infos, int debut, int fin, String statut) {
|
768 |
aurelien |
38 |
String chaineRequete = "?navigation.depart=" + debut + "&navigation.limite=" + (fin - debut);
|
1467 |
aurelien |
39 |
if (statut != null && !statut.equals("tous")) {
|
1101 |
gduche |
40 |
chaineRequete += "&masque.type=" + statut;
|
|
|
41 |
}
|
474 |
aurelien |
42 |
chaineRequete+= infos.versChaineRequete();
|
445 |
benjamin |
43 |
|
392 |
aurelien |
44 |
return chaineRequete;
|
|
|
45 |
}
|
845 |
aurelien |
46 |
|
|
|
47 |
@Override
|
1689 |
jpm |
48 |
public void getObservation(String idObservation, ObservationsCallback callback) {
|
1496 |
aurelien |
49 |
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "observations/"+idObservation);
|
939 |
benjamin |
50 |
callback.setMode(ModeRequete.LECTURE);
|
845 |
aurelien |
51 |
try {
|
|
|
52 |
rb.sendRequest(null, callback);
|
|
|
53 |
} catch (Exception e) {
|
|
|
54 |
// TODO: handle exception
|
|
|
55 |
}
|
|
|
56 |
}
|
1689 |
jpm |
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 |
}
|
2109 |
mathias |
69 |
// stats
|
|
|
70 |
Analytics.evenement("observation", "depublication", "{\"observation\": {\"id\": \"" + observation.getId() + "\", \"auteur\": \"" + observation.getAuteur() + "\"}}");
|
1689 |
jpm |
71 |
}
|
392 |
aurelien |
72 |
}
|