<commit_before>(ns cmr.umm-spec.umm-g.granule
  "Contains functions for parsing UMM-G JSON into umm-lib granule model
  and generating UMM-G JSON from umm-lib granule model."
  (:require
   [cheshire.core :as json]
   [cmr.umm.umm-granule :as g]
   [cmr.umm.umm-collection :as umm-c]
   [cmr.common.util :as util])
  (:import cmr.umm.umm_granule.UmmGranule))

(defn- get-date-by-type
  "Returns the date of the given type from the given provider dates"
  [provider-dates date-type]
  (some #(when (= date-type (:Type %)) (:Date %)) provider-dates))

(defn- umm-g->DataProviderTimestamps
  "Returns a UMM DataProviderTimestamps from a parsed XML structure"
  [umm-g]
  (let [provider-dates (:ProviderDates umm-g)
        ; create-time (get-date-by-type provider-dates "Create")
        insert-time (get-date-by-type provider-dates "Insert")
        update-time (get-date-by-type provider-dates "Update")
        delete-time (get-date-by-type provider-dates "Delete")]
    (g/map->DataProviderTimestamps
     {;;:create-time create-time
      :insert-time insert-time
      :update-time update-time
      :delete-time delete-time})))

(defn- umm-g->CollectionRef
  "Returns a UMM ref element from a parsed UMM-G JSON"
  [umm-g-json]
  (let [collection-ref (:CollectionReference umm-g-json)]
    (g/map->CollectionRef {:entry-title (:EntryTitle collection-ref)
                           :short-name (:ShortName collection-ref)
                           :version-id (:Version collection-ref)})))

(defn umm-g->Granule<commit_msg>CMR-5058: Added support for ProviderDates in UMM-G.<commit_after>(ns cmr.umm-spec.umm-g.granule
  "Contains functions for parsing UMM-G JSON into umm-lib granule model
  and generating UMM-G JSON from umm-lib granule model."
  (:require
   [cheshire.core :as json]
   [cmr.umm.umm-granule :as g]
   [cmr.umm.umm-collection :as umm-c]
   [cmr.common.util :as util])
  (:import cmr.umm.umm_granule.UmmGranule))

(defn- get-date-by-type
  "Returns the date of the given type from the given provider dates"
  [provider-dates date-type]
  (some #(when (= date-type (:Type %)) (:Date %)) provider-dates))

(defn- umm-g->DataProviderTimestamps
  "Returns a UMM DataProviderTimestamps from a parsed XML structure"
  [umm-g]
  (let [provider-dates (:ProviderDates umm-g)
        ;; umm-lib Granule model does not have create-time, so ignore it for now.
        ; create-time (get-date-by-type provider-dates "Create")
        insert-time (get-date-by-type provider-dates "Insert")
        update-time (get-date-by-type provider-dates "Update")
        delete-time (get-date-by-type provider-dates "Delete")]
    (g/map->DataProviderTimestamps
     {;;:create-time create-time
      :insert-time insert-time
      :update-time update-time
      :delete-time delete-time})))

(defn- umm-g->CollectionRef
  "Returns a UMM ref element from a parsed UMM-G JSON"
  [umm-g-json]
  (let [collection-ref (:CollectionReference umm-g-json)]
    (g/map->CollectionRef {:entry-title (:EntryTitle collection-ref)
                           :short-name (:ShortName collection-ref)
                           :version-id (:Version collection-ref)})))

(defn umm-g->Granule
{'fraction_non_alphanumeric': 0.1342155009451796, 'fraction_numerical': 0.001260239445494644, 'mean_word_length': 3.0497448979591835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5621254', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1059, 'n_words': 271}