From 72922dfe2a10b59b34996f8bccd952efeadfb254 Mon Sep 17 00:00:00 2001 From: jasquat Date: Fri, 18 Nov 2022 15:01:41 -0500 Subject: [PATCH 1/2] load diagram page even if processes are not set w/ burnettk cullerton --- spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx b/spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx index af691153..537406ee 100644 --- a/spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx +++ b/spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx @@ -838,9 +838,7 @@ export default function ProcessModelEditDiagram() { // if a file name is not given then this is a new model and the ReactDiagramEditor component will handle it if ( - (bpmnXmlForDiagramRendering || !params.file_name) && - processModel && - processes.length > 0 + (bpmnXmlForDiagramRendering || !params.file_name) && processModel ) { const processModelFileName = processModelFile ? processModelFile.name : ''; return ( From 3640657c7162f0ec32eb407784e356cc6ca83854 Mon Sep 17 00:00:00 2001 From: jasquat Date: Fri, 18 Nov 2022 15:06:02 -0500 Subject: [PATCH 2/2] ran some pyl w/ burnettk cullerton --- .../routes/process_api_blueprint.py | 9 +++---- .../services/process_model_service.py | 27 +++++++++++-------- .../unit/test_process_model_service.py | 4 ++- .../src/routes/ProcessModelEditDiagram.tsx | 4 +-- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py index 0e1d26ea..6918ad35 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -1,6 +1,5 @@ """APIs for dealing with process groups, process models, and process instances.""" import json -import os import random import string import uuid @@ -253,11 +252,11 @@ def process_model_create( status_code=400, ) - unmodified_process_group_id = un_modify_modified_process_model_id(modified_process_group_id) - process_model_service = ProcessModelService() - process_group = process_model_service.get_process_group( - unmodified_process_group_id + unmodified_process_group_id = un_modify_modified_process_model_id( + modified_process_group_id ) + process_model_service = ProcessModelService() + process_group = process_model_service.get_process_group(unmodified_process_group_id) if process_group is None: raise ApiError( error_code="process_model_could_not_be_created", diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_service.py index ccdf56b1..7f37c7cf 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_service.py @@ -49,7 +49,8 @@ class ProcessModelService(FileSystemService): return False @staticmethod - def write_json_file(file_path, json_data, indent=4, sort_keys=True): + def write_json_file(file_path: str, json_data: dict, indent: int = 4, sort_keys: bool = True): + """Write json file.""" with open(file_path, "w") as h_open: json.dump(json_data, h_open, indent=indent, sort_keys=sort_keys) @@ -81,14 +82,18 @@ class ProcessModelService(FileSystemService): def save_process_model(self, process_model: ProcessModelInfo) -> None: """Save_process_model.""" - process_model_path = os.path.abspath(os.path.join(FileSystemService.root_path(), process_model.id)) + process_model_path = os.path.abspath( + os.path.join(FileSystemService.root_path(), process_model.id) + ) os.makedirs(process_model_path, exist_ok=True) - json_path = os.path.abspath(os.path.join(process_model_path, self.PROCESS_MODEL_JSON_FILE)) + json_path = os.path.abspath( + os.path.join(process_model_path, self.PROCESS_MODEL_JSON_FILE) + ) process_model_id = process_model.id # we don't save id in the json file # this allows us to move models around on the filesystem # the id is determined by its location on the filesystem - delattr(process_model, 'id') + delattr(process_model, "id") json_data = self.PROCESS_MODEL_SCHEMA.dump(process_model) self.write_json_file(json_path, json_data) process_model.id = process_model_id @@ -184,9 +189,7 @@ class ProcessModelService(FileSystemService): """Look for a given process_group, and return it.""" if os.path.exists(FileSystemService.root_path()): process_group_path = os.path.abspath( - os.path.join( - FileSystemService.root_path(), process_group_id - ) + os.path.join(FileSystemService.root_path(), process_group_id) ) if self.is_group(process_group_path): return self.__scan_process_group(process_group_path) @@ -222,7 +225,7 @@ class ProcessModelService(FileSystemService): serialized_process_group = process_group.serialized # we don't store `id` in the json files # this allows us to move groups around on the filesystem - del serialized_process_group['id'] + del serialized_process_group["id"] self.write_json_file(json_path, serialized_process_group) return process_group @@ -296,7 +299,7 @@ class ProcessModelService(FileSystemService): data = json.load(cat_json) # we don't store `id` in the json files, so we add it back in here relative_path = os.path.relpath(dir_path, FileSystemService.root_path()) - data['id'] = relative_path + data["id"] = relative_path process_group = ProcessGroup(**data) if process_group is None: raise ApiError( @@ -352,7 +355,7 @@ class ProcessModelService(FileSystemService): data.pop("process_group_id") # we don't save `id` in the json file, so we add it back in here. relative_path = os.path.relpath(path, FileSystemService.root_path()) - data['id'] = relative_path + data["id"] = relative_path process_model_info = ProcessModelInfo(**data) if process_model_info is None: raise ApiError( @@ -372,7 +375,9 @@ class ProcessModelService(FileSystemService): display_order=0, is_review=False, ) - self.write_json_file(json_file_path, self.PROCESS_MODEL_SCHEMA.dump(process_model_info)) + self.write_json_file( + json_file_path, self.PROCESS_MODEL_SCHEMA.dump(process_model_info) + ) # we don't store `id` in the json files, so we add it in here process_model_info.id = name if process_group: diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_model_service.py b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_model_service.py index 42733775..7127eb41 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_model_service.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_model_service.py @@ -32,7 +32,9 @@ class TestProcessModelService(BaseTest): primary_process_id = process_model.primary_process_id assert primary_process_id == "Process_HelloWorld" - ProcessModelService().update_process_model(process_model, {"display_name": "new_name"}) + ProcessModelService().update_process_model( + process_model, {"display_name": "new_name"} + ) assert process_model.display_name == "new_name" assert process_model.primary_process_id == primary_process_id diff --git a/spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx b/spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx index 537406ee..1a954cf2 100644 --- a/spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx +++ b/spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx @@ -837,9 +837,7 @@ export default function ProcessModelEditDiagram() { }; // if a file name is not given then this is a new model and the ReactDiagramEditor component will handle it - if ( - (bpmnXmlForDiagramRendering || !params.file_name) && processModel - ) { + if ((bpmnXmlForDiagramRendering || !params.file_name) && processModel) { const processModelFileName = processModelFile ? processModelFile.name : ''; return ( <>