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/%22;*/ "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%5C"], + "associations":[{"itemIdentities":null, + "type":["http://psi.topicmaps.org/tmcl/applies-to%5C"], + "scopes":null, + "roles":[{"itemIdentities":null, + "type":["http://psi.topicmaps.org/tmcl/constraint-role%5C"], + "topicRef":["http://textgrid.org/isidorus/tmcl/exc%5C%22%5D%7D, + {"itemIdentities":null, + "type":["http://psi.topicmaps.org/tmcl/topictype-role%5C"], + "topicRef":["http://textgrid.org/isidorus/tmcl/service%5C%22%5D%7D%5D%7D], + "parent-topic":["http://textgrid.org/isidorus/my-service/my-service%5C"], + "parent-name":{"itemIdentities":null, + "type":["http://textgrid.org/isidorus/tmcl/service-name%5C"], + "scopes":null, + "value":"my-service", + "variants":null}, + "names":[{"itemIdentities":null, + "type":["http://textgrid.org/isidorus/tmcl/service-name%5C"], + "scopes":null, + "value":"my-service", + "variants":null}], + "variants":[{"itemIdentities":null, + "scopes":[["http://textgrid.org/isidorus/tmcl/display%5C"]], + "resourceData":{"datatype":"http://www.w3.org/2001/XMLSchema#string%5C", + "value":"http://textgrid.org/isidorus/tmcl/service%5C%22%7D, + "resourceRef":null}, + {"itemIdentities":null, + "scopes":[["http://textgrid.org/isidorus/tmcl/is-ref%5C"]], + "resourceData":null, + "resourceRef":"http://any-ref.org%5C%22%7D], + "occurrences":[{"itemIdentities":null, + "type":["http://textgrid.org/isidorus/tmcl/service-key%5C"], + "scopes":null, + "resourceData":{"datatype":"http://www.w3.org/2001/XMLSchema#string%5C", + "value":"service-key"}}], + "parent-association":{"itemIdentities":null, + "type":["http://psi.topicmaps.org/tmcl/applies-to%5C"], + "scopes":null, + "roles":[{"itemIdentities":null, + "type":["http://psi.topicmaps.org/tmcl/constraint-role%5C"], + "topicRef":["http://textgrid.org/isidorus/tmcl/exc%5C%22%5D%7D, + {"itemIdentities":null, + "type":["http://psi.topicmaps.org/tmcl/topictype-role%5C"], + "topicRef":["http://textgrid.org/isidorus/tmcl/service%5C%22%5D%7D%5D%7D, + "roles":[{"itemIdentities":null, + "type":["http://psi.topicmaps.org/tmcl/constraint-role%5C"], + "topicRef":["http://textgrid.org/isidorus/tmcl/exc%5C%22%5D%7D%5D%7D") + + +(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 --------------------------------------------------- ;; =============================================================================