887 |
aurelien |
1 |
package org.tela_botanica.del.client.services.rest.async;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.del.client.utils.UtilitairesServiceResultat;
|
|
|
4 |
|
|
|
5 |
import com.google.gwt.http.client.Request;
|
|
|
6 |
import com.google.gwt.http.client.RequestCallback;
|
|
|
7 |
import com.google.gwt.http.client.Response;
|
|
|
8 |
import com.google.gwt.json.client.JSONParser;
|
|
|
9 |
import com.google.gwt.user.client.Window;
|
|
|
10 |
|
|
|
11 |
public abstract class PropositionDeterminationCallBack implements RequestCallback {
|
|
|
12 |
|
|
|
13 |
//TODO: voir si l'on fusionne les classes de vote callback qui sont tout à fait semblables
|
|
|
14 |
// pour ne pas dire identiques
|
|
|
15 |
public enum ModeRequete {
|
|
|
16 |
AJOUT, MODIFICATION, SUPPRESSION
|
|
|
17 |
}
|
|
|
18 |
|
|
|
19 |
protected ModeRequete mode;
|
|
|
20 |
|
|
|
21 |
public PropositionDeterminationCallBack(ModeRequete mode) {
|
|
|
22 |
this.mode = mode;
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
public PropositionDeterminationCallBack() {
|
|
|
26 |
// TODO Auto-generated constructor stub
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
public void setMode(ModeRequete mode) {
|
|
|
30 |
this.mode = mode;
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
@Override
|
|
|
34 |
public void onResponseReceived(Request request, Response response){
|
|
|
35 |
int statusCode = response.getStatusCode();
|
|
|
36 |
int codeAttendu = 500;
|
|
|
37 |
switch (mode) {
|
|
|
38 |
case AJOUT:
|
|
|
39 |
codeAttendu = 201;
|
|
|
40 |
break;
|
|
|
41 |
case MODIFICATION:
|
|
|
42 |
codeAttendu = 200;
|
|
|
43 |
break;
|
|
|
44 |
case SUPPRESSION:
|
|
|
45 |
codeAttendu = 200;
|
|
|
46 |
break;
|
|
|
47 |
default:
|
|
|
48 |
codeAttendu = 500;
|
|
|
49 |
break;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
if (statusCode == codeAttendu) {
|
|
|
53 |
String id = UtilitairesServiceResultat.parserRetourAjoutCommentaire(JSONParser.parseStrict(response.getText()).isObject());
|
|
|
54 |
surRetour(id);
|
|
|
55 |
} else {
|
|
|
56 |
surErreur("Erreur " + statusCode + ": " + response.getText());
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
@Override
|
|
|
61 |
public void onError(Request request, Throwable exception) {
|
|
|
62 |
Window.alert(exception.getMessage());
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public abstract void surRetour(String messageRetour);
|
|
|
66 |
public abstract void surErreur(String messageErreur);
|
|
|
67 |
|
|
|
68 |
}
|