|
1 | 1 | import datetime |
| 2 | +from typing import List |
2 | 3 |
|
3 | 4 | from fastapi import Response |
4 | 5 | import jwt |
|
13 | 14 | from app.platforms.base import BaseProcessingPlatform |
14 | 15 | from app.platforms.dispatcher import register_platform |
15 | 16 | from app.schemas.enum import OutputFormatEnum, ProcessingStatusEnum, ProcessTypeEnum |
| 17 | +from app.schemas.parameters import ParamTypeEnum, Parameter |
16 | 18 | from app.schemas.unit_job import ServiceDetails |
17 | 19 |
|
18 | 20 | load_dotenv() |
@@ -267,3 +269,44 @@ async def get_job_results( |
267 | 269 | connection = await self._setup_connection(user_token, details.endpoint) |
268 | 270 | job = connection.job(job_id) |
269 | 271 | return Collection(**job.get_results().get_metadata()) |
| 272 | + |
| 273 | + async def get_service_parameters( |
| 274 | + self, user_token: str, details: ServiceDetails |
| 275 | + ) -> List[Parameter]: |
| 276 | + parameters = [] |
| 277 | + logger.debug( |
| 278 | + f"Fetching service parameters for OpenEO service at {details.application}" |
| 279 | + ) |
| 280 | + udp = requests.get(details.application) |
| 281 | + udp.raise_for_status() |
| 282 | + udp_params = udp.json().get("parameters", []) |
| 283 | + |
| 284 | + for param in udp_params: |
| 285 | + schemas = param.get("schema", {}) |
| 286 | + if not isinstance(schemas, list): |
| 287 | + schemas = [schemas] |
| 288 | + parameters.append( |
| 289 | + Parameter( |
| 290 | + name=param.get("name"), |
| 291 | + description=param.get("description"), |
| 292 | + default=param.get("default"), |
| 293 | + optional=param.get("optional", False), |
| 294 | + type=self._get_type_from_schemas(schemas), |
| 295 | + ) |
| 296 | + ) |
| 297 | + |
| 298 | + return parameters |
| 299 | + |
| 300 | + def _get_type_from_schemas(self, schemas: dict) -> ParamTypeEnum: |
| 301 | + for schema in schemas: |
| 302 | + type = schema.get("type") |
| 303 | + subtype = schema.get("subtype") |
| 304 | + if type == "array" and subtype == "temporal-interval": |
| 305 | + return ParamTypeEnum.DATE_INTERVAL |
| 306 | + elif subtype == "bounding-box": |
| 307 | + return ParamTypeEnum.BOUNDING_BOX |
| 308 | + elif type == "boolean": |
| 309 | + return ParamTypeEnum.BOOLEAN |
| 310 | + |
| 311 | + # If no matching schema found, raise an error |
| 312 | + raise ValueError(f"Unsupported parameter schemas: {schemas}") |
0 commit comments