Subversion Repositories eFlore/Applications.del

Rev

Rev 823 | Rev 1471 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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