Subversion Repositories eFlore/Applications.del

Compare Revisions

Ignore whitespace Rev 835 → Rev 836

/trunk/src/org/tela_botanica/del/client/services/rest/async/VoteDeterminationCallBack.java
New file
0,0 → 1,59
package org.tela_botanica.del.client.services.rest.async;
 
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
import com.google.gwt.user.client.Window;
 
public abstract class VoteDeterminationCallBack implements RequestCallback {
//TODO: voir si l'on fusionne les deux classes de vote callback qui sont tout à fait semblables
// pour ne pas dire identiques
public enum ModeRequete {
AJOUT, MODIFICATION
}
protected ModeRequete mode;
public VoteDeterminationCallBack(ModeRequete mode) {
this.mode = mode;
}
 
public VoteDeterminationCallBack() {
// TODO Auto-generated constructor stub
}
public void setMode(ModeRequete mode) {
this.mode = mode;
}
 
@Override
public void onResponseReceived(Request request, Response response){
int statusCode = response.getStatusCode();
int codeAttendu = 500;
switch (mode) {
case AJOUT:
codeAttendu = 201;
break;
case MODIFICATION:
codeAttendu = 200;
break;
default:
codeAttendu = 500;
break;
}
if (statusCode == codeAttendu) {
surRetour(response.getText());
} else {
surErreur("Erreur " + statusCode + ": " + response.getText());
}
}
 
@Override
public void onError(Request request, Throwable exception) {
Window.alert(exception.getMessage());
}
public abstract void surRetour(String messageRetour);
public abstract void surErreur(String messageErreur);
}
/trunk/src/org/tela_botanica/del/client/services/rest/VoteDeterminationServiceConcret.java
New file
0,0 → 1,65
package org.tela_botanica.del.client.services.rest;
 
import org.tela_botanica.del.client.config.Config;
import org.tela_botanica.del.client.modeles.VoteDetermination;
import org.tela_botanica.del.client.services.rest.async.VoteDeterminationCallBack;
import org.tela_botanica.del.client.services.rest.async.VoteDeterminationCallBack.ModeRequete;
 
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.user.client.Window;
 
public class VoteDeterminationServiceConcret implements VoteDeterminationService {
 
private String baseUrl;
 
public VoteDeterminationServiceConcret() {
Config config = new Config();
this.baseUrl = config.getServiceBaseUrl();
}
public VoteDeterminationServiceConcret(Config config) {
this.baseUrl = config.getServiceBaseUrl();
}
@Override
public void ajouterVote(VoteDetermination voteDetermination, VoteDeterminationCallBack callback) {
String idObservation = voteDetermination.getPropositionDetermination().getObservation().getId();
String idProposition = voteDetermination.getPropositionDetermination().getId();
String urlService = baseUrl+"observations/"+idObservation+"/"+idProposition+"/vote/";
RequestBuilder rb = new RequestBuilder(RequestBuilder.PUT, urlService);
Window.alert("Ajout :"+urlService);
/*callback.setMode(ModeRequete.AJOUT);
String chainePost = assemblerChaineRequeteAjoutModif(voteDetermination);
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 ?
}*/
}
 
@Override
public void modifierVote(VoteDetermination voteDetermination, VoteDeterminationCallBack callback) {
String idObservation = voteDetermination.getPropositionDetermination().getObservation().getId();
String idProposition = voteDetermination.getPropositionDetermination().getId();
String urlService = baseUrl+"observations/"+idObservation+"/"+idProposition+"/vote/";
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, urlService);
Window.alert("Ajout :"+urlService);
/*callback.setMode(ModeRequete.MODIFICATION);
String chainePost = assemblerChaineRequeteAjoutModif(voteDetermination);
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(VoteDetermination voteDetermination) {
String chaineRequete = "utilisateur="+voteDetermination.getContributeur()+"&"+
"valeur="+voteDetermination.getVote();
return chaineRequete;
}
}
/trunk/src/org/tela_botanica/del/client/services/rest/VoteDeterminationService.java
New file
0,0 → 1,11
package org.tela_botanica.del.client.services.rest;
 
import org.tela_botanica.del.client.modeles.VoteDetermination;
import org.tela_botanica.del.client.services.rest.async.VoteDeterminationCallBack;
 
public interface VoteDeterminationService {
 
void ajouterVote(VoteDetermination voteDetermination, VoteDeterminationCallBack callback);
public void modifierVote(VoteDetermination voteDetermination, VoteDeterminationCallBack callback);
}