2019-12-30 16:07:26 +00:00
|
|
|
from crc import db
|
2020-01-03 16:44:24 +00:00
|
|
|
from crc.models.workflow import WorkflowModel, WorkflowModelSchema, WorkflowSpecModelSchema, WorkflowSpecModel, \
|
2019-12-30 16:07:26 +00:00
|
|
|
Task, TaskSchema
|
2019-12-27 18:50:03 +00:00
|
|
|
from crc.workflow_processor import WorkflowProcessor
|
|
|
|
|
|
|
|
|
|
|
|
def all_specifications():
|
2020-01-03 16:44:24 +00:00
|
|
|
schema = WorkflowSpecModelSchema(many=True)
|
2019-12-27 18:50:03 +00:00
|
|
|
return schema.dump(db.session.query(WorkflowSpecModel).all())
|
|
|
|
|
|
|
|
|
2020-01-14 02:43:09 +00:00
|
|
|
def add_workflow_specification(body):
|
|
|
|
workflow_spec = WorkflowSpecModelSchema().load(body, session=db.session)
|
|
|
|
db.session.add(workflow_spec)
|
|
|
|
db.session.commit()
|
|
|
|
return WorkflowSpecModelSchema().dump(workflow_spec)
|
|
|
|
|
|
|
|
|
2019-12-27 18:50:03 +00:00
|
|
|
def get_workflow(workflow_id):
|
2020-01-03 16:44:24 +00:00
|
|
|
schema = WorkflowModelSchema()
|
2019-12-27 18:50:03 +00:00
|
|
|
workflow = db.session.query(WorkflowModel).filter_by(id=workflow_id).first()
|
|
|
|
return schema.dump(workflow)
|
|
|
|
|
2019-12-31 16:31:30 +00:00
|
|
|
|
2019-12-30 18:15:39 +00:00
|
|
|
def delete(workflow_id):
|
|
|
|
db.session.query(WorkflowModel).filter_by(id=workflow_id).delete()
|
2019-12-31 16:31:30 +00:00
|
|
|
db.session.commit()
|
|
|
|
|
2019-12-27 18:50:03 +00:00
|
|
|
|
|
|
|
def get_tasks(workflow_id):
|
|
|
|
workflow = db.session.query(WorkflowModel).filter_by(id=workflow_id).first()
|
|
|
|
processor = WorkflowProcessor(workflow.workflow_spec_id, workflow.bpmn_workflow_json)
|
|
|
|
spiff_tasks = processor.get_ready_user_tasks()
|
|
|
|
tasks = []
|
|
|
|
for st in spiff_tasks:
|
|
|
|
tasks.append(Task.from_spiff(st))
|
|
|
|
return TaskSchema(many=True).dump(tasks)
|
|
|
|
|
|
|
|
|
|
|
|
def get_task(workflow_id, task_id):
|
|
|
|
workflow = db.session.query(WorkflowModel).filter_by(id=workflow_id).first()
|
|
|
|
return workflow.bpmn_workflow().get_task(task_id)
|
|
|
|
|
|
|
|
|
2020-01-07 18:23:46 +00:00
|
|
|
def update_task(workflow_id, task_name, body):
|
2020-01-06 14:18:13 +00:00
|
|
|
workflow = db.session.query(WorkflowModel).filter_by(id=workflow_id).first()
|
2020-01-07 18:23:46 +00:00
|
|
|
processor = WorkflowProcessor(workflow.workflow_spec_id, workflow.bpmn_workflow_json)
|
|
|
|
task = processor.bpmn_workflow.get_tasks_from_spec_name(task_name)[0]
|
2020-01-06 14:18:13 +00:00
|
|
|
if workflow and task and body:
|
|
|
|
print('workflow', workflow.id)
|
|
|
|
print('task', task.id)
|
|
|
|
print('body', body)
|
|
|
|
processor = WorkflowProcessor(workflow.workflow_spec_id, workflow.bpmn_workflow_json)
|
|
|
|
processor.complete_task(task)
|
2019-12-27 18:50:03 +00:00
|
|
|
return body
|