2020-04-21 15:43:43 +00:00
|
|
|
import enum
|
|
|
|
|
2020-03-05 16:18:20 +00:00
|
|
|
import marshmallow
|
|
|
|
from marshmallow import INCLUDE
|
|
|
|
from marshmallow_enum import EnumField
|
|
|
|
|
|
|
|
from crc import ma
|
|
|
|
from crc.models.workflow import WorkflowStatus
|
|
|
|
|
|
|
|
|
2020-04-21 15:43:43 +00:00
|
|
|
class MultiInstanceType(enum.Enum):
|
|
|
|
none = "none"
|
|
|
|
looping = "looping"
|
|
|
|
parallel = "parallel"
|
|
|
|
sequential = "sequential"
|
|
|
|
|
|
|
|
|
2020-03-05 16:18:20 +00:00
|
|
|
class Task(object):
|
2020-04-15 15:13:32 +00:00
|
|
|
|
|
|
|
ENUM_OPTIONS_FILE_PROP = "enum.options.file"
|
|
|
|
EMUM_OPTIONS_VALUE_COL_PROP = "enum.options.value.column"
|
|
|
|
EMUM_OPTIONS_LABEL_COL_PROP = "enum.options.label.column"
|
2020-04-22 19:37:02 +00:00
|
|
|
EMUM_OPTIONS_AS_LOOKUP = "enum.options.lookup"
|
|
|
|
|
2020-04-15 15:13:32 +00:00
|
|
|
|
2020-04-21 15:43:43 +00:00
|
|
|
def __init__(self, id, name, title, type, state, form, documentation, data,
|
2020-04-28 17:48:44 +00:00
|
|
|
mi_type, mi_count, mi_index, process_name, properties):
|
2020-03-05 16:18:20 +00:00
|
|
|
self.id = id
|
|
|
|
self.name = name
|
|
|
|
self.title = title
|
|
|
|
self.type = type
|
|
|
|
self.state = state
|
|
|
|
self.form = form
|
|
|
|
self.documentation = documentation
|
|
|
|
self.data = data
|
2020-04-21 16:07:59 +00:00
|
|
|
self.mi_type = mi_type # Some tasks have a repeat behavior.
|
|
|
|
self.mi_count = mi_count # This is the number of times the task could repeat.
|
|
|
|
self.mi_index = mi_index # And the index of the currently repeating task.
|
2020-04-28 17:48:44 +00:00
|
|
|
self.process_name = process_name
|
2020-04-21 16:07:59 +00:00
|
|
|
self.properties = properties # Arbitrary extension properties from BPMN editor.
|
2020-03-05 16:18:20 +00:00
|
|
|
|
2020-04-28 17:48:44 +00:00
|
|
|
|
2020-03-05 16:18:20 +00:00
|
|
|
class OptionSchema(ma.Schema):
|
|
|
|
class Meta:
|
|
|
|
fields = ["id", "name"]
|
|
|
|
|
|
|
|
|
|
|
|
class ValidationSchema(ma.Schema):
|
|
|
|
class Meta:
|
|
|
|
fields = ["name", "config"]
|
|
|
|
|
|
|
|
|
|
|
|
class PropertiesSchema(ma.Schema):
|
|
|
|
class Meta:
|
|
|
|
fields = ["id", "value"]
|
|
|
|
|
|
|
|
|
|
|
|
class FormFieldSchema(ma.Schema):
|
|
|
|
class Meta:
|
|
|
|
fields = [
|
|
|
|
"id", "type", "label", "default_value", "options", "validation", "properties", "value"
|
|
|
|
]
|
|
|
|
|
|
|
|
default_value = marshmallow.fields.String(required=False, allow_none=True)
|
|
|
|
options = marshmallow.fields.List(marshmallow.fields.Nested(OptionSchema))
|
|
|
|
validation = marshmallow.fields.List(marshmallow.fields.Nested(ValidationSchema))
|
|
|
|
properties = marshmallow.fields.List(marshmallow.fields.Nested(PropertiesSchema))
|
|
|
|
|
|
|
|
|
|
|
|
class FormSchema(ma.Schema):
|
|
|
|
key = marshmallow.fields.String(required=True, allow_none=False)
|
|
|
|
fields = marshmallow.fields.List(marshmallow.fields.Nested(FormFieldSchema))
|
|
|
|
|
|
|
|
|
|
|
|
class TaskSchema(ma.Schema):
|
|
|
|
class Meta:
|
2020-04-21 15:43:43 +00:00
|
|
|
fields = ["id", "name", "title", "type", "state", "form", "documentation", "data", "mi_type",
|
2020-04-28 17:48:44 +00:00
|
|
|
"mi_count", "mi_index", "process_name", "properties"]
|
2020-03-05 16:18:20 +00:00
|
|
|
|
2020-04-21 15:43:43 +00:00
|
|
|
mi_type = EnumField(MultiInstanceType)
|
2020-03-05 16:18:20 +00:00
|
|
|
documentation = marshmallow.fields.String(required=False, allow_none=True)
|
|
|
|
form = marshmallow.fields.Nested(FormSchema, required=False, allow_none=True)
|
|
|
|
title = marshmallow.fields.String(required=False, allow_none=True)
|
2020-04-21 16:07:59 +00:00
|
|
|
properties = marshmallow.fields.List(marshmallow.fields.Nested(PropertiesSchema))
|
2020-04-28 17:48:44 +00:00
|
|
|
process_name = marshmallow.fields.String(required=False, allow_none=True)
|
2020-03-05 16:18:20 +00:00
|
|
|
|
|
|
|
@marshmallow.post_load
|
|
|
|
def make_task(self, data, **kwargs):
|
|
|
|
return Task(**data)
|
|
|
|
|
|
|
|
|
|
|
|
class WorkflowApi(object):
|
2020-03-27 18:27:50 +00:00
|
|
|
def __init__(self, id, status, user_tasks, last_task, next_task,
|
2020-03-27 18:55:53 +00:00
|
|
|
spec_version, is_latest_spec, workflow_spec_id):
|
2020-03-05 16:18:20 +00:00
|
|
|
self.id = id
|
|
|
|
self.status = status
|
|
|
|
self.user_tasks = user_tasks
|
|
|
|
self.last_task = last_task
|
|
|
|
self.next_task = next_task
|
2020-03-27 18:55:53 +00:00
|
|
|
self.workflow_spec_id = workflow_spec_id
|
2020-03-05 16:18:20 +00:00
|
|
|
self.spec_version = spec_version
|
2020-03-05 21:45:44 +00:00
|
|
|
self.is_latest_spec = is_latest_spec
|
2020-03-05 16:18:20 +00:00
|
|
|
|
|
|
|
class WorkflowApiSchema(ma.Schema):
|
|
|
|
class Meta:
|
|
|
|
model = WorkflowApi
|
2020-03-10 19:46:14 +00:00
|
|
|
fields = ["id", "status", "user_tasks", "last_task", "next_task",
|
2020-03-27 18:55:53 +00:00
|
|
|
"workflow_spec_id", "spec_version", "is_latest_spec"]
|
2020-03-05 16:18:20 +00:00
|
|
|
unknown = INCLUDE
|
|
|
|
|
|
|
|
status = EnumField(WorkflowStatus)
|
|
|
|
user_tasks = marshmallow.fields.List(marshmallow.fields.Nested(TaskSchema, dump_only=True))
|
|
|
|
last_task = marshmallow.fields.Nested(TaskSchema, dump_only=True)
|
|
|
|
next_task = marshmallow.fields.Nested(TaskSchema, dump_only=True, required=False)
|
|
|
|
|
|
|
|
@marshmallow.post_load
|
|
|
|
def make_workflow(self, data, **kwargs):
|
2020-03-15 19:52:59 +00:00
|
|
|
keys = ['id', 'status', 'user_tasks', 'last_task', 'next_task',
|
2020-03-27 18:55:53 +00:00
|
|
|
'workflow_spec_id', 'spec_version', 'is_latest_spec']
|
2020-03-10 19:46:14 +00:00
|
|
|
filtered_fields = {key: data[key] for key in keys}
|
|
|
|
return WorkflowApi(**filtered_fields)
|