|
25 | 25 | from typing import Annotated, Literal |
26 | 26 |
|
27 | 27 | import requests |
28 | | -import sqlalchemy |
29 | 28 | import stac_pydantic |
30 | 29 | from fastapi import APIRouter, HTTPException |
31 | 30 | from fastapi import Path as FPath |
32 | | -from fastapi import Query, Request, status |
| 31 | +from fastapi import Request, status |
33 | 32 | from fastapi.responses import RedirectResponse |
34 | 33 | from rs_server_adgs import adgs_tags |
35 | | -from rs_server_adgs.adgs_download_status import AdgsDownloadStatus |
36 | 34 | from rs_server_adgs.adgs_retriever import init_adgs_provider |
37 | 35 | from rs_server_adgs.adgs_utils import ( |
38 | 36 | auxip_map_mission, |
|
43 | 41 | stac_to_odata, |
44 | 42 | ) |
45 | 43 | from rs_server_common.authentication import authentication |
46 | | -from rs_server_common.authentication.authentication import auth_validator |
47 | 44 | from rs_server_common.authentication.authentication_to_external import ( |
48 | 45 | set_eodag_auth_token, |
49 | 46 | ) |
|
61 | 58 | handle_exceptions, |
62 | 59 | ) |
63 | 60 | from rs_server_common.utils.logging import Logging |
64 | | -from rs_server_common.utils.utils import ( |
65 | | - validate_inputs_format, |
66 | | - validate_sort_input, |
67 | | - write_search_products_to_db, |
68 | | -) |
| 61 | +from rs_server_common.utils.utils import validate_inputs_format, validate_sort_input |
69 | 62 |
|
70 | 63 | # pylint: disable=duplicate-code # with cadip_search |
71 | 64 |
|
@@ -395,91 +388,3 @@ def process_product_search( # pylint: disable=too-many-locals |
395 | 388 | status_code=status.HTTP_503_SERVICE_UNAVAILABLE, |
396 | 389 | detail=f"General failure: {exception}", |
397 | 390 | ) from exception |
398 | | - |
399 | | - |
400 | | -###################################### |
401 | | -# DEPRECATED CODE, WILL BE REMOVED !!! |
402 | | -###################################### |
403 | | -@router.get("/adgs/aux/search", deprecated=True) |
404 | | -@auth_validator(station="adgs", access_type="read") |
405 | | -async def search_products( # pylint: disable=too-many-locals |
406 | | - request: Request, # pylint: disable=unused-argument |
407 | | - datetime: Annotated[str, Query(description='Time interval e.g. "2024-01-01T00:00:00Z/2024-01-02T23:59:59Z"')], |
408 | | - limit: Annotated[int, Query(description="Maximum number of products to return")] = 1000, |
409 | | - sortby: Annotated[str, Query(description="Sort by +/-fieldName (ascending/descending)")] = "-created", |
410 | | -) -> list[dict] | stac_pydantic.ItemCollection: |
411 | | - """Endpoint to handle the search for products in the AUX station within a specified time interval. |
412 | | -
|
413 | | - This function validates the input 'datetime' format, performs a search for products using the ADGS provider, |
414 | | - writes the search results to the database, and generates a STAC Feature Collection from the products. |
415 | | -
|
416 | | - Args: |
417 | | - request (Request): The request object (unused). |
418 | | - datetime (str): Time interval in ISO 8601 format. |
419 | | - limit (int, optional): Maximum number of products to return. Defaults to 1000. |
420 | | - sortby (str, optional): Sort by +/-fieldName (ascending/descending). Defaults to "-datetime". |
421 | | -
|
422 | | - Returns: |
423 | | - list[dict] | dict: A list of STAC Feature Collections or an error message. |
424 | | - If no products are found in the specified time range, returns an empty list. |
425 | | -
|
426 | | - Raises: |
427 | | - HTTPException (fastapi.exceptions): If the pagination limit is less than 1. |
428 | | - HTTPException (fastapi.exceptions): If there is a bad station identifier (CreateProviderFailed). |
429 | | - HTTPException (fastapi.exceptions): If there is a database connection error (sqlalchemy.exc.OperationalError). |
430 | | - HTTPException (fastapi.exceptions): If there is a connection error to the station. |
431 | | - HTTPException (fastapi.exceptions): If there is a general failure during the process. |
432 | | - """ |
433 | | - |
434 | | - if limit < 1: |
435 | | - raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="Pagination cannot be less 0") |
436 | | - set_eodag_auth_token("adgs", "auxip") |
437 | | - try: |
438 | | - products = (init_adgs_provider("adgs")).search( |
439 | | - # Temp, will be removed. |
440 | | - **{"PublicationDate": validate_inputs_format(datetime)}, |
441 | | - items_per_page=limit, |
442 | | - sort_by=validate_sort_input(sortby), |
443 | | - ) |
444 | | - write_search_products_to_db(AdgsDownloadStatus, products) |
445 | | - feature_template_path = ADGS_CONFIG / "ODataToSTAC_template.json" |
446 | | - stac_mapper_path = ADGS_CONFIG / "adgs_stac_mapper.json" |
447 | | - with ( |
448 | | - open(feature_template_path, encoding="utf-8") as template, |
449 | | - open(stac_mapper_path, encoding="utf-8") as stac_map, |
450 | | - ): |
451 | | - feature_template = json.loads(template.read()) |
452 | | - stac_mapper = json.loads(stac_map.read()) |
453 | | - adgs_item_collection = create_stac_collection(products, feature_template, stac_mapper) |
454 | | - logger.info("Succesfully listed and processed products from AUX station") |
455 | | - return prepare_collection(serialize_adgs_asset(adgs_item_collection, products)) |
456 | | - |
457 | | - # pylint: disable=duplicate-code |
458 | | - except CreateProviderFailed as exception: |
459 | | - logger.error(f"Failed to create EODAG provider!\n{traceback.format_exc()}") |
460 | | - raise HTTPException( |
461 | | - status_code=status.HTTP_400_BAD_REQUEST, |
462 | | - detail=f"Bad station identifier: {exception}", |
463 | | - ) from exception |
464 | | - |
465 | | - # pylint: disable=duplicate-code |
466 | | - except sqlalchemy.exc.OperationalError as exception: |
467 | | - logger.error("Failed to connect to database!") |
468 | | - raise HTTPException( |
469 | | - status_code=status.HTTP_503_SERVICE_UNAVAILABLE, |
470 | | - detail=f"Database connection error: {exception}", |
471 | | - ) from exception |
472 | | - |
473 | | - except requests.exceptions.ConnectionError as exception: |
474 | | - logger.error("Failed to connect to station!") |
475 | | - raise HTTPException( |
476 | | - status_code=status.HTTP_503_SERVICE_UNAVAILABLE, |
477 | | - detail=f"Station ADGS connection error: {exception}", |
478 | | - ) from exception |
479 | | - |
480 | | - except Exception as exception: # pylint: disable=broad-exception-caught |
481 | | - logger.error(f"General failure! {exception}") |
482 | | - raise HTTPException( |
483 | | - status_code=status.HTTP_503_SERVICE_UNAVAILABLE, |
484 | | - detail=f"General failure: {exception}", |
485 | | - ) from exception |
0 commit comments