2 (defn option_handler [node handler]
3 (if (instance? com.interrupt.bookkeeping.cc.node.AOptsCommandInput (. node getCommandInput) )
5 (println "DEBUG > OPTIONS input > token[" (.. node getCommandInput getInputOption getCommandtoken) "] > options[" (.. node getCommandInput getInputOption getCommandoption) "]")
7 ;; get token string (ie user, entry, etc) ->
8 (def token (.. node getCommandInput getInputOption getCommandtoken))
10 ;; get option args & value -> use a 'CommandOptionVisitor'
11 (def options (seq (.. node getCommandInput getInputOption getCommandoption)))
16 (if (instance? com.interrupt.bookkeeping.cc.node.AIdCommandoption input )
24 (def db-id-ID ;; TODO - chain this to look for other options if 'id' is not there
26 (clojure.contrib.str-utils2/trim
28 (clojure.contrib.str-utils2/split (.. (nth option-id 0) ;; class 'com.interrupt.bookkeeping.cc.node.AIdCommandoption'
29 getIdOpt getText) #"-[a-z]+")
35 (println "DEBUG > extracted > [" token "] > [" options "] > [" db-id-ID "]")
37 ;; from HASH -> find containing folder for token
38 (def db-working-DIR (working-dir-lookup (.. token toString trim)))
40 ;; build another <my.group> to end of db-working-DIR
41 (def db-leaf (str (.. token toString trim) "." db-id-ID ) )
42 (def db-full-PARENT (str db-base-URL db-system-DIR db-working-DIR "/" db-leaf ))
44 (def db-document-NAME db-leaf)
47 (println "DEBUG > db-base-URL["db-base-URL"] > db-system-DIR["db-system-DIR"] > db-working-DIR["db-working-DIR"] > leaf["db-leaf"]")
48 (println "DEBUG > db-base-URL[" db-full-PARENT "]")
51 ;; this will find all <SPEECH> elements in the collection /db/shakespeare with "Juliet" as the <SPEAKER>
52 ;; http://localhost:8080/exist/rest/db/shakespeare?_query=//SPEECH[SPEAKER=%22JULIET%22]
54 ;; build XPATH expression to find 'token' based on option
55 ;; http://localhost:8080/exist/rest/db/two.xml?_query=
56 ;; declare default element namespace 'com/interrupt/bookkeeping/users'
57 ;; declare namespace aauth='com/interrupt/bookkeeping/cc/bkell/aauth';
58 ;; //system/aauth:aauthentication
60 ;; TODO - a check if we even need a query
61 (def db-query (str "_wrap=no&_query="
62 "declare default element namespace '"(namespace-lookup (.. token toString trim)) "';"
63 ;;"declare namespace users='com/interrupt/bookkeeping/users'; declare namespace bkell='com/interrupt/bookkeeping/cc/bkell'; declare namespace command='com/interrupt/bookkeeping/cc/bkell/command'; declare namespace interpret='com/interrupt/bookkeeping/interpret'; declare namespace aauth='com/interrupt/bookkeeping/cc/bkell/aauth'; "
65 ;; TODO - check if we need 'and' conditions
66 ;; "**/<token>[ @option='option_value' [ and @option='option_value' ] ]"
67 "//"(.. token toString trim)"[ @"
68 (. (nth (re-seq #"-[a-z]+" (.. (nth option-id 0) getIdOpt getText)) 0) substring 1) ;; TODO - put this part into a function (being re-used)
73 (println "DEBUG > db-query[" db-query "]")
75 (println "DEBUG > FINAL http query[" (str db-full-PARENT "/" db-leaf "?" (url-encode db-query) ) "]")
77 ;; from DB, get 'token' for 'option' args & value
78 (def result-XML (clojure.contrib.http.agent/string (clojure.contrib.http.agent/http-agent (str db-full-PARENT "/" db-leaf "?" (url-encode db-query) )
80 :header {"Content-Type" "text/xml"}
82 ;; TODO - parse results, check for i) null or ii) multiple results
86 ;; pass built XML sequence to handler
87 (handler (xml-seq result-XML))