-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
191 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import gremlin from 'gremlin' | ||
|
||
const gremlinStatistics = gremlin.process.statics | ||
|
||
export const verifyCampaignExistInGraphDb = async (datasetTitle, campaignName) => { | ||
// verify the dataset vertex with the given title exists | ||
const dataset = await global.testGremlinConnection | ||
.V() | ||
.has('dataset', 'title', datasetTitle) | ||
.next() | ||
const { value: { id: datasetId } } = dataset | ||
expect(datasetId).not.toBe(null) | ||
|
||
// verify the campaign vertex with the given name exists | ||
const doc = await global.testGremlinConnection | ||
.V() | ||
.has('campaign', 'name', campaignName) | ||
.next() | ||
const { value: { id: docId } } = doc | ||
expect(docId).not.toBe(null) | ||
|
||
// verify the edge exists between the two vertices | ||
const record = await global.testGremlinConnection | ||
.V() | ||
.has('dataset', 'title', datasetTitle) | ||
.outE('includedIn') | ||
.filter(gremlinStatistics.inV() | ||
.has('campaign', 'name', campaignName)) | ||
.next() | ||
const { value: { id: edgeId } } = record | ||
expect(edgeId).not.toBe(null) | ||
} | ||
|
||
export const verifyCampaignNotExistInGraphDb = async (datasetTitle, campaignName) => { | ||
// verify the dataset vertex with the given title does not exist | ||
const dataset = await global.testGremlinConnection | ||
.V() | ||
.has('dataset', 'title', datasetTitle) | ||
.next() | ||
const { value: datasetValue } = dataset | ||
expect(datasetValue).toBe(null) | ||
|
||
// verify the campaign vertex with the given name does not exist | ||
const doc = await global.testGremlinConnection | ||
.V() | ||
.has('campaign', 'name', campaignName) | ||
.next() | ||
const { value: docValue } = doc | ||
expect(docValue).toBe(null) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import gremlin from 'gremlin' | ||
|
||
const gremlinStatistics = gremlin.process.statics | ||
|
||
export const verifyDocumentationExistInGraphDb = async (datasetTitle, docName) => { | ||
// verify the dataset vertex with the given title exists | ||
const dataset = await global.testGremlinConnection | ||
.V() | ||
.has('dataset', 'title', datasetTitle) | ||
.next() | ||
const { value: { id: datasetId } } = dataset | ||
expect(datasetId).not.toBe(null) | ||
|
||
// verify the documentation vertex with the given name exists | ||
const doc = await global.testGremlinConnection | ||
.V() | ||
.has('documentation', 'name', docName) | ||
.next() | ||
const { value: { id: docId } } = doc | ||
expect(docId).not.toBe(null) | ||
|
||
// verify the edge exists between the two vertices | ||
const record = await global.testGremlinConnection | ||
.V() | ||
.has('dataset', 'title', datasetTitle) | ||
.outE('documentedBy') | ||
.filter(gremlinStatistics.inV() | ||
.has('documentation', 'name', docName)) | ||
.next() | ||
const { value: { id: edgeId } } = record | ||
expect(edgeId).not.toBe(null) | ||
} | ||
|
||
export const verifyDocumentationNotExistInGraphDb = async (datasetTitle, docName) => { | ||
// verify the dataset vertex with the given title does not exist | ||
const dataset = await global.testGremlinConnection | ||
.V() | ||
.has('dataset', 'title', datasetTitle) | ||
.next() | ||
const { value: datasetValue } = dataset | ||
expect(datasetValue).toBe(null) | ||
|
||
// verify the documentation vertex with the given name does not exist | ||
const doc = await global.testGremlinConnection | ||
.V() | ||
.has('documentation', 'name', docName) | ||
.next() | ||
const { value: docValue } = doc | ||
expect(docValue).toBe(null) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import gremlin from 'gremlin' | ||
|
||
const gremlinStatistics = gremlin.process.statics | ||
|
||
/** | ||
* create the acquiredBy edge between platform/instrument and collection | ||
* @param {String} piId the id of the platformInstrument vertex | ||
* @param {Connection} gremlinConnection a connection to the gremlin server | ||
* @param {Graph Node} dataset the parent collection vertex in the gremlin server | ||
* @returns null | ||
*/ | ||
export const createAcquiredByEdge = async (piId, gremlinConnection, dataset) => { | ||
// Create an edge between the given platform and the collection | ||
let platformEdge | ||
try { | ||
platformEdge = await gremlinConnection | ||
.V(piId).as('p') | ||
.V(dataset) | ||
.coalesce( | ||
gremlinStatistics.outE('acquiredBy').where(gremlinStatistics.inV().as('p')), | ||
gremlinConnection.addE('acquiredBy').to('p') | ||
) | ||
.next() | ||
} catch (error) { | ||
console.error(`ERROR creating acquiredBy edge: ${error}`) | ||
} | ||
|
||
const { value: edgeValue = {} } = platformEdge | ||
const { id: edgeId } = edgeValue | ||
|
||
console.log(`acquiredBy edge [${edgeId}] indexed to point to collection [${dataset}]`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import gremlin from 'gremlin' | ||
|
||
import { createAcquiredByEdge } from './createAcquiredByEdge' | ||
|
||
const gremlinStatistics = gremlin.process.statics | ||
|
||
/** | ||
* Given an Instrument object, Gremlin connection, and associated platform and collection, index instrument and build relationships between platform/instrument and collection | ||
* @param {JSON} instrument the instrument | ||
* @param {Connection} gremlinConnection a connection to the gremlin server | ||
* @param {String} platformName the name of the platform | ||
* @param {Graph Node} dataset the parent collection vertex in the gremlin server | ||
* @returns null | ||
*/ | ||
export const indexInstrument = async (instrument, gremlinConnection, platformName, dataset) => { | ||
const { | ||
ShortName: instrumentName | ||
} = instrument | ||
|
||
let piVertex | ||
try { | ||
piVertex = await gremlinConnection | ||
.V() | ||
.has('platformInstrument', 'platform', platformName) | ||
.has('instrument', instrumentName) | ||
.fold() | ||
.coalesce( | ||
gremlinStatistics.unfold(), | ||
gremlinConnection.addV('platformInstrument').property('platform', platformName).property('instrument', instrumentName) | ||
) | ||
.next() | ||
} catch (error) { | ||
console.error(`ERROR indexing instrument: ${error}`) | ||
} | ||
|
||
const { value: vertexValue = {} } = piVertex | ||
const { id: piId } = vertexValue | ||
console.log(`PlatformInstrument vertex [${piId}] indexed for collection [${dataset}]`) | ||
|
||
await createAcquiredByEdge(piId, gremlinConnection, dataset) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters