updated manual task with subprocess bpmn w/ burnettk

This commit is contained in:
jasquat 2023-03-22 10:45:40 -04:00
parent 26af07befd
commit 61da3d6b6f
5 changed files with 154 additions and 43 deletions

View File

@ -1335,7 +1335,7 @@ class ProcessInstanceProcessor:
and_(
or_(
TaskModel.end_in_seconds > to_task_model.end_in_seconds,
TaskModel.end_in_seconds.is_not(None), # type: ignore
TaskModel.end_in_seconds.is_(None), # type: ignore
),
TaskModel.process_instance_id == process_instance.id,
TaskModel.bpmn_process_id.in_(parent_bpmn_processes_ids), # type: ignore

View File

@ -342,11 +342,11 @@ class TaskService:
python_env_data_hash: Optional[str] = None,
) -> None:
if json_data_hash is None:
TaskService.update_task_data_on_task_model(task_model, {}, "json_data_hash")
cls.update_task_data_on_task_model(task_model, {}, "json_data_hash")
else:
task_model.json_data_hash = json_data_hash
if python_env_data_hash is None:
TaskService.update_task_data_on_task_model(task_model, {}, "python_env_data")
cls.update_task_data_on_task_model(task_model, {}, "python_env_data")
else:
task_model.python_env_data_hash = python_env_data_hash

View File

@ -22,11 +22,10 @@
<bpmn:script>set_in_top_level_script = 1</bpmn:script>
</bpmn:scriptTask>
<bpmn:sequenceFlow id="Flow_1fktmf7" sourceRef="top_level_script" targetRef="manual_task" />
<bpmn:sequenceFlow id="Flow_1i7syph" sourceRef="top_level_subprocess" targetRef="top_level_call_activity" />
<bpmn:sequenceFlow id="Flow_09gjylo" sourceRef="manual_task" targetRef="top_level_subprocess" />
<bpmn:subProcess id="top_level_subprocess">
<bpmn:incoming>Flow_09gjylo</bpmn:incoming>
<bpmn:outgoing>Flow_1i7syph</bpmn:outgoing>
<bpmn:outgoing>Flow_0yxus36</bpmn:outgoing>
<bpmn:startEvent id="Event_0g7txdo">
<bpmn:outgoing>Flow_00k1tii</bpmn:outgoing>
</bpmn:startEvent>
@ -48,7 +47,7 @@ except:
</bpmn:scriptTask>
</bpmn:subProcess>
<bpmn:callActivity id="top_level_call_activity" calledElement="test_process_to_call">
<bpmn:incoming>Flow_1i7syph</bpmn:incoming>
<bpmn:incoming>Flow_0yxus36</bpmn:incoming>
<bpmn:outgoing>Flow_187mcqe</bpmn:outgoing>
</bpmn:callActivity>
<bpmn:exclusiveGateway id="Gateway_0p8naw0" default="Flow_1t9ywmr">
@ -67,6 +66,7 @@ except:
<bpmn:script>set_top_level_process_script_after_gate = 1</bpmn:script>
</bpmn:scriptTask>
<bpmn:sequenceFlow id="Flow_1t9ywmr" sourceRef="Gateway_0p8naw0" targetRef="manual_task" />
<bpmn:sequenceFlow id="Flow_0yxus36" sourceRef="top_level_subprocess" targetRef="top_level_call_activity" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="top_level_process">
@ -102,10 +102,6 @@ except:
<di:waypoint x="370" y="177" />
<di:waypoint x="400" y="177" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1i7syph_di" bpmnElement="Flow_1i7syph">
<di:waypoint x="630" y="177" />
<di:waypoint x="680" y="177" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_09gjylo_di" bpmnElement="Flow_09gjylo">
<di:waypoint x="500" y="177" />
<di:waypoint x="530" y="177" />
@ -128,6 +124,10 @@ except:
<di:waypoint x="450" y="100" />
<di:waypoint x="450" y="137" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0yxus36_di" bpmnElement="Flow_0yxus36">
<di:waypoint x="630" y="177" />
<di:waypoint x="680" y="177" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
<bpmndi:BPMNDiagram id="BPMNDiagram_01cbxj3">

View File

@ -2,70 +2,131 @@
<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" id="Definitions_96f6665" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.0.0-dev">
<bpmn:process id="test_process_to_call" name="Test Process To Call" isExecutable="true">
<bpmn:endEvent id="Event_03zsjvn">
<bpmn:incoming>Flow_095sred</bpmn:incoming>
<bpmn:incoming>Flow_089aeua</bpmn:incoming>
</bpmn:endEvent>
<bpmn:startEvent id="Event_0pp84tn">
<bpmn:outgoing>Flow_1qsx5et</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:subProcess id="test_process_to_call_subprocess">
<bpmn:incoming>Flow_1qsx5et</bpmn:incoming>
<bpmn:outgoing>Flow_095sred</bpmn:outgoing>
<bpmn:outgoing>Flow_0zedtvv</bpmn:outgoing>
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_12zb3j0</bpmn:outgoing>
<bpmn:outgoing>Flow_0bkk554</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:scriptTask id="test_process_to_call_subprocess_script" name="Test Process To Call Subprocess Script">
<bpmn:incoming>Flow_12zb3j0</bpmn:incoming>
<bpmn:outgoing>Flow_0iu4d71</bpmn:outgoing>
<bpmn:script>set_in_test_process_to_call_script = 1</bpmn:script>
<bpmn:incoming>Flow_1cnuh2a</bpmn:incoming>
<bpmn:outgoing>Flow_17hgw9g</bpmn:outgoing>
<bpmn:script>set_in_test_process_to_call_subprocess_script = 1</bpmn:script>
</bpmn:scriptTask>
<bpmn:endEvent id="Event_1nn875f">
<bpmn:incoming>Flow_0iu4d71</bpmn:incoming>
<bpmn:incoming>Flow_17hgw9g</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_12zb3j0" sourceRef="StartEvent_1" targetRef="test_process_to_call_subprocess_script" />
<bpmn:sequenceFlow id="Flow_0iu4d71" sourceRef="test_process_to_call_subprocess_script" targetRef="Event_1nn875f" />
<bpmn:sequenceFlow id="Flow_17hgw9g" sourceRef="test_process_to_call_subprocess_script" targetRef="Event_1nn875f" />
<bpmn:sequenceFlow id="Flow_0bkk554" sourceRef="StartEvent_1" targetRef="test_process_to_call_subprocess_subprocess" />
<bpmn:sequenceFlow id="Flow_1cnuh2a" sourceRef="test_process_to_call_subprocess_subprocess" targetRef="test_process_to_call_subprocess_script" />
<bpmn:subProcess id="test_process_to_call_subprocess_subprocess">
<bpmn:incoming>Flow_0bkk554</bpmn:incoming>
<bpmn:outgoing>Flow_1cnuh2a</bpmn:outgoing>
<bpmn:startEvent id="Event_17bk1sd">
<bpmn:outgoing>Flow_1nri60d</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_1nri60d" sourceRef="Event_17bk1sd" targetRef="test_process_to_call_subprocess_subprocess_script" />
<bpmn:endEvent id="Event_1sec2vg">
<bpmn:incoming>Flow_1bfzrzu</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_1bfzrzu" sourceRef="test_process_to_call_subprocess_subprocess_script" targetRef="Event_1sec2vg" />
<bpmn:scriptTask id="test_process_to_call_subprocess_subprocess_script" name="Test Process To Call Subprocess Subprocess Script">
<bpmn:incoming>Flow_1nri60d</bpmn:incoming>
<bpmn:outgoing>Flow_1bfzrzu</bpmn:outgoing>
<bpmn:script>set_in_test_process_to_call_subprocess_subprocess_script = 1</bpmn:script>
</bpmn:scriptTask>
</bpmn:subProcess>
</bpmn:subProcess>
<bpmn:sequenceFlow id="Flow_1qsx5et" sourceRef="Event_0pp84tn" targetRef="test_process_to_call_subprocess" />
<bpmn:sequenceFlow id="Flow_095sred" sourceRef="test_process_to_call_subprocess" targetRef="Event_03zsjvn" />
<bpmn:sequenceFlow id="Flow_0zedtvv" sourceRef="test_process_to_call_subprocess" targetRef="test_process_to_call_script" />
<bpmn:sequenceFlow id="Flow_089aeua" sourceRef="test_process_to_call_script" targetRef="Event_03zsjvn" />
<bpmn:scriptTask id="test_process_to_call_script" name="Test Process To Call Script">
<bpmn:incoming>Flow_0zedtvv</bpmn:incoming>
<bpmn:outgoing>Flow_089aeua</bpmn:outgoing>
<bpmn:script>set_in_test_process_to_call_script = 1</bpmn:script>
</bpmn:scriptTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="test_process_to_call">
<bpmndi:BPMNShape id="Event_03zsjvn_di" bpmnElement="Event_03zsjvn">
<dc:Bounds x="612" y="132" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0pp84tn_di" bpmnElement="Event_0pp84tn">
<dc:Bounds x="162.33333333333334" y="132" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_03zsjvn_di" bpmnElement="Event_03zsjvn">
<dc:Bounds x="432" y="132" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_14ywg4w_di" bpmnElement="test_process_to_call_subprocess" isExpanded="false">
<dc:Bounds x="270" y="110" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_17algy3_di" bpmnElement="test_process_to_call_script">
<dc:Bounds x="450" y="110" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1qsx5et_di" bpmnElement="Flow_1qsx5et">
<di:waypoint x="198" y="150" />
<di:waypoint x="270" y="150" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_095sred_di" bpmnElement="Flow_095sred">
<bpmndi:BPMNEdge id="Flow_0zedtvv_di" bpmnElement="Flow_0zedtvv">
<di:waypoint x="370" y="150" />
<di:waypoint x="432" y="150" />
<di:waypoint x="450" y="150" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_089aeua_di" bpmnElement="Flow_089aeua">
<di:waypoint x="550" y="150" />
<di:waypoint x="612" y="150" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
<bpmndi:BPMNDiagram id="BPMNDiagram_1ikntvh">
<bpmndi:BPMNPlane id="BPMNPlane_18euprj" bpmnElement="test_process_to_call_subprocess">
<bpmndi:BPMNShape id="Activity_059upl6_di" bpmnElement="test_process_to_call_subprocess_script">
<dc:Bounds x="238" y="160" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1nn875f_di" bpmnElement="Event_1nn875f">
<dc:Bounds x="360" y="182" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="180" y="182" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_12zb3j0_di" bpmnElement="Flow_12zb3j0">
<di:waypoint x="216" y="200" />
<di:waypoint x="238" y="200" />
<bpmndi:BPMNShape id="Activity_059upl6_di" bpmnElement="test_process_to_call_subprocess_script">
<dc:Bounds x="420" y="160" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1nn875f_di" bpmnElement="Event_1nn875f">
<dc:Bounds x="562" y="182" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0hixo7p_di" bpmnElement="test_process_to_call_subprocess_subprocess">
<dc:Bounds x="270" y="160" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_17hgw9g_di" bpmnElement="Flow_17hgw9g">
<di:waypoint x="520" y="200" />
<di:waypoint x="562" y="200" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0iu4d71_di" bpmnElement="Flow_0iu4d71">
<di:waypoint x="338" y="200" />
<di:waypoint x="360" y="200" />
<bpmndi:BPMNEdge id="Flow_0bkk554_di" bpmnElement="Flow_0bkk554">
<di:waypoint x="216" y="200" />
<di:waypoint x="270" y="200" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1cnuh2a_di" bpmnElement="Flow_1cnuh2a">
<di:waypoint x="370" y="200" />
<di:waypoint x="420" y="200" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
<bpmndi:BPMNDiagram id="BPMNDiagram_0x7adrd">
<bpmndi:BPMNPlane id="BPMNPlane_17ay7ws" bpmnElement="test_process_to_call_subprocess_subprocess">
<bpmndi:BPMNShape id="Event_17bk1sd_di" bpmnElement="Event_17bk1sd">
<dc:Bounds x="262" y="172" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1sec2vg_di" bpmnElement="Event_1sec2vg">
<dc:Bounds x="502" y="172" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1kjd6i3_di" bpmnElement="test_process_to_call_subprocess_subprocess_script">
<dc:Bounds x="350" y="150" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_1nri60d_di" bpmnElement="Flow_1nri60d">
<di:waypoint x="298" y="190" />
<di:waypoint x="350" y="190" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1bfzrzu_di" bpmnElement="Flow_1bfzrzu">
<di:waypoint x="450" y="190" />
<di:waypoint x="502" y="190" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>

View File

@ -256,6 +256,54 @@ class TestProcessInstanceProcessor(BaseTest):
assert spiff_task is not None
assert spiff_task.state == TaskState.COMPLETED
def test_properly_resets_process_to_given_task(
self,
app: Flask,
client: FlaskClient,
with_db_and_bpmn_file_cleanup: None,
with_super_admin_user: UserModel,
) -> None:
self.create_process_group(client, with_super_admin_user, "test_group", "test_group")
initiator_user = self.find_or_create_user("initiator_user")
finance_user_three = self.find_or_create_user("testuser3")
assert initiator_user.principal is not None
assert finance_user_three.principal is not None
AuthorizationService.import_permissions_from_yaml_file()
finance_group = GroupModel.query.filter_by(identifier="Finance Team").first()
assert finance_group is not None
process_model = load_test_spec(
process_model_id="test_group/manual_task_with_subprocesses",
process_model_source_directory="manual_task_with_subprocesses",
)
process_instance = self.create_process_instance_from_process_model(
process_model=process_model, user=initiator_user
)
processor = ProcessInstanceProcessor(process_instance)
processor.do_engine_steps(save=True)
assert len(process_instance.active_human_tasks) == 1
initial_human_task_id = process_instance.active_human_tasks[0].id
# save again to ensure we go attempt to process the human tasks again
processor.save()
assert len(process_instance.active_human_tasks) == 1
assert initial_human_task_id == process_instance.active_human_tasks[0].id
processor = ProcessInstanceProcessor(process_instance)
human_task_one = process_instance.active_human_tasks[0]
spiff_manual_task = processor.__class__.get_task_by_bpmn_identifier(
human_task_one.task_name, processor.bpmn_process_instance
)
ProcessInstanceService.complete_form_task(processor, spiff_manual_task, {}, initiator_user, human_task_one)
# process_instance = ProcessInstanceModel.query.filter_by(id=process_instance.id).first()
# processor = ProcessInstanceProcessor(process_instance)
# human_task_one = process_instance.active_human_tasks[0]
# spiff_manual_task = processor.bpmn_process_instance.get_task(UUID(human_task_one.task_id))
# ProcessInstanceService.complete_form_task(processor, spiff_manual_task, {}, initiator_user, human_task_one)
def test_properly_saves_tasks_when_running(
self,
app: Flask,
@ -263,7 +311,6 @@ class TestProcessInstanceProcessor(BaseTest):
with_db_and_bpmn_file_cleanup: None,
with_super_admin_user: UserModel,
) -> None:
"""Test_does_not_recreate_human_tasks_on_multiple_saves."""
self.create_process_group(client, with_super_admin_user, "test_group", "test_group")
initiator_user = self.find_or_create_user("initiator_user")
finance_user_three = self.find_or_create_user("testuser3")
@ -317,7 +364,7 @@ class TestProcessInstanceProcessor(BaseTest):
}
third_data_set = {
**second_data_set,
**{"set_in_test_process_to_call_script": 1},
**{"set_in_test_process_to_call_script": 1, "set_in_test_process_to_call_subprocess_subprocess_script": 1, "set_in_test_process_to_call_subprocess_script": 1},
}
fourth_data_set = {**third_data_set, **{"a": 1, "we_move_on": True}}
fifth_data_set = {**fourth_data_set, **{"validate_only": False, "set_top_level_process_script_after_gate": 1}}
@ -338,10 +385,13 @@ class TestProcessInstanceProcessor(BaseTest):
# TODO: also check task data here from the spiff_task directly to ensure we hydrated spiff correctly
def assert_spiff_task_is_in_process(spiff_task_identifier: str, bpmn_process_identifier: str) -> None:
if spiff_task.task_spec.name == spiff_task_identifier:
base_failure_message = f"Failed on {bpmn_process_identifier} - {spiff_task_identifier}."
expected_python_env_data = expected_task_data[spiff_task.task_spec.name]
expected_task_data_key = spiff_task.task_spec.name
if spiff_task.task_spec.name in spiff_tasks_checked_once:
expected_python_env_data = expected_task_data[f"{spiff_task.task_spec.name}_second"]
expected_task_data_key = f"{spiff_task.task_spec.name}_second"
expected_python_env_data = expected_task_data[expected_task_data_key]
base_failure_message = f"Failed on {bpmn_process_identifier} - {spiff_task_identifier} - task data key {expected_task_data_key}."
task_model = TaskModel.query.filter_by(guid=str(spiff_task.id)).first()
assert task_model.start_in_seconds is not None
@ -354,7 +404,7 @@ class TestProcessInstanceProcessor(BaseTest):
assert task_definition.bpmn_process_definition.bpmn_identifier == bpmn_process_identifier
message = (
f"{base_failure_message} Expected: {expected_python_env_data}. Received: {task_model.json_data()}"
f"{base_failure_message} Expected: {sorted(expected_python_env_data)}. Received: {sorted(task_model.json_data())}"
)
# TODO: if we split out env data again we will need to use it here instead of json_data
# assert task_model.python_env_data() == expected_python_env_data, message