Rename CAT_JSON_FILE, WF_JSON_FILE, add_spec, update_spec
This commit is contained in:
parent
89233fda59
commit
f88f576dcb
|
@ -15,7 +15,7 @@ def main() -> None:
|
|||
"process_group_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__":
|
||||
|
|
|
@ -270,7 +270,7 @@ def process_model_create(
|
|||
status_code=400,
|
||||
)
|
||||
|
||||
process_model_service.add_spec(process_model_info)
|
||||
process_model_service.add_process_model(process_model_info)
|
||||
return Response(
|
||||
json.dumps(ProcessModelInfoSchema().dump(process_model_info)),
|
||||
status=201,
|
||||
|
@ -307,7 +307,7 @@ def process_model_update(
|
|||
|
||||
# process_model_identifier = f"{process_group_id}/{process_model_id}"
|
||||
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)
|
||||
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@ class FileSystemService:
|
|||
""" Simple Service meant for extension that provides some useful
|
||||
methods for dealing with the File system.
|
||||
"""
|
||||
CAT_JSON_FILE = "process_group.json"
|
||||
WF_JSON_FILE = "workflow.json"
|
||||
PROCESS_GROUP_JSON_FILE = "process_group.json"
|
||||
PROCESS_MODEL_JSON_FILE = "workflow.json"
|
||||
|
||||
@staticmethod
|
||||
def root_path() -> str:
|
||||
|
@ -135,7 +135,7 @@ class FileSystemService:
|
|||
if item.is_file():
|
||||
if item.name.startswith("."):
|
||||
continue # Ignore hidden files
|
||||
if item.name == FileSystemService.WF_JSON_FILE:
|
||||
if item.name == FileSystemService.PROCESS_MODEL_JSON_FILE:
|
||||
continue # Ignore the json files.
|
||||
if file_name is not None and item.name != file_name:
|
||||
continue
|
||||
|
|
|
@ -36,14 +36,14 @@ class ProcessModelService(FileSystemService):
|
|||
|
||||
def is_group(self, path: str) -> bool:
|
||||
"""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):
|
||||
return True
|
||||
return False
|
||||
|
||||
def is_model(self, path: str) -> bool:
|
||||
"""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):
|
||||
return True
|
||||
return False
|
||||
|
@ -59,13 +59,13 @@ class ProcessModelService(FileSystemService):
|
|||
end = start + per_page
|
||||
return items[start:end]
|
||||
|
||||
def add_spec(self, process_model: ProcessModelInfo) -> None:
|
||||
def add_process_model(self, process_model: ProcessModelInfo) -> None:
|
||||
"""Add_spec."""
|
||||
display_order = self.next_display_order(process_model)
|
||||
process_model.display_order = display_order
|
||||
self.save_process_model(process_model)
|
||||
|
||||
def update_spec(
|
||||
def update_process_model(
|
||||
self, process_model: ProcessModelInfo, attributes_to_update: dict
|
||||
) -> None:
|
||||
"""Update_spec."""
|
||||
|
@ -78,7 +78,7 @@ class ProcessModelService(FileSystemService):
|
|||
"""Save_process_model."""
|
||||
spec_path = os.path.join(FileSystemService.root_path(), process_model.id)
|
||||
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:
|
||||
json.dump(
|
||||
self.WF_SCHEMA.dump(process_model), wf_json, indent=4, sort_keys=True
|
||||
|
@ -205,7 +205,7 @@ class ProcessModelService(FileSystemService):
|
|||
"""Update_process_group."""
|
||||
cat_path = self.process_group_path(process_group.id)
|
||||
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:
|
||||
json.dump(
|
||||
process_group.serialized,
|
||||
|
@ -279,7 +279,7 @@ class ProcessModelService(FileSystemService):
|
|||
|
||||
def __scan_process_group(self, dir_path: str) -> ProcessGroup:
|
||||
"""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):
|
||||
with open(cat_path) as cat_json:
|
||||
data = json.load(cat_json)
|
||||
|
@ -329,7 +329,7 @@ class ProcessModelService(FileSystemService):
|
|||
process_group: Optional[ProcessGroup] = None,
|
||||
) -> ProcessModelInfo:
|
||||
"""__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):
|
||||
with open(spec_path) as wf_json:
|
||||
|
|
|
@ -171,7 +171,7 @@ class SpecFileService(FileSystemService):
|
|||
ref.is_primary = True
|
||||
|
||||
if ref.is_primary:
|
||||
ProcessModelService().update_spec(
|
||||
ProcessModelService().update_process_model(
|
||||
process_model_info,
|
||||
{
|
||||
"primary_process_id": ref.identifier,
|
||||
|
|
|
@ -39,7 +39,7 @@ class ExampleDataLoader:
|
|||
is_review=False,
|
||||
)
|
||||
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
|
||||
if not bpmn_file_name_with_extension:
|
||||
|
|
|
@ -1830,7 +1830,7 @@ class TestProcessApi(BaseTest):
|
|||
process_model = ProcessModelService().get_process_model(
|
||||
process_model_identifier
|
||||
)
|
||||
ProcessModelService().update_spec(
|
||||
ProcessModelService().update_process_model(
|
||||
process_model,
|
||||
{"fault_or_suspend_on_exception": NotificationType.suspend.value},
|
||||
)
|
||||
|
@ -1885,7 +1885,7 @@ class TestProcessApi(BaseTest):
|
|||
process_model = ProcessModelService().get_process_model(
|
||||
process_model_identifier
|
||||
)
|
||||
ProcessModelService().update_spec(
|
||||
ProcessModelService().update_process_model(
|
||||
process_model,
|
||||
{"exception_notification_addresses": ["with_super_admin_user@example.com"]},
|
||||
)
|
||||
|
|
|
@ -32,7 +32,7 @@ class TestProcessModelService(BaseTest):
|
|||
primary_process_id = process_model.primary_process_id
|
||||
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.primary_process_id == primary_process_id
|
||||
|
|
Loading…
Reference in New Issue