diff --git a/cads_processing_api_service/translators.py b/cads_processing_api_service/translators.py index b63f0ba4..a57c6cb6 100644 --- a/cads_processing_api_service/translators.py +++ b/cads_processing_api_service/translators.py @@ -17,9 +17,12 @@ from typing import Any import fastapi +import structlog from . import config +logger: structlog.stdlib.BoundLogger = structlog.get_logger(__name__) + def extract_groups_labels( groups: list[Any], values: dict[str, str] | None = None @@ -133,7 +136,7 @@ def translate_cds_form( def make_request_labels( - input_value_ids: list[str], + input_value_ids: Any, cds_input_schema: dict[str, Any], ) -> list[str]: if cds_input_schema["type"] in ( @@ -147,6 +150,21 @@ def make_request_labels( input_value_ids, ) ] + elif cds_input_schema["type"] == "GeographicLocationWidget": + location = input_value_ids[0] + try: + latitude = f"{location['latitude']}°" + longitude = f"{location['longitude']}°" + except Exception as e: + logger.error( + "Error extracting latitude and longitude from geographic location", + error=e, + ) + latitude = longitude = "Unknown" + request_labels = [ + f"Latitude: {latitude}", + f"Longitude: {longitude}", + ] else: input_value_label = extract_labels(cds_input_schema) request_labels = [] diff --git a/tests/test_10_translators.py b/tests/test_10_translators.py index cc9b2d85..03feb5d6 100644 --- a/tests/test_10_translators.py +++ b/tests/test_10_translators.py @@ -1,3 +1,5 @@ +# type: ignore + # Copyright 2022, European Union. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -41,6 +43,10 @@ "details": {"default": [1, 2, 3, 4]}, "type": "GeographicExtentMapWidget", }, + "geographic_location": { + "details": {}, + "type": "GeographicLocationWidget", + }, "string_list_array_groups": { "details": { "groups": [ @@ -205,6 +211,14 @@ def test_make_request_labels() -> None: ) assert res_output == exp_output + test_input_value_ids = [{"latitude": 10, "longitude": 10}] + test_input_cds_schema = TEST_INPUT_CDS_SCHEMAS["geographic_location"] + exp_output = ["Latitude: 10°", "Longitude: 10°"] + res_output = cads_processing_api_service.translators.make_request_labels( + test_input_value_ids, test_input_cds_schema + ) + assert res_output == exp_output + test_input_value_ids = ["val1", "val2"] test_input_cds_schema = TEST_INPUT_CDS_SCHEMAS["string_list"] exp_output = ["Val1", "Val2"]