Making manual import work in datomic

This commit is contained in:
Bryce Covert
2018-11-09 10:47:47 -08:00
parent 5a25462c5f
commit de8563a60b
11 changed files with 80 additions and 67 deletions

View File

@@ -66,17 +66,17 @@
(defn parse-account-id [i]
(try
(Integer/parseInt (second
(re-matches #"[^0-9,\\-]*([0-9,\\-]+)[^0-9,]*" (:account-id i))))
(Long/parseLong (second
(re-matches #"[^0-9,\\-]*([0-9,\\-]+)[^0-9,]*" (:bank-account-id i))))
(catch Exception e
(throw (Exception. (str "Could not parse account from value '" (:account-id i) "'") e)))))
(throw (Exception. (str "Could not parse account from value '" (:bank-account-id i) "'") e)))))
(defn parse-company-id [i]
(defn parse-client-id [i]
(try
(Integer/parseInt (second
(re-matches #"[^0-9,\\-]*([0-9,\\-]+)[^0-9,]*" (:company-id i))))
(Long/parseLong (second
(re-matches #"[^0-9,\\-]*([0-9,\\-]+)[^0-9,]*" (:client-id i))))
(catch Exception e
(throw (Exception. (str "Could not parse company from value '" (:company-id i) "'") e)))))
(throw (Exception. (str "Could not parse client from value '" (:client-id i) "'") e)))))
(defn parse-date [{:keys [raw-date]}]
(try
@@ -99,28 +99,28 @@
(POST "/batch-upload"
{{:keys [data]} :edn-params user :identity}
(assert-admin user)
(let [columns [:status :raw-date :description-original :high-level-category nil nil :amount nil nil nil nil nil :account-id :company-id]
(let [columns [:status :raw-date :description-original :high-level-category nil nil :amount nil nil nil nil nil :bank-account-id :client-id]
rows (->> (str/split data #"\n" )
(drop 1)
(map #(str/split % #"\t"))
(map #(into {} (filter identity (map (fn [c k] [k c] ) % columns))))
(map (parse-or-error :amount parse-amount))
(map (parse-or-error :account-id parse-account-id))
(map (parse-or-error :company-id parse-company-id))
(map (parse-or-error :bank-account-id parse-account-id))
(map (parse-or-error :client-id parse-client-id))
(map (parse-or-error :date parse-date)))
error-rows (filter :errors rows)
raw-transactions (vec (->> rows
(filter #(not (seq (:errors %))) )
(map (fn [{:keys [description-original company-id status high-level-category amount account-id date]}]
(map (fn [{:keys [description-original client-id status high-level-category amount bank-account-id date]}]
{:description-original description-original
:date date
:status status
:high-level-category high-level-category
:amount amount
:company-id company-id
:account-id account-id}))))]
:client-id client-id
:bank-account-id bank-account-id}))))]
(manual-import raw-transactions)