Subversion Repositories eFlore/Applications.del

Rev

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

package org.tela_botanica.del.client.services.rest;

import java.util.List;

import org.tela_botanica.del.client.config.Config;
import org.tela_botanica.del.client.modeles.VoteProtocole;
import org.tela_botanica.del.client.services.rest.async.VoteProtocoleCallback;
import org.tela_botanica.del.client.services.rest.async.VoteProtocoleCallback.ModeRequete;
import com.google.gwt.http.client.RequestBuilder;

public class VoteProtocoleServiceConcret implements VoteProtocoleService {

        private String baseUrl;

        public VoteProtocoleServiceConcret() {
                Config config = new Config();
                this.baseUrl = config.getServiceBaseUrl();
        }
        
        public VoteProtocoleServiceConcret(Config config) {
                this.baseUrl = config.getServiceBaseUrl();
        }
        
        @Override
        public List<VoteProtocole> getVote(String idImage) {
                // TODO Auto-generated method stub
                return null;
        }

        @Override
        public List<VoteProtocole> getVotePourImageEtProtocole(String idImage,
                        String protocolName) {
                // TODO Auto-generated method stub
                return null;
        }

        @Override
        public void ajouterVote(String idImage, VoteProtocole voteProtocole, VoteProtocoleCallback callback) {
                RequestBuilder rb = new RequestBuilder(RequestBuilder.PUT, baseUrl+"images/"+idImage+"/votes/");
                callback.setMode(ModeRequete.AJOUT);
                String chainePost = assemblerChaineRequeteAjoutModif(voteProtocole);
                try {
                        rb.sendRequest(chainePost, callback);
                } catch (Exception e) {
                        //TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
                }
        }

        private String assemblerChaineRequeteAjoutModif(VoteProtocole voteProtocole) {
                String chaineRequete = "utilisateur="+voteProtocole.getContributeur()+"&"+
                                                                "protocole="+voteProtocole.getIdProtocole()+"&"+
                                                                "valeur="+voteProtocole.getVote();
                return chaineRequete;
        }

        @Override
        public void modifierVote(String idImage, VoteProtocole voteProtocole, VoteProtocoleCallback callback) {
                RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, baseUrl+"images/"+idImage+"/votes/");
                callback.setMode(ModeRequete.MODIFICATION);
                String chainePost = assemblerChaineRequeteAjoutModif(voteProtocole);
                try {
                        rb.sendRequest(chainePost, callback);
                } catch (Exception e) {
                        //TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
                }
        }
}