@@ -85,15 +85,14 @@ class EodagCoreClient(CustomCoreClient):
8585 post_request_model : type [BaseModel ] = attr .ib (default = BaseSearchPostRequest )
8686 stac_metadata_model : type [CommonStacMetadata ] = attr .ib (default = CommonStacMetadata )
8787
88- def _get_collection (
89- self , collection : EodagCollection , request : Request , collections_providers : dict [str , set ]
90- ) -> Collection :
91- """Convert a EODAG produt type to a STAC collection."""
88+ def _format_collection (self , collection : EodagCollection , request : Request ) -> Collection :
89+ """Convert a EODAG STAC collection to a STAC collection for API."""
9290
9391 # keep only federation backends which allow order mechanism
9492 # to create "retrieve" collection links from them
9593 # TODO: this needs to be changed: we cannot request the search plugins for each collection, it is too costly.
96- # TODO: We should find a way to know which federation backends support the order mechanism without requesting the plugins manager
94+ # TODO: We should find a way to know which federation backends support
95+ # the order mechanism without requesting the plugins manager
9796 def has_ecmwf_search_plugin (federation_backends , request ):
9897 for fb in federation_backends :
9998 search_plugins = request .app .state .dag ._plugins_manager .get_search_plugins (provider = fb )
@@ -111,13 +110,20 @@ def has_ecmwf_search_plugin(federation_backends, request):
111110 ):
112111 extension_names .remove ("CollectionOrderExtension" )
113112
114- coll_with_links = collection .model_dump (mode = "json" , exclude = {"alias" , "eodag_stac_collection" })
115- coll_with_links ["links" ] = CollectionLinks (
113+ coll_dict = collection .model_dump (mode = "json" , exclude = {"alias" , "eodag_stac_collection" })
114+ for link in coll_dict ["links" ]:
115+ if link .get ("label:assets" ) is None :
116+ link .pop ("label:assets" )
117+
118+ # add API-required links
119+ all_coll_links = CollectionLinks (
116120 collection_id = collection .id ,
117121 request = request ,
118- ).get_links (extensions = extension_names , extra_links = coll_with_links ["links" ])
122+ ).get_links (extensions = extension_names , extra_links = coll_dict ["links" ])
119123
120- return Collection (** coll_with_links )
124+ # remove eodag-specific fields
125+ coll_dict ["links" ] = all_coll_links
126+ return Collection (** coll_dict )
121127
122128 async def _search_base (self , search_request : BaseSearchPostRequest , request : Request ) -> ItemCollection :
123129 eodag_args = prepare_search_base_args (search_request = search_request , model = self .stac_metadata_model )
@@ -237,7 +243,7 @@ async def all_collections(
237243 limit = limit ,
238244 q = q ,
239245 cql2_json = cql2_json ,
240- sortby = sortby
246+ sortby = sortby ,
241247 )
242248 )
243249
@@ -269,7 +275,8 @@ async def all_collections(
269275
270276 first_link = {"body" : {"limit" : limit , "offset" : 0 }}
271277
272- formatted_collections = [self ._get_collection (coll , request ) for coll in collections ]
278+ # format collections
279+ formatted_collections = [self ._format_collection (coll , request ) for coll in collections ]
273280
274281 extension_names = [type (ext ).__name__ for ext in self .extensions ]
275282
@@ -298,18 +305,14 @@ async def get_collection(self, collection_id: str, request: Request, **kwargs: A
298305 :returns: The collection.
299306 :raises NotFoundError: If the collection does not exist.
300307 """
301- collection = cast (Optional [EodagCollection ], await asyncio .to_thread (request .app .state .dag .get_collection , id = collection_id ))
308+ collection = cast (
309+ Optional [EodagCollection ], await asyncio .to_thread (request .app .state .dag .get_collection , id = collection_id )
310+ )
302311
303312 if collection is None :
304313 raise NotFoundError (f"Collection { collection_id } does not exist." )
305314
306- providers = request .app .state .dag .providers
307- collection_providers : dict [str , set ] = {collection ._id : set ()}
308- for p_name , p in providers .items ():
309- if getattr (p .config , "products" , None ) and collection ._id in p .config .products :
310- collection_providers [collection ._id ].add (p_name )
311-
312- return self ._get_collection (collection , request , collection_providers )
315+ return self ._format_collection (collection , request )
313316
314317 async def item_collection (
315318 self ,
@@ -352,10 +355,11 @@ async def item_collection(
352355 )
353356
354357 search_request = self .post_request_model .model_validate (clean )
355- item_collection = await self ._search_base (search_request , request )
358+ item_collection = cast ( ItemCollection , await self ._search_base (search_request , request ) )
356359 extension_names = [type (ext ).__name__ for ext in self .extensions ]
360+ extra_links = item_collection .get ("links" , [])
357361 links = ItemCollectionLinks (collection_id = collection_id , request = request ).get_links (
358- extensions = extension_names , extra_links = item_collection [ "links" ]
362+ extensions = extension_names , extra_links = extra_links
359363 )
360364 item_collection ["links" ] = links
361365 return item_collection
0 commit comments