Merge pull request #310 from sartography/get-primary-workflow-301

Get primary workflow #301
This commit is contained in:
Dan Funk 2021-05-14 12:41:48 -04:00 committed by GitHub
commit ade7812540
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -22,7 +22,7 @@ from jinja2 import Template
from crc import db, app
from crc.api.common import ApiError
from crc.models.api_models import Task, MultiInstanceType, WorkflowApi
from crc.models.file import LookupDataModel
from crc.models.file import LookupDataModel, FileModel
from crc.models.study import StudyModel
from crc.models.task_event import TaskEventModel
from crc.models.user import UserModel, UserModelSchema
@ -808,3 +808,12 @@ class WorkflowService(object):
def get_standalone_workflow_specs():
specs = db.session.query(WorkflowSpecModel).filter_by(standalone=True).all()
return specs
@staticmethod
def get_primary_workflow(workflow_spec_id):
# Returns the FileModel of the primary workflow for a workflow_spec
primary = None
file = db.session.query(FileModel).filter(FileModel.workflow_spec_id==workflow_spec_id, FileModel.primary==True).first()
if file:
primary = file
return primary

View File

@ -10,6 +10,7 @@ from example_data import ExampleDataLoader
from crc import db
from crc.models.task_event import TaskEventModel
from crc.models.api_models import Task
from crc.models.file import FileModel
from crc.api.common import ApiError
@ -114,3 +115,12 @@ class TestWorkflowService(BaseTest):
result2 = WorkflowService.get_dot_value(path, {"a.b.c":"garbage"})
self.assertEqual("garbage", result2)
def test_get_primary_workflow(self):
workflow = self.create_workflow('hello_world')
workflow_spec_id = workflow.workflow_spec.id
primary_workflow = WorkflowService.get_primary_workflow(workflow_spec_id)
self.assertIsInstance(primary_workflow, FileModel)
self.assertEqual(workflow_spec_id, primary_workflow.workflow_spec_id)
self.assertEqual('hello_world.bpmn', primary_workflow.name)