             [clojure.java.io :as io]
             [cmr.umm.core :as umm]
             [cmr.umm-spec.core :as umm-spec]
-            [cmr.umm-spec.legacy :as legacy]
+            [cmr.umm-spec.legacy :as umm-legacy]
             [cmr.common.mime-types :as mime-types]
             [cmr.system-int-test.utils.ingest-util :as ingest]
             [cmr.system-int-test.utils.url-helper :as url]

(defn- item->native-id
  "Returns the native id of an ingest item."
  [item]
  (some #(get item %) [:granule-ur :entry-title :native-id :EntryTitle]))

(defn generate-metadata
  "Returns a metadata string representing the ingest item (umm-lib or umm-spec-lib UMM record) in
  the desired format."
  [item concept-type format-key]
  (if (= :umm-json format-key)
    ;; assuming umm-json is already UMM-spec UMM
    (umm-spec/generate-metadata concept-type format-key item)
    (umm/umm->xml item format-key)))

(defn item->concept
  "Returns a concept map from a UMM item or tombstone. Default provider-id to PROV1 if not present."
  ([item]
   (item->concept item :echo10))
  ([item format-key]
   (let [format (mime-types/format->mime-type format-key)
         concept-type (legacy/item->concept-type item)]
     (merge {:concept-type concept-type
             :provider-id (or (:provider-id item) "PROV1")
             :native-id (or (:native-id item) (item->native-id item))
             :metadata (when-not (:deleted item) (generate-metadata (dissoc item :provider-id) concept-type format-key))
             :format format}
            (when (:concept-id item)
              {:concept-id (:concept-id item)})

                 :metadata metadata
                 :format (mime-types/format->mime-type format-key)}
        response (ingest/ingest-concept concept)]
    (merge (umm-legacy/parse-concept concept) response)))

(defn ingest-concept-with-metadata-file
  "Ingest the given concept with the metadata file. The metadata file has to be located on the
