[isidorus-cvs] r275 - in trunk/src: ajax/javascripts json rest_interface

Lukas Giessmann lgiessmann at common-lisp.net
Mon Apr 12 20:56:37 UTC 2010


Author: lgiessmann
Date: Mon Apr 12 16:56:36 2010
New Revision: 275

Log:
json: started to implement a mark-as-deleted-handler that deleted from a given json-package topics, names, variants, occurrences and roles

Modified:
   trunk/src/ajax/javascripts/constants.js
   trunk/src/json/json_tmcl.lisp
   trunk/src/rest_interface/rest-interface.lisp
   trunk/src/rest_interface/set-up-json-interface.lisp

Modified: trunk/src/ajax/javascripts/constants.js
==============================================================================
--- trunk/src/ajax/javascripts/constants.js	(original)
+++ trunk/src/ajax/javascripts/constants.js	Mon Apr 12 16:56:36 2010
@@ -11,7 +11,7 @@
 
 
 // --- Some constants fot the http connections via the XMLHttpRequest-Object
-var HOST_PREF = "http://localhost:8000/"; // of the form "http://(.+)/"
+var HOST_PREF = /*"http://localhost:8000/";*/ "192.168.178.23:8000/"; // of the form "http://(.+)/"
 var GET_PREFIX = HOST_PREF + "json/get/";
 var GET_STUB_PREFIX = HOST_PREF + "json/topicstubs/";
 var TMCL_TYPE_URL = HOST_PREF + "json/tmcl/type/";

Modified: trunk/src/json/json_tmcl.lisp
==============================================================================
--- trunk/src/json/json_tmcl.lisp	(original)
+++ trunk/src/json/json_tmcl.lisp	Mon Apr 12 16:56:36 2010
@@ -11,6 +11,86 @@
 
 
 ;; =============================================================================
+;; --- mark-as-deleted handler -------------------------------------------------
+;; =============================================================================
+; a test string ...
+(defvar cl-user::*js-1*
+  "{\"type\":\"Topic\",
+    \"topics\":[\"http://textgrid.org/isidorus/tmcl/service\"],
+    \"associations\":[{\"itemIdentities\":null,
+                      \"type\":[\"http://psi.topicmaps.org/tmcl/applies-to\"],
+                      \"scopes\":null,
+                      \"roles\":[{\"itemIdentities\":null,
+                                  \"type\":[\"http://psi.topicmaps.org/tmcl/constraint-role\"],
+                                  \"topicRef\":[\"http://textgrid.org/isidorus/tmcl/exc\"]},
+                                 {\"itemIdentities\":null,
+                                  \"type\":[\"http://psi.topicmaps.org/tmcl/topictype-role\"],
+                                  \"topicRef\":[\"http://textgrid.org/isidorus/tmcl/service\"]}]}],
+    \"parent-topic\":[\"http://textgrid.org/isidorus/my-service/my-service\"],
+    \"parent-name\":{\"itemIdentities\":null,
+                     \"type\":[\"http://textgrid.org/isidorus/tmcl/service-name\"],
+                     \"scopes\":null,
+                     \"value\":\"my-service\",
+                     \"variants\":null},
+    \"names\":[{\"itemIdentities\":null,
+                \"type\":[\"http://textgrid.org/isidorus/tmcl/service-name\"],
+                \"scopes\":null,
+                \"value\":\"my-service\",
+                \"variants\":null}],
+    \"variants\":[{\"itemIdentities\":null,
+                   \"scopes\":[[\"http://textgrid.org/isidorus/tmcl/display\"]],
+                   \"resourceData\":{\"datatype\":\"http://www.w3.org/2001/XMLSchema#string\",
+                                     \"value\":\"http://textgrid.org/isidorus/tmcl/service\"},
+                   \"resourceRef\":null},
+                  {\"itemIdentities\":null,
+                   \"scopes\":[[\"http://textgrid.org/isidorus/tmcl/is-ref\"]],
+                   \"resourceData\":null,
+                   \"resourceRef\":\"http://any-ref.org\"}],
+    \"occurrences\":[{\"itemIdentities\":null,
+                      \"type\":[\"http://textgrid.org/isidorus/tmcl/service-key\"],
+                      \"scopes\":null,
+                      \"resourceData\":{\"datatype\":\"http://www.w3.org/2001/XMLSchema#string\",
+                                        \"value\":\"service-key\"}}],
+    \"parent-association\":{\"itemIdentities\":null,
+                            \"type\":[\"http://psi.topicmaps.org/tmcl/applies-to\"],
+                            \"scopes\":null,
+                            \"roles\":[{\"itemIdentities\":null,
+                                        \"type\":[\"http://psi.topicmaps.org/tmcl/constraint-role\"],
+                                        \"topicRef\":[\"http://textgrid.org/isidorus/tmcl/exc\"]},
+                                       {\"itemIdentities\":null,
+                                        \"type\":[\"http://psi.topicmaps.org/tmcl/topictype-role\"],
+                                        \"topicRef\":[\"http://textgrid.org/isidorus/tmcl/service\"]}]},
+    \"roles\":[{\"itemIdentities\":null,
+                \"type\":[\"http://psi.topicmaps.org/tmcl/constraint-role\"],
+                \"topicRef\":[\"http://textgrid.org/isidorus/tmcl/exc\"]}]}")
+
+
+(defun mark-as-deleted-from-json (json-data)
+  (declare (string json-data))
+  
+;{\"type\":<\"Topic\" | \"Occurrence\" | \"Name\"
+;           \"Association\" | \"Role\" | \"Variant\" >,
+; \"topics\": <one psi per topic of the topic that have to be deleted>,
+; \"associations\": <a list of associations that should be deleted in the
+;                   specified json format>,
+; \"parent-topic\": <one psi of the parent topic the deleted
+;                    objects are contained in or null if the
+;                    deleted object is the topic itself>,
+; \"parent-name\": <the owner parent of the deleted variants>,
+; \"names\": <a list of names that have to be deleted>,
+; \"variants\": <a list of variants that have to be deleted>,
+; \"occurrences\": <a list of occurrences that have to be deleted>,
+; \"parent-association\": <one association in the specified json
+;                          format, that is the parent of the passed
+;                          role>
+; \"roles\": <a list of roles in the specified json format>}
+  (let ((values (json:decode-json-from-string json-data)))
+    values
+    ))
+
+
+
+;; =============================================================================
 ;; --- all fragment constraints ------------------------------------------------
 ;; =============================================================================
 (defun get-constraints-of-fragment(topic-psis &key (treat-as 'type))

Modified: trunk/src/rest_interface/rest-interface.lisp
==============================================================================
--- trunk/src/rest_interface/rest-interface.lisp	(original)
+++ trunk/src/rest_interface/rest-interface.lisp	Mon Apr 12 16:56:36 2010
@@ -40,7 +40,8 @@
 	   :*ajax-user-interface-url*
 	   :*ajax-user-interface-file-path*
 	   :*ajax-javascript-directory-path*
-	   :*ajax-javascript-url-prefix*))
+	   :*ajax-javascript-url-prefix*
+	   :*mark-as-deleted-url*))
 
 
 (in-package :rest-interface)

Modified: trunk/src/rest_interface/set-up-json-interface.lisp
==============================================================================
--- trunk/src/rest_interface/set-up-json-interface.lisp	(original)
+++ trunk/src/rest_interface/set-up-json-interface.lisp	Mon Apr 12 16:56:36 2010
@@ -26,6 +26,7 @@
 (defparameter *ajax-user-interface-file-path* "ajax/isidorus.html") ;the file path to the HTML file implements the user interface
 (defparameter *ajax-javascript-directory-path* "ajax/javascripts") ;the directory which contains all necessary javascript files
 (defparameter *ajax-javascript-url-prefix* "/javascripts") ; the url prefix of all javascript files
+(defparameter *mark-as-deleted-url* "/mark-as-deleted") ; the url suffix that calls the mark-as-deleted handler
 
 (defun set-up-json-interface (&key (json-get-prefix *json-get-prefix*)
 			      (get-rdf-prefix *get-rdf-prefix*)
@@ -43,7 +44,8 @@
 			      (ajax-user-interface-css-prefix *ajax-user-interface-css-prefix*)
 			      (ajax-user-interface-css-directory-path *ajax-user-interface-css-directory-path*)
 			      (ajax-javascripts-directory-path *ajax-javascript-directory-path*)
-			      (ajax-javascripts-url-prefix *ajax-javascript-url-prefix*))
+			      (ajax-javascripts-url-prefix *ajax-javascript-url-prefix*)
+			      (mark-as-deleted-url *mark-as-deleted-url*))
   "registers the json im/exporter to the passed base-url in hunchentoot's dispatch-table
    and also registers a file-hanlder to the html-user-interface"
 
@@ -111,6 +113,9 @@
    hunchentoot:*dispatch-table*)
   (push
    (create-regex-dispatcher json-get-summary-url #'return-topic-summaries)
+   hunchentoot:*dispatch-table*)
+  (push
+   (create-regex-dispatcher mark-as-deleted-url #'mark-as-deleted)
    hunchentoot:*dispatch-table*))
 
 ;; =============================================================================
@@ -342,6 +347,31 @@
 			 (format nil "Condition: \"~a\"" err))))))
 
 
+(defun mark-as-deleted-handler (&optional param)
+  "Marks the corresponding elem as deleted.
+   {\"type\":<\"'TopicC\" | \"'OccurrenceC\" | \"'NameC\"
+              \"'AssociationC\" | \"'RoleC\" | \"VariantC\" >,
+    \"object\":<specified json-object: name or occurrence,
+                if the deleted object is a topic this field
+                has to be set to null>,
+    \"parent-topic\":<psis or null>,
+    \"parent-name\": <specified json-object: name>}."
+  (declare (ignorable param)) ;param is currently not used
+  (let ((http-method (hunchentoot:request-method*)))
+    (if (or (eq http-method :PUT)
+	    (eq http-method :POST))
+	(let ((external-format (flexi-streams:make-external-format :UTF-8 :eol-style :LF)))
+	  (let ((json-data (hunchentoot:raw-post-data :external-format external-format :force-text t)))
+	    (handler-case
+		(with-writer-lock
+		  (json-tmcl::mark-as-deleted-from-json json-data))
+	      (condition (err)
+		(progn
+		  (setf (hunchentoot:return-code*) hunchentoot:+http-internal-server-error+)
+		  (setf (hunchentoot:content-type*) "text")
+		  (format nil "Condition: \"~a\"" err))))))
+	(setf (hunchentoot:return-code*) hunchentoot:+http-bad-request+))))
+
 ;; =============================================================================
 ;; --- some helper functions ---------------------------------------------------
 ;; =============================================================================




More information about the Isidorus-cvs mailing list