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