Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMR-9794: Fixing linting issues. #2108

Merged
merged 7 commits into from
May 2, 2024
139 changes: 70 additions & 69 deletions system-int-test/src/cmr/system_int_test/utils/search_util.clj

Large diffs are not rendered by default.

13 changes: 1 addition & 12 deletions umm-lib/dev/user.clj
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
(ns user
(:require [cmr.common.dev.capture-reveal]
[clojure.pprint :refer (pprint pp)]
[clojure.tools.namespace.repl :refer (refresh refresh-all)]
proto-repl.saved-values)
(:use [clojure.test :only [run-all-tests]]
[clojure.repl]
;; Needed to make debug-repl available
[alex-and-georges.debug-repl]))

(defn reset []
(refresh))
(ns user)

(println "Custom user.clj loaded.")
3 changes: 1 addition & 2 deletions umm-lib/src/cmr/umm/collection/entry_id.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns cmr.umm.collection.entry-id
"Functions to create and retrieve entry-id for collections."
(:require [clojure.string :as str]))
"Functions to create and retrieve entry-id for collections.")

(def DEFAULT_VERSION "Not provided")

Expand Down
105 changes: 34 additions & 71 deletions umm-lib/src/cmr/umm/collection/product_specific_attribute.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
(ns cmr.umm.collection.product-specific-attribute
(:require [clojure.string :as str]
[clj-time.format :as f]
[camel-snake-kebab.core :as csk]
[cmr.common.services.errors :as errors]))
(:require
[camel-snake-kebab.core :as csk]
[clj-time.format :as time-format]
[clojure.string :as string]
[cmr.common.services.errors :as errors]))

(defn parse-data-type
"Parses the string data type from the XML into the keyword data type."
Expand All @@ -16,71 +17,44 @@
(when data-type
(csk/->SCREAMING_SNAKE_CASE_STRING (name data-type))))

(defmulti parse-value
"Parses a value based on the data type given"
(fn [data-type value]
data-type))

(defmethod parse-value :default
[data-type value]
(when value
(str value)))

(defmethod parse-value :int
[data-type ^String value]
(when value (Long. value)))

(defmethod parse-value :float
[data-type ^String value]
(when value (Double. value)))

(defmethod parse-value :boolean
[data-type ^String value]
(when value
(case value
"true" true
"false" false
"1" true
"0" false
:else (errors/internal-error! (format "Unexpected boolean value [%s]" value)))))

(def datetime-regex->formatter
"A map of regular expressions matching a date time to the formatter to use"
{#"^[^T]+T[^.]+\.\d+(?:(?:[+-]\d\d:\d\d)|Z)$" (f/formatters :date-time)
#"^[^T]+T[^.]+(?:(?:[+-]\d\d:\d\d)|Z)$" (f/formatters :date-time-no-ms)
#"^[^T]+T[^.]+\.\d+$" (f/formatters :date-hour-minute-second-ms)
#"^[^T]+T[^.]+$" (f/formatters :date-hour-minute-second)})
{#"^[^T]+T[^.]+\.\d+(?:(?:[+-]\d\d:\d\d)|Z)$" (time-format/formatters :date-time)
#"^[^T]+T[^.]+(?:(?:[+-]\d\d:\d\d)|Z)$" (time-format/formatters :date-time-no-ms)
#"^[^T]+T[^.]+\.\d+$" (time-format/formatters :date-hour-minute-second-ms)
#"^[^T]+T[^.]+$" (time-format/formatters :date-hour-minute-second)})

(def time-regex->formatter
"A map of regular expressions matching a time to the formatter to use"
{#"^[^.]+\.\d+(?:(?:[+-]\d\d:\d\d)|Z)$" (f/formatters :time)
#"^[^.]+(?:(?:[+-]\d\d:\d\d)|Z)$" (f/formatters :time-no-ms)
#"^[^.]+\.\d+$" (f/formatters :hour-minute-second-ms)
#"^[^.]+$" (f/formatters :hour-minute-second)})
{#"^[^.]+\.\d+(?:(?:[+-]\d\d:\d\d)|Z)$" (time-format/formatters :time)
#"^[^.]+(?:(?:[+-]\d\d:\d\d)|Z)$" (time-format/formatters :time-no-ms)
#"^[^.]+\.\d+$" (time-format/formatters :hour-minute-second-ms)
#"^[^.]+$" (time-format/formatters :hour-minute-second)})

(defn find-formatter
[datetime regex-formatter-map]
(->> regex-formatter-map
(filter (fn [[regex formatter]]
(filter (fn [[regex _formatter]]
(re-matches regex datetime)))
first
second))

(defmethod parse-value :datetime
[data-type value]
(when value
(f/parse (find-formatter value datetime-regex->formatter) value)))

(defmethod parse-value :time
[data-type value]
(when value
(f/parse (find-formatter value time-regex->formatter) value)))

(defmethod parse-value :date
(defn parse-value
"Parses a value based on the data type given"
[data-type value]
(when value
(let [value (str/replace value "Z" "")]
(f/parse (f/formatters :date) value))))
(case data-type
jceaser marked this conversation as resolved.
Show resolved Hide resolved
:int (Long. value)
:float (Double. value)
:boolean (case value
("true" "1") true
("0" "false") false
(errors/internal-error! (format "Unexpected boolean value [%s]" value)))
:datetime (time-format/parse (find-formatter value datetime-regex->formatter) value)
:time (time-format/parse (find-formatter value time-regex->formatter) value)
:date (let [value (string/replace value "Z" "")]
(time-format/parse (time-format/formatters :date) value))
(str value))))

(defn safe-parse-value
"Returns the parsed value. It is different from parse-value function in that it will catch any
Expand All @@ -90,22 +64,11 @@
(parse-value data-type value)
(catch Exception _ nil)))

(defmulti gen-value
(defn gen-value
"Converts the given value to a string for placement in XML."
(fn [data-type value]
data-type))

(defmethod gen-value :default
[data-type value]
(when-not (nil? value)
(str value)))

(defmethod gen-value :time
[data-type value]
(when value
(f/unparse (f/formatters :hour-minute-second-ms) value)))

(defmethod gen-value :date
[data-type value]
(when value
(f/unparse (f/formatters :date) value)))
(when (some? value)
(case data-type
:time (time-format/unparse (time-format/formatters :hour-minute-second-ms) value)
:date (time-format/unparse (time-format/formatters :date) value)
(str value))))
7 changes: 4 additions & 3 deletions umm-lib/src/cmr/umm/collection/temporal.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(ns cmr.umm.collection.temporal
"Provides functions for collection temporal coverage construction"
(:require [cmr.common.services.errors :as errors]
[cmr.umm.umm-collection :as c]))
(:require
[cmr.common.services.errors :as errors]
[cmr.umm.umm-collection :as coll]))

;; default temporal date times map
(def temporal-date-times {:range-date-times []
Expand All @@ -20,4 +21,4 @@
"Constructs a temporal coverage record with the given map, verifies only one of the temporal datetimes can exist."
[temporal-map]
(validate-temporal-map temporal-map)
(c/map->Temporal (merge temporal-date-times temporal-map)))
(coll/map->Temporal (merge temporal-date-times temporal-map)))
13 changes: 7 additions & 6 deletions umm-lib/src/cmr/umm/dif/collection/collection_association.clj
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
(ns cmr.umm.dif.collection.collection-association
"Provide functions to parse and generate DIF collection associations."
(:require [clojure.data.xml :as x]
[cmr.common.xml :as cx]
[cmr.umm.umm-collection :as c]))
(:require
[clojure.data.xml :as xml]
[cmr.common.xml :as cx]
[cmr.umm.umm-collection :as coll]))

(defn xml-elem->CollectionAssociations
[collection-element]
(let [cas (cx/strings-at-path collection-element [:Parent_DIF])]
(seq (map #(c/map->CollectionAssociation {:short-name %
:version-id c/not-provided}) cas))))
(seq (map #(coll/map->CollectionAssociation {:short-name %
:version-id coll/not-provided}) cas))))

(defn generate-collection-associations
[cas]
(for [ca cas]
(let [{:keys [short-name]} ca]
(x/element :Parent_DIF {} short-name))))
(xml/element :Parent_DIF {} short-name))))
9 changes: 2 additions & 7 deletions umm-lib/src/cmr/umm/dif/collection/location_keywords.clj
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
(ns cmr.umm.dif.collection.location-keywords
"Provide functions to parse and generate DIF location / spatial keyword elements."
(:require
[clojure.data.xml :as x]
[clojure.set :as set]
[cmr.common.xml :as cx]
[cmr.umm.umm-collection :as c]
[cmr.umm.dif.dif-core :as dif]
[cmr.umm.generator-util :as gu]
[cmr.common-app.services.kms-lookup :as kms-lookup]
[clojure.string :as str]
[clojure.set :as set]))
[cmr.common-app.services.kms-lookup :as kms-lookup]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The following functions are all copied directly from the cmr.umm-spec.location-keywords namespace
Expand Down
40 changes: 20 additions & 20 deletions umm-lib/src/cmr/umm/dif/collection/platform.clj
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
(ns cmr.umm.dif.collection.platform
(:require [clojure.data.xml :as x]
[cmr.common.xml :as cx]
[cmr.umm.umm-collection :as c]
[cmr.umm.dif.dif-core :as dif]))
(:require
[clojure.data.xml :as xml]
[cmr.common.xml :as cx]
[cmr.umm.umm-collection :as coll]))

(defn xml-elem->Instrument
[elem]
(let [short-name (cx/string-at-path elem [:Short_Name])
long-name (cx/string-at-path elem [:Long_Name])]
(c/map->Instrument
{:short-name short-name
:long-name long-name})))
(coll/map->Instrument
{:short-name short-name
:long-name long-name})))

(defn xml-elem->Platform
[elem]
(let [short-name (cx/string-at-path elem [:Short_Name])
long-name (cx/string-at-path elem [:Long_Name])]
(c/map->Platform
{:short-name short-name
:long-name long-name
;; DIF does not have platform type in its xml, but it is a required field in ECHO10.
;; We make a dummy type here to facilitate cross format conversion
:type c/not-provided})))
(coll/map->Platform
{:short-name short-name
:long-name long-name
;; DIF does not have platform type in its xml, but it is a required field in ECHO10.
;; We make a dummy type here to facilitate cross format conversion
:type coll/not-provided})))

(defn xml-elem->Platforms
[collection-element]
Expand All @@ -34,20 +34,20 @@
(if (= 1 (count platforms))
(map #(assoc % :instruments instruments) platforms)
(if instruments
(conj platforms (c/map->Platform {:short-name c/not-provided
:long-name c/not-provided
:type c/not-provided
:instruments instruments}))
(conj platforms (coll/map->Platform {:short-name coll/not-provided
:long-name coll/not-provided
:type coll/not-provided
:instruments instruments}))
platforms))))

(defn- generate-element
"Generate a xml element with just Short_Name and Long_Name"
[elem-key values]
(for [value values]
(let [{:keys [short-name long-name]} value]
(x/element elem-key {}
(x/element :Short_Name {} short-name)
(x/element :Long_Name {} long-name)))))
(xml/element elem-key {}
(xml/element :Short_Name {} short-name)
(xml/element :Long_Name {} long-name)))))

(defn generate-instruments
[instruments]
Expand Down
42 changes: 21 additions & 21 deletions umm-lib/src/cmr/umm/dif/collection/science_keyword.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(ns cmr.umm.dif.collection.science-keyword
"Provide functions to parse and generate DIF Parameters elements."
(:require [clojure.data.xml :as x]
[cmr.common.xml :as cx]
[cmr.umm.umm-collection :as c]
[cmr.umm.dif.dif-core :as dif]
[cmr.umm.generator-util :as gu]))
(:require
[clojure.data.xml :as xml]
[cmr.common.xml :as cx]
[cmr.umm.umm-collection :as coll]
[cmr.umm.generator-util :as gu]))

(defn xml-elem->ScienceKeyword
[science-keyword-elem]
Expand All @@ -15,14 +15,14 @@
variable-level-2 (cx/string-at-path science-keyword-elem [:Variable_Level_2])
variable-level-3 (cx/string-at-path science-keyword-elem [:Variable_Level_3])
detailed-variable (cx/string-at-path science-keyword-elem [:Detailed_Variable])]
(c/map->ScienceKeyword
{:category category
:topic topic
:term term
:variable-level-1 variable-level-1
:variable-level-2 variable-level-2
:variable-level-3 variable-level-3
:detailed-variable detailed-variable})))
(coll/map->ScienceKeyword
{:category category
:topic topic
:term term
:variable-level-1 variable-level-1
:variable-level-2 variable-level-2
:variable-level-3 variable-level-3
:detailed-variable detailed-variable})))

(defn xml-elem->ScienceKeywords
[collection-element]
Expand All @@ -36,16 +36,16 @@
(if (seq science-keywords)
(for [science-keyword science-keywords]
(let [{:keys [category topic term variable-level-1 variable-level-2 variable-level-3 detailed-variable]} science-keyword]
(x/element :Parameters {}
(x/element :Category {} category)
(x/element :Topic {} topic)
(x/element :Term {} term)
(xml/element :Parameters {}
(xml/element :Category {} category)
(xml/element :Topic {} topic)
(xml/element :Term {} term)
(gu/optional-elem :Variable_Level_1 variable-level-1)
(gu/optional-elem :Variable_Level_2 variable-level-2)
(gu/optional-elem :Variable_Level_3 variable-level-3)
(gu/optional-elem :Detailed_Variable detailed-variable))))
;; Added since Science Keywords is a required field in DIF9. CMRIN-81
(x/element :Parameters {}
(x/element :Category {} c/not-provided)
(x/element :Topic {} c/not-provided)
(x/element :Term {} c/not-provided))))
(xml/element :Parameters {}
(xml/element :Category {} coll/not-provided)
(xml/element :Topic {} coll/not-provided)
(xml/element :Term {} coll/not-provided))))