1151 |
aurelien |
1 |
package org.tela_botanica.del.client.services.rest;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.del.client.cache.CacheClient;
|
|
|
4 |
import org.tela_botanica.del.client.config.Config;
|
1162 |
aurelien |
5 |
import org.tela_botanica.del.client.services.rest.async.AjoutMotsClesImageCallback;
|
1151 |
aurelien |
6 |
import org.tela_botanica.del.client.services.rest.async.ListeMotsClesImageCallBack;
|
|
|
7 |
import org.tela_botanica.del.client.services.rest.async.PHPCallback.ModeRequete;
|
2109 |
mathias |
8 |
import org.tela_botanica.del.client.utils.Analytics;
|
1162 |
aurelien |
9 |
import org.tela_botanica.del.client.services.rest.async.SuppressionMotCleImageCallback;
|
1151 |
aurelien |
10 |
|
1496 |
aurelien |
11 |
import org.tela_botanica.del.client.services.RequestBuilderWithCredentials;
|
1151 |
aurelien |
12 |
import com.google.gwt.http.client.URL;
|
|
|
13 |
|
|
|
14 |
public class MotsClesServiceConcret implements MotsClesService {
|
|
|
15 |
|
|
|
16 |
private String baseUrl;
|
|
|
17 |
|
|
|
18 |
public MotsClesServiceConcret() {
|
|
|
19 |
Config config = new Config();
|
|
|
20 |
this.baseUrl = config.getServiceBaseUrl();
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
public MotsClesServiceConcret(Config config) {
|
|
|
24 |
this.baseUrl = config.getServiceBaseUrl();
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
@Override
|
|
|
28 |
public void getMotsClesImage(String idImage,
|
|
|
29 |
ListeMotsClesImageCallBack callback) {
|
1496 |
aurelien |
30 |
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, baseUrl + "mots-cles" + assemblerChaineRequete(idImage));
|
1151 |
aurelien |
31 |
callback.setMode(ModeRequete.LECTURE);
|
|
|
32 |
try {
|
|
|
33 |
rb.sendRequest(null, callback);
|
|
|
34 |
} catch (Exception e) {
|
|
|
35 |
// TODO: handle exception
|
|
|
36 |
}
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
private String assemblerChaineRequete(String idImage) {
|
1860 |
jpm |
40 |
String chaineRequete = "?image="+idImage;
|
1151 |
aurelien |
41 |
return chaineRequete;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
@Override
|
|
|
45 |
public void ajouterMotCleImage(String idImage, String motCle,
|
1162 |
aurelien |
46 |
AjoutMotsClesImageCallback callback) {
|
1151 |
aurelien |
47 |
String urlService = baseUrl+"mots-cles/";
|
1496 |
aurelien |
48 |
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.PUT, urlService);
|
1151 |
aurelien |
49 |
|
|
|
50 |
callback.setMode(ModeRequete.AJOUT);
|
|
|
51 |
String chainePost = assemblerChaineRequeteAjout(idImage, motCle);
|
|
|
52 |
try {
|
|
|
53 |
rb.sendRequest(chainePost, callback);
|
|
|
54 |
} catch (Exception e) {
|
|
|
55 |
//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
|
|
|
56 |
}
|
2109 |
mathias |
57 |
// stats
|
|
|
58 |
Analytics.evenement("mot-cle-image", "ajout", "{\"mot-cle\": \"" + motCle + "\", \"image\": \"" + idImage + "\"}");
|
1151 |
aurelien |
59 |
}
|
|
|
60 |
|
|
|
61 |
private String assemblerChaineRequeteAjout(String idImage, String motCle) {
|
|
|
62 |
return "image="+URL.encodeQueryString(idImage)+
|
|
|
63 |
"&mot_cle="+URL.encodeQueryString(motCle)+
|
|
|
64 |
"&"+URL.encodeQueryString("auteur.id")+"="+URL.encodeQueryString(CacheClient.getInstance().getUtilisateur().getId());
|
|
|
65 |
}
|
|
|
66 |
|
1162 |
aurelien |
67 |
@Override
|
|
|
68 |
public void supprimerMotCleImage(String idMotCle, SuppressionMotCleImageCallback callback) {
|
|
|
69 |
String urlService = baseUrl+"mots-cles/"+idMotCle;
|
1496 |
aurelien |
70 |
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.DELETE, urlService);
|
1162 |
aurelien |
71 |
|
|
|
72 |
callback.setMode(ModeRequete.SUPPRESSION);
|
|
|
73 |
try {
|
|
|
74 |
rb.sendRequest(null, callback);
|
|
|
75 |
} catch (Exception e) {
|
|
|
76 |
//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
|
|
|
77 |
}
|
2109 |
mathias |
78 |
// stats
|
|
|
79 |
Analytics.evenement("mot-cle-image", "suppression", "{\"id_mot-cle\": \"" + idMotCle + "\"}");
|
1162 |
aurelien |
80 |
}
|
1151 |
aurelien |
81 |
}
|