2019-12-30 16:07:26 +00:00
|
|
|
from crc import db
|
2019-12-31 21:32:47 +00:00
|
|
|
from crc.models.workflow import WorkflowModel, WorkflowSchema, WorkflowSpecSchema, 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():
|
|
|
|
schema = WorkflowSpecSchema(many=True)
|
|
|
|
return schema.dump(db.session.query(WorkflowSpecModel).all())
|
|
|
|
|
|
|
|
|
|
|
|
def get_workflow(workflow_id):
|
|
|
|
schema = WorkflowSchema()
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
def update_task(workflow_id, task_id, body):
|
2019-12-31 21:32:47 +00:00
|
|
|
workflow_spec_model = db.session.query(WorkflowSpecModel).filter_by(id=body["id"]).first()
|
|
|
|
task = TaskSchema().load(body)
|
|
|
|
if task.form:
|
|
|
|
for field in task.form["fields"]:
|
|
|
|
print("Setting " + field["id"] + " to " + field["value"])
|
2019-12-27 18:50:03 +00:00
|
|
|
return body
|