Subversion Repositories eFlore/Applications.del

Rev

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

Rev Author Line No. Line
836 aurelien 1
package org.tela_botanica.del.client.services.rest;
2
 
3
import org.tela_botanica.del.client.config.Config;
4
import org.tela_botanica.del.client.modeles.VoteDetermination;
5
import org.tela_botanica.del.client.services.rest.async.VoteDeterminationCallBack;
6
import org.tela_botanica.del.client.services.rest.async.VoteDeterminationCallBack.ModeRequete;
7
 
8
import com.google.gwt.http.client.RequestBuilder;
9
import com.google.gwt.user.client.Window;
10
 
11
public class VoteDeterminationServiceConcret implements VoteDeterminationService {
12
 
13
	private String baseUrl;
14
 
15
	public VoteDeterminationServiceConcret() {
16
		Config config = new Config();
17
		this.baseUrl = config.getServiceBaseUrl();
18
	}
19
 
20
	public VoteDeterminationServiceConcret(Config config) {
21
		this.baseUrl = config.getServiceBaseUrl();
22
	}
23
 
24
	@Override
25
	public void ajouterVote(VoteDetermination voteDetermination, VoteDeterminationCallBack callback) {
26
		String idObservation = voteDetermination.getPropositionDetermination().getObservation().getId();
27
		String idProposition = voteDetermination.getPropositionDetermination().getId();
28
 
29
		String urlService = baseUrl+"observations/"+idObservation+"/"+idProposition+"/vote/";
30
		RequestBuilder rb = new RequestBuilder(RequestBuilder.PUT, urlService);
31
 
32
		Window.alert("Ajout :"+urlService);
33
		/*callback.setMode(ModeRequete.AJOUT);
34
		String chainePost = assemblerChaineRequeteAjoutModif(voteDetermination);
35
		try {
36
			rb.sendRequest(chainePost, callback);
37
		} catch (Exception e) {
38
			//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
39
		}*/
40
	}
41
 
42
	@Override
43
	public void modifierVote(VoteDetermination voteDetermination, VoteDeterminationCallBack callback) {
44
		String idObservation = voteDetermination.getPropositionDetermination().getObservation().getId();
45
		String idProposition = voteDetermination.getPropositionDetermination().getId();
46
 
47
		String urlService = baseUrl+"observations/"+idObservation+"/"+idProposition+"/vote/";
48
		RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, urlService);
49
 
50
		Window.alert("Ajout :"+urlService);
51
		/*callback.setMode(ModeRequete.MODIFICATION);
52
		String chainePost = assemblerChaineRequeteAjoutModif(voteDetermination);
53
		try {
54
			rb.sendRequest(chainePost, callback);
55
		} catch (Exception e) {
56
			//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
57
		}*/
58
	}
59
 
60
	private String assemblerChaineRequeteAjoutModif(VoteDetermination voteDetermination) {
61
		String chaineRequete = "utilisateur="+voteDetermination.getContributeur()+"&"+
62
								"valeur="+voteDetermination.getVote();
63
		return chaineRequete;
64
	}
65
}