 
 
 (defn make-foxml
-  [[mods workdir] [oai_dcs workdir-1]]
-  {:pre [(= workdir workdir-1)]}
+  [[mods workdir] [oai_dcs workdir-1] [full-file preview-file workdir-2] fedora-import-dir]
+  {:pre [(= workdir workdir-1 workdir-2)]}
   (let [uuid (slurp (io/file workdir "uuid"))
         foxml-dir (io/file workdir uuid)
         ]
-    (.mkdir foxml-dir)
-    (let [foxml (f/foxml mods oai_dcs 
+    (let [foxml (f/foxml mods oai_dcs full-file preview-file
                          {:uuid uuid :label "ahoj" 
                           :created (t/now)
                           :last-modified (t/now)
+                          :fedora-import-dir fedora-import-dir
                           })
           out-file (io/file workdir uuid (str uuid ".xml"))
           ]
       ;(pp/pprint foxml)
       (with-open [out (io/writer out-file)]
         (xml/emit foxml out))
-      [uuid workdir]
-      )
-    )
-  )
+      [uuid workdir])))
 
 (defn parse-and-export [metadata ^bytes payload]
   (let [msg (json/read-str (String. payload) :key-fn keyword) 

  [{:uuid (.toString workdir)}
   {:marc_xml (slurp (io/file workdir "oai_marc.xml"))
    :uuid (slurp (io/file workdir "uuid"))
    }
   ]
  )

(defn save-marcxml2mods-response
  [[metadata payload]]

    (let [ mods_files (-> payload 
         (json/read-str :key-fn keyword) 
         :mods_files)]
      [mods_files workdir])))

(defn parse-mods-files
  "takes strings and returns xml root for each xml string"
  [[mods_files workdir]]
  [(map xml/parse-str mods_files) workdir])

(defn save-img-files
  [[mods_files workdir]]
  (let [uuid (slurp (io/file workdir "uuid"))
        slurp-img-full (comp slurp (partial io/file workdir "img_full"))
        slurp-img-preview (comp slurp (partial io/file workdir "img_preview"))
        ]
    (.mkdir (io/file workdir uuid))
    (.mkdir (io/file workdir uuid "img"))
    (fs/copy (io/file workdir "img_full" (slurp-img-full "filename")) 
             (io/file workdir uuid "img" (slurp-img-full "filename")))
    (fs/copy (io/file workdir "img_preview" (slurp-img-preview "filename")) 
             (io/file workdir uuid "img" (slurp-img-preview "filename")))
    [{:img-type :img_full
      :mime-type (slurp-img-full "mimetype")
      :filename (slurp-img-full "filename")
      }
     {:img-type :img_preview
      :mime-type (slurp-img-preview "mimetype")
      :filename (slurp-img-preview "filename")
      } 
     workdir]))

(defn add-urnnbn-to-first-mods
  [[mods workdir]]
  (let [urnnbn (slurp (io/file workdir "urnnbn"))]
    [(into [(mods/with-urnnbn-identifier (first mods) urnnbn)] (rest mods))  workdir]))

(defn mods->oai_dcs
  [[mods workdir]]
