From 23ac85b3e5780746ff9d08764b1f861265ed986b Mon Sep 17 00:00:00 2001 From: Timothy Washington Date: Wed, 8 Sep 2010 17:06:49 -0400 Subject: [PATCH] -- maing add-user only operate on variables passed into it --- etc/xml/bookkeeping.system.xml | 2 +- src/commands/add.clj | 59 ++++++++++++++++++++++++++++-------------- src/depth_adapter.clj | 14 ++++++---- 3 files changed, 50 insertions(+), 25 deletions(-) diff --git a/etc/xml/bookkeeping.system.xml b/etc/xml/bookkeeping.system.xml index 0b59d59..74dfe2a 100755 --- a/etc/xml/bookkeeping.system.xml +++ b/etc/xml/bookkeeping.system.xml @@ -104,7 +104,7 @@ - + diff --git a/src/commands/add.clj b/src/commands/add.clj index 24d9020..13dff76 100644 --- a/src/commands/add.clj +++ b/src/commands/add.clj @@ -1,4 +1,4 @@ -(defn add-user [db-base-URL db-system-DIR] +(defn add-user [db-base-URL db-system-DIR working-USER] ;; 1. check that there's not an existing user (let [check-user @@ -6,17 +6,17 @@ (str db-base-URL db-system-DIR - (working-dir-lookup (:tag (:previous @bkell/shell ))) ;; stringing together lookup URL leaf + (working-dir-lookup (:tag working-USER)) ;; stringing together lookup URL leaf "/" (str - (name (:tag (:previous @bkell/shell ))) + (name (:tag working-USER)) "." - (:id (:attrs (:previous @bkell/shell )))) + (:id (:attrs working-USER))) "/" (str ;; repeating user name as leaf document - (name (:tag (:previous @bkell/shell ))) + (name (:tag working-USER)) "." - (:id (:attrs (:previous @bkell/shell ))))) + (:id (:attrs working-USER)))) "GET" {"Content-Type" "text/xml"} nil @@ -31,29 +31,29 @@ (do - (println "ADDING user[" (:previous @bkell/shell ) "]") + (println "ADDING user[" working-USER "]") ;; 2. add to aauth.groups and corresponding default group to the new user (let [aauth-group (clojure.xml/parse "etc/xml/add.group.xml")] (println "...loading add.group.xml[" aauth-group "]") (let [local-id (str - (name (:tag (:previous @bkell/shell ))) + (name (:tag working-USER)) "." - (:id (:attrs (:previous @bkell/shell ))))] + (:id (:attrs working-USER)))] (let [db-group (assoc aauth-group :attrs { :id local-id , :name local-id , - :owner (:id (:attrs (:previous @bkell/shell ))) + :owner (:id (:attrs working-USER)) }, :content [ { :tag (keyword "user"), :attrs { :xmlns "com/interrupt/bookkeeping/users", - :id (:id (:attrs (:previous @bkell/shell ))) + :id (:id (:attrs working-USER)) } } ] @@ -65,8 +65,8 @@ (println "CREATing group [" db-group "] / XML[" (with-out-str (clojure.xml/emit db-group)) "]" ) (execute-http-call (str db-base-URL db-system-DIR (working-dir-lookup :group) - "/" "group." (:id (:attrs (:previous @bkell/shell ))) - "/" "group." (:id (:attrs (:previous @bkell/shell )))) + "/" "group." (:id (:attrs working-USER)) + "/" "group." (:id (:attrs working-USER))) "PUT" { "Content-Type" "text/xml" "Authorization" "Basic YWRtaW46"} @@ -77,21 +77,21 @@ ;; 3. add to aauth.users ... PUT to eXist ;; 4. profile Details ... PUT to eXist ... TODO - (println "CREATing user [" (:previous @bkell/shell ) "] / XML[" (with-out-str (clojure.xml/emit (:previous @bkell/shell ))) "]" ) + (println "CREATing user [" working-USER "] / XML[" (with-out-str (clojure.xml/emit working-USER)) "]" ) (execute-http-call (str db-base-URL db-system-DIR (working-dir-lookup :user) - "/" "user." (:id (:attrs (:previous @bkell/shell ))) - "/" "user." (:id (:attrs (:previous @bkell/shell )))) + "/" "user." (:id (:attrs working-USER)) + "/" "user." (:id (:attrs working-USER))) "PUT" { "Content-Type" "text/xml" "Authorization" "Basic YWRtaW46"} - (with-out-str (clojure.xml/emit (:previous @bkell/shell ))) + (with-out-str (clojure.xml/emit working-USER)) ) ;; 5. add associated Bookkeeping to Group ... PUT to eXist (execute-http-call (str db-base-URL db-system-DIR (working-dir-lookup :bookkeeping) - "/" "group." (:id (:attrs (:previous @bkell/shell ))) + "/" "group." (:id (:attrs working-USER)) "/bookkeeping.main.bookkeeping/bookkeeping.main.bookkeeping" ) "PUT" { "Content-Type" "text/xml" @@ -105,4 +105,25 @@ ) ) ) -) \ No newline at end of file +) + +(defn add-generic [db-base-URL db-system-DIR working-ITEM] + + + ;; ... TODO - logic to build XQuery to use to insert + + ;; PUT to eXist + (println "CREATing [" working-ITEM "] / XML[" (with-out-str (clojure.xml/emit working-ITEM)) "]" ) + (execute-http-call + (str db-base-URL db-system-DIR (working-dir-lookup :bookkeeping) + "/" "group." (:id (:attrs working-ITEM)) + "/bookkeeping.main.bookkeeping/bookkeeping.main.bookkeeping" + "?_wrap=no&_query=" + ) + "POST" + { "Content-Type" "text/xml" + "Authorization" "Basic YWRtaW46" } + (slurp "etc/xml/default.bookkeeping.xml" ) + ) +) + diff --git a/src/depth_adapter.clj b/src/depth_adapter.clj index e3688d1..799a049 100644 --- a/src/depth_adapter.clj +++ b/src/depth_adapter.clj @@ -223,11 +223,15 @@ (and (= (keyword "users") (:tag (:command-context @bkell/shell ))) (= (keyword "user") (:tag (:previous @bkell/shell )))) "]") - ;; check if we are adding a 'User' to 'Users' - (and (= (keyword "users") (:tag (:command-context @bkell/shell ))) - (= (keyword "user") (:tag (:previous @bkell/shell ))) - - (add-user db-base-URL db-system-DIR) + (if (and (= (keyword "users") (:tag (:command-context @bkell/shell ))) + (= (keyword "user") (:tag (:previous @bkell/shell )))) + + ;; we are adding a user + (add-user db-base-URL db-system-DIR (:previous @bkell/shell)) + + ;; this is a generic 'add' + (add-generic db-base-URL db-system-DIR (:previous @bkell/shell)) + ) ) -- 2.11.4.GIT