<commit_before>(ns cmr.umm.validation.collection
  "Defines validations for UMM collections."
  (:require [clj-time.core :as t]
            [cmr.common.validations.core :as v]
            [cmr.umm.validation.utils :as vu]
            [cmr.umm.spatial :as umm-s]
            [cmr.spatial.validation :as sv]
            [cmr.umm.validation.validation-helper :as h]
            [cmr.umm.validation.product-specific-attribute :as psa]))

(defn orbit-collection-has-orbit-parameters
  "Validates the existence of orbit parameters when the granule spatial representation is orbit"
  [field-path spatial-coverage-ref]
  (let [{:keys [granule-spatial-representation orbit-parameters]} spatial-coverage-ref]
    (if (and (= granule-spatial-representation :orbit) (nil? orbit-parameters))
      {field-path
       [(str "Orbit Parameters must be defined for a collection "
             "whose granule spatial representation is ORBIT.")]})))

(defn set-geometries-spatial-representation
  "Sets the spatial represention from the spatial coverage on the geometries"
  [spatial-coverage]
  (let [{:keys [spatial-representation geometries]} spatial-coverage]
    (assoc spatial-coverage
      :geometries
      (map #(umm-s/set-coordinate-system spatial-representation %) geometries))))

(defn- spatial-representation-present-validation
  "Enforces presence of a spatial representation because translation from some schemas allow spatial
   data with no reference. (ISO19115 for example)"
  [field-path spatial-coverage]
  (let [{:keys [spatial-representation granule-spatial-representation geometries]} spatial-coverage]
    (when (seq geometries)
      (when (nil? spatial-representation)
        {field-path ["Spatial coordinate reference type must be supplied."]}))))

(def spatial-coverage-validations
  "Defines spatial coverage validations for collections."<commit_msg>CMR-2927 CMR-2928 Cleanup the demo files and an unused parameter<commit_after>(ns cmr.umm.validation.collection
  "Defines validations for UMM collections."
  (:require [clj-time.core :as t]
            [cmr.common.validations.core :as v]
            [cmr.umm.validation.utils :as vu]
            [cmr.umm.spatial :as umm-s]
            [cmr.spatial.validation :as sv]
            [cmr.umm.validation.validation-helper :as h]
            [cmr.umm.validation.product-specific-attribute :as psa]))

(defn orbit-collection-has-orbit-parameters
  "Validates the existence of orbit parameters when the granule spatial representation is orbit"
  [field-path spatial-coverage-ref]
  (let [{:keys [granule-spatial-representation orbit-parameters]} spatial-coverage-ref]
    (if (and (= granule-spatial-representation :orbit) (nil? orbit-parameters))
      {field-path
       [(str "Orbit Parameters must be defined for a collection "
             "whose granule spatial representation is ORBIT.")]})))

(defn set-geometries-spatial-representation
  "Sets the spatial represention from the spatial coverage on the geometries"
  [spatial-coverage]
  (let [{:keys [spatial-representation geometries]} spatial-coverage]
    (assoc spatial-coverage
      :geometries
      (map #(umm-s/set-coordinate-system spatial-representation %) geometries))))

(defn- spatial-representation-present-validation
  "Enforces presence of a spatial representation because translation from some schemas allow spatial
   data with no reference. (ISO19115 for example)"
  [field-path spatial-coverage]
  (let [{:keys [spatial-representation geometries]} spatial-coverage]
    (when (seq geometries)
      (when (nil? spatial-representation)
        {field-path ["Spatial coordinate reference type must be supplied."]}))))

(def spatial-coverage-validations
  "Defines spatial coverage validations for collections."
{'fraction_non_alphanumeric': 0.10576923076923077, 'fraction_numerical': 0.004807692307692308, 'mean_word_length': 3.7225725094577555, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4546278', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1039, 'n_words': 309}