Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
372e649
Skip token exchange for OGC API if token was issued by iam.terradue.com
floeschau Jun 8, 2026
ba9966c
Changes for test deployment (Terradue)
floeschau Jun 24, 2026
ec90107
Changes for test deployment (Terradue) (2)
floeschau Jun 24, 2026
88ead06
Changes for test deployment (Terradue) (3)
floeschau Jun 24, 2026
a26e596
Enabled Cross Domain Federation/Trusted Token Delegation
floeschau Jul 7, 2026
efa0559
Merge branch 'main' into feature/token-exchange-cd-ttd
floeschau Jul 7, 2026
366a1bd
Merge branch 'main' into feature/token-exchange-cd-ttd
JanssenBrm Aug 25, 2026
8b2686a
feat: add FeatureCollection to result
floeschau Oct 21, 2026
80d1e27
feat: enable ItemCollection als results response payload
floeschau Oct 22, 2026
9537ef9
feat: enable ItemCollection as results response payload (2)
floeschau Oct 23, 2026
14b50e2
fix: remove collection from features in FeatureCollection
floeschau Oct 29, 2026
f8ccf83
test: adjust test for FeatureCollection OGC API response and ItemColl…
floeschau Oct 29, 2026
ed463f9
Merge branch 'main' into feature/result-change
JanssenBrm Nov 17, 2026
3fd8f4a
chore: code cleanup and test fixes
JanssenBrm Nov 17, 2026
c063bbe
test: fixed validation
JanssenBrm Nov 17, 2026
25a61a9
feat: implemented changes to align openEO results to itemcollection
JanssenBrm Nov 17, 2026
88f848e
chore: fixed linting
JanssenBrm Nov 17, 2026
7991bd5
ogc: aligned result handling
JanssenBrm Nov 17, 2026
3c9dbdb
chore: code cleanup for flake8
JanssenBrm Nov 17, 2026
11ab594
chore: removed env file
JanssenBrm Nov 17, 2026
41e25da
fix: revert asset to Pydantic object
floeschau Nov 19, 2026
b719ad7
fix: set correct type annotation for Asset
floeschau Nov 19, 2026
fb1fb41
fix: set correctly typed asset in test
floeschau Nov 19, 2026
d8dc791
chore: format
floeschau Nov 19, 2026
0aaf522
fix: set correctly typed asset in test (2)
floeschau Nov 19, 2026
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,6 @@ cython_debug/

.vscode/settings.json
.codex


env*
4 changes: 2 additions & 2 deletions app/platforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from app.schemas.parameters import Parameter
from app.schemas.unit_job import ServiceDetails

from stac_pydantic import Collection
from stac_pydantic.item_collection import ItemCollection


class BaseProcessingPlatform(ABC):
Expand Down Expand Up @@ -75,7 +75,7 @@ async def get_job_status(
@abstractmethod
async def get_job_results(
self, user_token: str, job_id: str, details: ServiceDetails
) -> Collection:
) -> ItemCollection:
"""
Retrieve the job results of a processing job that is running on the platform.

Expand Down
227 changes: 114 additions & 113 deletions app/platforms/implementations/ogc_api_process.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import json
import re
from typing import List
from asyncio import to_thread

import requests
from app.auth import exchange_token, get_current_user_claims
from fastapi import Response
from httpx import Response as HTTPXResponse
from httpx import get as http_get
from loguru import logger

from app.platforms.base import BaseProcessingPlatform
from app.platforms.dispatcher import register_platform
from app.schemas.enum import OutputFormatEnum, ProcessTypeEnum, ProcessingStatusEnum
from app.schemas.parameters import ParamTypeEnum, Parameter
from app.schemas.unit_job import ServiceDetails
from httpx import get as http_get, Response as HTTPXResponse
from stac_pydantic.collection import Collection, Extent, SpatialExtent, TimeInterval
from stac_pydantic.links import Links
from stac_pydantic.version import STAC_VERSION
from ogc_api_processes_client.api_client_wrapper import ApiClientWrapper
from ogc_api_processes_client.configuration import Configuration
from ogc_api_processes_client.models.inline_or_ref_data import InlineOrRefData
Expand All @@ -24,7 +15,18 @@
from ogc_api_processes_client.models.qualified_input_value import QualifiedInputValue
from ogc_api_processes_client.models.status_code import StatusCode
from ogc_api_processes_client.models.status_info import StatusInfo
from typing import Dict
from stac_pydantic.collection import Collection
from stac_pydantic.item import Item
from stac_pydantic.item_collection import ItemCollection
from stac_pydantic.links import Links
from stac_pydantic.shared import Asset

from app.auth import exchange_token, get_current_user_claims
from app.platforms.base import BaseProcessingPlatform
from app.platforms.dispatcher import register_platform
from app.schemas.enum import OutputFormatEnum, ProcessingStatusEnum, ProcessTypeEnum
from app.schemas.parameters import Parameter, ParamTypeEnum
from app.schemas.unit_job import ServiceDetails

STAC_COLLECTION_SCHEMA = (
"https://schemas.stacspec.org/v1.0.0/collection-spec/json-schema/collection.json"
Expand Down Expand Up @@ -300,7 +302,7 @@ def _map_ogcapi_status(self, ogcapi_status: StatusCode) -> ProcessingStatusEnum:
logger.warning(f"Mapping of unknown OGC API status: {ogcapi_status}")
return ProcessingStatusEnum.UNKNOWN

def _extract_download_link_from_asset(self, asset: dict) -> str | None:
def _extract_download_link_from_asset(self, asset: Asset) -> str | None:
"""
Extracts the download link from an asset dictionary. Checks if the
`href` field is present and contains an HTTPS URL. If this is not
Expand All @@ -314,8 +316,8 @@ def _extract_download_link_from_asset(self, asset: dict) -> str | None:
str | None: The download link if available, otherwise None.
"""
refs = [
asset.get("href"),
asset.get("alternate", {}).get("https", {}).get("href"),
asset.href,
asset.to_dict().get("alternate", {}).get("https", {}).get("href"),
]
for href in refs:
if href and href.startswith("https://"):
Expand Down Expand Up @@ -377,7 +379,7 @@ def _generate_signed_url(self, href: str, user_token: str) -> str | None:
)
return None

def _update_assets_hrefs(self, assets: dict, user_token: str) -> dict:
def _update_assets_hrefs(self, assets: dict[str, Asset], user_token: str) -> dict:
"""
Update the hrefs of the assets to be HTTPS URLs. If the current
href is an S3 URL, the code will look into `alternate` links to
Expand All @@ -402,29 +404,23 @@ def _update_assets_hrefs(self, assets: dict, user_token: str) -> dict:
"original HTTPS href."
)
signed_url = href
updated_asset["href"] = signed_url
updated_asset.href = signed_url
updated_assets[asset_name] = updated_asset

return updated_assets

def _build_collection_from_features(
def _build_item_collection_from_features(
self,
features: list,
assets: dict,
result_name: str,
user_token: str,
details: ServiceDetails,
internal_job_id: str,
) -> Collection:
) -> ItemCollection:
"""
Build a STAC Collection from a list of GeoJSON features and their
aggregated assets. The spatial extent is derived from the feature
bounding boxes and the temporal extent from the feature datetime
properties.
Build a STAC Collection from a list of GeoJSON features.
The spatial extent is derived from the feature bounding boxes
and the temporal extent from the feature datetime properties.

Args:
features: GeoJSON feature list.
assets: Aggregated asset dict collected from those features.
result_name: Identifier used as the collection ID.
user_token: Token used to sign asset hrefs.
details: Service details containing namespace and application information.
Expand All @@ -438,7 +434,7 @@ def _build_collection_from_features(
max_x, max_y = float("-inf"), float("-inf")
found_bbox = False
for feature in features:
bbox = feature.get("bbox")
bbox = feature.bbox
if isinstance(bbox, (list, tuple)) and len(bbox) >= 4:
min_x = min(min_x, float(bbox[0]))
min_y = min(min_y, float(bbox[1]))
Expand All @@ -452,88 +448,93 @@ def _build_collection_from_features(
# Temporal extent — min/max of all datetime-like properties
datetimes: list[str] = []
for feature in features:
props = feature.get("properties") or {}
for dt_key in ("datetime", "start_datetime", "end_datetime"):
dt_val = props.get(dt_key)
props = feature.properties
for dt_val in (props.datetime, props.start_datetime, props.end_datetime):
if isinstance(dt_val, str):
datetimes.append(dt_val)
temporal_interval: list[list] = (
[[min(datetimes), max(datetimes)]] if datetimes else [[None, None]]
)

updated_assets = self._update_assets_hrefs(assets, user_token)
logger.debug(f"Features: {features}")

logger.debug(
f"Building STAC Collection '{result_name}' from {len(features)} feature(s) "
f"with {len(updated_assets)} asset(s)."
)

return Collection(
id=f"{details.namespace}-{internal_job_id}",
stac_version=STAC_VERSION,
title=f"Results for {details.application}",
description=(
f"OGC API process result items for job '{internal_job_id}' "
f"of application '{details.application}'."
),
type="Collection",
license="proprietary",
logger.debug(f"bbox = {spatial_bbox}")

return ItemCollection(
bbox=spatial_bbox,
type="FeatureCollection",
links=Links([]),
extent=Extent(
spatial=SpatialExtent(bbox=[spatial_bbox]),
temporal=TimeInterval(interval=temporal_interval),
),
assets=updated_assets,
features=features,
)

def _extract_assets_from_feature_collection(
def _remove_stac_links(self, links: Links, keep: list[str] | None = None):
if not keep:
keep = []
stac_links = [
link
for link in links.root
if link.rel in ["self", "item", "items", "collection", "parent", "root"]
and link.rel not in keep
or link.rel.endswith("queryables")
]
for link in stac_links:
links.root.remove(link)
return links.root

def _process_feature_collection(
self,
feature_collection: dict,
*,
result_name: str,
user_token: str,
details: ServiceDetails,
internal_job_id: str,
) -> Collection:
assets: dict = {}
features = feature_collection.get("features", [])
) -> ItemCollection:
logger.debug(f"Feature collection: {json.dumps(feature_collection, indent=2)}")

features_dict = feature_collection.get("features", [])
features = [Item.model_validate(f) for f in features_dict]

collection = None

for feature in features:
feature_assets = feature.get("assets")
if isinstance(feature_assets, dict):
assets.update(feature_assets)
continue
collection_link = next(
(link for link in feature.links.root if link.rel == "collection"), None
)
feature.links = Links(
self._remove_stac_links(feature.links, keep=["collection"])
)
feature.assets = self._update_assets_hrefs(feature.assets, user_token)
feature.collection = None

# Some providers expose assets through an item link
# instead of inlining them in the feature.
for link in feature.get("links", []):
if "collection" == link.get("rel") and link.get("href"):
collection_link: str = link.get("href")
logger.debug(
f"GeoJSON FeatureCollection results: '{result_name}' "
f"points to a valid collection URL: {collection_link}"
)
if collection is None and collection_link is not None:
logger.debug(
f"GeoJSON FeatureCollection results: '{result_name}' "
f"points to a valid collection URL: {collection_link.href}"
)

response: HTTPXResponse = http_get(
collection_link,
follow_redirects=True,
headers={"Authorization": f"Bearer {user_token}"},
)
response.raise_for_status()
collection_data = response.json()
collection_data["assets"] = self._update_assets_hrefs(
collection_data.get("assets", {}), user_token
)
collection = Collection.model_validate(collection_data)
logger.debug(
f"Extracted collection '{collection.id}' "
f"with assets: {list((collection.assets or {}).keys())}"
)
return collection
response: HTTPXResponse = http_get(
collection_link.href,
follow_redirects=True,
headers={"Authorization": f"Bearer {user_token}"},
)
response.raise_for_status()
collection_data = response.json()
collection = Collection.model_validate(collection_data)
collection.assets = self._update_assets_hrefs(
collection.assets or {}, user_token
)
logger.debug(
f"Extracted collection '{collection.id}' "
f"with assets: {list((collection.assets or {}).keys())}"
)
collection.links = Links(self._remove_stac_links(collection.links))

return self._build_collection_from_features(
features, assets, result_name, user_token, details, internal_job_id
item_collection = self._build_item_collection_from_features(
features, result_name
)
return item_collection

async def get_job_status(
self, user_token: str, job_id: str, details: ServiceDetails
Expand All @@ -556,7 +557,7 @@ async def get_job_status(

async def get_job_results(
self, user_token: str, job_id: str, details: ServiceDetails
) -> Collection:
) -> ItemCollection:
logger.debug(f"Fetching job result for opfenEO job with ID {job_id}")

logger.debug("Exchanging user token for OGC API Process execution...")
Expand All @@ -570,7 +571,7 @@ async def get_job_results(
details.endpoint, namespace, exchanged_token
)

result: Dict[str, InlineOrRefData] = api_client.get_result(
result: dict[str, InlineOrRefData] = api_client.get_result(
job_id=internal_job_id
)

Expand Down Expand Up @@ -612,22 +613,39 @@ async def get_job_results(

if STAC_COLLECTION_SCHEMA == schema_reference:
logger.success(f"STAC Collection found in results: '{result_name}'")
return Collection.model_validate(
collection = Collection.model_validate(
qualified_value.value.actual_instance
)
features = []
for link in collection.links.root:
if link.rel != "item":
continue
response = await to_thread(
http_get,
link.href,
follow_redirects=True,
headers={
"Authorization": f"Bearer {exchanged_token or user_token}"
},
)
response.raise_for_status()
features.append(response.json())
return self._process_feature_collection(
{"features": features},
result_name=result_name,
user_token=exchanged_token or user_token,
)
elif GEOJSON_FEATURECOLLECTION_SCHEMA == schema_reference:
logger.success(
f"GeoJSON FeatureCollection found in results: '{result_name}'"
)
feature_collection = (
qualified_value.value.oneof_schema_2_validator or {}
)
return self._extract_assets_from_feature_collection(
return self._process_feature_collection(
feature_collection,
result_name=result_name,
user_token=exchanged_token or user_token,
details=details,
internal_job_id=internal_job_id,
)
else:
logger.warning(
Expand All @@ -636,28 +654,11 @@ async def get_job_results(
)

# result not found, send back an empty collection

return Collection(
id=f"{details.namespace}-{internal_job_id}",
stac_version=STAC_VERSION,
title=f"Results for {details.application}",
description=(
f"OGC API process result items for job '{internal_job_id}' "
f"of application '{details.application}'."
),
type="Collection",
license="proprietary",
links=Links([]),
extent=Extent(
spatial=SpatialExtent(bbox=[(-180.0, -90.0, 180.0, 90.0)]),
temporal=TimeInterval(interval=[[None, None]]),
),
assets={},
)
return self._build_item_collection_from_features([], "No results found")

async def get_service_parameters(
self, user_token: str, details: ServiceDetails
) -> List[Parameter]:
) -> list[Parameter]:

parameters = []
logger.debug(
Expand Down
Loading
Loading