Rename CAT_JSON_FILE, WF_JSON_FILE, add_spec, update_spec

This commit is contained in:
mike cullerton 2022-11-17 12:08:42 -05:00
parent 89233fda59
commit f88f576dcb
8 changed files with 19 additions and 19 deletions

View File

@ -15,7 +15,7 @@ def main() -> None:
"process_group_id": "", "process_group_id": "",
"id": f"{group.id}/{process_model.id}", "id": f"{group.id}/{process_model.id}",
} }
ProcessModelService().update_spec(process_model, update_items) ProcessModelService().update_process_model(process_model, update_items)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -270,7 +270,7 @@ def process_model_create(
status_code=400, status_code=400,
) )
process_model_service.add_spec(process_model_info) process_model_service.add_process_model(process_model_info)
return Response( return Response(
json.dumps(ProcessModelInfoSchema().dump(process_model_info)), json.dumps(ProcessModelInfoSchema().dump(process_model_info)),
status=201, status=201,
@ -307,7 +307,7 @@ def process_model_update(
# process_model_identifier = f"{process_group_id}/{process_model_id}" # process_model_identifier = f"{process_group_id}/{process_model_id}"
process_model = get_process_model(process_model_identifier) process_model = get_process_model(process_model_identifier)
ProcessModelService().update_spec(process_model, body_filtered) ProcessModelService().update_process_model(process_model, body_filtered)
return ProcessModelInfoSchema().dump(process_model) return ProcessModelInfoSchema().dump(process_model)

View File

@ -20,8 +20,8 @@ class FileSystemService:
""" Simple Service meant for extension that provides some useful """ Simple Service meant for extension that provides some useful
methods for dealing with the File system. methods for dealing with the File system.
""" """
CAT_JSON_FILE = "process_group.json" PROCESS_GROUP_JSON_FILE = "process_group.json"
WF_JSON_FILE = "workflow.json" PROCESS_MODEL_JSON_FILE = "workflow.json"
@staticmethod @staticmethod
def root_path() -> str: def root_path() -> str:
@ -135,7 +135,7 @@ class FileSystemService:
if item.is_file(): if item.is_file():
if item.name.startswith("."): if item.name.startswith("."):
continue # Ignore hidden files continue # Ignore hidden files
if item.name == FileSystemService.WF_JSON_FILE: if item.name == FileSystemService.PROCESS_MODEL_JSON_FILE:
continue # Ignore the json files. continue # Ignore the json files.
if file_name is not None and item.name != file_name: if file_name is not None and item.name != file_name:
continue continue

View File

@ -36,14 +36,14 @@ class ProcessModelService(FileSystemService):
def is_group(self, path: str) -> bool: def is_group(self, path: str) -> bool:
"""Is_group.""" """Is_group."""
group_json_path = os.path.join(path, self.CAT_JSON_FILE) group_json_path = os.path.join(path, self.PROCESS_GROUP_JSON_FILE)
if os.path.exists(group_json_path): if os.path.exists(group_json_path):
return True return True
return False return False
def is_model(self, path: str) -> bool: def is_model(self, path: str) -> bool:
"""Is_model.""" """Is_model."""
model_json_path = os.path.join(path, self.WF_JSON_FILE) model_json_path = os.path.join(path, self.PROCESS_MODEL_JSON_FILE)
if os.path.exists(model_json_path): if os.path.exists(model_json_path):
return True return True
return False return False
@ -59,13 +59,13 @@ class ProcessModelService(FileSystemService):
end = start + per_page end = start + per_page
return items[start:end] return items[start:end]
def add_spec(self, process_model: ProcessModelInfo) -> None: def add_process_model(self, process_model: ProcessModelInfo) -> None:
"""Add_spec.""" """Add_spec."""
display_order = self.next_display_order(process_model) display_order = self.next_display_order(process_model)
process_model.display_order = display_order process_model.display_order = display_order
self.save_process_model(process_model) self.save_process_model(process_model)
def update_spec( def update_process_model(
self, process_model: ProcessModelInfo, attributes_to_update: dict self, process_model: ProcessModelInfo, attributes_to_update: dict
) -> None: ) -> None:
"""Update_spec.""" """Update_spec."""
@ -78,7 +78,7 @@ class ProcessModelService(FileSystemService):
"""Save_process_model.""" """Save_process_model."""
spec_path = os.path.join(FileSystemService.root_path(), process_model.id) spec_path = os.path.join(FileSystemService.root_path(), process_model.id)
os.makedirs(spec_path, exist_ok=True) os.makedirs(spec_path, exist_ok=True)
json_path = os.path.join(spec_path, self.WF_JSON_FILE) json_path = os.path.join(spec_path, self.PROCESS_MODEL_JSON_FILE)
with open(json_path, "w") as wf_json: with open(json_path, "w") as wf_json:
json.dump( json.dump(
self.WF_SCHEMA.dump(process_model), wf_json, indent=4, sort_keys=True self.WF_SCHEMA.dump(process_model), wf_json, indent=4, sort_keys=True
@ -205,7 +205,7 @@ class ProcessModelService(FileSystemService):
"""Update_process_group.""" """Update_process_group."""
cat_path = self.process_group_path(process_group.id) cat_path = self.process_group_path(process_group.id)
os.makedirs(cat_path, exist_ok=True) os.makedirs(cat_path, exist_ok=True)
json_path = os.path.join(cat_path, self.CAT_JSON_FILE) json_path = os.path.join(cat_path, self.PROCESS_GROUP_JSON_FILE)
with open(json_path, "w") as cat_json: with open(json_path, "w") as cat_json:
json.dump( json.dump(
process_group.serialized, process_group.serialized,
@ -279,7 +279,7 @@ class ProcessModelService(FileSystemService):
def __scan_process_group(self, dir_path: str) -> ProcessGroup: def __scan_process_group(self, dir_path: str) -> ProcessGroup:
"""Reads the process_group.json file, and any nested directories.""" """Reads the process_group.json file, and any nested directories."""
cat_path = os.path.join(dir_path, self.CAT_JSON_FILE) cat_path = os.path.join(dir_path, self.PROCESS_GROUP_JSON_FILE)
if os.path.exists(cat_path): if os.path.exists(cat_path):
with open(cat_path) as cat_json: with open(cat_path) as cat_json:
data = json.load(cat_json) data = json.load(cat_json)
@ -329,7 +329,7 @@ class ProcessModelService(FileSystemService):
process_group: Optional[ProcessGroup] = None, process_group: Optional[ProcessGroup] = None,
) -> ProcessModelInfo: ) -> ProcessModelInfo:
"""__scan_spec.""" """__scan_spec."""
spec_path = os.path.join(path, self.WF_JSON_FILE) spec_path = os.path.join(path, self.PROCESS_MODEL_JSON_FILE)
if os.path.exists(spec_path): if os.path.exists(spec_path):
with open(spec_path) as wf_json: with open(spec_path) as wf_json:

View File

@ -171,7 +171,7 @@ class SpecFileService(FileSystemService):
ref.is_primary = True ref.is_primary = True
if ref.is_primary: if ref.is_primary:
ProcessModelService().update_spec( ProcessModelService().update_process_model(
process_model_info, process_model_info,
{ {
"primary_process_id": ref.identifier, "primary_process_id": ref.identifier,

View File

@ -39,7 +39,7 @@ class ExampleDataLoader:
is_review=False, is_review=False,
) )
workflow_spec_service = ProcessModelService() workflow_spec_service = ProcessModelService()
workflow_spec_service.add_spec(spec) workflow_spec_service.add_process_model(spec)
bpmn_file_name_with_extension = bpmn_file_name bpmn_file_name_with_extension = bpmn_file_name
if not bpmn_file_name_with_extension: if not bpmn_file_name_with_extension:

View File

@ -1830,7 +1830,7 @@ class TestProcessApi(BaseTest):
process_model = ProcessModelService().get_process_model( process_model = ProcessModelService().get_process_model(
process_model_identifier process_model_identifier
) )
ProcessModelService().update_spec( ProcessModelService().update_process_model(
process_model, process_model,
{"fault_or_suspend_on_exception": NotificationType.suspend.value}, {"fault_or_suspend_on_exception": NotificationType.suspend.value},
) )
@ -1885,7 +1885,7 @@ class TestProcessApi(BaseTest):
process_model = ProcessModelService().get_process_model( process_model = ProcessModelService().get_process_model(
process_model_identifier process_model_identifier
) )
ProcessModelService().update_spec( ProcessModelService().update_process_model(
process_model, process_model,
{"exception_notification_addresses": ["with_super_admin_user@example.com"]}, {"exception_notification_addresses": ["with_super_admin_user@example.com"]},
) )

View File

@ -32,7 +32,7 @@ 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_spec(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