From aed1ff7ee6d3e8251658c22c7a575b6dcb075d5b Mon Sep 17 00:00:00 2001 From: eereiter Date: Fri, 14 Apr 2023 15:39:06 -0400 Subject: [PATCH] CMR-8975 Fixing when migrating down to 1.17.2 and a collection doesn't have a RelatedURL that an empty element doesn't show up. (#1886) --- .../migration/related_url_migration.clj | 17 ++++++++-------- .../umm_spec/migration/version/collection.clj | 20 +++++++++---------- .../test/migration/version/collection.clj | 10 ++++++++-- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/umm-spec-lib/src/cmr/umm_spec/migration/related_url_migration.clj b/umm-spec-lib/src/cmr/umm_spec/migration/related_url_migration.clj index 451942af80..47db0d1942 100644 --- a/umm-spec-lib/src/cmr/umm_spec/migration/related_url_migration.clj +++ b/umm-spec-lib/src/cmr/umm_spec/migration/related_url_migration.clj @@ -411,11 +411,12 @@ "Change application/x-vnd.iso.19139-2+xml to Not provided for the RelatedUrls/GetService/MimeType element." [related-urls] - (vec - (for [related-url related-urls - :let [service (:GetService related-url)]] - (if service - (if (= (:MimeType service) "application/x-vnd.iso.19139-2+xml") - (assoc-in related-url [:GetService :MimeType] "Not provided") - related-url) - related-url)))) + (let [urls (for [related-url related-urls + :let [service (:GetService related-url)]] + (if service + (if (= (:MimeType service) "application/x-vnd.iso.19139-2+xml") + (assoc-in related-url [:GetService :MimeType] "Not provided") + related-url) + related-url))] + (when (seq urls) + (vec urls)))) diff --git a/umm-spec-lib/src/cmr/umm_spec/migration/version/collection.clj b/umm-spec-lib/src/cmr/umm_spec/migration/version/collection.clj index 1078c6a799..a269a8ea12 100644 --- a/umm-spec-lib/src/cmr/umm_spec/migration/version/collection.clj +++ b/umm-spec-lib/src/cmr/umm_spec/migration/version/collection.clj @@ -687,7 +687,6 @@ [context collection & _] ;; if TilingIdentificationSystems Names are any but Military Grid Reference System, ;; Migrate TilingIdentificationSystems/Coordinate1 and Coordinate2 from string to number. - (def collection collection) (-> collection (m-spec/update-version :collection "1.17.3") (util/update-in-all [:TilingIdentificationSystems] #(if (= "Military Grid Reference System" (:TilingIdentificationSystemName %)) @@ -700,12 +699,13 @@ (defmethod interface/migrate-umm-version [:collection "1.17.3" "1.17.2"] [context collection & _] - ;; Remove the EULAIdentifiers field in UseConstraints - ;; Migrate TilingIdentificationSystems/Coordinate1 and Coordinate2 down if they are numbers, otherwise remove entire tiling identification system - (-> collection - (m-spec/update-version :collection "1.17.2") - (util/update-in-all [:TilingIdentificationSystems :Coordinate1 :MinimumValue] str) - (util/update-in-all [:TilingIdentificationSystems :Coordinate1 :MaximumValue] str) - (util/update-in-all [:TilingIdentificationSystems :Coordinate2 :MinimumValue] str) - (util/update-in-all [:TilingIdentificationSystems :Coordinate2 :MaximumValue] str) - (update :RelatedUrls related-url/migrating-down-to_1_17_2))) + ;; Migrate TilingIdentificationSystems/Coordinate1 and Coordinate2 down if they are numbers. + ;; Replace a GetService MimeType to a valid value. + (util/remove-nils-empty-maps-seqs + (-> collection + (m-spec/update-version :collection "1.17.2") + (util/update-in-all [:TilingIdentificationSystems :Coordinate1 :MinimumValue] str) + (util/update-in-all [:TilingIdentificationSystems :Coordinate1 :MaximumValue] str) + (util/update-in-all [:TilingIdentificationSystems :Coordinate2 :MinimumValue] str) + (util/update-in-all [:TilingIdentificationSystems :Coordinate2 :MaximumValue] str) + (update :RelatedUrls related-url/migrating-down-to_1_17_2)))) diff --git a/umm-spec-lib/test/cmr/umm_spec/test/migration/version/collection.clj b/umm-spec-lib/test/cmr/umm_spec/test/migration/version/collection.clj index 3d38cd5f7b..0218d5a424 100644 --- a/umm-spec-lib/test/cmr/umm_spec/test/migration/version/collection.clj +++ b/umm-spec-lib/test/cmr/umm_spec/test/migration/version/collection.clj @@ -3747,7 +3747,7 @@ (let [result (vm/migrate-umm {} :collection "1.17.3" "1.17.2" sample-collection)] (is (= expected result))) - "Migrating TilingIdentificationSystems Coordinate1/Coordinate2 up" + "Migrating TilingIdentificationSystems Coordinate1/Coordinate2 down" {:TilingIdentificationSystems [{:TilingIdentificationSystemName "Military Grid Reference System", :Coordinate1 {:MinimumValue "-100", :MaximumValue "-50"}, @@ -3774,4 +3774,10 @@ :Coordinate2 {:MinimumValue 1.5 :MaximumValue 10.5}}] :RelatedUrls [{:GetService {:MimeType "application/x-vnd.iso.19139-2+xml"}} - {:GetService {:MimeType "application/json"}}]})) + {:GetService {:MimeType "application/json"}}]} + + "Migrating nothing down" + {:MetadataSpecification {:URL "https://cdn.earthdata.nasa.gov/umm/collection/v1.17.2" + :Name "UMM-C", + :Version "1.17.2"}} + {}))