8000 StudyManifestTools: Check reference before export by RudraNilBasu · Pull Request #485 · Medable/mdctl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

StudyManifestTools: Check reference before export #485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions packages/mdctl-axon-tools/lib/StudyManifestTools.js
D877
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const fs = require('fs'),
packageFileDir = path.join(__dirname, '../packageScripts'),
{ Fault } = require('@medable/mdctl-core'),
{
first, intersection, isObject, isArray, get: getProperty
first, intersection, isObject, isArray, get: getProperty, uniq, difference
} = require('lodash'),
{ getMappingScript, getEcMappingScript } = require('./mappings')

Expand Down Expand Up @@ -882,12 +882,55 @@ class StudyManifestTools {
return [...tasks, ...steps, ...branches]
}

async validateWorkflowNotificationsPresentInOrg(org, workflowObjects) {
const notificationsList = await org.objects.org.find().paths('configuration.notifications').limit(false).toArray()
const notificationsObjectList = notificationsList[0].configuration.notifications
const notificationsNamesList = notificationsObjectList.map(item => { return item.name;})
const notificationsInWorkflow = uniq(workflowObjects.map(wf => getProperty(wf, 'wf__actions', []).map(a => getProperty(a, 'wf__params.wf__notification_name')).filter(e => !!e)).flat())

const missingNotificationNames = difference(notificationsInWorkflow, notificationsNamesList)
if (missingNotificationNames.length > 0) {
throw Fault.create('kInvalidArgument', {
message: `Workflow ID notification not present: ${missingNotificationNames.join(', ')}`
})
}
}

async validateWorkflowStepReferencePresentInOrg(org, workflowObjects) {
const conditionInclusionStepNames = workflowObjects.map(wf => getProperty(wf, 'wf__conditions_inclusion', []).map(a => getProperty(a, 'wf__params.wf__step')).filter(e => !!e)).flat()
const conditionExclusionStepNames = workflowObjects.map(wf => getProperty(wf, 'wf__conditions_exclusion', []).map(a => getProperty(a, 'wf__params.wf__step')).filter(e => !!e)).flat()
const stepKeys = uniq(conditionInclusionStepNames.concat(conditionExclusionStepNames))
const stepKeysInOrg = await org.objects.c_step.find({c_key: {$in: stepKeys}}).paths('c_key').limit(false).toArray()

if (stepKeysInOrg.length !== stepKeys.length) {
throw Fault.create('kInvalidArgument', {
message: 'Workflow Step not found',
reason: `Step not found for the step keys: ${difference(stepKeys, stepKeysInOrg.map(s => s.c_key)).join(', ')}`
})
}
}

async validateWorkflowTasksPresentInOrg(taskData, workflowTaskKeys) {
if (taskData.length !== workflowTaskKeys.length) {
throw Fault.create('kInvalidArgument', {
message: 'Workflow Tasks not found',
reason: `Tasks not found for the task keys: ${difference(workflowTaskKeys, taskData.map(t => t.c_key)).join(', ')}`
})
}
}

async getWorkflowManifestEntities(org, workflowIds, orgReferenceProps) {
const workflowObjects = await org.objects.wf__workflow.find({_id: {$in: workflowIds}}).limit(false).toArray();
const workflowTaskKeys = workflowObjects.map(v => getProperty(v, 'wf__start.wf__params.wf__tasks')).flat()
const workflowTaskKeys = uniq(workflowObjects.map(v => getProperty(v, 'wf__start.wf__params.wf__tasks')).flat())
const workflows = await this.getExportObjects(org, 'wf__workflows', {_id: {$in: workflowIds}}, orgReferenceProps)
const taskIds = await org.objects.c_task.find({c_key: {$in: workflowTaskKeys}}).paths('_id').limit(false).toArray()
const tasks = await this.getTaskManifestEntities(org, taskIds.map(t => t._id), orgReferenceProps)

const taskData = await org.objects.c_task.find({c_key: {$in: workflowTaskKeys}}).paths('_id', 'c_key').limit(false).toArray()

await this.validateWorkflowTasksPresentInOrg(taskData, workflowTaskKeys)
await this.validateWorkflowNotificationsPresentInOrg(org, workflowObjects)
await this.validateWorkflowStepReferencePresentInOrg(org, workflowObjects)

const tasks = await this.getTaskManifestEntities(org, taskData.map(t => t._id), orgReferenceProps)

return [...workflows, ...tasks]
}
Expand Down
0