cleaned up api to run process model w/ burnettk

This commit is contained in:
jasquat 2022-06-07 11:07:38 -04:00
parent 60c60e7ea3
commit 053571500f
6 changed files with 128 additions and 32 deletions

View File

@ -39,33 +39,6 @@ paths:
schema: schema:
$ref: "#/components/schemas/WorkflowSpecCategory" $ref: "#/components/schemas/WorkflowSpecCategory"
/process-models: /process-models:
# get:
# operationId: crc.api.workflow.all_specifications
# summary: Provides a list of workflows specifications that can be added to a study manually. Please note that Protocol Builder will handle this most of the time.
# tags:
# - Workflow Specifications
# parameters :
# - name : libraries
# in : query
# required : false
# description : True if we should return just library schemas
# schema :
# type : boolean
# - name : standalone
# in : query
# required : false
# description : True if we should return just standalone schemas
# schema :
# type : boolean
# responses:
# '200':
# description: An array of workflow specifications
# content:
# application/json:
# schema:
# type: array
# items:
# $ref: "#/components/schemas/WorkflowSpec"
post: post:
operationId: spiffworkflow_backend.routes.process_api_blueprint.add_process_model operationId: spiffworkflow_backend.routes.process_api_blueprint.add_process_model
summary: Creates a new workflow specification with the given parameters. summary: Creates a new workflow specification with the given parameters.
@ -147,7 +120,7 @@ paths:
schema: schema:
$ref: "#/components/schemas/WorkflowSpec" $ref: "#/components/schemas/WorkflowSpec"
post: post:
operationId: spiffworkflow_backend.routes.process_api_blueprint.create_process_instance operationId: spiffworkflow_backend.routes.process_api_blueprint.process_instance_create
summary: Creates a workflow from a workflow spec and returns the workflow summary: Creates a workflow from a workflow spec and returns the workflow
tags: tags:
- Workflow Specifications - Workflow Specifications

View File

@ -79,8 +79,9 @@ def add_file(process_model_id):
) )
def create_process_instance(process_model_id): def process_instance_create(process_model_id):
"""Create_process_instance.""" """Create_process_instance."""
# import pdb; pdb.set_trace()
process_instance = ProcessInstanceService.create_process_instance(process_model_id, g.user) process_instance = ProcessInstanceService.create_process_instance(process_model_id, g.user)
processor = ProcessInstanceProcessor(process_instance) processor = ProcessInstanceProcessor(process_instance)
@ -88,11 +89,14 @@ def create_process_instance(process_model_id):
processor.save() processor.save()
# ProcessInstanceService.update_task_assignments(processor) # ProcessInstanceService.update_task_assignments(processor)
workflow_api_model = ProcessInstanceService.processor_to_process_instance_api( process_instance_api = ProcessInstanceService.processor_to_process_instance_api(
processor processor
) )
process_instance_data = processor.get_data()
process_instance_metadata = ProcessInstanceApiSchema().dump(process_instance_api)
process_instance_metadata["data"] = process_instance_data
return Response( return Response(
json.dumps(ProcessInstanceApiSchema().dump(workflow_api_model)), status=201, mimetype="application/json" json.dumps(process_instance_metadata), status=201, mimetype="application/json"
) )

View File

@ -480,7 +480,7 @@ class ProcessInstanceProcessor:
# Assure that we find the end event for this process_instance, and not for any sub-process_instances. # Assure that we find the end event for this process_instance, and not for any sub-process_instances.
if ( if (
isinstance(task.task_spec, EndEvent) isinstance(task.task_spec, EndEvent)
and task.process_instance == self.bpmn_process_instance and task.workflow == self.bpmn_process_instance
): ):
endtasks.append(task) endtasks.append(task)
return endtasks[-1] return endtasks[-1]

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1ny7jp4" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.0.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.17.0">
<bpmn:process id="sample" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_10jwwqy</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_10jwwqy" sourceRef="StartEvent_1" targetRef="Activity_0pxf6g1" />
<bpmn:endEvent id="Event_1qb1u6a">
<bpmn:incoming>Flow_1hd6o66</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_0htxke7" sourceRef="Activity_0pxf6g1" targetRef="Activity_0a21ntf" />
<bpmn:scriptTask id="Activity_0pxf6g1" name="My Script">
<bpmn:incoming>Flow_10jwwqy</bpmn:incoming>
<bpmn:outgoing>Flow_0htxke7</bpmn:outgoing>
<bpmn:script>my_var = "Hello World"
Mike = "Awesome"
person = "Kevin"</bpmn:script>
</bpmn:scriptTask>
<bpmn:sequenceFlow id="Flow_1hd6o66" sourceRef="Activity_0a21ntf" targetRef="Event_1qb1u6a" />
<bpmn:businessRuleTask id="Activity_0a21ntf" name="is wonderful?" camunda:decisionRef="wonderful">
<bpmn:incoming>Flow_0htxke7</bpmn:incoming>
<bpmn:outgoing>Flow_1hd6o66</bpmn:outgoing>
</bpmn:businessRuleTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="sample">
<bpmndi:BPMNEdge id="Flow_1hd6o66_di" bpmnElement="Flow_1hd6o66">
<di:waypoint x="600" y="230" />
<di:waypoint x="656" y="230" />
<di:waypoint x="656" y="110" />
<di:waypoint x="802" y="110" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0htxke7_di" bpmnElement="Flow_0htxke7">
<di:waypoint x="340" y="120" />
<di:waypoint x="420" y="120" />
<di:waypoint x="420" y="230" />
<di:waypoint x="500" y="230" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_10jwwqy_di" bpmnElement="Flow_10jwwqy">
<di:waypoint x="188" y="120" />
<di:waypoint x="240" y="120" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="152" y="102" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1qb1u6a_di" bpmnElement="Event_1qb1u6a">
<dc:Bounds x="802" y="92" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_17ohe7r_di" bpmnElement="Activity_0pxf6g1">
<dc:Bounds x="240" y="80" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_06nka7s_di" bpmnElement="Activity_0a21ntf">
<dc:Bounds x="500" y="190" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="wonderful_process" name="DRD" namespace="http://camunda.org/schema/1.0/dmn" exporter="Camunda Modeler" exporterVersion="5.0.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.0.0">
<decision id="wonderful" name="wonderful">
<decisionTable id="DecisionTable_02m334z">
<input id="Input_1">
<inputExpression id="InputExpression_1" typeRef="string">
<text>person</text>
</inputExpression>
</input>
<output id="Output_1" name="wonderfulness" typeRef="string" />
<rule id="DecisionRule_1hnzjl8">
<inputEntry id="UnaryTests_1pb0ou0">
<text>"Dan"</text>
</inputEntry>
<outputEntry id="LiteralExpression_0rtsxgu">
<text>"pretty wonderful"</text>
</outputEntry>
</rule>
<rule id="DecisionRule_1cc73tk">
<inputEntry id="UnaryTests_1fbj1wn">
<text>"Kevin"</text>
</inputEntry>
<outputEntry id="LiteralExpression_1d9nsnp">
<text>"Very wonderful"</text>
</outputEntry>
</rule>
<rule id="DecisionRule_09y32t9">
<inputEntry id="UnaryTests_05h3qcx">
<text>"Mike"</text>
</inputEntry>
<outputEntry id="LiteralExpression_15b83d9">
<text>"Powerful wonderful"</text>
</outputEntry>
</rule>
</decisionTable>
</decision>
<dmndi:DMNDI>
<dmndi:DMNDiagram>
<dmndi:DMNShape dmnElementRef="wonderful">
<dc:Bounds height="80" width="180" x="160" y="100" />
</dmndi:DMNShape>
</dmndi:DMNDiagram>
</dmndi:DMNDI>
</definitions>

View File

@ -132,6 +132,22 @@ def test_get_process_model_when_not_found(app, client: FlaskClient, with_bpmn_fi
assert response.json["code"] == "process_mode_cannot_be_found" assert response.json["code"] == "process_mode_cannot_be_found"
def test_process_instance_create(app, client: FlaskClient, with_bpmn_file_cleanup):
user = find_or_create_user()
test_process_group_id = "runs_without_input"
process_model_dir_name = "sample"
load_test_spec(app, process_model_dir_name, process_group_id=test_process_group_id)
response = client.post(
f"/v1.0/process-models/{process_model_dir_name}", headers=logged_in_headers(user)
)
assert response.status_code == 201
assert response.json["status"] == "complete"
assert response.json["process_model_identifier"] == "sample"
assert response.json["data"]["current_user"]["username"] == "test_user1"
assert response.json["data"]["Mike"] == "Awesome"
assert response.json["data"]["person"] == "Kevin"
def create_process_model(app, client: FlaskClient): def create_process_model(app, client: FlaskClient):
"""Create_process_model.""" """Create_process_model."""
process_model_service = ProcessModelService() process_model_service = ProcessModelService()