       true
       (catch SAXException e false))))
 
-(defn import-file []
-  (doseq [f (filter #(.isFile %) 
-                    (file-seq (io/file import-dir)))] 
+(defn import-file
+  "Import new productions from ABACUS and put them on the create queue"
+  []
+  (doseq [f (filter #(.isFile %)
+                    (file-seq (file import-dir)))]
     (when (valid? f)
       (msg/publish "queue.create" (read-file f))
-      (io/delete-file f))))
+      (delete-file f))))

           javax.xml.transform.stream.StreamSource
           java.io.File))

(def root "/AbaConnectContainer/Task/Transaction/DocumentData/")
(def schema "resources/schema/abacus_export.xsd")
;;(def import-dir "/var/spool/mdr2")
(def import-dir "/home/eglic/tmp/mdr2")

(def param-mapping
  {:productNumber "artikel_nr"
   :title "MetaData/dc/title"
   :creator "MetaData/dc/creator"

   ;; :source_publisher "MetaData/sbs/verlag"
   })

(defn- read-file
  "Read an export file from ABACUS and return a map with all the data"
  [file]
  (let [xml (-> file slurp xml->doc)]
    (into {} (for [[key path] param-mapping]
               [key ($x:text (str root path) xml)]))))

(defn- valid?
  "Check if an export file from ABACUS is valid"
  [file]
  ;; basically a minimal port of
  ;; http://stackoverflow.com/questions/15732/whats-the-best-way-to-validate-an-xml-file-against-an-xsd-file
  (let [validator (.newValidator
