Skip to content

Commit

Permalink
fix migrate and migrate unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaeng72 committed Oct 28, 2024
1 parent be169a6 commit be47588
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 43 deletions.
72 changes: 46 additions & 26 deletions umm-spec-lib/src/cmr/umm_spec/migration/version/collection.clj
Original file line number Diff line number Diff line change
Expand Up @@ -748,32 +748,52 @@
;; Add AssociatedDOIs/Type enums: IsPreviousVersionOf and IsNewVersionOf
;; Add PREPRINT, INREVIEW, and SUPERSEDED enums to CollectionProgress
;; Remove NOT APPLICABLE enum from CollectionProgress
(m-spec/update-version collection :collection "1.18.2")
;; Change CollectionProgress to "NOT PROVIDED" if its value is "NOT APPLICABLE"
(let [CollectionProgress (:CollectionProgress collection)]
(if (or (= "NOT APPLICABLE" CollectionProgress))
(assoc collection :CollectionProgress "NOT PROVIDED")
collection)))
(-> collection
(m-spec/update-version :collection "1.18.2")
;; Change CollectionProgress to "NOT PROVIDED" if its value is "NOT APPLICABLE"
(as-> coll (if (= "NOT APPLICABLE" (:CollectionProgress coll))
(-> coll
(update :CollectionProgress (constantly "NOT PROVIDED")))
coll))))

(defn- migrate-associated-doi-type-down
[associatedDOI]
(if (or (= "IsPreviousVersionOf" (:Type associatedDOI))
(= "IsNewVersionOf" (:Type associatedDOI)))
(-> associatedDOI
(update :Type (constantly "Related Dataset"))
(remove-nil-keys))
associatedDOI))

(defn- migrate-collection-progress-down
[collectionProgress]

(if (nil? collectionProgress)
"NOT PROVIDED"
(if (or (= "PREPRINT" collectionProgress)
(= "INREVIEW" collectionProgress)
(= "SUPERSEDED" collectionProgress))
"COMPLETE"
collectionProgress)))

(defmethod interface/migrate-umm-version [:collection "1.18.2" "1.18.1"]
[_context collection & _]
;; Migrating down version 1.18.2 to 1.18.1
;; Remove AssociatedDOIs/Type enums: IsPreviousVersionOf and IsNewVersionOf
;; Remove PREPRINT, INREVIEW, and SUPERSEDED enums to CollectionProgress
;; Add back in NOT APPLICABLE enum in CollectionProgress
(m-spec/update-version collection :collection "1.18.1")
;; Change AssociatedDOIs/Type to 'Related Dataset' if its enum value is IsPreviousVersionOf and IsNewVersionOf
;; TODO
;(as-> rc
; (let [sct (get-in rc [:AssociatedDOIs :Type])]
; (if (or (= "IsPreviousVersionOf" sct)
; (= "IsNewVersionOf" sct))
; (update-in rc [:AssociatedDOIs] dissoc :Type)
; rc)))
;; Change CollectionProgress enum to COMPLETED if its enum value is PREPRINT, INREVIEW, or SUPERSEDED
(let [CollectionProgress (:CollectionProgress collection)]
(if (or (= "PREPRINT" CollectionProgress)
(= "INREVIEW" CollectionProgress)
(= "SUPERSEDED" CollectionProgress))
(assoc collection :CollectionProgress "COMPLETED")
collection)))
;; Migrating down version 1.18.2 to 1.18.1
;; Remove AssociatedDOIs/Type enums: IsPreviousVersionOf and IsNewVersionOf
;; Remove PREPRINT, INREVIEW, and SUPERSEDED enums to CollectionProgress
;; Add back in NOT APPLICABLE enum in CollectionProgress
;(m-spec/update-version collection :collection "1.18.1")

(-> collection
(m-spec/update-version :collection "1.18.1")
;; Change AssociatedDOIs/Type to 'Related Dataset' if its enum value is IsPreviousVersionOf and IsNewVersionOf
(as-> coll (if (contains? coll :AssociatedDOIs)
(-> coll
(util/update-in-each [:AssociatedDOIs] migrate-associated-doi-type-down))
coll))
;; Change CollectionProgress enum to COMPLETED if its enum value is PREPRINT, INREVIEW, or SUPERSEDED
(as-> coll (if (contains? coll :CollectionProgress)
(-> coll
(update :CollectionProgress migrate-collection-progress-down))
coll))))

101 changes: 84 additions & 17 deletions umm-spec-lib/test/cmr/umm_spec/test/migration/version/collection.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3838,20 +3838,87 @@
:Name "UMM-C",
:Version "1.18.0"}}))

;; TODO
;(deftest migrate-1-18-1-to-1-18-2
; ;; Test migration up from 1.18.1 to 1.18.2
; (are3 [expected sample-collection]
; (let [result (vm/migrate-umm {} :collection "1.18.1" "1.18.2" sample-collection)]
; (is (= expected result)))
;
; "Adding preprint to collectionprogress"
;
;
; )
;)

;; TODO
;(deftest migrate-1-18-2-to-1-18-1
; ;; Test migration down from 1.18.2 to 1.18.1
;)
(deftest migrate-1-18-1-to-1-18-2
;; Test migration up from 1.18.1 to 1.18.2
(are3 [expected sample-collection]
(let [result (vm/migrate-umm {} :collection "1.18.1" "1.18.2" sample-collection)]
(is (= expected result)))

"Removing NOT APPLICABLE CollectionProgress enum and replacing with NOT PROVIDED"
;; expected
{:CollectionProgress "NOT PROVIDED"
:MetadataSpecification {:URL "https://cdn.earthdata.nasa.gov/umm/collection/v1.18.2",
:Name "UMM-C",
:Version "1.18.2"}}
;; sample-collection
{:CollectionProgress "NOT APPLICABLE"
:MetadataSpecification {:URL "https://cdn.earthdata.nasa.gov/umm/collection/v1.18.1",
:Name "UMM-C",
:Version "1.18.1"}}))

(deftest migrate-1-18-2-to-1-18-1
;; Test migration down from 1.18.2 to 1.18.1
(are3 [expected sample-collection]
(let [result (vm/migrate-umm {} :collection "1.18.2" "1.18.1" sample-collection)]
(is (= expected result)))

"Migrating AssociateDOI enum IsPreviousVersionOf and IsNewVersionOf back to Related Dataset"
;; expected
{:AssociatedDOIs [{:Type "Related Dataset"}
{:Type "Related Dataset"}
{:Type "Field Campaign"}]
:DOI {:DOI "10.5067/fake.record.01"}
:SpatialExtent {:GranuleSpatialRepresentation "NO_SPATIAL"}
:TemporalExtents [{:EndsAtPresentFlag false
:SingleDateTimes ["2024-02-14T01:02:03Z"]}]
:MetadataSpecification {:URL "https://cdn.earthdata.nasa.gov/umm/collection/v1.18.1",
:Name "UMM-C",
:Version "1.18.1"}}
;; sample-collection
{:AssociatedDOIs [{:Type "IsPreviousVersionOf"}
{:Type "IsNewVersionOf"}
{:Type "Field Campaign"}]
:DOI {:DOI "10.5067/fake.record.01"}
:SpatialExtent {:GranuleSpatialRepresentation "NO_SPATIAL"}
:TemporalExtents [{:EndsAtPresentFlag false
:SingleDateTimes ["2024-02-14T01:02:03Z"]}]
:MetadataSpecification {:URL "https://cdn.earthdata.nasa.gov/umm/collection/v1.18.2",
:Name "UMM-C",
:Version "1.18.2"}}
)

"Migrating CollectionProgress enum PREPRINT back to COMPLETED"
;; expected
{:CollectionProgress "COMPLETED"
:MetadataSpecification {:URL "https://cdn.earthdata.nasa.gov/umm/collection/v1.18.1",
:Name "UMM-C",
:Version "1.18.1"}}
;; sample-collection
{:CollectionProgress "PREPRINT"
:MetadataSpecification {:URL "https://cdn.earthdata.nasa.gov/umm/collection/v1.18.2",
:Name "UMM-C",
:Version "1.18.2"}}

"Migrating CollectionProgress enum PREPRINT back to COMPLETED"
;; expected
{:CollectionProgress "COMPLETED"
:MetadataSpecification {:URL "https://cdn.earthdata.nasa.gov/umm/collection/v1.18.1",
:Name "UMM-C",
:Version "1.18.1"}}
;; sample-collection
{:CollectionProgress "INREVIEW"
:MetadataSpecification {:URL "https://cdn.earthdata.nasa.gov/umm/collection/v1.18.2",
:Name "UMM-C",
:Version "1.18.2"}}

"Migrating CollectionProgress enum SUPERSEDED back to COMPLETED"
;; expected
{:CollectionProgress "COMPLETED"
:MetadataSpecification {:URL "https://cdn.earthdata.nasa.gov/umm/collection/v1.18.1",
:Name "UMM-C",
:Version "1.18.1"}}
;; sample-collection
{:CollectionProgress "SUPERSEDED"
:MetadataSpecification {:URL "https://cdn.earthdata.nasa.gov/umm/collection/v1.18.2",
:Name "UMM-C",
:Version "1.18.2"}})

0 comments on commit be47588

Please sign in to comment.