Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/actinia_module_plugin/api/modules/actinia.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
SPDX-FileCopyrightText: (c) 2018-2025 by mundialis GmbH & Co. KG
SPDX-FileCopyrightText: (c) 2018-2026 by mundialis GmbH & Co. KG

SPDX-License-Identifier: Apache-2.0

Expand All @@ -14,11 +14,11 @@

__license__ = "Apache-2.0"
__author__ = "Carmen Tawalika"
__copyright__ = "Copyright 2019-2025, mundialis"
__copyright__ = "Copyright 2019-2026, mundialis"
__maintainer__ = "Carmen Tawalika"


from flask import jsonify, make_response
from flask import jsonify, make_response, request
from flask_restful_swagger_2 import swagger
from flask_restful import Resource

Expand Down Expand Up @@ -71,8 +71,10 @@ class DescribeProcessChainTemplate(ResourceBase):
def get(self, actiniamodule):
"""Describe an actinia module (process chain template)."""

returns = request.args.get("returns") or None

try:
virtual_module = createActiniaModule(self, actiniamodule)
virtual_module = createActiniaModule(self, actiniamodule, returns)
return make_response(jsonify(virtual_module), 200)
except Exception:
msg = 'Error looking for actinia module "' + actiniamodule + '".'
Expand Down
8 changes: 5 additions & 3 deletions src/actinia_module_plugin/api/modules/combined.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
SPDX-FileCopyrightText: (c) 2018-2021 by mundialis GmbH & Co. KG
SPDX-FileCopyrightText: (c) 2018-2026 by mundialis GmbH & Co. KG
SPDX-License-Identifier: Apache-2.0
Expand All @@ -14,7 +14,7 @@

__license__ = "Apache-2.0"
__author__ = "Carmen Tawalika"
__copyright__ = "Copyright 2019, mundialis"
__copyright__ = "Copyright 2019-2026, mundialis"
__maintainer__ = "Carmen Tawalika"


Expand Down Expand Up @@ -86,11 +86,13 @@ class DescribeVirtualModule(ResourceBase):
def get(self, module):
"""Describe a module."""

returns = request.args.get("returns") or None

try:
try:
virtual_module = createGrassModule(self, module)
except Exception:
virtual_module = createActiniaModule(self, module)
virtual_module = createActiniaModule(self, module, returns)
finally:
return make_response(jsonify(virtual_module), 200)

Expand Down
23 changes: 20 additions & 3 deletions src/actinia_module_plugin/apidocs/modules.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
SPDX-FileCopyrightText: (c) 2018-2021 by mundialis GmbH & Co. KG
SPDX-FileCopyrightText: (c) 2018-2026 by mundialis GmbH & Co. KG

SPDX-License-Identifier: Apache-2.0

Documentation objects for GRASS modules and actinia modules api endpoints
"""

__author__ = "Carmen Tawalika"
__copyright__ = "2018-2021 mundialis GmbH & Co. KG"
__copyright__ = "2018-2026 mundialis GmbH & Co. KG"
__license__ = "Apache-2.0"


Expand Down Expand Up @@ -95,7 +95,20 @@
"type": "string",
"description": "The name of a module",
"required": True,
}
},
{
"in": "path",
"name": "returns",
"type": "string",
"description": "Defines which outputs are returned for actinia "
"modules. 'export' shows the exported results. 'persistent' to "
"show persistent results might be added. Without this parameter "
"no outputs are returned. No effect for single GRASS GIS modules.",
"enum": [
"export",
# "persistent",
],
},
],
"description": "Get the description of a module. "
"Minimum required user role: user."
Expand All @@ -111,6 +124,10 @@
"describing modules did not succeeded",
"schema": SimpleStatusCodeResponseModel,
},
"404": {
"description": "The error message that the module was not found.",
"schema": SimpleStatusCodeResponseModel,
},
},
}

Expand Down
53 changes: 48 additions & 5 deletions src/actinia_module_plugin/core/modules/actinia_common.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
SPDX-FileCopyrightText: (c) 2018-2025 by mundialis GmbH & Co. KG
SPDX-FileCopyrightText: (c) 2018-2026 by mundialis GmbH & Co. KG

SPDX-License-Identifier: Apache-2.0

actinia-module viewer
Common module for file based and kvdb templates
"""
from __future__ import annotations

__license__ = "Apache-2.0"
__author__ = "Carmen Tawalika, Anika Weinmann"
__copyright__ = "Copyright 2019-2025, mundialis"
__copyright__ = "Copyright 2019-2026, mundialis"
__maintainer__ = "Carmen Tawalika"


Expand Down Expand Up @@ -436,7 +437,45 @@ def set_not_needed_param_to_optional(params, returns, undef, tpl_source):
ret["description"] += reason_text[reason]


def createActiniaModule(resourceBaseSelf, processchain):
def _generate_exported_results(pc_template_list_items):
"""
Populate returns array with results which are generated by the exporter.
"""
exported_results = []

for i in pc_template_list_items:
module = i.get("module")
outputs = i.get("outputs")

if not module or not outputs:
continue

for o in outputs:
export = o.get("export")
if not export:
continue

exported_results.append(
{
"name": o["value"],
"description": (
f"Exported result from exporter {module} "
f"{o["param"]} parameter",
),
"schema": {
"type": export.get("type", "string"),
"subtype": export.get("format", "undefined"),
},
}
)
return exported_results


def createActiniaModule(
resourceBaseSelf,
processchain,
returns: str | None = None,
):
"""
This method is used to create self-descriptions for actinia-modules.
In this method the terms "processchain" and "exec_process_chain" are
Expand Down Expand Up @@ -517,13 +556,17 @@ def createActiniaModule(resourceBaseSelf, processchain):
if "projects" in pc_template:
projects = pc_template["projects"]

exported_results = []
if returns == "export":
exported_results = _generate_exported_results(pc_template_list_items)

virtual_module = Module(
id=pc_template["id"],
description=pc_template["description"],
categories=categories,
projects=projects,
parameters=pt.vm_params,
returns=pt.vm_returns,
parameters=pt.vm_params + pt.vm_returns,
returns=exported_results,
)

return virtual_module