[isidorus-cvs] r829 - branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Mon Sep 5 09:48:19 UTC 2011


Author: lgiessmann
Date: Mon Sep  5 02:48:18 2011
New Revision: 829

Log:
gdl-frontend: Widgets: implemented the class IsidorusConstants that contains all addresses etc. of isidorus and can be easily changed; finalised the commit-handler for instances of http://textgrid.org/serviceregistry/model/types/Hash-Object

Added:
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/IsidorusConstants.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/DeleteCallback.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/LoadSchemaCallback.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	Mon Sep  5 01:56:36 2011	(r828)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java	Mon Sep  5 02:48:18 2011	(r829)
@@ -11,7 +11,10 @@
 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.JSONArray;
 import com.google.gwt.json.client.JSONObject;
+import com.google.gwt.json.client.JSONParser;
+import com.google.gwt.json.client.JSONString;
 import com.google.gwt.json.client.JSONValue;
 import com.google.gwt.user.client.Window;
 import us.isidor.gdl.anaToMia.TopicMaps.TmEngineModel.ExporterException;
@@ -28,9 +31,9 @@
 
 
 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
+	public final String DELETE_REUQEST_URL = IsidorusConstants.DELETE_REUQEST_URL;
+	public final String COMMIT_REQUEST_URL = IsidorusConstants.COMMIT_REQUEST_URL;
+	public final String GET_REQUEST_URL = IsidorusConstants.GET_FRAGMENT_REQUEST_URL;
 	
 	
 	@Override
@@ -199,7 +202,6 @@
 	}
 
 	
-	
 	private class HashObjectCommitRequest implements RequestCallback {
 		private String objectToBeSend = null;
 		
@@ -231,7 +233,6 @@
 	}
 	
 	
-	
 	private class EditedHashObjectCommitRequest implements RequestCallback{
 		private JSONValue requestedData = null;
 		private String objectToBeSend = null;
@@ -255,15 +256,18 @@
 		public void onResponseReceived(Request request, Response response) {
 			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());
-					}
+					JSONObject occurrenceToBeDeleted = this.getOccurrenceTobeDeleted(response.getText());
+					if(occurrenceToBeDeleted != null){
+						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 {
+						Window.alert("commit operation of the object " + this.objectToBeSend + " failed, because: the occurrence http://textgrid.org/serviceregistry/model/hash-type could not be updated");
+					}				
 				} else if(deletedOldOccurrence){
 					RequestBuilder commitBuilder = new RequestBuilder(RequestBuilder.POST, this.commitUrl);
 					commitBuilder.setHeader("Content-type", "application/json");
@@ -286,5 +290,36 @@
 		public void onError(Request request, Throwable exception) {
 			Window.alert("could not commit the data: " + this.objectToBeSend);
 		}
+	
+	
+		private JSONObject getOccurrenceTobeDeleted(String json){
+			if(json == null) return null;
+			
+			JSONValue jsonValue = JSONParser.parseStrict(json);
+			JSONObject fragment = jsonValue.isObject();
+			JSONObject topic = null;
+			if(fragment != null){
+				JSONValue val = fragment.get("topic");
+				if(val != null) topic = val.isObject();
+			}
+			if(topic != null){
+				JSONValue occs = topic.get("occurrences");
+				JSONArray occsArray = null;
+				if(occs != null) occsArray = occs.isArray();
+				if(occsArray != null) {
+					for(int i = 0; i != occsArray.size(); ++i){
+						JSONValue val = occsArray.get(i);
+						JSONObject occ = val.isObject();
+						if(occ == null) continue;
+						
+						JSONValue type = occ.get("type");
+						JSONString typeStr = type.isString();
+						if(typeStr.stringValue().endsWith("hash-type")) return occ; // fr our purpose this soft check is sufficient enough, so the prefix need not to be varified
+					}
+				}
+			}
+			
+			return null;
+		}
 	}
 }

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	Mon Sep  5 01:56:36 2011	(r828)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/DeleteCallback.java	Mon Sep  5 02:48:18 2011	(r829)
@@ -19,7 +19,7 @@
 
 
 public class DeleteCallback implements IDeleteCallback {
-	public final String REUQEST_URL = ""; // TODO: set actual URL value
+	public final String REUQEST_URL = IsidorusConstants.DELETE_REUQEST_URL;
 	
 
 	@Override

Added: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/IsidorusConstants.java
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/IsidorusConstants.java	Mon Sep  5 02:48:18 2011	(r829)
@@ -0,0 +1,9 @@
+package us.isidor.gdl.anaToMia.Widgets.isidorus;
+
+public class IsidorusConstants {
+	// TODO: set the actual values
+	public final static String DELETE_REUQEST_URL = "";
+	public final static String COMMIT_REQUEST_URL = "";
+	public final static String GET_FRAGMENT_REQUEST_URL = "";
+	public final static String GET_SCHEMA_REQUEST_URL = "TextGrid_ServiceRegistry_required_TMCL_and_GDL_Schema_with_test_data.jtm";
+}

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/LoadSchemaCallback.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/LoadSchemaCallback.java	Mon Sep  5 01:56:36 2011	(r828)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/LoadSchemaCallback.java	Mon Sep  5 02:48:18 2011	(r829)
@@ -23,7 +23,7 @@
 // this class can be used as a callback that requests the Topic Map data
 // addressable by the URI isidorusUrl
 public class LoadSchemaCallback implements ILoadSchemaCallback{
-	private final String isidorusUrl = URL.encode(GWT.getModuleBaseURL() + "TextGrid_ServiceRegistry_required_TMCL_and_GDL_Schema_with_test_data.jtm"); // TODO: replace with the correct URL
+	private final String isidorusUrl = URL.encode(GWT.getModuleBaseURL() + IsidorusConstants.GET_SCHEMA_REQUEST_URL);
 	private ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToCreate = new ArrayList<Pair<String,TopicIdentifierTypes>>(); 
 	private Pair<String, TopicIdentifierTypes> requestedTopicToEdit = null;
 	private RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, isidorusUrl);




More information about the Isidorus-cvs mailing list