823 |
aurelien |
1 |
package org.tela_botanica.del.client.services.rest;
|
|
|
2 |
|
|
|
3 |
import java.util.List;
|
|
|
4 |
|
|
|
5 |
import org.tela_botanica.del.client.config.Config;
|
|
|
6 |
import org.tela_botanica.del.client.modeles.VoteProtocole;
|
|
|
7 |
import org.tela_botanica.del.client.services.rest.async.VoteProtocoleCallback;
|
|
|
8 |
import org.tela_botanica.del.client.services.rest.async.VoteProtocoleCallback.ModeRequete;
|
|
|
9 |
import com.google.gwt.http.client.RequestBuilder;
|
|
|
10 |
|
|
|
11 |
public class VoteProtocoleServiceConcret implements VoteProtocoleService {
|
|
|
12 |
|
|
|
13 |
private String baseUrl;
|
|
|
14 |
|
|
|
15 |
public VoteProtocoleServiceConcret() {
|
|
|
16 |
Config config = new Config();
|
|
|
17 |
this.baseUrl = config.getServiceBaseUrl();
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
public VoteProtocoleServiceConcret(Config config) {
|
|
|
21 |
this.baseUrl = config.getServiceBaseUrl();
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
@Override
|
|
|
25 |
public List<VoteProtocole> getVote(String idImage) {
|
|
|
26 |
// TODO Auto-generated method stub
|
|
|
27 |
return null;
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
@Override
|
|
|
31 |
public List<VoteProtocole> getVotePourImageEtProtocole(String idImage,
|
|
|
32 |
String protocolName) {
|
|
|
33 |
// TODO Auto-generated method stub
|
|
|
34 |
return null;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
@Override
|
|
|
38 |
public void ajouterVote(String idImage, VoteProtocole voteProtocole, VoteProtocoleCallback callback) {
|
|
|
39 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.PUT, baseUrl+"images/"+idImage+"/votes/");
|
|
|
40 |
callback.setMode(ModeRequete.AJOUT);
|
|
|
41 |
String chainePost = assemblerChaineRequeteAjoutModif(voteProtocole);
|
|
|
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 ?
|
|
|
46 |
}
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
private String assemblerChaineRequeteAjoutModif(VoteProtocole voteProtocole) {
|
|
|
50 |
String chaineRequete = "utilisateur="+voteProtocole.getContributeur()+"&"+
|
|
|
51 |
"protocole="+voteProtocole.getIdProtocole()+"&"+
|
|
|
52 |
"valeur="+voteProtocole.getVote();
|
|
|
53 |
return chaineRequete;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
@Override
|
|
|
57 |
public void modifierVote(String idImage, VoteProtocole voteProtocole, VoteProtocoleCallback callback) {
|
|
|
58 |
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, baseUrl+"images/"+idImage+"/votes/");
|
|
|
59 |
callback.setMode(ModeRequete.MODIFICATION);
|
|
|
60 |
String chainePost = assemblerChaineRequeteAjoutModif(voteProtocole);
|
|
|
61 |
try {
|
|
|
62 |
rb.sendRequest(chainePost, callback);
|
|
|
63 |
} catch (Exception e) {
|
|
|
64 |
//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
}
|