Subversion Repositories eFlore/Applications.del

Rev

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

Rev Author Line No. Line
879 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.Commentaire;
5
import org.tela_botanica.del.client.modeles.PropositionDetermination;
6
import org.tela_botanica.del.client.services.rest.async.CommentaireCallback;
7
import org.tela_botanica.del.client.services.rest.async.CommentaireCallback.ModeRequete;
8
 
9
import com.google.gwt.http.client.RequestBuilder;
10
import com.google.gwt.user.client.Window;
11
 
12
public class CommentaireServiceConcret implements CommentaireService {
13
 
14
	private String baseUrl;
15
 
16
	public CommentaireServiceConcret() {
17
		Config config = new Config();
18
		this.baseUrl = config.getServiceBaseUrl();
19
	}
20
 
21
	public CommentaireServiceConcret(Config config) {
22
		this.baseUrl = config.getServiceBaseUrl();
23
	}
24
 
25
	@Override
26
	public void ajouterCommentaire(Commentaire commentaire, CommentaireCallback callback) {
27
 
28
		String urlService = baseUrl+"commentaires/";
29
		RequestBuilder rb = new RequestBuilder(RequestBuilder.PUT, urlService);
30
 
31
		callback.setMode(ModeRequete.AJOUT);
32
		String chainePost = assemblerChaineRequeteAjoutModif(commentaire);
33
		try {
34
			rb.sendRequest(chainePost, callback);
35
		} catch (Exception e) {
36
			//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
37
		}
38
	}
39
 
40
	private String assemblerChaineRequeteAjoutModif(Commentaire commentaire) {
41
 
42
		String chaineRequete = "";
43
		if(commentaire.getObservation() != null && commentaire.getObservation().getId() != null) {
44
			chaineRequete += "observation="+commentaire.getObservation().getId();
45
		}
46
		if(commentaire.getContributeur().getId() != null) {
47
			chaineRequete += "&auteur.id="+commentaire.getContributeur().getId();
48
		}
49
 
50
		// TODO voir à quoi on rattache les commentaires
51
		if(commentaire.getParent() != null && commentaire.getParent().getId() != null) {
52
			if(commentaire.getParent() instanceof PropositionDetermination) {
53
				chaineRequete += "&ce_proposition="+commentaire.getParent().getId();
54
			} else if(commentaire.getParent() instanceof Commentaire) {
55
				chaineRequete += "&ce_commentaire_parent="+commentaire.getParent().getId();
56
			}
57
		}
58
		chaineRequete += "&texte="+commentaire.getCommentaire()+
59
		"&auteur.prenom="+commentaire.getContributeur().getPrenom()+
60
		"&auteur.nom="+commentaire.getContributeur().getNom()+
61
		"&auteur.courriel="+commentaire.getContributeur().getAdresseEmail();
62
		return chaineRequete;
63
	}
64
}