From 2cd78e152919fd43b1863ece64fd7f87f9c3e4b8 Mon Sep 17 00:00:00 2001 From: daniel-zamora Date: Mon, 23 Apr 2018 10:58:16 -0400 Subject: [PATCH] CMR-4874 fixes bug, adds test coverage (#504) * CMR-4874 fixes bug, adds test coverage * CMR-4874 more bug fixes * CMR-4874 doc string --- .../umm_spec/migration/version/service.clj | 31 +++++++++++++------ .../test/migration/version/service.clj | 19 ++++++++---- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/umm-spec-lib/src/cmr/umm_spec/migration/version/service.clj b/umm-spec-lib/src/cmr/umm_spec/migration/version/service.clj index e5b66580c2..60578fe819 100644 --- a/umm-spec-lib/src/cmr/umm_spec/migration/version/service.clj +++ b/umm-spec-lib/src/cmr/umm_spec/migration/version/service.clj @@ -12,21 +12,34 @@ (assoc related-url :SubType nil) related-url)) +(defn- migrate-types-down + "Migrates CoverageSpatialExtent and CoverageTemporalExtent types from 1.1 to 1.0" + [coverage-type] + (if-let [type (get-in coverage-type [:CoverageSpatialExtent :CoverageSpatialExtentTypeType])] + (-> coverage-type + (assoc :Type type) + (assoc-in [:CoverageSpatialExtent :Type] type)))) + (defn- migrate-coverage-type-down "Migrate CoverageType changes down from 1.1 to 1.0" [coverage-type] (-> coverage-type (assoc :Type (get-in coverage-type [:CoverageSpatialExtent :CoverageSpatialExtentTypeType])) - (update :CoverageTemporalExtent dissoc :CoverageTemporalExtentTypeType) + migrate-types-down + (update :CoverageTemporalExtent dissoc :CoverageTemporalExtentType) (update :CoverageSpatialExtent dissoc :CoverageSpatialExtentTypeType))) (defn- migrate-coverage-type-up "Migrate CoverageType changes up from 1.0 to 1.1" [coverage-type] - (-> coverage-type - (update :CoverageSpatialExtent - assoc :CoverageSpatialExtentTypeType (get coverage-type :Type)) - (dissoc :Type))) + (if-let [type (or (get-in coverage-type [:CoverageSpatialExtent :Type]) + (get coverage-type :Type))] + (-> coverage-type + (update :CoverageSpatialExtent + assoc :CoverageSpatialExtentTypeType type) + (update :CoverageSpatialExtent dissoc :Type) + (dissoc :Type)) + (dissoc coverage-type :Type))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Service Migration Implementations @@ -35,10 +48,8 @@ [context s & _] (-> s (assoc :AccessConstraints (first (:AccessConstraints s))) - (update :AccessConstraints #(util/trunc % 1024)) - (update :UseConstraints #(util/trunc % 1024)) - (update-in [:ServiceQuality :Lineage] #(util/trunc % 100)) (assoc :RelatedURLs [(:RelatedURL s)]) + (assoc :UseConstraints (first (:UseConstraints s))) (update :Coverage migrate-coverage-type-up) (dissoc :RelatedURL) (util/update-in-each [:ServiceOrganizations] dissoc :Uuid) @@ -47,7 +58,9 @@ (defmethod interface/migrate-umm-version [:service "1.1" "1.0"] [context s & _] (-> s - (assoc :AccessConstraints [(:AccessConstraints s)]) + (assoc :AccessConstraints [(util/trunc (:AccessConstraints s) 1024)]) + (assoc :UseConstraints [(util/trunc (:UseConstraints s) 1024)]) + (update-in [:ServiceQuality :Lineage] #(util/trunc % 100)) (assoc :RelatedURL (first (:RelatedURLs s))) (update :RelatedURL migrate-related-url-subtype-down) (update :Coverage migrate-coverage-type-down) diff --git a/umm-spec-lib/test/cmr/umm_spec/test/migration/version/service.clj b/umm-spec-lib/test/cmr/umm_spec/test/migration/version/service.clj index b1b1619bcd..2e2eb03854 100644 --- a/umm-spec-lib/test/cmr/umm_spec/test/migration/version/service.clj +++ b/umm-spec-lib/test/cmr/umm_spec/test/migration/version/service.clj @@ -17,12 +17,17 @@ :Description "OPeNDAP Service" :Type "GET SERVICE" :URL "https://acdisc.gesdisc.eosdis.nasa.gov/opendap/Aqua_AIRS_Level3/AIRX3STD.006/"}, - :Coverage {:Type "SPATIAL_POINT"} - :AccessConstraints ["TEST"]}) + :Coverage {:Type "SPATIAL_POINT" + :CoverageSpatialExtent {:Type "SPATIAL_POINT"}} + :AccessConstraints [(apply str (repeat 1024 "x"))] + :UseConstraints [(apply str (repeat 1024 "x"))] + :ServiceQuality {:QualityFlag "Available" + :Lineage (apply str (repeat 100 "x"))}}) (def service-concept-1-1 {:Coverage {:CoverageSpatialExtent {:CoverageSpatialExtentTypeType "SPATIAL_POINT"}} :AccessConstraints "TEST" + :UseConstraints "TEST" :ServiceOrganizations [{:Roles ["SERVICE PROVIDER"] :ShortName "TEST ShortName"}] :RelatedURLs [{:URLContentType "CollectionURL" @@ -49,6 +54,7 @@ (vm/migrate-umm {} :service "1.0" "1.1" {:Coverage {:Type "SPATIAL_POINT"} :AccessConstraints ["TEST"] + :UseConstraints ["TEST"] :ServiceOrganizations [{:Roles ["SERVICE PROVIDER"] :ShortName "TEST ShortName" :Uuid "TEST Uuid"}] @@ -62,8 +68,9 @@ {:RelatedURLs [{:URL "https://acdisc.gesdisc.eosdis.nasa.gov/opendap/Aqua_AIRS_Level3/AIRX3STD.006/" :Description "OPeNDAP Service" :Type "GET SERVICE" :URLContentType "CollectionURL"}] - :AccessConstraints "TEST" + :AccessConstraints (apply str (repeat 4000 "x")) + :UseConstraints (apply str (repeat 20000 "x")) + :ServiceQuality {:QualityFlag "Available" + :Lineage (apply str (repeat 4000 "x"))} :Coverage {:CoverageSpatialExtent {:CoverageSpatialExtentTypeType - "SPATIAL_POINT"} - :CoverageTemporalExtent {:CoverageTemporalExtentTypeType - "TIME_STAMP"}}})))) + "SPATIAL_POINT"}}}))))