Make use of cleaner data provided by Spiffworkflow about multi-instance settings.

This commit is contained in:
Dan Funk 2020-04-21 11:43:43 -04:00
parent 7b32198795
commit ec112f52be
5 changed files with 32 additions and 20 deletions

2
Pipfile.lock generated
View File

@ -783,7 +783,7 @@
"spiffworkflow": { "spiffworkflow": {
"editable": true, "editable": true,
"git": "https://github.com/sartography/SpiffWorkflow.git", "git": "https://github.com/sartography/SpiffWorkflow.git",
"ref": "976ac8b28f8168666efef7b4f0ec819f4a7dece1" "ref": "ecd3f64d96886ea9e2c03242bc2ded9b10821e88"
}, },
"sqlalchemy": { "sqlalchemy": {
"hashes": [ "hashes": [

View File

@ -1,3 +1,5 @@
import enum
import marshmallow import marshmallow
from marshmallow import INCLUDE from marshmallow import INCLUDE
from marshmallow_enum import EnumField from marshmallow_enum import EnumField
@ -6,13 +8,21 @@ from crc import ma
from crc.models.workflow import WorkflowStatus from crc.models.workflow import WorkflowStatus
class MultiInstanceType(enum.Enum):
none = "none"
looping = "looping"
parallel = "parallel"
sequential = "sequential"
class Task(object): class Task(object):
ENUM_OPTIONS_FILE_PROP = "enum.options.file" ENUM_OPTIONS_FILE_PROP = "enum.options.file"
EMUM_OPTIONS_VALUE_COL_PROP = "enum.options.value.column" EMUM_OPTIONS_VALUE_COL_PROP = "enum.options.value.column"
EMUM_OPTIONS_LABEL_COL_PROP = "enum.options.label.column" EMUM_OPTIONS_LABEL_COL_PROP = "enum.options.label.column"
def __init__(self, id, name, title, type, state, form, documentation, data, is_multi_instance, mi_count, mi_index): def __init__(self, id, name, title, type, state, form, documentation, data,
mi_type, mi_count, mi_index):
self.id = id self.id = id
self.name = name self.name = name
self.title = title self.title = title
@ -21,7 +31,7 @@ class Task(object):
self.form = form self.form = form
self.documentation = documentation self.documentation = documentation
self.data = data self.data = data
self.is_multi_instance = is_multi_instance self.mi_type = mi_type
self.mi_count = mi_count self.mi_count = mi_count
self.mi_index = mi_index self.mi_index = mi_index
@ -59,9 +69,10 @@ class FormSchema(ma.Schema):
class TaskSchema(ma.Schema): class TaskSchema(ma.Schema):
class Meta: class Meta:
fields = ["id", "name", "title", "type", "state", "form", "documentation", "data", "is_multi_instance", fields = ["id", "name", "title", "type", "state", "form", "documentation", "data", "mi_type",
"mi_count", "mi_index"] "mi_count", "mi_index"]
mi_type = EnumField(MultiInstanceType)
documentation = marshmallow.fields.String(required=False, allow_none=True) documentation = marshmallow.fields.String(required=False, allow_none=True)
form = marshmallow.fields.Nested(FormSchema, required=False, allow_none=True) form = marshmallow.fields.Nested(FormSchema, required=False, allow_none=True)
title = marshmallow.fields.String(required=False, allow_none=True) title = marshmallow.fields.String(required=False, allow_none=True)

View File

@ -9,7 +9,7 @@ from SpiffWorkflow.specs import CancelTask, StartTask
from pandas import ExcelFile from pandas import ExcelFile
from crc.api.common import ApiError from crc.api.common import ApiError
from crc.models.api_models import Task from crc.models.api_models import Task, MultiInstanceType
import jinja2 import jinja2
from jinja2 import Template from jinja2 import Template
@ -69,13 +69,15 @@ class WorkflowService(object):
else: else:
task_type = "NoneTask" task_type = "NoneTask"
multi_instance = isinstance(spiff_task.task_spec, MultiInstanceTask) info = spiff_task.task_info()
mi_count = 0 if info["is_looping"]:
mi_index = 0 mi_type = MultiInstanceType.looping
if multi_instance: elif info["is_sequential_mi"]:
mi_count = spiff_task.task_spec._get_count(spiff_task) mi_type = MultiInstanceType.sequential
mi_index = int(spiff_task._get_internal_data('runtimes', 1)) elif info["is_parallel_mi"]:
mi_type = MultiInstanceType.parallel
else:
mi_type = MultiInstanceType.none
task = Task(spiff_task.id, task = Task(spiff_task.id,
spiff_task.task_spec.name, spiff_task.task_spec.name,
@ -85,11 +87,9 @@ class WorkflowService(object):
None, None,
"", "",
spiff_task.data, spiff_task.data,
multi_instance, mi_type,
mi_count, info["mi_count"],
mi_index) info["mi_index"])
# Only process the form and documentation if this is something that is ready or completed. # Only process the form and documentation if this is something that is ready or completed.
if not (spiff_task._is_predicted()): if not (spiff_task._is_predicted()):

View File

@ -3,7 +3,7 @@ import os
from unittest.mock import patch from unittest.mock import patch
from crc import session, app from crc import session, app
from crc.models.api_models import WorkflowApiSchema from crc.models.api_models import WorkflowApiSchema, MultiInstanceType
from crc.models.file import FileModelSchema from crc.models.file import FileModelSchema
from crc.models.stats import WorkflowStatsModel, TaskEventModel from crc.models.stats import WorkflowStatsModel, TaskEventModel
from crc.models.workflow import WorkflowStatus from crc.models.workflow import WorkflowStatus
@ -272,7 +272,7 @@ class TestTasksApi(BaseTest):
tasks = self.get_workflow_api(workflow).user_tasks tasks = self.get_workflow_api(workflow).user_tasks
self.assertEquals(1, len(tasks)) self.assertEquals(1, len(tasks))
self.assertEquals("UserTask", tasks[0].type) self.assertEquals("UserTask", tasks[0].type)
self.assertTrue(tasks[0].is_multi_instance) self.assertEquals(MultiInstanceType.sequential, tasks[0].mi_type)
self.assertEquals(3, tasks[0].mi_count) self.assertEquals(3, tasks[0].mi_count)
workflow_api = self.complete_form(workflow, tasks[0], {"name": "Dan"}) workflow_api = self.complete_form(workflow, tasks[0], {"name": "Dan"})

View File

@ -8,6 +8,7 @@ from SpiffWorkflow.bpmn.specs.EndEvent import EndEvent
from crc import session, db, app from crc import session, db, app
from crc.api.common import ApiError from crc.api.common import ApiError
from crc.models.api_models import MultiInstanceType
from crc.models.file import FileModel, FileDataModel, CONTENT_TYPES from crc.models.file import FileModel, FileDataModel, CONTENT_TYPES
from crc.models.study import StudyModel from crc.models.study import StudyModel
from crc.models.workflow import WorkflowSpecModel, WorkflowStatus, WorkflowModel from crc.models.workflow import WorkflowSpecModel, WorkflowStatus, WorkflowModel
@ -35,7 +36,6 @@ class TestWorkflowProcessorMultiInstance(BaseTest):
mock_get.return_value.ok = True mock_get.return_value.ok = True
mock_get.return_value.text = self.protocol_builder_response('investigators.json') mock_get.return_value.text = self.protocol_builder_response('investigators.json')
self.load_example_data() self.load_example_data()
workflow_spec_model = self.load_test_spec("multi_instance") workflow_spec_model = self.load_test_spec("multi_instance")
study = session.query(StudyModel).first() study = session.query(StudyModel).first()
@ -62,6 +62,7 @@ class TestWorkflowProcessorMultiInstance(BaseTest):
self.assertEqual("MutiInstanceTask", task.get_name()) self.assertEqual("MutiInstanceTask", task.get_name())
api_task = WorkflowService.spiff_task_to_api_task(task) api_task = WorkflowService.spiff_task_to_api_task(task)
self.assertEquals(MultiInstanceType.sequential, api_task.mi_type)
self.assertEquals(3, api_task.mi_count) self.assertEquals(3, api_task.mi_count)
self.assertEquals(1, api_task.mi_index) self.assertEquals(1, api_task.mi_index)
task.update_data({"email":"asd3v@virginia.edu"}) task.update_data({"email":"asd3v@virginia.edu"})