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-05-15 19:54:53 +00:00
|
|
|
class NavigationItem(object):
|
2020-06-15 16:33:51 +00:00
|
|
|
def __init__(self, id, task_id, name, title, backtracks, level, indent, child_count, state, is_decision,
|
|
|
|
task=None, lane=None):
|
2020-05-15 19:54:53 +00:00
|
|
|
self.id = id
|
|
|
|
self.task_id = task_id
|
|
|
|
self.name = name,
|
|
|
|
self.title = title
|
|
|
|
self.backtracks = backtracks
|
|
|
|
self.level = level
|
|
|
|
self.indent = indent
|
2020-05-15 20:38:37 +00:00
|
|
|
self.child_count = child_count
|
2020-05-15 19:54:53 +00:00
|
|
|
self.state = state
|
2020-05-15 20:38:37 +00:00
|
|
|
self.is_decision = is_decision
|
2020-05-15 19:54:53 +00:00
|
|
|
self.task = task
|
2020-07-14 14:29:25 +00:00
|
|
|
self.lane = lane
|
2020-05-15 19:54:53 +00:00
|
|
|
|
2020-03-05 16:18:20 +00:00
|
|
|
class Task(object):
|
2020-04-15 15:13:32 +00:00
|
|
|
|
2020-07-10 18:48:38 +00:00
|
|
|
##########################################################################
|
|
|
|
# Custom properties and validations defined in Camunda form fields #
|
|
|
|
##########################################################################
|
|
|
|
|
|
|
|
# Repeating form section
|
2020-05-30 19:37:04 +00:00
|
|
|
PROP_OPTIONS_REPEAT = "repeat"
|
2020-07-10 18:48:38 +00:00
|
|
|
|
|
|
|
# Read-only field
|
2020-06-17 21:11:15 +00:00
|
|
|
PROP_OPTIONS_READ_ONLY = "read_only"
|
2020-07-10 18:48:38 +00:00
|
|
|
|
|
|
|
# LDAP lookup
|
2020-05-19 20:11:43 +00:00
|
|
|
PROP_LDAP_LOOKUP = "ldap.lookup"
|
2020-07-10 18:48:38 +00:00
|
|
|
|
|
|
|
# Autocomplete field
|
2020-05-19 20:11:43 +00:00
|
|
|
FIELD_TYPE_AUTO_COMPLETE = "autocomplete"
|
|
|
|
|
2020-07-10 18:48:38 +00:00
|
|
|
# Required field
|
|
|
|
VALIDATION_REQUIRED = "required"
|
|
|
|
|
|
|
|
# Enum field options values pulled from a spreadsheet
|
|
|
|
PROP_OPTIONS_FILE_NAME = "spreadsheet.name"
|
|
|
|
PROP_OPTIONS_FILE_VALUE_COLUMN = "spreadsheet.value.column"
|
|
|
|
PROP_OPTIONS_FILE_LABEL_COLUMN = "spreadsheet.label.column"
|
|
|
|
|
|
|
|
# Enum field options values pulled from task data
|
|
|
|
PROP_OPTIONS_DATA_NAME = "data.name"
|
|
|
|
PROP_OPTIONS_DATA_VALUE_COLUMN = "data.value.column"
|
|
|
|
PROP_OPTIONS_DATA_LABEL_COLUMN = "data.label.column"
|
|
|
|
|
|
|
|
##########################################################################
|
2020-04-22 19:37:02 +00:00
|
|
|
|
2020-07-15 02:16:44 +00:00
|
|
|
def __init__(self, id, name, title, type, state, lane, form, documentation, data,
|
|
|
|
multi_instance_type, multi_instance_count, multi_instance_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-07-15 02:16:44 +00:00
|
|
|
self.lane = lane
|
2020-05-15 20:38:37 +00:00
|
|
|
self.multi_instance_type = multi_instance_type # Some tasks have a repeat behavior.
|
|
|
|
self.multi_instance_count = multi_instance_count # This is the number of times the task could repeat.
|
|
|
|
self.multi_instance_index = multi_instance_index # And the index of the currently repeating task.
|
|
|
|
self.process_name = process_name
|
2020-05-04 14:57:09 +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:
|
2020-07-03 16:20:10 +00:00
|
|
|
fields = ["id", "name", "data"]
|
2020-03-05 16:18:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ValidationSchema(ma.Schema):
|
|
|
|
class Meta:
|
|
|
|
fields = ["name", "config"]
|
|
|
|
|
2020-05-15 20:38:37 +00:00
|
|
|
|
2020-05-14 18:39:14 +00:00
|
|
|
class FormFieldPropertySchema(ma.Schema):
|
|
|
|
class Meta:
|
2020-07-03 16:20:10 +00:00
|
|
|
fields = ["id", "value"]
|
2020-03-05 16:18:20 +00:00
|
|
|
|
|
|
|
class FormFieldSchema(ma.Schema):
|
|
|
|
class Meta:
|
2020-07-03 16:20:10 +00:00
|
|
|
fields = ["id", "type", "label", "default_value", "options", "validation", "properties", "value"]
|
2020-03-05 16:18:20 +00:00
|
|
|
|
|
|
|
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))
|
2020-05-14 18:39:14 +00:00
|
|
|
properties = marshmallow.fields.List(marshmallow.fields.Nested(FormFieldPropertySchema))
|
2020-03-05 16:18:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
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-07-15 02:16:44 +00:00
|
|
|
fields = ["id", "name", "title", "type", "state", "lane", "form", "documentation", "data", "multi_instance_type",
|
2020-05-15 20:38:37 +00:00
|
|
|
"multi_instance_count", "multi_instance_index", "process_name", "properties"]
|
2020-03-05 16:18:20 +00:00
|
|
|
|
2020-05-15 20:38:37 +00:00
|
|
|
multi_instance_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-05-15 20:38:37 +00:00
|
|
|
process_name = marshmallow.fields.String(required=False, allow_none=True)
|
2020-07-15 02:16:44 +00:00
|
|
|
lane = 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)
|
|
|
|
|
|
|
|
|
2020-05-15 19:54:53 +00:00
|
|
|
class NavigationItemSchema(ma.Schema):
|
|
|
|
class Meta:
|
2020-05-15 20:38:37 +00:00
|
|
|
fields = ["id", "task_id", "name", "title", "backtracks", "level", "indent", "child_count", "state",
|
2020-07-14 14:29:25 +00:00
|
|
|
"is_decision", "task", "lane"]
|
2020-05-15 19:54:53 +00:00
|
|
|
unknown = INCLUDE
|
|
|
|
task = marshmallow.fields.Nested(TaskSchema, dump_only=True, required=False, allow_none=True)
|
|
|
|
backtracks = marshmallow.fields.String(required=False, allow_none=True)
|
2020-07-14 14:29:25 +00:00
|
|
|
lane = marshmallow.fields.String(required=False, allow_none=True)
|
2020-05-15 19:54:53 +00:00
|
|
|
title = marshmallow.fields.String(required=False, allow_none=True)
|
|
|
|
task_id = marshmallow.fields.String(required=False, allow_none=True)
|
|
|
|
|
|
|
|
|
2020-03-05 16:18:20 +00:00
|
|
|
class WorkflowApi(object):
|
2020-05-15 19:54:53 +00:00
|
|
|
def __init__(self, id, status, next_task, navigation,
|
2020-07-28 17:33:38 +00:00
|
|
|
spec_version, is_latest_spec, workflow_spec_id, total_tasks, completed_tasks,
|
|
|
|
last_updated, title, read_only):
|
2020-03-05 16:18:20 +00:00
|
|
|
self.id = id
|
|
|
|
self.status = status
|
2020-05-01 16:11:39 +00:00
|
|
|
self.next_task = next_task # The next task that requires user input.
|
2020-05-15 19:54:53 +00:00
|
|
|
self.navigation = navigation
|
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-05-04 14:57:09 +00:00
|
|
|
self.total_tasks = total_tasks
|
|
|
|
self.completed_tasks = completed_tasks
|
|
|
|
self.last_updated = last_updated
|
2020-06-16 17:34:21 +00:00
|
|
|
self.title = title
|
2020-07-28 17:33:38 +00:00
|
|
|
self.read_only = read_only
|
2020-03-05 16:18:20 +00:00
|
|
|
|
|
|
|
class WorkflowApiSchema(ma.Schema):
|
|
|
|
class Meta:
|
|
|
|
model = WorkflowApi
|
2020-05-15 19:54:53 +00:00
|
|
|
fields = ["id", "status", "next_task", "navigation",
|
2020-05-04 14:57:09 +00:00
|
|
|
"workflow_spec_id", "spec_version", "is_latest_spec", "total_tasks", "completed_tasks",
|
2020-07-28 17:33:38 +00:00
|
|
|
"last_updated", "title", "read_only"]
|
2020-03-05 16:18:20 +00:00
|
|
|
unknown = INCLUDE
|
|
|
|
|
|
|
|
status = EnumField(WorkflowStatus)
|
|
|
|
next_task = marshmallow.fields.Nested(TaskSchema, dump_only=True, required=False)
|
2020-05-15 19:54:53 +00:00
|
|
|
navigation = marshmallow.fields.List(marshmallow.fields.Nested(NavigationItemSchema, dump_only=True))
|
2020-03-05 16:18:20 +00:00
|
|
|
|
|
|
|
@marshmallow.post_load
|
|
|
|
def make_workflow(self, data, **kwargs):
|
2020-05-15 19:54:53 +00:00
|
|
|
keys = ['id', 'status', 'next_task', 'navigation',
|
2020-05-04 14:57:09 +00:00
|
|
|
'workflow_spec_id', 'spec_version', 'is_latest_spec', "total_tasks", "completed_tasks",
|
2020-07-28 17:33:38 +00:00
|
|
|
"last_updated", "title", "read_only"]
|
2020-03-10 19:46:14 +00:00
|
|
|
filtered_fields = {key: data[key] for key in keys}
|
2020-05-15 19:54:53 +00:00
|
|
|
filtered_fields['next_task'] = TaskSchema().make_task(data['next_task'])
|
2020-03-10 19:46:14 +00:00
|
|
|
return WorkflowApi(**filtered_fields)
|