From b79ab28054cc4643c12d99d60dfa92ea2d244ef3 Mon Sep 17 00:00:00 2001 From: Timothy Washington Date: Thu, 14 Oct 2010 15:58:23 -0400 Subject: [PATCH] -- putting auto-commit to 'update' command as well -- creating a separate update.clj file for DB interaction -- using multimethod abstraction for xpath_handler --- src/commands/update.clj | 34 ++++++++++++++++++++++++++++++++++ src/depth_adapter.clj | 11 ++++++++--- src/xml_handler.clj | 6 +++--- src/xpath_handler.clj | 30 +++++++++++++++++++++++++----- 4 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 src/commands/update.clj diff --git a/src/commands/update.clj b/src/commands/update.clj new file mode 100644 index 0000000..14dfd7e --- /dev/null +++ b/src/commands/update.clj @@ -0,0 +1,34 @@ +(require 'clojure.contrib.string) +(use 'helpers) +(require 'bkell) + + +(defn update-generic [db-base-URL db-system-DIR working-ITEM command-context] + + + ;; ... TODO - logic to build XQuery to use to insert + + ;; PUT to eXist + (println "UPDATing [" working-ITEM "] / XML[" (with-out-str (clojure.xml/emit working-ITEM)) "]" ) + (let [result (execute-http-call + (url-encode-newlines (url-encode-spaces (str db-base-URL db-system-DIR (working-dir-lookup :bookkeeping) + "/" "group." (:id (:attrs (:logged-in-user @bkell/shell))) ".group" + "/" "group." (:id (:attrs (:logged-in-user @bkell/shell))) ".group" + ;;"/bookkeeping.main.bookkeeping/bookkeeping.main.bookkeeping" + "?_wrap=no&_query=" + "declare default element namespace '" + (namespace-lookup (clojure.contrib.string/as-str (:tag working-ITEM)))"';" + "update replace //"(clojure.contrib.string/as-str (:tag command-context)) + "[@id='" (:id (:attrs command-context)) "']" + " with " (strip-xml-header (with-out-str (clojure.xml/emit working-ITEM))) + ))) + "GET" + { "Content-Type" "text/xml" + "Connection" "Keep-Alive" + "Authorization" "Basic YWRtaW46" } + nil + )] + (println "result[" result "]") + ) +) + diff --git a/src/depth_adapter.clj b/src/depth_adapter.clj index aafffc2..96d68a0 100644 --- a/src/depth_adapter.clj +++ b/src/depth_adapter.clj @@ -16,6 +16,7 @@ (:require xpath_handler) (:require commands.add) + (:require commands.update) (:require commands.authenticate) ) @@ -183,6 +184,7 @@ (println "DEBUG > update CONTEXT result > " result_seq) (dosync (alter bkell/shell conj { :previous result_seq })) + (dosync (alter bkell/shell conj { :command-context result_seq } )) )) ) ) @@ -199,9 +201,13 @@ (println "DEBUG > update CLIENT input [ " (.. node getC1) " ] > result > " result_seq) - (dosync (alter bkell/shell assoc :mode "update")) (dosync (alter bkell/shell conj { :previous result_seq })) )) + (println "Update command > context[" (:tag (:command-context @bkell/shell )) + "] > :previous / each_copy[" (:previous @bkell/shell)"]" ) + + ;; this is a generic 'add' + (update-generic db-base-URL db-system-DIR (:previous @bkell/shell) (:command-context @bkell/shell )) ) ) @@ -399,8 +405,7 @@ (.. node getCommandInput (apply this) ) ;; set the :previous result as the :command-context - (dosync (alter bkell/shell conj - { :command-context (:previous @bkell/shell) } )) + (dosync (alter bkell/shell conj { :command-context (:previous @bkell/shell) } )) ) ) diff --git a/src/xml_handler.clj b/src/xml_handler.clj index b6d30a0..26561e6 100644 --- a/src/xml_handler.clj +++ b/src/xml_handler.clj @@ -20,8 +20,8 @@ (defmethod xml_handler [:Node :handler] [node handler] - (println "xml_handler CALLED[:Node :handler] > AXmlCommandInput instance? > " - (instance? com.interrupt.bookkeeping.cc.node.AXmlCommandInput (. node getCommandInput) )) + ;;(println "xml_handler CALLED[:Node :handler] > AXmlCommandInput instance? > " + ;; (instance? com.interrupt.bookkeeping.cc.node.AXmlCommandInput (. node getCommandInput) )) (try (if (instance? com.interrupt.bookkeeping.cc.node.AXmlCommandInput (. node getCommandInput) ) @@ -29,7 +29,7 @@ (println "EEeee.. xml_hanlder not processing") ) (catch Exception e - (println "EEeee.. xml_hanlder not processing > Error Message[" (. e getMessage) "] > StackTrace[" (. e printStackTrace) "]")) + (println "EEeee.. xml_hanlder not processing > Error Message[" (. e getMessage) "]")) ;; > StackTrace[" (. e printStackTrace) "]")) ) ) diff --git a/src/xpath_handler.clj b/src/xpath_handler.clj index aecba65..ab6103d 100644 --- a/src/xpath_handler.clj +++ b/src/xpath_handler.clj @@ -233,17 +233,37 @@ ) -(defn xpath_handler [node handler] +(defmulti xpath_handler (fn [input handler] + [ + (if (instance? com.interrupt.bookkeeping.cc.node.AXpathCommandInput input ) + :AXpathCommandInput ;; com.interrupt.bookkeeping.cc.node.AXpathCommandInput + :Node ;;com.interrupt.bookkeeping.cc.node.Node + ) + :handler + ]) +) +(defmethod xpath_handler [:Node :handler] [node handler] + + (try + (if (instance? com.interrupt.bookkeeping.cc.node.AXpathCommandInput (. node getCommandInput) ) + (xpath_handler (. node getCommandInput) handler) + (println "EEeee.. xpath_handler not processing") + ) + (catch Exception e + (println "EEeee.. xpath_handler not processing > Error Message[" (. e getMessage) "]")) ;; > StackTrace[" (. e printStackTrace) "]")) + ) +) +(defmethod xpath_handler [:AXpathCommandInput :handler] [xinput handler] (try - (if (instance? com.interrupt.bookkeeping.cc.node.AXpathCommandInput (. node getCommandInput) ) + (if (instance? com.interrupt.bookkeeping.cc.node.AXpathCommandInput xinput ) (do - (println "xpath_handler > node[" (.. node getClass) "] > getLoad[" (.. node getLoad getText) "]") - (println "XPATH input[" (.. node getCommandInput toString) "]") + (println "xpath_handler > xinput[" (. xinput getClass) "]") + (println "XPATH input[" (. xinput toString) "]") ;; 1. filter out and ` - (def input-string (filter-xpath-input (.. node getCommandInput toString))) + (def input-string (filter-xpath-input (. xinput toString))) (println "input-string \t[" input-string "]") ;;(println "stripped XPath \t[" (clojure.contrib.string/replace-re #"\\[[^\\]]*\\]" "" input-string) "]" ) -- 2.11.4.GIT