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;
|
1471 |
aurelien |
7 |
import org.tela_botanica.del.client.services.rest.async.AjoutVoteProtocoleCallback;
|
939 |
benjamin |
8 |
import org.tela_botanica.del.client.services.rest.async.PHPCallback.ModeRequete;
|
823 |
aurelien |
9 |
import org.tela_botanica.del.client.services.rest.async.VoteProtocoleCallback;
|
939 |
benjamin |
10 |
|
1496 |
aurelien |
11 |
import org.tela_botanica.del.client.services.RequestBuilderWithCredentials;
|
823 |
aurelien |
12 |
|
|
|
13 |
public class VoteProtocoleServiceConcret implements VoteProtocoleService {
|
|
|
14 |
|
|
|
15 |
private String baseUrl;
|
|
|
16 |
|
|
|
17 |
public VoteProtocoleServiceConcret() {
|
|
|
18 |
Config config = new Config();
|
|
|
19 |
this.baseUrl = config.getServiceBaseUrl();
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
public VoteProtocoleServiceConcret(Config config) {
|
|
|
23 |
this.baseUrl = config.getServiceBaseUrl();
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
@Override
|
|
|
27 |
public List<VoteProtocole> getVote(String idImage) {
|
|
|
28 |
// TODO Auto-generated method stub
|
|
|
29 |
return null;
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
@Override
|
|
|
33 |
public List<VoteProtocole> getVotePourImageEtProtocole(String idImage,
|
|
|
34 |
String protocolName) {
|
|
|
35 |
// TODO Auto-generated method stub
|
|
|
36 |
return null;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
@Override
|
1471 |
aurelien |
40 |
public void ajouterVote(String idImage, VoteProtocole voteProtocole, AjoutVoteProtocoleCallback callback) {
|
1496 |
aurelien |
41 |
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.PUT, baseUrl+"images/"+idImage+"/votes/");
|
823 |
aurelien |
42 |
callback.setMode(ModeRequete.AJOUT);
|
|
|
43 |
String chainePost = assemblerChaineRequeteAjoutModif(voteProtocole);
|
|
|
44 |
try {
|
|
|
45 |
rb.sendRequest(chainePost, callback);
|
|
|
46 |
} catch (Exception e) {
|
|
|
47 |
//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
private String assemblerChaineRequeteAjoutModif(VoteProtocole voteProtocole) {
|
|
|
52 |
String chaineRequete = "utilisateur="+voteProtocole.getContributeur()+"&"+
|
|
|
53 |
"protocole="+voteProtocole.getIdProtocole()+"&"+
|
|
|
54 |
"valeur="+voteProtocole.getVote();
|
|
|
55 |
return chaineRequete;
|
|
|
56 |
}
|
1471 |
aurelien |
57 |
|
823 |
aurelien |
58 |
@Override
|
|
|
59 |
public void modifierVote(String idImage, VoteProtocole voteProtocole, VoteProtocoleCallback callback) {
|
1496 |
aurelien |
60 |
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.POST, baseUrl+"images/"+idImage+"/votes/");
|
823 |
aurelien |
61 |
callback.setMode(ModeRequete.MODIFICATION);
|
|
|
62 |
String chainePost = assemblerChaineRequeteAjoutModif(voteProtocole);
|
|
|
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 ?
|
|
|
67 |
}
|
|
|
68 |
}
|
1471 |
aurelien |
69 |
|
|
|
70 |
@Override
|
|
|
71 |
public void supprimerVote(String idImage, VoteProtocole voteProtocole,
|
|
|
72 |
VoteProtocoleCallback callback) {
|
1496 |
aurelien |
73 |
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.DELETE, baseUrl+"images/"+idImage+"/votes/"+voteProtocole.getId());
|
1471 |
aurelien |
74 |
callback.setMode(ModeRequete.SUPPRESSION);
|
|
|
75 |
try {
|
|
|
76 |
rb.sendRequest(null, callback);
|
|
|
77 |
} catch (Exception e) {
|
|
|
78 |
//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
|
|
|
79 |
}
|
|
|
80 |
}
|
823 |
aurelien |
81 |
}
|