Skip to content

Commit ee07353

Browse files
committed
CMR-6702: Changed collection vertex to not set doi property when there is no doi value.
1 parent 7b5cc45 commit ee07353

File tree

4 files changed

+87
-45
lines changed

4 files changed

+87
-45
lines changed

graph-db/serverless/src/indexCmrCollection/__test__/handler.test.js

+52-27
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,56 @@ describe('indexCmrCollection handler', () => {
3535
const platform1 = 'Platform One'
3636
const instrument1 = 'Instrument One'
3737
const platform2 = 'Platform Two'
38-
const docName = 'https://en.wikipedia.org/wiki/latent_nfi'
38+
const relatedUrl = 'https://en.wikipedia.org/wiki/latent_nfi'
39+
const doi = 'doi:10.16904/envidat.166'
3940

4041
await updateCollection(
4142
conceptId,
4243
datasetTitle,
4344
{
4445
campaigns: [campaign1],
4546
platforms: [{ platform: platform1, instruments: [instrument1] }, { platform: platform2 }],
46-
docNames: [docName]
47+
relatedUrls: [relatedUrl],
48+
doi
4749
}
4850
)
4951

5052
await verifyCollectionPropertiesInGraphDb(
5153
{
5254
datasetTitle,
5355
conceptId,
54-
doi: 'doi:10.16904/envidat.166'
56+
doi
5557
}
5658
)
5759

5860
await verifyCampaignExistInGraphDb(datasetTitle, campaign1)
5961
await verifyPlatformInstrumentsExistInGraphDb(datasetTitle,
6062
{ platform: platform1, instruments: [instrument1] })
6163
await verifyPlatformInstrumentsExistInGraphDb(datasetTitle, { platform: platform2 })
62-
await verifyDocumentationExistInGraphDb(datasetTitle, docName)
64+
await verifyDocumentationExistInGraphDb(datasetTitle, relatedUrl)
65+
})
66+
67+
test('test indexing of a collection with no DOI value', async () => {
68+
const datasetTitle = 'Latent reserves within the Swiss NFI'
69+
const conceptId = 'C1237293909-TESTPROV'
70+
const platform1 = 'Platform One'
71+
72+
await updateCollection(
73+
conceptId,
74+
datasetTitle,
75+
{
76+
platforms: [{ platform: platform1 }]
77+
}
78+
)
79+
80+
await verifyCollectionPropertiesInGraphDb(
81+
{
82+
datasetTitle,
83+
conceptId
84+
}
85+
)
86+
87+
await verifyPlatformInstrumentsExistInGraphDb(datasetTitle, { platform: platform1 })
6388
})
6489

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

130155
// first index the collection and verify dataset and documentation vertices are created
131156
await updateCollection(
@@ -136,23 +161,23 @@ describe('indexCmrCollection handler', () => {
136161
platforms: [
137162
{ platform: platform1, instruments: [instrument1, instrument2] },
138163
{ platform: platform2 }],
139-
docNames: [docName]
164+
relatedUrls: [relatedUrl]
140165
}
141166
)
142167

143168
await verifyCampaignExistInGraphDb(datasetTitle, campaign1)
144169
await verifyPlatformInstrumentsExistInGraphDb(datasetTitle,
145170
{ platform: platform1, instruments: [instrument1, instrument2] })
146171
await verifyPlatformInstrumentsExistInGraphDb(datasetTitle, { platform: platform2 })
147-
await verifyDocumentationExistInGraphDb(datasetTitle, docName)
172+
await verifyDocumentationExistInGraphDb(datasetTitle, relatedUrl)
148173

149174
// delete the collection and verify dataset and campaign/documentation vertices are deleted
150175
await deleteCollection('C1237293909-TESTPROV')
151176
await verifyCampaignNotExistInGraphDb(datasetTitle, campaign1)
152177
await verifyPlatformInstrumentsNotExistInGraphDb(datasetTitle,
153178
{ platform: platform1, instruments: [instrument1, instrument2] })
154179
await verifyPlatformInstrumentsNotExistInGraphDb(datasetTitle, { platform: platform2 })
155-
await verifyDocumentationNotExistInGraphDb(datasetTitle, docName)
180+
await verifyDocumentationNotExistInGraphDb(datasetTitle, relatedUrl)
156181
})
157182

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

174199
// this documentation url is referenced by two collections
175-
const sharedDocName = 'https://en.wikipedia.org/wiki/latent_nfi'
200+
const sharedDocUrl = 'https://en.wikipedia.org/wiki/latent_nfi'
176201
// this documentation url is referenced only by one collection
177-
const ownDocName = 'https://en.wikipedia.org/wiki/latent_nfi2'
202+
const ownDocUrl = 'https://en.wikipedia.org/wiki/latent_nfi2'
178203

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

@@ -194,8 +219,8 @@ describe('indexCmrCollection handler', () => {
194219
await verifyPlatformInstrumentsExistInGraphDb(datasetTitle,
195220
{ platform: sharedPlatform, instruments: [sharedInstrument, ownInstrument] })
196221
await verifyPlatformInstrumentsExistInGraphDb(datasetTitle, { platform: ownPlatform })
197-
await verifyDocumentationExistInGraphDb(datasetTitle, sharedDocName)
198-
await verifyDocumentationExistInGraphDb(datasetTitle, ownDocName)
222+
await verifyDocumentationExistInGraphDb(datasetTitle, sharedDocUrl)
223+
await verifyDocumentationExistInGraphDb(datasetTitle, ownDocUrl)
199224

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

213238
await verifyCampaignExistInGraphDb(anotherDatasetTitle, sharedCampaign)
214239
await verifyPlatformInstrumentsExistInGraphDb(anotherDatasetTitle,
215240
{ platform: sharedPlatform, instruments: [sharedInstrument] })
216-
await verifyDocumentationExistInGraphDb(anotherDatasetTitle, sharedDocName)
241+
await verifyDocumentationExistInGraphDb(anotherDatasetTitle, sharedDocUrl)
217242

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

231-
await verifyDocumentationNotExistInGraphDb(datasetTitle, ownDocName)
232-
await verifyDocumentationExistInGraphDb(anotherDatasetTitle, sharedDocName)
256+
await verifyDocumentationNotExistInGraphDb(datasetTitle, ownDocUrl)
257+
await verifyDocumentationExistInGraphDb(anotherDatasetTitle, sharedDocUrl)
233258
})
234259

235260
test('test update collection', async () => {
@@ -258,11 +283,11 @@ describe('indexCmrCollection handler', () => {
258283
const newInstrument = 'NewInstrument'
259284

260285
// this documentation url is referenced by both the old and new version of the collection
261-
const keptDocName = 'https://en.wikipedia.org/wiki/latent_nfi'
286+
const keptDocUrl = 'https://en.wikipedia.org/wiki/latent_nfi'
262287
// this documentation url is referenced only by the old version of collection
263-
const removedDocName = 'https://en.wikipedia.org/wiki/latent_nfi_old'
288+
const removedDocUrl = 'https://en.wikipedia.org/wiki/latent_nfi_old'
264289
// this documentation url is referenced only by the new version of collection
265-
const newDocName = 'https://en.wikipedia.org/wiki/latent_nfi_new'
290+
const newDocUrl = 'https://en.wikipedia.org/wiki/latent_nfi_new'
266291

267292
// first index the collection and verify dataset and documentation vertices are created
268293
await updateCollection(
@@ -273,7 +298,7 @@ describe('indexCmrCollection handler', () => {
273298
platforms: [
274299
{ platform: keptPlatform, instruments: [keptInstrument, removedInstrument] },
275300
{ platform: removedPlatform }],
276-
docNames: [keptDocName, removedDocName]
301+
relatedUrls: [keptDocUrl, removedDocUrl]
277302
}
278303
)
279304

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

287-
await verifyDocumentationExistInGraphDb(datasetTitle, keptDocName)
288-
await verifyDocumentationExistInGraphDb(datasetTitle, removedDocName)
312+
await verifyDocumentationExistInGraphDb(datasetTitle, keptDocUrl)
313+
await verifyDocumentationExistInGraphDb(datasetTitle, removedDocUrl)
289314

290315
// update the collection
291316
await updateCollection(
@@ -296,7 +321,7 @@ describe('indexCmrCollection handler', () => {
296321
platforms: [
297322
{ platform: keptPlatform, instruments: [keptInstrument, newInstrument] },
298323
{ platform: newPlatform, instruments: [newInstrument] }],
299-
docNames: [keptDocName, newDocName]
324+
relatedUrls: [keptDocUrl, newDocUrl]
300325
}
301326
)
302327

@@ -305,7 +330,7 @@ describe('indexCmrCollection handler', () => {
305330
await verifyPlatformInstrumentsNotExistInGraphDb(datasetTitle,
306331
{ platform: keptPlatform, instruments: [removedInstrument] })
307332
await verifyPlatformInstrumentsNotExistInGraphDb(datasetTitle, { platform: removedPlatform })
308-
await verifyDocumentationNotExistInGraphDb(datasetTitle, removedDocName)
333+
await verifyDocumentationNotExistInGraphDb(datasetTitle, removedDocUrl)
309334

310335
// verify the dataset vertext with the new title exist,
311336
// verify the campaign/documentation vertices referenced by another collection exist,
@@ -316,7 +341,7 @@ describe('indexCmrCollection handler', () => {
316341
{ platform: keptPlatform, instruments: [keptInstrument, newInstrument] })
317342
await verifyPlatformInstrumentsExistInGraphDb(anotherDatasetTitle,
318343
{ platform: newPlatform, instruments: [newInstrument] })
319-
await verifyDocumentationExistInGraphDb(anotherDatasetTitle, keptDocName)
320-
await verifyDocumentationExistInGraphDb(anotherDatasetTitle, newDocName)
344+
await verifyDocumentationExistInGraphDb(anotherDatasetTitle, keptDocUrl)
345+
await verifyDocumentationExistInGraphDb(anotherDatasetTitle, newDocUrl)
321346
})
322347
})

graph-db/serverless/src/testUtil/indexCollection.js

+16-10
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ const platformInstruments = (attributes) => {
2727
}
2828
}
2929

30-
const relatedUrl = (docName) => ({
30+
const relatedUrlObj = (relatedUrl) => ({
3131
URLContentType: 'PublicationURL',
3232
Type: 'VIEW RELATED INFORMATION',
3333
Subtype: 'GENERAL DOCUMENTATION',
34-
URL: docName
34+
URL: relatedUrl
3535
})
3636

3737
/**
@@ -42,10 +42,14 @@ const relatedUrl = (docName) => ({
4242
* @returns null
4343
*/
4444
export const updateCollection = async (conceptId, datasetTitle, attributes) => {
45-
const { docNames, campaigns, platforms } = attributes
45+
const {
46+
relatedUrls, campaigns, platforms, doi
47+
} = attributes
48+
4649
let projects
4750
let platformInstrumentObjs
48-
let relatedUrls
51+
let relatedUrlObjs
52+
let doiValue = { MissingReason: 'Not Applicable' }
4953

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

58-
if (docNames) {
59-
relatedUrls = docNames.map(relatedUrl)
62+
if (relatedUrls) {
63+
relatedUrlObjs = relatedUrls.map(relatedUrlObj)
64+
}
65+
66+
if (doi) {
67+
doiValue = { DOI: doi }
6068
}
6169

6270
nock(/local-cmr/)
@@ -73,10 +81,8 @@ export const updateCollection = async (conceptId, datasetTitle, attributes) => {
7381
umm: {
7482
Projects: projects,
7583
Platforms: platformInstrumentObjs,
76-
RelatedUrls: relatedUrls,
77-
DOI: {
78-
DOI: 'doi:10.16904/envidat.166'
79-
},
84+
RelatedUrls: relatedUrlObjs,
85+
DOI: doiValue,
8086
ShortName: 'latent-reserves-in-the-swiss-nfi',
8187
EntryTitle: datasetTitle
8288
}

graph-db/serverless/src/testUtil/verifyCollection.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ export const verifyCollectionPropertiesInGraphDb = async (attrs) => {
33
conceptId, datasetTitle, doi
44
} = attrs
55

6-
// verify the collection vertex with the given properties exists
7-
const collection = await global.testGremlinConnection
6+
const verifyCommand = global.testGremlinConnection
87
.V()
98
.has('collection', 'title', datasetTitle)
109
.has('id', conceptId)
11-
.has('doi', doi)
12-
.next()
10+
11+
if (doi) {
12+
verifyCommand.has('doi', doi)
13+
} else {
14+
verifyCommand.hasNot('doi')
15+
}
16+
17+
// verify the collection vertex with the given properties exists
18+
const collection = await verifyCommand.next()
1319

1420
const { value: { id: collectionId } } = collection
1521
expect(collectionId).not.toBe(null)

graph-db/serverless/src/utils/cmr/indexCmrCollection.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ export const indexCmrCollection = async (collectionObj, gremlinConnection) => {
3434
await deleteCmrCollection(conceptId, gremlinConnection)
3535

3636
let collection = null
37+
const addVCommand = gremlinConnection.addV('collection')
38+
.property('title', entryTitle)
39+
.property('id', conceptId)
40+
41+
if (doiDescription) {
42+
addVCommand.property('doi', doiDescription)
43+
}
44+
3745
try {
3846
// Use `fold` and `coalesce` to check existance of vertex, and create one if none exists.
3947
collection = await gremlinConnection
@@ -43,10 +51,7 @@ export const indexCmrCollection = async (collectionObj, gremlinConnection) => {
4351
.fold()
4452
.coalesce(
4553
gremlinStatistics.unfold(),
46-
gremlinConnection.addV('collection')
47-
.property('title', entryTitle)
48-
.property('id', conceptId)
49-
.property('doi', doiDescription || 'Not provided')
54+
addVCommand
5055
)
5156
.next()
5257
} catch (error) {

0 commit comments

Comments
 (0)