Skip to content

Commit

Permalink
CMR-6702: Changed collection vertex to not set doi property when ther…
Browse files Browse the repository at this point in the history
…e is no doi value.
  • Loading branch information
ygliuvt committed Aug 6, 2021
1 parent 7b5cc45 commit ee07353
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 45 deletions.
79 changes: 52 additions & 27 deletions graph-db/serverless/src/indexCmrCollection/__test__/handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,56 @@ describe('indexCmrCollection handler', () => {
const platform1 = 'Platform One'
const instrument1 = 'Instrument One'
const platform2 = 'Platform Two'
const docName = 'https://en.wikipedia.org/wiki/latent_nfi'
const relatedUrl = 'https://en.wikipedia.org/wiki/latent_nfi'
const doi = 'doi:10.16904/envidat.166'

await updateCollection(
conceptId,
datasetTitle,
{
campaigns: [campaign1],
platforms: [{ platform: platform1, instruments: [instrument1] }, { platform: platform2 }],
docNames: [docName]
relatedUrls: [relatedUrl],
doi
}
)

await verifyCollectionPropertiesInGraphDb(
{
datasetTitle,
conceptId,
doi: 'doi:10.16904/envidat.166'
doi
}
)

await verifyCampaignExistInGraphDb(datasetTitle, campaign1)
await verifyPlatformInstrumentsExistInGraphDb(datasetTitle,
{ platform: platform1, instruments: [instrument1] })
await verifyPlatformInstrumentsExistInGraphDb(datasetTitle, { platform: platform2 })
await verifyDocumentationExistInGraphDb(datasetTitle, docName)
await verifyDocumentationExistInGraphDb(datasetTitle, relatedUrl)
})

test('test indexing of a collection with no DOI value', async () => {
const datasetTitle = 'Latent reserves within the Swiss NFI'
const conceptId = 'C1237293909-TESTPROV'
const platform1 = 'Platform One'

await updateCollection(
conceptId,
datasetTitle,
{
platforms: [{ platform: platform1 }]
}
)

await verifyCollectionPropertiesInGraphDb(
{
datasetTitle,
conceptId
}
)

await verifyPlatformInstrumentsExistInGraphDb(datasetTitle, { platform: platform1 })
})

test('test index of not found collection', async () => {
Expand Down Expand Up @@ -125,7 +150,7 @@ describe('indexCmrCollection handler', () => {
const instrument1 = 'Instrument One'
const instrument2 = 'Instrument Two'
const platform2 = 'Platform Two'
const docName = 'https://en.wikipedia.org/wiki/latent_nfi'
const relatedUrl = 'https://en.wikipedia.org/wiki/latent_nfi'

// first index the collection and verify dataset and documentation vertices are created
await updateCollection(
Expand All @@ -136,23 +161,23 @@ describe('indexCmrCollection handler', () => {
platforms: [
{ platform: platform1, instruments: [instrument1, instrument2] },
{ platform: platform2 }],
docNames: [docName]
relatedUrls: [relatedUrl]
}
)

await verifyCampaignExistInGraphDb(datasetTitle, campaign1)
await verifyPlatformInstrumentsExistInGraphDb(datasetTitle,
{ platform: platform1, instruments: [instrument1, instrument2] })
await verifyPlatformInstrumentsExistInGraphDb(datasetTitle, { platform: platform2 })
await verifyDocumentationExistInGraphDb(datasetTitle, docName)
await verifyDocumentationExistInGraphDb(datasetTitle, relatedUrl)

// delete the collection and verify dataset and campaign/documentation vertices are deleted
await deleteCollection('C1237293909-TESTPROV')
await verifyCampaignNotExistInGraphDb(datasetTitle, campaign1)
await verifyPlatformInstrumentsNotExistInGraphDb(datasetTitle,
{ platform: platform1, instruments: [instrument1, instrument2] })
await verifyPlatformInstrumentsNotExistInGraphDb(datasetTitle, { platform: platform2 })
await verifyDocumentationNotExistInGraphDb(datasetTitle, docName)
await verifyDocumentationNotExistInGraphDb(datasetTitle, relatedUrl)
})

test('test deletion collection not delete linked documentation vertex if it is also linked to another collection', async () => {
Expand All @@ -172,9 +197,9 @@ describe('indexCmrCollection handler', () => {
const ownInstrument = 'OwnInstrument'

// this documentation url is referenced by two collections
const sharedDocName = 'https://en.wikipedia.org/wiki/latent_nfi'
const sharedDocUrl = 'https://en.wikipedia.org/wiki/latent_nfi'
// this documentation url is referenced only by one collection
const ownDocName = 'https://en.wikipedia.org/wiki/latent_nfi2'
const ownDocUrl = 'https://en.wikipedia.org/wiki/latent_nfi2'

// first index the collection and verify dataset and campaign/documentation vertices are created
await updateCollection(
Expand All @@ -185,7 +210,7 @@ describe('indexCmrCollection handler', () => {
platforms: [
{ platform: sharedPlatform, instruments: [sharedInstrument, ownInstrument] },
{ platform: ownPlatform }],
docNames: [sharedDocName, ownDocName]
relatedUrls: [sharedDocUrl, ownDocUrl]
}
)

Expand All @@ -194,8 +219,8 @@ describe('indexCmrCollection handler', () => {
await verifyPlatformInstrumentsExistInGraphDb(datasetTitle,
{ platform: sharedPlatform, instruments: [sharedInstrument, ownInstrument] })
await verifyPlatformInstrumentsExistInGraphDb(datasetTitle, { platform: ownPlatform })
await verifyDocumentationExistInGraphDb(datasetTitle, sharedDocName)
await verifyDocumentationExistInGraphDb(datasetTitle, ownDocName)
await verifyDocumentationExistInGraphDb(datasetTitle, sharedDocUrl)
await verifyDocumentationExistInGraphDb(datasetTitle, ownDocUrl)

// index a second collection that reference the same campaign/documentation vertex
// and verify dataset and campaign/documentation vertices are created
Expand All @@ -206,14 +231,14 @@ describe('indexCmrCollection handler', () => {
campaigns: [sharedCampaign],
platforms: [
{ platform: sharedPlatform, instruments: [sharedInstrument] }],
docNames: [sharedDocName]
relatedUrls: [sharedDocUrl]
}
)

await verifyCampaignExistInGraphDb(anotherDatasetTitle, sharedCampaign)
await verifyPlatformInstrumentsExistInGraphDb(anotherDatasetTitle,
{ platform: sharedPlatform, instruments: [sharedInstrument] })
await verifyDocumentationExistInGraphDb(anotherDatasetTitle, sharedDocName)
await verifyDocumentationExistInGraphDb(anotherDatasetTitle, sharedDocUrl)

// delete the collection and verify dataset vertex is deleted
// the campaign/documentation/platformInstrument vertex that is not referenced by another collection is deleted
Expand All @@ -228,8 +253,8 @@ describe('indexCmrCollection handler', () => {
await verifyPlatformInstrumentsExistInGraphDb(anotherDatasetTitle,
{ platform: sharedPlatform, instruments: [sharedInstrument] })

await verifyDocumentationNotExistInGraphDb(datasetTitle, ownDocName)
await verifyDocumentationExistInGraphDb(anotherDatasetTitle, sharedDocName)
await verifyDocumentationNotExistInGraphDb(datasetTitle, ownDocUrl)
await verifyDocumentationExistInGraphDb(anotherDatasetTitle, sharedDocUrl)
})

test('test update collection', async () => {
Expand Down Expand Up @@ -258,11 +283,11 @@ describe('indexCmrCollection handler', () => {
const newInstrument = 'NewInstrument'

// this documentation url is referenced by both the old and new version of the collection
const keptDocName = 'https://en.wikipedia.org/wiki/latent_nfi'
const keptDocUrl = 'https://en.wikipedia.org/wiki/latent_nfi'
// this documentation url is referenced only by the old version of collection
const removedDocName = 'https://en.wikipedia.org/wiki/latent_nfi_old'
const removedDocUrl = 'https://en.wikipedia.org/wiki/latent_nfi_old'
// this documentation url is referenced only by the new version of collection
const newDocName = 'https://en.wikipedia.org/wiki/latent_nfi_new'
const newDocUrl = 'https://en.wikipedia.org/wiki/latent_nfi_new'

// first index the collection and verify dataset and documentation vertices are created
await updateCollection(
Expand All @@ -273,7 +298,7 @@ describe('indexCmrCollection handler', () => {
platforms: [
{ platform: keptPlatform, instruments: [keptInstrument, removedInstrument] },
{ platform: removedPlatform }],
docNames: [keptDocName, removedDocName]
relatedUrls: [keptDocUrl, removedDocUrl]
}
)

Expand All @@ -284,8 +309,8 @@ describe('indexCmrCollection handler', () => {
{ platform: keptPlatform, instruments: [keptInstrument, removedInstrument] })
await verifyPlatformInstrumentsExistInGraphDb(datasetTitle, { platform: removedPlatform })

await verifyDocumentationExistInGraphDb(datasetTitle, keptDocName)
await verifyDocumentationExistInGraphDb(datasetTitle, removedDocName)
await verifyDocumentationExistInGraphDb(datasetTitle, keptDocUrl)
await verifyDocumentationExistInGraphDb(datasetTitle, removedDocUrl)

// update the collection
await updateCollection(
Expand All @@ -296,7 +321,7 @@ describe('indexCmrCollection handler', () => {
platforms: [
{ platform: keptPlatform, instruments: [keptInstrument, newInstrument] },
{ platform: newPlatform, instruments: [newInstrument] }],
docNames: [keptDocName, newDocName]
relatedUrls: [keptDocUrl, newDocUrl]
}
)

Expand All @@ -305,7 +330,7 @@ describe('indexCmrCollection handler', () => {
await verifyPlatformInstrumentsNotExistInGraphDb(datasetTitle,
{ platform: keptPlatform, instruments: [removedInstrument] })
await verifyPlatformInstrumentsNotExistInGraphDb(datasetTitle, { platform: removedPlatform })
await verifyDocumentationNotExistInGraphDb(datasetTitle, removedDocName)
await verifyDocumentationNotExistInGraphDb(datasetTitle, removedDocUrl)

// verify the dataset vertext with the new title exist,
// verify the campaign/documentation vertices referenced by another collection exist,
Expand All @@ -316,7 +341,7 @@ describe('indexCmrCollection handler', () => {
{ platform: keptPlatform, instruments: [keptInstrument, newInstrument] })
await verifyPlatformInstrumentsExistInGraphDb(anotherDatasetTitle,
{ platform: newPlatform, instruments: [newInstrument] })
await verifyDocumentationExistInGraphDb(anotherDatasetTitle, keptDocName)
await verifyDocumentationExistInGraphDb(anotherDatasetTitle, newDocName)
await verifyDocumentationExistInGraphDb(anotherDatasetTitle, keptDocUrl)
await verifyDocumentationExistInGraphDb(anotherDatasetTitle, newDocUrl)
})
})
26 changes: 16 additions & 10 deletions graph-db/serverless/src/testUtil/indexCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ const platformInstruments = (attributes) => {
}
}

const relatedUrl = (docName) => ({
const relatedUrlObj = (relatedUrl) => ({
URLContentType: 'PublicationURL',
Type: 'VIEW RELATED INFORMATION',
Subtype: 'GENERAL DOCUMENTATION',
URL: docName
URL: relatedUrl
})

/**
Expand All @@ -42,10 +42,14 @@ const relatedUrl = (docName) => ({
* @returns null
*/
export const updateCollection = async (conceptId, datasetTitle, attributes) => {
const { docNames, campaigns, platforms } = attributes
const {
relatedUrls, campaigns, platforms, doi
} = attributes

let projects
let platformInstrumentObjs
let relatedUrls
let relatedUrlObjs
let doiValue = { MissingReason: 'Not Applicable' }

if (campaigns) {
projects = campaigns.map(campaign)
Expand All @@ -55,8 +59,12 @@ export const updateCollection = async (conceptId, datasetTitle, attributes) => {
platformInstrumentObjs = platforms.map(platformInstruments)
}

if (docNames) {
relatedUrls = docNames.map(relatedUrl)
if (relatedUrls) {
relatedUrlObjs = relatedUrls.map(relatedUrlObj)
}

if (doi) {
doiValue = { DOI: doi }
}

nock(/local-cmr/)
Expand All @@ -73,10 +81,8 @@ export const updateCollection = async (conceptId, datasetTitle, attributes) => {
umm: {
Projects: projects,
Platforms: platformInstrumentObjs,
RelatedUrls: relatedUrls,
DOI: {
DOI: 'doi:10.16904/envidat.166'
},
RelatedUrls: relatedUrlObjs,
DOI: doiValue,
ShortName: 'latent-reserves-in-the-swiss-nfi',
EntryTitle: datasetTitle
}
Expand Down
14 changes: 10 additions & 4 deletions graph-db/serverless/src/testUtil/verifyCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ export const verifyCollectionPropertiesInGraphDb = async (attrs) => {
conceptId, datasetTitle, doi
} = attrs

// verify the collection vertex with the given properties exists
const collection = await global.testGremlinConnection
const verifyCommand = global.testGremlinConnection
.V()
.has('collection', 'title', datasetTitle)
.has('id', conceptId)
.has('doi', doi)
.next()

if (doi) {
verifyCommand.has('doi', doi)
} else {
verifyCommand.hasNot('doi')
}

// verify the collection vertex with the given properties exists
const collection = await verifyCommand.next()

const { value: { id: collectionId } } = collection
expect(collectionId).not.toBe(null)
Expand Down
13 changes: 9 additions & 4 deletions graph-db/serverless/src/utils/cmr/indexCmrCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export const indexCmrCollection = async (collectionObj, gremlinConnection) => {
await deleteCmrCollection(conceptId, gremlinConnection)

let collection = null
const addVCommand = gremlinConnection.addV('collection')
.property('title', entryTitle)
.property('id', conceptId)

if (doiDescription) {
addVCommand.property('doi', doiDescription)
}

try {
// Use `fold` and `coalesce` to check existance of vertex, and create one if none exists.
collection = await gremlinConnection
Expand All @@ -43,10 +51,7 @@ export const indexCmrCollection = async (collectionObj, gremlinConnection) => {
.fold()
.coalesce(
gremlinStatistics.unfold(),
gremlinConnection.addV('collection')
.property('title', entryTitle)
.property('id', conceptId)
.property('doi', doiDescription || 'Not provided')
addVCommand
)
.next()
} catch (error) {
Expand Down

0 comments on commit ee07353

Please sign in to comment.