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

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Wed Sep 21 08:18:17 UTC 2011


Author: lgiessmann
Date: Wed Sep 21 01:18:16 2011
New Revision: 946

Log:
gdl-frontend: Widgets: started to implement a separate delete-handler for environment topics => each hash-object associated with the environment that will be deleted must also be deleted and the delete-operation must be confirmed by the user

Modified:
   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/isidorus/DeleteCallback.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/DeleteCallback.java	Wed Sep 21 00:50:25 2011	(r945)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/DeleteCallback.java	Wed Sep 21 01:18:16 2011	(r946)
@@ -18,12 +18,21 @@
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Construct;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.TopicMapsTypes;
+import us.isidor.gdl.anaToMia.Widgets.base.TmHelper;
+import us.isidor.gdl.anaToMia.Widgets.base.Utils;
 import us.isidor.gdl.anaToMia.Widgets.environment.IDeleteCallback;
 import us.isidor.gdl.anaToMia.Widgets.environment.Pair;
 
 
 public class DeleteCallback implements IDeleteCallback {
-	public final String REUQEST_URL = IsidorusConstants.DELETE_REQUEST_URL;
+	private final String REUQEST_URL = IsidorusConstants.DELETE_REQUEST_URL;
+	private final String TM_SPARQL_QUERY_PART_1 = "PREFIX types:<http://textgrid.org/serviceregistry/model/types/>\n" +
+										   		  "PREFIX model:<http://textgrid.org/serviceregistry/model/>\n" +
+										   		  "PREFIX env:<http://textgrid.org/serviceregistry/environment/>\n" +
+										   		  "SELECT ?topics WHERE {\n" +
+										   		  "?topics a types:Hash-Object.\n" +
+										   		  "?topics model:environment env:";
+	private final String TM_SPARQL_QUERY_PART_2 = ".\n}";
 	
 
 	@Override
@@ -35,36 +44,61 @@
 	private void deleteTopic(ArrayList<Pair<Construct, TopicMapsTypes>> constructs, TmEngine tmEngine){
 		for (Pair<Construct, TopicMapsTypes> pair : constructs) {
 			if(pair.getSecond().equals(TopicMapsTypes.Topic)){
-				Topic env = (Topic)pair.getFirst();
-				if(env.getSubjectIdentifiers().length() != 0){
-					String psi = env.getSubjectIdentifiers().get(0).getReference();
-					
-					JSONArray psis = new JSONArray();
-					psis.set(0, new JSONString(psi));
-					
-					JSONObject delObj = new JSONObject();
-					delObj.put("type", new JSONString("Topic"));
-					
-					try{
-						JSONValue val = JSONParser.parseStrict(tmEngine.exportTm(env));
-						delObj.put("delete", val.isObject());
-						
-						String url = URL.encode(this.REUQEST_URL);
-						RequestBuilder builder = new RequestBuilder(RequestBuilder.DELETE, url);
-						builder.setHeader("Content-type", "application/json");
-						
-						builder.sendRequest(delObj.toString(), new DeleteRequest(delObj, env));
-					}catch(RequestException e){
-						Window.alert("could not delete the topic: " + psi + ", because(" + e.getClass() + "): " + e.getMessage());
-					}catch(ExporterException e){
-						Window.alert("could not delete the topic: " + psi + ", because(" + e.getClass() + "): " + e.getMessage());
-					}
-				}
+				Topic top = (Topic)pair.getFirst();
+				
+				if(TmHelper.isInstanceOf(top, IsidorusConstants.ENVIRONMENT_PSI)) this.deleteEnvironmentTopic(top);
+				else this.deleteNonEnvironment(top, tmEngine);
 			}
 		}		
 	}
 	
 	
+	
+	private String createTmSparqlQuery(Topic environment){
+		String psi = environment.getSubjectLocators().get(0).getReference();
+		String psiSuffix = Utils.splitUriByLastFragment(psi)[1];
+		return this.TM_SPARQL_QUERY_PART_1 + psiSuffix + this.TM_SPARQL_QUERY_PART_2;
+	}
+	
+	
+	private void deleteEnvironmentTopic(Topic env){
+		Window.alert(this.createTmSparqlQuery(env));
+		// TODO: get all associated hash-objects
+		// TODO: create a list for the user
+		// TODO: check the user's input
+		// TODO: delete all hash-objects
+		// TODO: delete the environment
+	}
+	
+	
+	private void deleteNonEnvironment(Topic top, TmEngine tmEngine){
+		if(top.getSubjectIdentifiers().length() != 0){
+			String psi = top.getSubjectIdentifiers().get(0).getReference();
+			
+			JSONArray psis = new JSONArray();
+			psis.set(0, new JSONString(psi));
+			
+			JSONObject delObj = new JSONObject();
+			delObj.put("type", new JSONString("Topic"));
+			
+			try{
+				JSONValue val = JSONParser.parseStrict(tmEngine.exportTm(top));
+				delObj.put("delete", val.isObject());
+				
+				String url = URL.encode(this.REUQEST_URL);
+				RequestBuilder builder = new RequestBuilder(RequestBuilder.DELETE, url);
+				builder.setHeader("Content-type", "application/json");
+				
+				builder.sendRequest(delObj.toString(), new DeleteRequest(delObj, top));
+			}catch(RequestException e){
+				Window.alert("could not delete the topic: " + psi + ", because(" + e.getClass() + "): " + e.getMessage());
+			}catch(ExporterException e){
+				Window.alert("could not delete the topic: " + psi + ", because(" + e.getClass() + "): " + e.getMessage());
+			}
+		}
+	}
+	
+	
 	private class DeleteRequest implements RequestCallback {
 		private JSONObject objectToBeSend = null;
 		private Topic topicToBeDeleted = null;
@@ -85,7 +119,6 @@
 			if (200 == response.getStatusCode()) {
 				Window.Location.reload();
 				this.topicToBeDeleted.remove();
-				// TODO: reset the web page
 			} else {
 				Window.alert("delete operation of the object " + this.objectToBeSend + " failed: " + response.getStatusCode() + "(" + response.getStatusText() + ")\n" + response.getText());
 			}




More information about the Isidorus-cvs mailing list