From 91d33305defdad059a39e25da60b5bb6a5866fd8 Mon Sep 17 00:00:00 2001 From: jasquat Date: Fri, 8 Dec 2023 16:23:08 -0500 Subject: [PATCH] added bpmn template file that will get added when a new process model is created with the api w/ burnettk --- .../routes/process_models_controller.py | 7 +++ .../services/spec_file_service.py | 7 ++- .../templates/bpmn_for_new_process_model.bpmn | 51 +++++++++++++++++++ .../integration/test_process_api.py | 4 +- 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 spiffworkflow-backend/src/spiffworkflow_backend/templates/bpmn_for_new_process_model.bpmn diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_models_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_models_controller.py index cef714c9..af96aaac 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_models_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_models_controller.py @@ -77,6 +77,13 @@ def process_model_create( ) ProcessModelService.add_process_model(process_model_info) + template_file = os.path.join(current_app.root_path, "templates", "bpmn_for_new_process_model.bpmn") + contents = "" + with open(template_file) as f: + contents = f.read() + process_model_id_for_bpmn_file = process_model_info.id.split("/")[-1] + SpecFileService.update_file(process_model_info, f"{process_model_id_for_bpmn_file}.bpmn", contents.encode()) + _commit_and_push_to_git(f"User: {g.user.username} created process model {process_model_info.id}") return Response( json.dumps(ProcessModelInfoSchema().dump(process_model_info)), diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py index 48778e32..476cb86d 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py @@ -1,6 +1,9 @@ +from __future__ import annotations + import os import shutil from datetime import datetime +from typing import TYPE_CHECKING from lxml import etree # type: ignore from SpiffWorkflow.bpmn.parser.BpmnParser import BpmnValidator # type: ignore @@ -12,7 +15,6 @@ from spiffworkflow_backend.models.file import File from spiffworkflow_backend.models.file import FileType from spiffworkflow_backend.models.file import Reference from spiffworkflow_backend.models.message_triggerable_process_model import MessageTriggerableProcessModel -from spiffworkflow_backend.models.process_model import ProcessModelInfo from spiffworkflow_backend.models.reference_cache import ReferenceCacheModel from spiffworkflow_backend.models.user import UserModel from spiffworkflow_backend.services.custom_parser import MyCustomParser @@ -20,6 +22,9 @@ from spiffworkflow_backend.services.file_system_service import FileSystemService from spiffworkflow_backend.services.process_caller_service import ProcessCallerService from spiffworkflow_backend.services.process_model_service import ProcessModelService +if TYPE_CHECKING: + from spiffworkflow_backend.models.process_model import ProcessModelInfo + class ProcessModelFileInvalidError(Exception): pass diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/templates/bpmn_for_new_process_model.bpmn b/spiffworkflow-backend/src/spiffworkflow_backend/templates/bpmn_for_new_process_model.bpmn new file mode 100644 index 00000000..7e191796 --- /dev/null +++ b/spiffworkflow-backend/src/spiffworkflow_backend/templates/bpmn_for_new_process_model.bpmn @@ -0,0 +1,51 @@ + + + + + Flow_17db3yp + + + + + The process instance completed successfully. + + Flow_12pkbxb + + + + + This is an example **Manual Task**. A **Manual Task** is designed to allow someone to complete a task outside of the system and then report back that it is complete. You can click the *Continue* button to proceed. When you are done running this process, you can edit the **Process Model** to include a: + + * **Script Task** - write a short snippet of python code to update some data + * **User Task** - generate a form that collects information from a user + * **Service Task** - communicate with an external API to fetch or update some data. + +You can also change the text you are reading here by updating the *Instructions* on this example manual task. + + Flow_17db3yp + Flow_12pkbxb + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py index 8e31218b..674e7b7c 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py @@ -390,8 +390,8 @@ class TestProcessApi(BaseTest): process_model = ProcessModelService.get_process_model(process_model_identifier) assert process_model.id == process_model_identifier assert process_model.display_name == "Cooooookies" - assert process_model.primary_file_name is None - assert process_model.primary_process_id is None + assert process_model.primary_file_name is not None + assert process_model.primary_process_id is not None process_model.display_name = "Updated Display Name" process_model.primary_file_name = "superduper.bpmn"