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