Skip to content

Commit

Permalink
fix(server): merge providers from external STAC collection (#1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunato authored May 31, 2024
1 parent 8822525 commit 2c5a0e0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
21 changes: 15 additions & 6 deletions eodag/rest/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def __generate_stac_collection(
# override EODAG's collection with the external collection
ext_stac_collection = self.ext_stac_collections.get(product_type["ID"], {})

# update links
# update links (keep eodag links as defaults)
ext_stac_collection.setdefault("links", {})
for link in product_type_collection["links"]:
ext_stac_collection["links"] = [
Expand All @@ -707,12 +707,21 @@ def __generate_stac_collection(

# merge "keywords" lists
if "keywords" in ext_stac_collection:
ext_stac_collection["keywords"] = list(
set(
ext_stac_collection["keywords"]
+ product_type_collection["keywords"]
try:
ext_stac_collection["keywords"] = list(
set(
ext_stac_collection["keywords"]
+ product_type_collection["keywords"]
)
)
)
except TypeError as e:
logger.warning(
f"Could not merge keywords from external collection for {product_type}: {str(e)}"
)

# merge providers
if "providers" in ext_stac_collection:
ext_stac_collection["providers"] += product_type_collection["providers"]

product_type_collection.update(ext_stac_collection)

Expand Down
7 changes: 7 additions & 0 deletions tests/units/test_stac_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def test_fetch_external_stac_collections(self):
"new_field":"New Value",
"title":"A different title for Sentinel 2 MSI Level 1C",
"keywords":["New Keyword"],
"providers":[{"name":"foo_provider","roles":["producer"]}],
"links":[
{"rel":"self","href":"http://another.self"},
{"rel":"license","href":"http://foo.bar"}
Expand Down Expand Up @@ -292,6 +293,12 @@ def test_fetch_external_stac_collections(self):
links_license = [x for x in stac_coll["links"] if x["rel"] == "license"]
self.assertEqual(links_license[0]["href"], "http://foo.bar")

# Merged providers
self.assertIn(
{"name": "foo_provider", "roles": ["producer"]}, stac_coll["providers"]
)
self.assertGreater(len(stac_coll["providers"]), 1)

# Merged keywords
self.assertListEqual(
["L1", "MSI", "New Keyword", "OPTICAL", "S2A,S2B", "SENTINEL2"],
Expand Down

0 comments on commit 2c5a0e0

Please sign in to comment.