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

feat: return all available providers for collection #835

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions eodag/resources/stac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,7 @@ collection:
- '$.product_type.processingLevel'
- '$.product_type.sensorType'
license: '$.product_type.license'
providers:
- name: '$.provider.name'
description: '$.provider.description'
# one or more of "producer" "licensor" "processor" "host"
roles: '$.provider.roles'
url: '$.provider.url'
providers: '$.providers'
summaries:
constellation:
- '$.product_type.platform'
Expand All @@ -126,6 +121,14 @@ collection:
- '$.product_type.instrument'
processing:level: '$.product_type.processingLevel'

provider:
name: '$.provider.name'
description: '$.provider.description'
# one or more of "producer" "licensor" "processor" "host"
roles: '$.provider.roles'
url: '$.provider.url'
priority: '$.provider.priority'

# Data ------------------------------------------------------------------------

# https://stacspec.org/STAC-api.html#operation/getFeatures
Expand Down
29 changes: 18 additions & 11 deletions eodag/rest/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,29 +545,36 @@ def __get_collection_list(self, filters=None):
:rtype: list
"""
collection_model = deepcopy(self.stac_config["collection"])
provider_model = deepcopy(self.stac_config["provider"])

product_types = self.__get_product_types(filters)

collection_list = []
for product_type in product_types:
# get default provider for each product_type
product_type_provider = (
self.provider
or next(
self.eodag_api._plugins_manager.get_search_plugins(
if self.provider:
providers = [self.provider]
else:
# get available providers for each product_type
providers = [
plugin.provider
for plugin in self.eodag_api._plugins_manager.get_search_plugins(
product_type=product_type["ID"]
)
).provider
)
]
providers_models = []
for provider in providers:
provider_m = jsonpath_parse_dict_items(
provider_model,
{"provider": self.eodag_api.providers_config[provider].__dict__},
)
providers_models.append(provider_m)

# parse jsonpath
product_type_collection = jsonpath_parse_dict_items(
collection_model,
{
"product_type": product_type,
"provider": self.eodag_api.providers_config[
product_type_provider
].__dict__,
"providers": providers_models,
},
)
# parse f-strings
Expand Down Expand Up @@ -622,7 +629,7 @@ def get_collection_by_id(self, collection_id):

:param collection_id: Product type as collection ID
:type collection_id: str
:returns: Collection dictionnary
:returns: Collection dictionary
:rtype: dict
"""
collection_list = self.__get_collection_list()
Expand Down
2 changes: 1 addition & 1 deletion eodag/rest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def get_stac_collection_by_id(url, root, collection_id, provider=None):
:type collection_id: str
:param provider: (optional) Chosen provider
:type provider: str
:returns: Collection dictionnary
:returns: Collection dictionary
:rtype: dict
"""
return StacCollection(
Expand Down
13 changes: 12 additions & 1 deletion tests/units/test_stac_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,20 @@ def test_get_stac_catalogs(self):

def test_get_stac_collection_by_id(self):
"""get_stac_collection_by_id runs without any error"""
self.rest_utils.get_stac_collection_by_id(
r = self.rest_utils.get_stac_collection_by_id(
url="", root="", collection_id="S2_MSI_L1C"
)
self.assertIsNotNone(r)
self.assertEqual(9, len(r["providers"]))
self.assertEqual(1, r["providers"][0]["priority"])
self.assertEqual("peps", r["providers"][0]["name"])
self.assertEqual(["host"], r["providers"][0]["roles"])
self.assertEqual("https://peps.cnes.fr", r["providers"][0]["url"])
self.assertTrue(
r["providers"][0]["description"].startswith(
'The PEPS platform, the French "mirror site"'
)
)

def test_get_stac_collections(self):
"""get_stac_collections runs without any error"""
Expand Down