836 |
aurelien |
1 |
package org.tela_botanica.del.client.services.rest;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.del.client.config.Config;
|
899 |
aurelien |
4 |
import org.tela_botanica.del.client.modeles.PropositionDetermination;
|
836 |
aurelien |
5 |
import org.tela_botanica.del.client.modeles.VoteDetermination;
|
939 |
benjamin |
6 |
import org.tela_botanica.del.client.services.rest.async.AjoutVoteDeterminationCallback;
|
|
|
7 |
import org.tela_botanica.del.client.services.rest.async.ListeVotesDeterminationCallback;
|
|
|
8 |
import org.tela_botanica.del.client.services.rest.async.PHPCallback.ModeRequete;
|
2109 |
mathias |
9 |
import org.tela_botanica.del.client.utils.Analytics;
|
1496 |
aurelien |
10 |
import org.tela_botanica.del.client.services.RequestBuilderWithCredentials;
|
890 |
gduche |
11 |
import com.google.gwt.user.client.Window;
|
836 |
aurelien |
12 |
|
|
|
13 |
public class VoteDeterminationServiceConcret implements VoteDeterminationService {
|
|
|
14 |
|
|
|
15 |
private String baseUrl;
|
|
|
16 |
|
|
|
17 |
public VoteDeterminationServiceConcret() {
|
|
|
18 |
Config config = new Config();
|
|
|
19 |
this.baseUrl = config.getServiceBaseUrl();
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
public VoteDeterminationServiceConcret(Config config) {
|
|
|
23 |
this.baseUrl = config.getServiceBaseUrl();
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
@Override
|
939 |
benjamin |
27 |
public void ajouterVote(VoteDetermination voteDetermination, AjoutVoteDeterminationCallback callback) {
|
890 |
gduche |
28 |
|
|
|
29 |
|
836 |
aurelien |
30 |
String idObservation = voteDetermination.getPropositionDetermination().getObservation().getId();
|
|
|
31 |
String idProposition = voteDetermination.getPropositionDetermination().getId();
|
869 |
aurelien |
32 |
//cas de la proposition de détermination crée automatiquement à partir de l'obs
|
|
|
33 |
if(idProposition == null) {
|
|
|
34 |
idProposition = "0";
|
|
|
35 |
}
|
836 |
aurelien |
36 |
|
|
|
37 |
String urlService = baseUrl+"observations/"+idObservation+"/"+idProposition+"/vote/";
|
1496 |
aurelien |
38 |
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.PUT, urlService);
|
836 |
aurelien |
39 |
|
852 |
aurelien |
40 |
callback.setMode(ModeRequete.AJOUT);
|
836 |
aurelien |
41 |
String chainePost = assemblerChaineRequeteAjoutModif(voteDetermination);
|
|
|
42 |
try {
|
|
|
43 |
rb.sendRequest(chainePost, callback);
|
|
|
44 |
} catch (Exception e) {
|
|
|
45 |
//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
|
852 |
aurelien |
46 |
}
|
2109 |
mathias |
47 |
// stats
|
|
|
48 |
Analytics.evenement("vote", "ajout", "{\"vote\": {\"valeur\": \"" + voteDetermination.getVote() + "\", \"auteur\": \"" + voteDetermination.getAuteur()
|
|
|
49 |
+ "\"}, \"proposition\": {\"auteur\": \"" + voteDetermination.getPropositionDetermination().getAuteur() + "\", \"nom_sci\": \"" + voteDetermination.getPropositionDetermination().getEspece() + "\", \"referentiel\": \"" + voteDetermination.getPropositionDetermination().getReferentiel() + "\"}}");
|
836 |
aurelien |
50 |
}
|
|
|
51 |
|
|
|
52 |
@Override
|
939 |
benjamin |
53 |
public void modifierVote(VoteDetermination voteDetermination, AjoutVoteDeterminationCallback callback) {
|
836 |
aurelien |
54 |
String idObservation = voteDetermination.getPropositionDetermination().getObservation().getId();
|
|
|
55 |
String idProposition = voteDetermination.getPropositionDetermination().getId();
|
869 |
aurelien |
56 |
//cas de la proposition de détermination crée automatiquement à partir de l'obs
|
|
|
57 |
if(idProposition == null) {
|
|
|
58 |
idProposition = "0";
|
|
|
59 |
}
|
836 |
aurelien |
60 |
|
|
|
61 |
String urlService = baseUrl+"observations/"+idObservation+"/"+idProposition+"/vote/";
|
1496 |
aurelien |
62 |
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.POST, urlService);
|
869 |
aurelien |
63 |
|
852 |
aurelien |
64 |
callback.setMode(ModeRequete.MODIFICATION);
|
836 |
aurelien |
65 |
String chainePost = assemblerChaineRequeteAjoutModif(voteDetermination);
|
|
|
66 |
try {
|
|
|
67 |
rb.sendRequest(chainePost, callback);
|
|
|
68 |
} catch (Exception e) {
|
|
|
69 |
//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
|
852 |
aurelien |
70 |
}
|
2109 |
mathias |
71 |
// stats
|
|
|
72 |
Analytics.evenement("vote", "modification", "{\"vote\": {\"valeur\": \"" + voteDetermination.getVote() + "\", \"auteur\": \"" + voteDetermination.getAuteur()
|
|
|
73 |
+ "\"}, \"proposition\": {\"auteur\": \"" + voteDetermination.getPropositionDetermination().getAuteur() + "\", \"nom_sci\": \"" + voteDetermination.getPropositionDetermination().getEspece() + "\", \"referentiel\": \"" + voteDetermination.getPropositionDetermination().getReferentiel() + "\"}}");
|
836 |
aurelien |
74 |
}
|
|
|
75 |
|
|
|
76 |
private String assemblerChaineRequeteAjoutModif(VoteDetermination voteDetermination) {
|
|
|
77 |
String chaineRequete = "utilisateur="+voteDetermination.getContributeur()+"&"+
|
|
|
78 |
"valeur="+voteDetermination.getVote();
|
|
|
79 |
return chaineRequete;
|
|
|
80 |
}
|
899 |
aurelien |
81 |
|
|
|
82 |
@Override
|
939 |
benjamin |
83 |
public void consulterVotesPourPropositionDetermination(PropositionDetermination propositionDetermination, ListeVotesDeterminationCallback callback) {
|
899 |
aurelien |
84 |
String idObservation = propositionDetermination.getObservation().getId();
|
|
|
85 |
String idProposition = propositionDetermination.getId();
|
|
|
86 |
//cas de la proposition de détermination crée automatiquement à partir de l'obs
|
|
|
87 |
if(idProposition == null) {
|
|
|
88 |
idProposition = "0";
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
String urlService = baseUrl+"observations/"+idObservation+"/"+idProposition+"/vote/";
|
1496 |
aurelien |
92 |
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, urlService);
|
899 |
aurelien |
93 |
|
|
|
94 |
callback.setMode(ModeRequete.LECTURE);
|
|
|
95 |
try {
|
|
|
96 |
rb.sendRequest(null, callback);
|
|
|
97 |
} catch (Exception e) {
|
|
|
98 |
//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
|
|
|
99 |
}
|
|
|
100 |
}
|
836 |
aurelien |
101 |
}
|