1 (defn add-user [db-base-URL db-system-DIR working-USER]
3 ;; 1. check that there's not an existing user
5 (execute-http-call ;; TODO - put in 404 check
9 (working-dir-lookup (:tag working-USER)) ;; stringing together lookup URL leaf
12 (name (:tag working-USER))
14 (:id (:attrs working-USER)))
16 (str ;; repeating user name as leaf document
17 (name (:tag working-USER))
19 (:id (:attrs working-USER))))
21 {"Content-Type" "text/xml"}
26 (println "check-user[" check-user "]") ;; TODO - if <error/>, ADD user; user exists otherwise
28 (if (not (= (:msg check-user) "Error"))
30 (println "user ALREADY exists") ;; TODO - throw error to user
34 (println "ADDING user[" working-USER "]")
36 ;; 2. add to aauth.groups and corresponding default group to the new user
37 (let [aauth-group (clojure.xml/parse "etc/xml/add.group.xml")]
39 (println "...loading add.group.xml[" aauth-group "]")
41 (name (:tag working-USER))
43 (:id (:attrs working-USER)))]
45 (let [db-group (assoc aauth-group
49 :owner (:id (:attrs working-USER))
53 :tag (keyword "user"),
55 :xmlns "com/interrupt/bookkeeping/users",
56 :id (:id (:attrs working-USER))
65 (println "CREATing group [" db-group "] / XML[" (with-out-str (clojure.xml/emit db-group)) "]" )
67 (str db-base-URL db-system-DIR (working-dir-lookup :group)
68 "/" "group." (:id (:attrs working-USER))
69 "/" "group." (:id (:attrs working-USER)))
71 { "Content-Type" "text/xml"
72 "Authorization" "Basic YWRtaW46"}
73 (with-out-str (clojure.xml/emit db-group))
78 ;; 3. add to aauth.users ... PUT to eXist
79 ;; 4. profile Details ... PUT to eXist ... TODO
80 (println "CREATing user [" working-USER "] / XML[" (with-out-str (clojure.xml/emit working-USER)) "]" )
82 (str db-base-URL db-system-DIR (working-dir-lookup :user)
83 "/" "user." (:id (:attrs working-USER))
84 "/" "user." (:id (:attrs working-USER)))
86 { "Content-Type" "text/xml"
87 "Authorization" "Basic YWRtaW46"}
88 (with-out-str (clojure.xml/emit working-USER))
91 ;; 5. add associated Bookkeeping to Group ... PUT to eXist
93 (str db-base-URL db-system-DIR (working-dir-lookup :bookkeeping)
94 "/" "group." (:id (:attrs working-USER))
95 "/bookkeeping.main.bookkeeping/bookkeeping.main.bookkeeping" )
97 { "Content-Type" "text/xml"
98 "Authorization" "Basic YWRtaW46"}
99 (slurp "etc/xml/default.bookkeeping.xml" )
110 (defn add-generic [db-base-URL db-system-DIR working-ITEM]
113 ;; ... TODO - logic to build XQuery to use to insert
116 (println "CREATing [" working-ITEM "] / XML[" (with-out-str (clojure.xml/emit working-ITEM)) "]" )
118 (str db-base-URL db-system-DIR (working-dir-lookup :bookkeeping)
119 "/" "group." (:id (:attrs working-ITEM))
120 "/bookkeeping.main.bookkeeping/bookkeeping.main.bookkeeping"
124 { "Content-Type" "text/xml"
125 "Authorization" "Basic YWRtaW46" }
126 (slurp "etc/xml/default.bookkeeping.xml" )