diff --git a/env/test/resources/SN_Alfresco_EB11111.xml b/env/test/resources/SN_Alfresco_EB11111.xml new file mode 100644 index 00000000..9748aea9 --- /dev/null +++ b/env/test/resources/SN_Alfresco_EB11111.xml @@ -0,0 +1,61 @@ + + + + + + + + EB11111 + Eine für de Thesi + + + Eine für de Thesi + Gwerder, Anna + + de + EB11111 + 2011-12-23 + + + 54430 + + DVA + Altdorf + 1. / 2011 + 311 + IN ARBEIT + 13.12.2011 (pdf per Mail) / ts + Grossdruck s/w + + OCCS250 + doppelseitig + + 0 + 0 + + + + 0 + + 0 + 501097 + 0 + + 0 + 0 + 0 + 0 + ja + ja + nein + ja + D + + + 0 + + + + + + diff --git a/src/clj/daisyproducer2/documents/abacus.clj b/src/clj/daisyproducer2/documents/abacus.clj index 132bc0f7..19c01044 100644 --- a/src/clj/daisyproducer2/documents/abacus.clj +++ b/src/clj/daisyproducer2/documents/abacus.clj @@ -100,11 +100,10 @@ :narrator (string/join "; " (apply xml-> zipper (concat root-path path))) (apply xml1-> zipper (concat root-path path))))) -(defn read-file - "Read an export file from ABACUS and return a map with all the data, - i.e. a document" - [file] - (let [zipper (-> file io/file xml/parse zip/xml-zip)] +(defn read-xml + "Read XML from ABACUS and return a map with all the data, i.e. a document" + [xml] + (let [zipper (-> xml zip/xml-zip)] (->> (for [key (keys param-mapping) :let [val (extract-value zipper key)] @@ -113,6 +112,12 @@ (into {}) clean-raw-document))) +(defn read-file + "Read an export file from ABACUS and return a map with all the data, + i.e. a document" + [file] + (read-xml (-> file io/file xml/parse))) + (def ^:private abacus-export-schema "schema/abacus_export.rng") (def ^:private relevant-metadata-keys #{:title :author :date :source :source-date diff --git a/test/clj/daisyproducer2/test/abacus_import.clj b/test/clj/daisyproducer2/test/abacus_import.clj new file mode 100644 index 00000000..8af81410 --- /dev/null +++ b/test/clj/daisyproducer2/test/abacus_import.clj @@ -0,0 +1,71 @@ +(ns daisyproducer2.test.abacus-import + (:require + [clojure.java.io :as io] + [clojure.test :refer :all] + [daisyproducer2.documents.abacus :refer :all] + [java-time.api :as time] + [clojure.data.xml :as xml])) + +(defn- xml-sample + [product-number title creator source language date production-series-number reihe aufwand daisyproducer?] + [:AbaConnectContainer + [:Task + [:Transaction + [:DocumentData + [:artikel_nr product-number] + [:title title] + [:MetaData + [:dc + [:title title] + [:creator creator] + [:source source] + [:language language] + [:date date]] + [:sbs + [:rucksackNr production-series-number] + [:reihe reihe] + [:daisy_producer (if daisyproducer? "ja" "nein")] + [:Aufwand_A2 aufwand]]]]]]]) + +(deftest abacus-import + (testing "ABACUS import" + + (testing "Read XML" + (let [document {:product-number "EB11111" + :title "Eine für de Thesi" + :author "Gwerder, Anna" + :language "de" + :date (time/local-date "2011-12-23") + :publisher "SBS Schweizerische Bibliothek für Blinde, Seh- und Lesebehinderte" + :daisyproducer? false + :product-type :ebook}] + (are [expected data] (= expected (read-xml (xml/sexp-as-element (apply xml-sample data)))) + document ["EB11111" "Eine für de Thesi" "Gwerder, Anna" "" "de" "2011-12-23" 0 "" "" false] + (assoc document :daisyproducer? true) ["EB11111" "Eine für de Thesi" "Gwerder, Anna" "" "de" "2011-12-23" 0 "" "" true] + (assoc document :production-series-number "500" :production-series "PPP") + ["EB11111" "Eine für de Thesi" "Gwerder, Anna" "" "de" "2011-12-23" 500 "" "" false] + (assoc document :production-series-number "7000" :production-series "SJW") + ["EB11111" "Eine für de Thesi" "Gwerder, Anna" "" "de" "2011-12-23" 0 "SJW 7000" "" false] + (assoc document :product-number "GD11111" :product-type :large-print) + ["GD11111" "Eine für de Thesi" "Gwerder, Anna" "" "de" "2011-12-23" 0 "" "" false] + (assoc document :product-number "PS11111" :product-type :braille) + ["PS11111" "Eine für de Thesi" "Gwerder, Anna" "" "de" "2011-12-23" 0 "" "" false] + (assoc document :production-source "electronicData") + ["EB11111" "Eine für de Thesi" "Gwerder, Anna" "" "de" "2011-12-23" 0 "" "D" false] + document + ["EB11111" "Eine für de Thesi" "Gwerder, Anna" "" "de" "2011-12-23" 0 "" "C" false]))) + + (testing "Read a file" + (let [sample (io/file (io/resource "SN_Alfresco_EB11111.xml"))] + (is (= {:source-publisher "DVA" + :date (time/local-date "2011-12-23") + :source-edition "1. / 2011" + :publisher "SBS Schweizerische Bibliothek für Blinde, Seh- und Lesebehinderte" + :product-number "EB11111" + :title "Eine für de Thesi" + :author "Gwerder, Anna" + :production-source "electronicData" + :product-type :ebook + :language "de" + :daisyproducer? true} + (import-new-document-file sample)))))))