Subversion Repositories eFlore/Applications.del

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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