[isidorus-cvs] r825 - in branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets: base isidorus
lgiessmann at common-lisp.net
lgiessmann at common-lisp.net
Fri Sep 2 16:20:21 UTC 2011
Author: lgiessmann
Date: Fri Sep 2 09:20:20 2011
New Revision: 825
Log:
gdl-frontend: Widgets: fixed some bugs when building the XHR-Requests
Modified:
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java
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/DeleteCallback.java
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java Fri Sep 2 08:44:57 2011 (r824)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java Fri Sep 2 09:20:20 2011 (r825)
@@ -36,8 +36,8 @@
//requestedTopicsToCreate.add(new Pair<String, TopicIdentifierTypes>("http://psi.test.org/gdl-test/Poet", TopicIdentifierTypes.SubjectIdentifier));
//requestedTopicsToCreate.add(new Pair<String, TopicIdentifierTypes>("http://psi.test.org/gdl-test/Musician", TopicIdentifierTypes.SubjectIdentifier));
- Pair<String, TopicIdentifierTypes> requestedTopicToEdit = new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/test-env-1", TopicIdentifierTypes.SubjectIdentifier);
- //Pair<String, TopicIdentifierTypes> requestedTopicToEdit = new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/test-hash-2", TopicIdentifierTypes.SubjectIdentifier);
+ //Pair<String, TopicIdentifierTypes> requestedTopicToEdit = new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/test-env-1", TopicIdentifierTypes.SubjectIdentifier);
+ Pair<String, TopicIdentifierTypes> requestedTopicToEdit = new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/test-hash-2", TopicIdentifierTypes.SubjectIdentifier);
GdlPanel.addClickHandler("hash_object_reset_button_id", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
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 08:44:57 2011 (r824)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java Fri Sep 2 09:20:20 2011 (r825)
@@ -26,19 +26,22 @@
public class CommitCallback implements ICommitCallback{
- public final String REUQEST_URL = ""; // TODO: set actual URL value
+ public final String DELETE_REUQEST_URL = ""; // TODO: set actual URL value
+ public final String COMMIT_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);
+ this.commitCreatedHashObject(constructs, tmEngine, false);
+ } else if("edited_hash_object_commit_button_id".equals(buttonId)){
+ this.commitCreatedHashObject(constructs, tmEngine, true);
} else if("environment_commit_button_id".equals(buttonId)){
this.commitCreatedEnvironment(constructs, tmEngine);
}
}catch(ExporterException ee){
- Window.alert("faild to commit the Topic Maps data, because: " + ee.getMessage());
+ Window.alert("failed to commit the Topic Maps data, because: " + ee.getMessage());
}
}
@@ -82,21 +85,19 @@
jtm = tmEngine.exportTm(topics, new ArrayList<Association>());
}
- String url = URL.encode(this.REUQEST_URL);
+ String url = URL.encode(this.COMMIT_REQUEST_URL);
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
try{
// a check for an existing environment topic is not necessary,
// since it would be exactly the same topic.
builder.sendRequest(null, new EnvironmentCommitRequest(jtm));
}catch(RequestException e){
- Window.alert("could not delete the topic: " + jtm + ", because(" + e.getClass() + "): " + e.getMessage());
+ Window.alert("could not commit the topic: " + jtm + ", because(" + e.getClass() + "): " + e.getMessage());
}
-
- // TODO: implement actual commit and check if the topic already exists
}
- private void commitCreatedHashObject(ArrayList<Pair<Construct, TopicMapsTypes>> constructs, TmEngine tmEngine) throws ExporterException{
+ private void commitCreatedHashObject(ArrayList<Pair<Construct, TopicMapsTypes>> constructs, TmEngine tmEngine, boolean edited) throws ExporterException{
final String carrierPsi = PSIs.GDL.gdl + "hash_object_default_creator_topic_view_id";
ArrayList<Topic> topics = new ArrayList<Topic>();
ArrayList<Association> associations = new ArrayList<Association>();
@@ -143,22 +144,36 @@
Locator psi = tm.createLocator("http://textgrid.org/serviceregistry/hash-object/" + env.getValue() + "/" + key.getValue());
top.removeSubjectIdentifier(carrierLocator);
top.addSubjectIdentifier(psi);
- }
- String jtm = null;
- if(topicMaps.size() != 0){
- jtm = tmEngine.exportTm(topicMaps.get(0));
- } else if(associations.size() != 0 || topics.size() != 0){
- jtm = tmEngine.exportTm(topics, associations);
+ String jtm = null;
+ if(topicMaps.size() != 0){
+ jtm = tmEngine.exportTm(topicMaps.get(0));
+ } else if(associations.size() != 0 || topics.size() != 0){
+ jtm = tmEngine.exportTm(topics, associations);
+ }
+
+ String commitUrl = URL.encode(this.DELETE_REUQEST_URL);
+ String deleteUrl = URL.encode(this.COMMIT_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");
+ 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));
+ }
+ }catch(RequestException e){
+ Window.alert("could not commit the topic: " + jtm + ", because(" + e.getClass() + "): " + e.getMessage());
+ }
}
-
- Window.alert(jtm);
- // TODO: implement actual commit and check if the topic already exists
}
-
-
private class EnvironmentCommitRequest implements RequestCallback {
private String objectToBeSend = null;
@@ -167,8 +182,8 @@
private EnvironmentCommitRequest(){}
- public EnvironmentCommitRequest(String objectToBeDeleted){
- this.objectToBeSend = objectToBeDeleted;
+ public EnvironmentCommitRequest(String objectToBeCommitted){
+ this.objectToBeSend = objectToBeCommitted;
}
@@ -188,5 +203,59 @@
Window.alert("could not commit the data: " + this.objectToBeSend);
}
}
+
+
+ private class HashObjectCommitRequest implements RequestCallback {
+ private String objectToBeSend = null;
+
+
+ @SuppressWarnings("unused")
+ private HashObjectCommitRequest(){}
+
+
+ public HashObjectCommitRequest(String objectToBeCommitted){
+ this.objectToBeSend = objectToBeCommitted;
+ }
+
+
+ @Override
+ public void onResponseReceived(Request request, Response response) {
+ if (200 == response.getStatusCode()) {
+ 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) {
+ Window.alert("could not commit the data: " + this.objectToBeSend);
+ }
+ }
+
+
+
+ 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;
+ }
+
+
+ @Override
+ public void onResponseReceived(Request request, Response response) {
+ // TODO: implement
+ }
+
+ @Override
+ public void onError(Request request, Throwable exception) {
+ // TODO: implement
+ }
+ }
}
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/DeleteCallback.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/DeleteCallback.java Fri Sep 2 08:44:57 2011 (r824)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/DeleteCallback.java Fri Sep 2 09:20:20 2011 (r825)
@@ -46,10 +46,11 @@
String url = URL.encode(this.REUQEST_URL);
- RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
-
+ RequestBuilder builder = new RequestBuilder(RequestBuilder.DELETE, url);
+ builder.setHeader("Content-type", "application/json");
+
try{
- builder.sendRequest(null, new DeleteRequest(delObj));
+ builder.sendRequest(delObj.toString(), new DeleteRequest(delObj));
}catch(RequestException e){
Window.alert("could not delete the topic: " + psi + ", because(" + e.getClass() + "): " + e.getMessage());
}
More information about the Isidorus-cvs
mailing list