Merge branch 'update-workflow-json' of https://github.com/sartography/spiff-arena into update-workflow-json

# Conflicts:
#	spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_service.py
This commit is contained in:
mike cullerton 2022-11-18 15:41:37 -05:00
commit 6cdd630605
4 changed files with 23 additions and 21 deletions

View File

@ -1,6 +1,5 @@
"""APIs for dealing with process groups, process models, and process instances.""" """APIs for dealing with process groups, process models, and process instances."""
import json import json
import os
import random import random
import string import string
import uuid import uuid
@ -253,11 +252,11 @@ def process_model_create(
status_code=400, status_code=400,
) )
unmodified_process_group_id = un_modify_modified_process_model_id(modified_process_group_id) unmodified_process_group_id = un_modify_modified_process_model_id(
process_model_service = ProcessModelService() modified_process_group_id
process_group = process_model_service.get_process_group(
unmodified_process_group_id
) )
process_model_service = ProcessModelService()
process_group = process_model_service.get_process_group(unmodified_process_group_id)
if process_group is None: if process_group is None:
raise ApiError( raise ApiError(
error_code="process_model_could_not_be_created", error_code="process_model_could_not_be_created",

View File

@ -50,6 +50,7 @@ class ProcessModelService(FileSystemService):
@staticmethod @staticmethod
def write_json_file(file_path: str, json_data: dict, indent: int = 4, sort_keys: bool = True) -> None: def write_json_file(file_path: str, json_data: dict, indent: int = 4, sort_keys: bool = True) -> None:
"""Write json file."""
with open(file_path, "w") as h_open: with open(file_path, "w") as h_open:
json.dump(json_data, h_open, indent=indent, sort_keys=sort_keys) 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: def save_process_model(self, process_model: ProcessModelInfo) -> None:
"""Save_process_model.""" """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) 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 process_model_id = process_model.id
# we don't save id in the json file # we don't save id in the json file
# this allows us to move models around on the filesystem # this allows us to move models around on the filesystem
# the id is determined by its location 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) json_data = self.PROCESS_MODEL_SCHEMA.dump(process_model)
self.write_json_file(json_path, json_data) self.write_json_file(json_path, json_data)
process_model.id = process_model_id process_model.id = process_model_id
@ -184,9 +189,7 @@ class ProcessModelService(FileSystemService):
"""Look for a given process_group, and return it.""" """Look for a given process_group, and return it."""
if os.path.exists(FileSystemService.root_path()): if os.path.exists(FileSystemService.root_path()):
process_group_path = os.path.abspath( process_group_path = os.path.abspath(
os.path.join( os.path.join(FileSystemService.root_path(), process_group_id)
FileSystemService.root_path(), process_group_id
)
) )
if self.is_group(process_group_path): if self.is_group(process_group_path):
return self.__scan_process_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 serialized_process_group = process_group.serialized
# we don't store `id` in the json files # we don't store `id` in the json files
# this allows us to move groups around on the filesystem # 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) self.write_json_file(json_path, serialized_process_group)
return process_group return process_group
@ -296,7 +299,7 @@ class ProcessModelService(FileSystemService):
data = json.load(cat_json) data = json.load(cat_json)
# we don't store `id` in the json files, so we add it back in here # 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()) relative_path = os.path.relpath(dir_path, FileSystemService.root_path())
data['id'] = relative_path data["id"] = relative_path
process_group = ProcessGroup(**data) process_group = ProcessGroup(**data)
if process_group is None: if process_group is None:
raise ApiError( raise ApiError(
@ -353,7 +356,7 @@ class ProcessModelService(FileSystemService):
data.pop("process_group_id") data.pop("process_group_id")
# we don't save `id` in the json file, so we add it back in here. # 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()) relative_path = os.path.relpath(path, FileSystemService.root_path())
data['id'] = relative_path data["id"] = relative_path
process_model_info = ProcessModelInfo(**data) process_model_info = ProcessModelInfo(**data)
if process_model_info is None: if process_model_info is None:
raise ApiError( raise ApiError(
@ -374,7 +377,9 @@ class ProcessModelService(FileSystemService):
display_order=0, display_order=0,
is_review=False, 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 # we don't store `id` in the json files, so we add it in here
process_model_info.id = name process_model_info.id = name
if process_group: if process_group:

View File

@ -32,7 +32,9 @@ class TestProcessModelService(BaseTest):
primary_process_id = process_model.primary_process_id primary_process_id = process_model.primary_process_id
assert primary_process_id == "Process_HelloWorld" 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.display_name == "new_name"
assert process_model.primary_process_id == primary_process_id assert process_model.primary_process_id == primary_process_id

View File

@ -837,11 +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 a file name is not given then this is a new model and the ReactDiagramEditor component will handle it
if ( if ((bpmnXmlForDiagramRendering || !params.file_name) && processModel) {
(bpmnXmlForDiagramRendering || !params.file_name) &&
processModel &&
processes.length > 0
) {
const processModelFileName = processModelFile ? processModelFile.name : ''; const processModelFileName = processModelFile ? processModelFile.name : '';
return ( return (
<> <>