Author: lgiessmann
Date: Fri Sep 2 09:52:10 2011
New Revision: 826
Log:
gdl-frontend: Widgets: implemented the actual request mechanism for submitting hash-object topics
Modified:
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java Fri Sep 2 09:20:20 2011 (r825)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java Fri Sep 2 09:52:10 2011 (r826)
@@ -11,6 +11,8 @@
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.http.client.URL;
+import com.google.gwt.json.client.JSONObject;
+import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.Window;
import us.isidor.gdl.anaToMia.TopicMaps.TmEngineModel.ExporterException;
import us.isidor.gdl.anaToMia.TopicMaps.TmEngineModel.TmEngine;
@@ -28,15 +30,14 @@
public class CommitCallback implements ICommitCallback{
public final String DELETE_REUQEST_URL = ""; // TODO: set actual URL value
public final String COMMIT_REQUEST_URL = ""; // TODO: set actual URL value
+ public final String GET_REQUEST_URL = ""; // TODO: set actual URL value
@Override
public void commitTmConstruct(ArrayList<Pair<Construct, TopicMapsTypes>> constructs, TmEngine tmEngine, String buttonId) {
try{
if("hash_object_commit_button_id".equals(buttonId)){
- this.commitCreatedHashObject(constructs, tmEngine, false);
- } else if("edited_hash_object_commit_button_id".equals(buttonId)){
- this.commitCreatedHashObject(constructs, tmEngine, true);
+ this.commitCreatedHashObject(constructs, tmEngine, "edited_hash_object_commit_button_id".equals(buttonId));
} else if("environment_commit_button_id".equals(buttonId)){
this.commitCreatedEnvironment(constructs, tmEngine);
}
@@ -153,20 +154,13 @@
}
String commitUrl = URL.encode(this.DELETE_REUQEST_URL);
- String deleteUrl = URL.encode(this.COMMIT_REQUEST_URL);
+ String getUrl = URL.encode(this.GET_REQUEST_URL);
RequestBuilder commitBuilder = new RequestBuilder(RequestBuilder.POST, commitUrl);
commitBuilder.setHeader("Content-type", "application/json");
- RequestBuilder deleteBuilder = new RequestBuilder(RequestBuilder.DELETE, deleteUrl);
- deleteBuilder.setHeader("Content-type", "application/json");
+ RequestBuilder getBuilder = new RequestBuilder(RequestBuilder.GET, getUrl);
try{
- if(edited){
- // get the original occurrence
- // mark the original occurrence as deleted
- // commit the new occurrence
- deleteBuilder.sendRequest(null, new HashObjectDeleteOccurrenceRequest(null, jtm)); // TODO: set the sent data to the occurrence that must be deleted
- } else{
- commitBuilder.sendRequest(jtm, new HashObjectCommitRequest(jtm));
- }
+ if(edited)getBuilder.sendRequest(null, new EditedHashObjectCommitRequest(null, jtm, false));
+ else commitBuilder.sendRequest(jtm, new HashObjectCommitRequest(jtm));
}catch(RequestException e){
Window.alert("could not commit the topic: " + jtm + ", because(" + e.getClass() + "): " + e.getMessage());
}
@@ -238,24 +232,59 @@
- private class HashObjectDeleteOccurrenceRequest implements RequestCallback{
- private String occurrenceString = null;
- private String topicToCommit = null;
-
- private HashObjectDeleteOccurrenceRequest(String occurrenceToDelete, String topicToCommit){
- this.occurrenceString = occurrenceToDelete;
- this.topicToCommit = topicToCommit;
+ private class EditedHashObjectCommitRequest implements RequestCallback{
+ private JSONValue requestedData = null;
+ private String objectToBeSend = null;
+ private boolean deletedOldOccurrence = false;
+ private final String deleteUrl = URL.encode(CommitCallback.this.DELETE_REUQEST_URL);
+ private final String commitUrl = URL.encode(CommitCallback.this.COMMIT_REQUEST_URL);
+
+
+ @SuppressWarnings("unused")
+ private EditedHashObjectCommitRequest(){}
+
+
+ public EditedHashObjectCommitRequest(JSONValue requestedData, String objectToBeSend, boolean deletedOldOccurrence){
+ this.requestedData = requestedData;
+ this.objectToBeSend = objectToBeSend;
+ this.deletedOldOccurrence = deletedOldOccurrence;
}
@Override
public void onResponseReceived(Request request, Response response) {
- // TODO: implement
+ if (200 == response.getStatusCode()) {
+ if(this.requestedData == null){
+ JSONObject occurrenceToBeDeleted = null; // TODO: get from response
+
+ RequestBuilder deleteBuilder = new RequestBuilder(RequestBuilder.DELETE, this.deleteUrl);
+ deleteBuilder.setHeader("Content-type", "application/json");
+ try{
+ deleteBuilder.sendRequest(occurrenceToBeDeleted.toString(), new EditedHashObjectCommitRequest(occurrenceToBeDeleted, this.objectToBeSend, true));
+ }catch(RequestException e){
+ Window.alert("could not commit the topic: " + this.objectToBeSend + ", because(" + e.getClass() + "): " + e.getMessage());
+ }
+ } else if(deletedOldOccurrence){
+ RequestBuilder commitBuilder = new RequestBuilder(RequestBuilder.POST, this.commitUrl);
+ commitBuilder.setHeader("Content-type", "application/json");
+ try{
+ commitBuilder.sendRequest(this.objectToBeSend, new HashObjectCommitRequest(this.objectToBeSend));
+ }catch(RequestException e){
+ Window.alert("could not commit the topic: " + this.objectToBeSend + ", because(" + e.getClass() + "): " + e.getMessage());
+ }
+ } else {
+ Window.alert("commit operation of the object " + this.objectToBeSend + " successed");
+ // TODO: reset the web page
+ }
+ } else {
+ Window.alert("commit operation of the object " + this.objectToBeSend + " failed: " + response.getStatusCode() + "(" + response.getStatusText() + ")\n" + response.getText());
+ }
}
+
@Override
public void onError(Request request, Throwable exception) {
- // TODO: implement
+ Window.alert("could not commit the data: " + this.objectToBeSend);
}
}
}