   (:require
    [bidi.bidi :as bidi]
    [clojure.string :as string]
+   [clojure.tools.logging :as log]
    [kixi.hecuba.protocols :as hecuba]
    [kixi.hecuba.queue :as q]
    [kixi.hecuba.security :as sec]

  :allowed-methods       #{:get :post}
  :available-media-types #{"application/edn" "text/html"}
  :authorized?           (authorized? querier :datasets)
  :post!                 (partial index-post! querier)
  :handle-ok             (partial index-handle-ok querier)
  :handle-created        (partial index-handle-created handlers))

(defn resource-exists? [querier req]
  (let [{route-params :route-params} req
        {:keys [entity-id name]} route-params]
    (when-let [item (first (hecuba/items querier :dataset {:entity-id entity-id
                                                           :name name}))]
        {::item item}
        #_(throw (ex-info (format "Cannot find item of id %s"))))))


  (get-in ctx [:request :route-params :entity-id]))

(defn- name-from [ctx]
  (get-in ctx [:request :route-params :name]))

(defn index-post! [commander ctx]
   (log/info "index-post!")

   (let [request                (:request ctx)
        {:keys [members name]} (decode-body request)
        entity-id              (entity-id-from ctx)
        members-str            (string/join \, members)
