Fixes for adding nested groups.
We pass modified ids to the api, and need to clean them up before calling services.
This commit is contained in:
parent
2cda810a04
commit
7d5c6b8efc
|
@ -185,9 +185,9 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/ProcessModelCategory"
|
$ref: "#/components/schemas/ProcessModelCategory"
|
||||||
|
|
||||||
/process-groups/{process_group_id}:
|
/process-groups/{modified_process_group_id}:
|
||||||
parameters:
|
parameters:
|
||||||
- name: process_group_id
|
- name: modified_process_group_id
|
||||||
in: path
|
in: path
|
||||||
required: true
|
required: true
|
||||||
description: The unique id of an existing process group.
|
description: The unique id of an existing process group.
|
||||||
|
|
|
@ -27,6 +27,9 @@ class ProcessGroup:
|
||||||
process_models: list[ProcessModelInfo] = field(
|
process_models: list[ProcessModelInfo] = field(
|
||||||
default_factory=list[ProcessModelInfo]
|
default_factory=list[ProcessModelInfo]
|
||||||
)
|
)
|
||||||
|
process_groups: list[ProcessGroup] = field(
|
||||||
|
default_factory=list['ProcessGroup']
|
||||||
|
)
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
"""__post_init__."""
|
"""__post_init__."""
|
||||||
|
|
|
@ -153,13 +153,14 @@ def process_group_add(body: dict) -> flask.wrappers.Response:
|
||||||
return make_response(jsonify(process_group), 201)
|
return make_response(jsonify(process_group), 201)
|
||||||
|
|
||||||
|
|
||||||
def process_group_delete(process_group_id: str) -> flask.wrappers.Response:
|
def process_group_delete(modified_process_group_id: str) -> flask.wrappers.Response:
|
||||||
"""Process_group_delete."""
|
"""Process_group_delete."""
|
||||||
|
process_group_id = un_modify_modified_process_model_id(modified_process_group_id)
|
||||||
ProcessModelService().process_group_delete(process_group_id)
|
ProcessModelService().process_group_delete(process_group_id)
|
||||||
return Response(json.dumps({"ok": True}), status=200, mimetype="application/json")
|
return Response(json.dumps({"ok": True}), status=200, mimetype="application/json")
|
||||||
|
|
||||||
|
|
||||||
def process_group_update(process_group_id: str, body: dict) -> flask.wrappers.Response:
|
def process_group_update(modified_process_group_id: str, body: dict) -> flask.wrappers.Response:
|
||||||
"""Process Group Update."""
|
"""Process Group Update."""
|
||||||
body_include_list = ["display_name", "description"]
|
body_include_list = ["display_name", "description"]
|
||||||
body_filtered = {
|
body_filtered = {
|
||||||
|
@ -168,6 +169,7 @@ def process_group_update(process_group_id: str, body: dict) -> flask.wrappers.Re
|
||||||
if include_item in body
|
if include_item in body
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process_group_id = un_modify_modified_process_model_id(modified_process_group_id)
|
||||||
process_group = ProcessGroup(id=process_group_id, **body_filtered)
|
process_group = ProcessGroup(id=process_group_id, **body_filtered)
|
||||||
ProcessModelService().update_process_group(process_group)
|
ProcessModelService().update_process_group(process_group)
|
||||||
return make_response(jsonify(process_group), 200)
|
return make_response(jsonify(process_group), 200)
|
||||||
|
@ -196,9 +198,10 @@ def process_groups_list(page: int = 1, per_page: int = 100) -> flask.wrappers.Re
|
||||||
|
|
||||||
|
|
||||||
def process_group_show(
|
def process_group_show(
|
||||||
process_group_id: str,
|
modified_process_group_id: str,
|
||||||
) -> Any:
|
) -> Any:
|
||||||
"""Process_group_show."""
|
"""Process_group_show."""
|
||||||
|
process_group_id = un_modify_modified_process_model_id(modified_process_group_id)
|
||||||
try:
|
try:
|
||||||
process_group = ProcessModelService().get_process_group(process_group_id)
|
process_group = ProcessModelService().get_process_group(process_group_id)
|
||||||
except ProcessEntityNotFoundError as exception:
|
except ProcessEntityNotFoundError as exception:
|
||||||
|
@ -224,10 +227,13 @@ def process_model_add(
|
||||||
status_code=400,
|
status_code=400,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
modified_process_model_id = process_model_info.id
|
||||||
|
unmodified_process_model_id = un_modify_modified_process_model_id(modified_process_model_id)
|
||||||
|
process_model_info.id = unmodified_process_model_id
|
||||||
process_group_id, _ = os.path.split(process_model_info.id)
|
process_group_id, _ = os.path.split(process_model_info.id)
|
||||||
process_model_service = ProcessModelService()
|
process_model_service = ProcessModelService()
|
||||||
process_group = process_model_service.get_process_group(
|
process_group = process_model_service.get_process_group(
|
||||||
process_group_id
|
un_modify_modified_process_model_id(process_group_id)
|
||||||
)
|
)
|
||||||
if process_group is None:
|
if process_group is None:
|
||||||
raise ApiError(
|
raise ApiError(
|
||||||
|
|
|
@ -125,7 +125,7 @@ def verify_token(
|
||||||
# no user_info
|
# no user_info
|
||||||
else:
|
else:
|
||||||
raise ApiError(
|
raise ApiError(
|
||||||
error_code="no_user_info", message="Cannot retrieve user info"
|
error_code="no_user_info", message="Cannot retrieve user info", status_code=401
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -168,6 +168,7 @@ class ProcessModelService(FileSystemService):
|
||||||
def get_process_group(self, process_group_id: str) -> ProcessGroup:
|
def get_process_group(self, process_group_id: str) -> ProcessGroup:
|
||||||
"""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.join(FileSystemService.root_path(), process_group_id)
|
process_group_path = os.path.join(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)
|
||||||
|
@ -264,12 +265,17 @@ class ProcessModelService(FileSystemService):
|
||||||
json.dump(self.GROUP_SCHEMA.dump(process_group), wf_json, indent=4)
|
json.dump(self.GROUP_SCHEMA.dump(process_group), wf_json, indent=4)
|
||||||
with os.scandir(dir_path) as nested_items:
|
with os.scandir(dir_path) as nested_items:
|
||||||
process_group.process_models = []
|
process_group.process_models = []
|
||||||
|
process_group.process_groups = []
|
||||||
for nested_item in nested_items:
|
for nested_item in nested_items:
|
||||||
if nested_item.is_dir():
|
if nested_item.is_dir():
|
||||||
# TODO: check whether this is a group or model
|
# TODO: check whether this is a group or model
|
||||||
if self.is_group(nested_item.path):
|
if self.is_group(nested_item.path):
|
||||||
# This is a nested group
|
# This is a nested group
|
||||||
...
|
process_group.process_groups.append(
|
||||||
|
self.__scan_process_group(
|
||||||
|
nested_item.path
|
||||||
|
)
|
||||||
|
)
|
||||||
elif self.is_model(nested_item.path):
|
elif self.is_model(nested_item.path):
|
||||||
process_group.process_models.append(
|
process_group.process_models.append(
|
||||||
self.__scan_spec(
|
self.__scan_spec(
|
||||||
|
@ -277,6 +283,7 @@ class ProcessModelService(FileSystemService):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
process_group.process_models.sort()
|
process_group.process_models.sort()
|
||||||
|
# process_group.process_groups.sort()
|
||||||
return process_group
|
return process_group
|
||||||
|
|
||||||
def __scan_spec(
|
def __scan_spec(
|
||||||
|
|
Loading…
Reference in New Issue