Add workflow to study
This commit is contained in:
parent
fd60dc99c3
commit
53a8811769
|
@ -52,8 +52,13 @@ def add_workflow_to_study(study_id, body):
|
||||||
if workflow_spec_model is None:
|
if workflow_spec_model is None:
|
||||||
error = ApiError('unknown_spec', 'The specification "' + body['id'] + '" is not recognized.')
|
error = ApiError('unknown_spec', 'The specification "' + body['id'] + '" is not recognized.')
|
||||||
return ApiErrorSchema.dump(error), 404
|
return ApiErrorSchema.dump(error), 404
|
||||||
processor = WorkflowProcessor.create(workflow_spec_model.id)
|
|
||||||
|
|
||||||
|
processor = WorkflowProcessor.create(workflow_spec_model.id)
|
||||||
|
workflow = WorkflowModel(bpmn_workflow_json=processor.serialize(),
|
||||||
|
status=processor.get_status(),
|
||||||
|
study_id=study_id,
|
||||||
|
workflow_spec_id=workflow_spec_model.id)
|
||||||
|
db.session.add(workflow)
|
||||||
|
|
||||||
def get_workflow(workflow_id):
|
def get_workflow(workflow_id):
|
||||||
return db.session.query(WorkflowModel).filter_by(id=workflow_id).first()
|
return db.session.query(WorkflowModel).filter_by(id=workflow_id).first()
|
||||||
|
|
|
@ -55,7 +55,6 @@ class WorkflowModel(db.Model):
|
||||||
status = db.Column(db.Enum(WorkflowStatus))
|
status = db.Column(db.Enum(WorkflowStatus))
|
||||||
study_id = db.Column(db.Integer, db.ForeignKey('study.id'))
|
study_id = db.Column(db.Integer, db.ForeignKey('study.id'))
|
||||||
workflow_spec_id = db.Column(db.Integer, db.ForeignKey('workflow_spec.id'))
|
workflow_spec_id = db.Column(db.Integer, db.ForeignKey('workflow_spec.id'))
|
||||||
messages: db.Column
|
|
||||||
|
|
||||||
class WorkflowSchema(ModelSchema):
|
class WorkflowSchema(ModelSchema):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -33,12 +33,12 @@ class CustomBpmnScriptEngine(BpmnScriptEngine):
|
||||||
|
|
||||||
class WorkflowProcessor:
|
class WorkflowProcessor:
|
||||||
|
|
||||||
script_engine = CustomBpmnScriptEngine()
|
_script_engine = CustomBpmnScriptEngine()
|
||||||
serializer = CompactWorkflowSerializer()
|
_serializer = CompactWorkflowSerializer()
|
||||||
|
|
||||||
def __init__(self, workflow_spec_id, bpmn_json):
|
def __init__(self, workflow_spec_id, bpmn_json):
|
||||||
self.bpmn_workflow = self.serializer.deserialize_workflow(bpmn_json, self.get_spec(workflow_spec_id))
|
self.bpmn_workflow = self._serializer.deserialize_workflow(bpmn_json, self.get_spec(workflow_spec_id))
|
||||||
self.bpmn_workflow.script_engine = self.script_engine
|
self.bpmn_workflow.script_engine = self._script_engine
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_spec(workflow_spec_id):
|
def get_spec(workflow_spec_id):
|
||||||
|
@ -48,9 +48,9 @@ class WorkflowProcessor:
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, workflow_spec_id):
|
def create(cls, workflow_spec_id):
|
||||||
spec = cls.get_spec(workflow_spec_id)
|
spec = cls.get_spec(workflow_spec_id)
|
||||||
bpmn_workflow = BpmnWorkflow(spec, script_engine=cls.script_engine)
|
bpmn_workflow = BpmnWorkflow(spec, script_engine=cls._script_engine)
|
||||||
bpmn_workflow.do_engine_steps()
|
bpmn_workflow.do_engine_steps()
|
||||||
json = cls.serializer.serialize_workflow(bpmn_workflow)
|
json = cls._serializer.serialize_workflow(bpmn_workflow)
|
||||||
processor = cls(workflow_spec_id, json)
|
processor = cls(workflow_spec_id, json)
|
||||||
return processor
|
return processor
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import json
|
import json
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from sqlalchemy import func
|
||||||
|
|
||||||
from crc import db
|
from crc import db
|
||||||
from crc.models import StudyModel, StudySchema, WorkflowSpecModel, WorkflowSpecSchema
|
from crc.models import StudyModel, StudySchema, WorkflowSpecModel, WorkflowSpecSchema, WorkflowModel, WorkflowStatus
|
||||||
from tests.base_test import BaseTest
|
from tests.base_test import BaseTest
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,9 +50,14 @@ class TestStudy(BaseTest, unittest.TestCase):
|
||||||
def test_add_workflow_to_study(self):
|
def test_add_workflow_to_study(self):
|
||||||
self.load_example_data()
|
self.load_example_data()
|
||||||
study = db.session.query(StudyModel).first()
|
study = db.session.query(StudyModel).first()
|
||||||
|
self.assertEqual(0, db.session.query(WorkflowModel).count())
|
||||||
spec = db.session.query(WorkflowSpecModel).first()
|
spec = db.session.query(WorkflowSpecModel).first()
|
||||||
rv = self.app.post('/v1.0/study/%i/workflows' % study.id,content_type="application/json",
|
rv = self.app.post('/v1.0/study/%i/workflows' % study.id,content_type="application/json",
|
||||||
data=json.dumps(WorkflowSpecSchema().dump(spec)))
|
data=json.dumps(WorkflowSpecSchema().dump(spec)))
|
||||||
self.assert_success(rv)
|
self.assert_success(rv)
|
||||||
|
self.assertEqual(1, db.session.query(WorkflowModel).count())
|
||||||
|
workflow = db.session.query(WorkflowModel).first()
|
||||||
|
self.assertEqual(study.id, workflow.study_id)
|
||||||
|
self.assertEqual(WorkflowStatus.user_input_required, workflow.status)
|
||||||
|
self.assertIsNotNone(workflow.bpmn_workflow_json)
|
||||||
|
self.assertEqual(spec.id, workflow.workflow_spec_id)
|
Loading…
Reference in New Issue