From 680fbd965896f49de317aa39a736fe1d6b246a3f Mon Sep 17 00:00:00 2001 From: jbirddog <100367399+jbirddog@users.noreply.github.com> Date: Thu, 15 Feb 2024 09:57:53 -0500 Subject: [PATCH] Store data store specifications in process_group.json (#1040) --- .../models/process_group.py | 2 ++ .../routes/data_store_controller.py | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/process_group.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/process_group.py index 2537387b..aa5db0a5 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/process_group.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/process_group.py @@ -17,6 +17,7 @@ from spiffworkflow_backend.models.process_model import ProcessModelInfo PROCESS_GROUP_SUPPORTED_KEYS_FOR_DISK_SERIALIZATION = [ "display_name", "description", + "data_store_specifications", ] @@ -29,6 +30,7 @@ class ProcessGroup: description: str | None = None process_models: list[ProcessModelInfo] = field(default_factory=list[ProcessModelInfo]) process_groups: list[ProcessGroup] = field(default_factory=list["ProcessGroup"]) + data_store_specifications: dict[str, Any] = field(default_factory=dict) parent_groups: list[ProcessGroupLite] | None = None # TODO: delete these once they no no longer mentioned in current diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/data_store_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/data_store_controller.py index 26624010..232999f7 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/data_store_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/data_store_controller.py @@ -11,6 +11,7 @@ from spiffworkflow_backend.data_stores.kkv import KKVDataStore from spiffworkflow_backend.data_stores.typeahead import TypeaheadDataStore from spiffworkflow_backend.exceptions.api_error import ApiError from spiffworkflow_backend.models.db import db +from spiffworkflow_backend.services.process_model_service import ProcessModelService DATA_STORES = { "json": (JSONDataStore, "JSON Data Store"), @@ -125,9 +126,34 @@ def _data_store_upsert(body: dict, insert: bool) -> flask.wrappers.Response: db.session.add(model) db.session.commit() + _write_specification_to_process_group(data_store_type, model) + return make_response(jsonify({"ok": True}), 200) +def _write_specification_to_process_group(data_store_type: str, model: Any) -> None: + # TODO: once the top level is a process group this check should be removed + if model.location == "": + return + + process_group = ProcessModelService.get_process_group(model.location, False, False) + if not process_group: + return + + if data_store_type not in process_group.data_store_specifications: + process_group.data_store_specifications[data_store_type] = {} + + process_group.data_store_specifications[data_store_type][model.identifier] = { + "name": model.name, + "identifier": model.identifier, + "location": model.location, + "schema": model.schema, + "description": model.description, + } + + ProcessModelService.update_process_group(process_group) + + def data_store_show(data_store_type: str, identifier: str, process_group_identifier: str) -> flask.wrappers.Response: """Returns a description of a data store."""