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;
|
836 |
aurelien |
9 |
|
|
|
10 |
import com.google.gwt.http.client.RequestBuilder;
|
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/";
|
|
|
38 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.PUT, urlService);
|
|
|
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 |
}
|
836 |
aurelien |
47 |
}
|
|
|
48 |
|
|
|
49 |
@Override
|
939 |
benjamin |
50 |
public void modifierVote(VoteDetermination voteDetermination, AjoutVoteDeterminationCallback callback) {
|
836 |
aurelien |
51 |
String idObservation = voteDetermination.getPropositionDetermination().getObservation().getId();
|
|
|
52 |
String idProposition = voteDetermination.getPropositionDetermination().getId();
|
869 |
aurelien |
53 |
//cas de la proposition de détermination crée automatiquement à partir de l'obs
|
|
|
54 |
if(idProposition == null) {
|
|
|
55 |
idProposition = "0";
|
|
|
56 |
}
|
836 |
aurelien |
57 |
|
|
|
58 |
String urlService = baseUrl+"observations/"+idObservation+"/"+idProposition+"/vote/";
|
|
|
59 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, urlService);
|
869 |
aurelien |
60 |
|
852 |
aurelien |
61 |
callback.setMode(ModeRequete.MODIFICATION);
|
836 |
aurelien |
62 |
String chainePost = assemblerChaineRequeteAjoutModif(voteDetermination);
|
|
|
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 ?
|
852 |
aurelien |
67 |
}
|
836 |
aurelien |
68 |
}
|
|
|
69 |
|
|
|
70 |
private String assemblerChaineRequeteAjoutModif(VoteDetermination voteDetermination) {
|
|
|
71 |
String chaineRequete = "utilisateur="+voteDetermination.getContributeur()+"&"+
|
|
|
72 |
"valeur="+voteDetermination.getVote();
|
|
|
73 |
return chaineRequete;
|
|
|
74 |
}
|
899 |
aurelien |
75 |
|
|
|
76 |
@Override
|
939 |
benjamin |
77 |
public void consulterVotesPourPropositionDetermination(PropositionDetermination propositionDetermination, ListeVotesDeterminationCallback callback) {
|
899 |
aurelien |
78 |
String idObservation = propositionDetermination.getObservation().getId();
|
|
|
79 |
String idProposition = propositionDetermination.getId();
|
|
|
80 |
//cas de la proposition de détermination crée automatiquement à partir de l'obs
|
|
|
81 |
if(idProposition == null) {
|
|
|
82 |
idProposition = "0";
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
String urlService = baseUrl+"observations/"+idObservation+"/"+idProposition+"/vote/";
|
|
|
86 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, urlService);
|
|
|
87 |
|
|
|
88 |
callback.setMode(ModeRequete.LECTURE);
|
|
|
89 |
try {
|
|
|
90 |
rb.sendRequest(null, callback);
|
|
|
91 |
} catch (Exception e) {
|
|
|
92 |
//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
|
|
|
93 |
}
|
|
|
94 |
}
|
836 |
aurelien |
95 |
}
|