| 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;
  | 
        
        
           | 1471 | 
           aurelien | 
           7 | 
           import org.tela_botanica.del.client.services.rest.async.AjoutVoteProtocoleCallback;
  | 
        
        
           | 939 | 
           benjamin | 
           8 | 
           import org.tela_botanica.del.client.services.rest.async.PHPCallback.ModeRequete;
  | 
        
        
           | 2109 | 
           mathias | 
           9 | 
           import org.tela_botanica.del.client.utils.Analytics;
  | 
        
        
           | 823 | 
           aurelien | 
           10 | 
           import org.tela_botanica.del.client.services.rest.async.VoteProtocoleCallback;
  | 
        
        
           | 939 | 
           benjamin | 
           11 | 
              | 
        
        
           | 1496 | 
           aurelien | 
           12 | 
           import org.tela_botanica.del.client.services.RequestBuilderWithCredentials;
  | 
        
        
           | 823 | 
           aurelien | 
           13 | 
              | 
        
        
            | 
            | 
           14 | 
           public class VoteProtocoleServiceConcret implements VoteProtocoleService {
  | 
        
        
            | 
            | 
           15 | 
              | 
        
        
            | 
            | 
           16 | 
           	private String baseUrl;
  | 
        
        
            | 
            | 
           17 | 
              | 
        
        
            | 
            | 
           18 | 
           	public VoteProtocoleServiceConcret() {
  | 
        
        
            | 
            | 
           19 | 
           		Config config = new Config();
  | 
        
        
            | 
            | 
           20 | 
           		this.baseUrl = config.getServiceBaseUrl();
  | 
        
        
            | 
            | 
           21 | 
           	}
  | 
        
        
            | 
            | 
           22 | 
              | 
        
        
            | 
            | 
           23 | 
           	public VoteProtocoleServiceConcret(Config config) {
  | 
        
        
            | 
            | 
           24 | 
           		this.baseUrl = config.getServiceBaseUrl();
  | 
        
        
            | 
            | 
           25 | 
           	}
  | 
        
        
            | 
            | 
           26 | 
              | 
        
        
            | 
            | 
           27 | 
           	@Override
  | 
        
        
            | 
            | 
           28 | 
           	public List<VoteProtocole> getVote(String idImage) {
  | 
        
        
            | 
            | 
           29 | 
           		// TODO Auto-generated method stub
  | 
        
        
            | 
            | 
           30 | 
           		return null;
  | 
        
        
            | 
            | 
           31 | 
           	}
  | 
        
        
            | 
            | 
           32 | 
              | 
        
        
            | 
            | 
           33 | 
           	@Override
  | 
        
        
            | 
            | 
           34 | 
           	public List<VoteProtocole> getVotePourImageEtProtocole(String idImage,
  | 
        
        
            | 
            | 
           35 | 
           			String protocolName) {
  | 
        
        
            | 
            | 
           36 | 
           		// TODO Auto-generated method stub
  | 
        
        
            | 
            | 
           37 | 
           		return null;
  | 
        
        
            | 
            | 
           38 | 
           	}
  | 
        
        
            | 
            | 
           39 | 
              | 
        
        
            | 
            | 
           40 | 
           	@Override
  | 
        
        
           | 1471 | 
           aurelien | 
           41 | 
           	public void ajouterVote(String idImage, VoteProtocole voteProtocole, AjoutVoteProtocoleCallback callback) {
  | 
        
        
           | 1496 | 
           aurelien | 
           42 | 
           		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.PUT, baseUrl+"images/"+idImage+"/votes/");
  | 
        
        
           | 823 | 
           aurelien | 
           43 | 
           		callback.setMode(ModeRequete.AJOUT);
  | 
        
        
            | 
            | 
           44 | 
           		String chainePost = assemblerChaineRequeteAjoutModif(voteProtocole);
  | 
        
        
            | 
            | 
           45 | 
           		try {
  | 
        
        
            | 
            | 
           46 | 
           			rb.sendRequest(chainePost, callback);
  | 
        
        
            | 
            | 
           47 | 
           		} catch (Exception e) {
  | 
        
        
            | 
            | 
           48 | 
           			//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
  | 
        
        
            | 
            | 
           49 | 
           		}
  | 
        
        
           | 2109 | 
           mathias | 
           50 | 
           		// stats
  | 
        
        
            | 
            | 
           51 | 
           		Analytics.evenement("vote", "ajout", "{\"valeur\": \"" + voteProtocole.getVote() + "\", \"auteur\": \"" + voteProtocole.getAuteur() + "\", \"id_image\": \"" + idImage + "\"}");
  | 
        
        
           | 823 | 
           aurelien | 
           52 | 
           	}
  | 
        
        
            | 
            | 
           53 | 
              | 
        
        
            | 
            | 
           54 | 
           	private String assemblerChaineRequeteAjoutModif(VoteProtocole voteProtocole) {
  | 
        
        
            | 
            | 
           55 | 
           		String chaineRequete = "utilisateur="+voteProtocole.getContributeur()+"&"+
  | 
        
        
            | 
            | 
           56 | 
           								"protocole="+voteProtocole.getIdProtocole()+"&"+
  | 
        
        
            | 
            | 
           57 | 
           								"valeur="+voteProtocole.getVote();
  | 
        
        
            | 
            | 
           58 | 
           		return chaineRequete;
  | 
        
        
            | 
            | 
           59 | 
           	}
  | 
        
        
           | 1471 | 
           aurelien | 
           60 | 
              | 
        
        
           | 823 | 
           aurelien | 
           61 | 
           	@Override
  | 
        
        
            | 
            | 
           62 | 
           	public void modifierVote(String idImage, VoteProtocole voteProtocole, VoteProtocoleCallback callback) {
  | 
        
        
           | 1496 | 
           aurelien | 
           63 | 
           		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.POST, baseUrl+"images/"+idImage+"/votes/");
  | 
        
        
           | 823 | 
           aurelien | 
           64 | 
           		callback.setMode(ModeRequete.MODIFICATION);
  | 
        
        
            | 
            | 
           65 | 
           		String chainePost = assemblerChaineRequeteAjoutModif(voteProtocole);
  | 
        
        
            | 
            | 
           66 | 
           		try {
  | 
        
        
            | 
            | 
           67 | 
           			rb.sendRequest(chainePost, callback);
  | 
        
        
            | 
            | 
           68 | 
           		} catch (Exception e) {
  | 
        
        
            | 
            | 
           69 | 
           			//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
  | 
        
        
            | 
            | 
           70 | 
           		}
  | 
        
        
           | 2109 | 
           mathias | 
           71 | 
           		// stats
  | 
        
        
            | 
            | 
           72 | 
           		Analytics.evenement("vote", "modification", "{\"valeur\": \"" + voteProtocole.getVote() + "\", \"auteur\": \"" + voteProtocole.getAuteur() + "\", \"id_image\": \"" + idImage + "\"}");
  | 
        
        
           | 823 | 
           aurelien | 
           73 | 
           	}
  | 
        
        
           | 1471 | 
           aurelien | 
           74 | 
              | 
        
        
            | 
            | 
           75 | 
           	@Override
  | 
        
        
            | 
            | 
           76 | 
           	public void supprimerVote(String idImage, VoteProtocole voteProtocole,
  | 
        
        
            | 
            | 
           77 | 
           			VoteProtocoleCallback callback) {
  | 
        
        
           | 1496 | 
           aurelien | 
           78 | 
           		RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.DELETE, baseUrl+"images/"+idImage+"/votes/"+voteProtocole.getId());
  | 
        
        
           | 1471 | 
           aurelien | 
           79 | 
           		callback.setMode(ModeRequete.SUPPRESSION);
  | 
        
        
            | 
            | 
           80 | 
           		try {
  | 
        
        
            | 
            | 
           81 | 
           			rb.sendRequest(null, callback);
  | 
        
        
            | 
            | 
           82 | 
           		} catch (Exception e) {
  | 
        
        
            | 
            | 
           83 | 
           			//TODO: quoi faire si la requete est mal formée coté client avant d'être envoyée ?
  | 
        
        
            | 
            | 
           84 | 
           		}
  | 
        
        
           | 2109 | 
           mathias | 
           85 | 
           		// stats
  | 
        
        
            | 
            | 
           86 | 
           		Analytics.evenement("vote", "suppression", "{\"valeur\": \"" + voteProtocole.getVote() + "\", \"auteur\": \"" + voteProtocole.getAuteur() + "\", \"id_image\": \"" + idImage + "\"}");
  | 
        
        
           | 1471 | 
           aurelien | 
           87 | 
           	}
  | 
        
        
           | 823 | 
           aurelien | 
           88 | 
           }
  |