Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server additional props #1170

Merged
merged 5 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions eodag/resources/providers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,8 @@

# Additional metadata provided by the providers but that don't appear in the reference spec
thumbnail: '$.properties.thumbnail'
links: $.null
services: $.null
products:
S1_SAR_OCN:
productType: OCN
Expand Down
55 changes: 54 additions & 1 deletion eodag/rest/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import shapefile
from dateutil import tz
from dateutil.relativedelta import relativedelta
from jsonpath_ng.jsonpath import Child
from shapely.geometry import shape
from shapely.geometry.base import BaseGeometry
from shapely.ops import unary_union
Expand Down Expand Up @@ -68,6 +69,36 @@

STAC_CATALOGS_PREFIX = "catalogs"

# fields not to put in item properties
COLLECTION_PROPERTIES = [
"abstract",
"instrument",
"platform",
"platformSerialIdentifier",
"processingLevel",
"sensorType",
"md5",
"license",
"title",
"missionStartDate",
"missionEndDate",
"keywords",
"stacCollection",
]
IGNORED_ITEM_PROPERTIES = [
"_id",
"id",
"keyword",
"quicklook",
"thumbnail",
"downloadLink",
"orderLink",
"_dc_qs",
"qs",
"defaultGeometry",
"_date",
]


class StacCommon:
"""Stac common object
Expand Down Expand Up @@ -248,6 +279,13 @@ def __get_item_list(
k, item_model["properties"][k]
)

item_props = [
p.right.fields[0]
for p in item_model["properties"].values()
if isinstance(p, Child)
]
ignored_props = COLLECTION_PROPERTIES + item_props + IGNORED_ITEM_PROPERTIES

item_list: List[Dict[str, Any]] = []
for product in search_results:
product_dict = deepcopy(product.__dict__)
Expand All @@ -259,6 +297,17 @@ def __get_item_list(
"providers": [self.get_provider_dict(product.provider)],
},
)

# add additional item props
for p in set(product.properties) - set(ignored_props):
prefix = getattr(
self.eodag_api.providers_config[product.provider],
"group",
product.provider,
)
key = p if ":" in p else f"{prefix}:{p}"
product_item["properties"][key] = product.properties[p]

# parse download link
downloadlink_href = (
f"{catalog['url']}/items/{product.properties['title']}/download"
Expand Down Expand Up @@ -716,7 +765,11 @@ def __generate_stac_collection(
)
except TypeError as e:
logger.warning(
f"Could not merge keywords from external collection for {product_type}: {str(e)}"
f"Could not merge keywords from external collection for {product_type['ID']}: {str(e)}"
)
logger.debug(
f"External collection keywords: {str(ext_stac_collection['keywords'])}, ",
f"Product type keywords: {str(product_type_collection['keywords'])}",
)

# merge providers
Expand Down
4 changes: 4 additions & 0 deletions tests/units/test_http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def mock_search_result(self):
"sensorMode": None,
"quicklook": None,
"storageStatus": ONLINE_STATUS,
"providerProperty": "foo",
},
"id": "578f1768-e66e-5b86-9363-b19f8931cc7b",
"type": "Feature",
Expand Down Expand Up @@ -826,6 +827,9 @@ def test_date_search_from_catalog_items_with_provider(self):
self_link = link
self.assertIsNotNone(self_link)
self.assertIn("?provider=peps", self_link["href"])
self.assertEqual(
results["features"][0]["properties"]["peps:providerProperty"], "foo"
)

def test_search_item_id_from_catalog(self):
"""Search by id through eodag server /catalog endpoint should return a valid response"""
Expand Down
Loading