99import elasticsearch
1010from elasticsearch_dsl import Q , Search
1111from fastapi import HTTPException
12+ from overrides import overrides
1213
1314# from geojson_pydantic.geometries import Polygon
1415from pydantic import ValidationError
2223# from stac_fastapi.elasticsearch.types.error_checks import ErrorChecks
2324from stac_fastapi .types .core import BaseCoreClient
2425from stac_fastapi .types .errors import NotFoundError
25- from stac_fastapi .types .search import BaseSearchPostRequest
2626from stac_fastapi .types .stac import Collection , Collections , Item , ItemCollection
2727
2828logger = logging .getLogger (__name__ )
2929
3030NumType = Union [float , int ]
3131
32+ ITEMS_INDEX = "stac_items"
33+ COLLECTIONS_INDEX = "stac_collections"
34+
3235
3336@attr .s
3437class CoreCrudClient (BaseCoreClient ):
@@ -44,17 +47,13 @@ class CoreCrudClient(BaseCoreClient):
4447 settings = ElasticsearchSettings ()
4548 client = settings .create_client
4649
47- @staticmethod
48- def _lookup_id (id : str , table , session ):
49- """Lookup row by id."""
50- pass
51-
50+ @overrides
5251 def all_collections (self , ** kwargs ) -> Collections :
5352 """Read all collections from the database."""
5453 base_url = str (kwargs ["request" ].base_url )
5554 try :
5655 collections = self .client .search (
57- index = "stac_collections" , doc_type = "_doc" , query = {"match_all" : {}}
56+ index = COLLECTIONS_INDEX , query = {"match_all" : {}}
5857 )
5958 except elasticsearch .exceptions .NotFoundError :
6059 raise NotFoundError ("No collections exist" )
@@ -86,18 +85,20 @@ def all_collections(self, **kwargs) -> Collections:
8685 )
8786 return collection_list
8887
88+ @overrides
8989 def get_collection (self , collection_id : str , ** kwargs ) -> Collection :
9090 """Get collection by id."""
9191 base_url = str (kwargs ["request" ].base_url )
9292 try :
93- collection = self .client .get (index = "stac_collections" , id = collection_id )
93+ collection = self .client .get (index = COLLECTIONS_INDEX , id = collection_id )
9494 except elasticsearch .exceptions .NotFoundError :
9595 raise NotFoundError (f"Collection { collection_id } not found" )
9696
9797 return self .collection_serializer .db_to_stac (collection ["_source" ], base_url )
9898
99+ @overrides
99100 def item_collection (
100- self , collection_id : str , limit : int = 10 , ** kwargs
101+ self , collection_id : str , limit : int = 10 , token : str = None , ** kwargs
101102 ) -> ItemCollection :
102103 """Read an item collection from the database."""
103104 links = []
@@ -136,11 +137,12 @@ def item_collection(
136137 context = context_obj ,
137138 )
138139
140+ @overrides
139141 def get_item (self , item_id : str , collection_id : str , ** kwargs ) -> Item :
140142 """Get item by item id, collection id."""
141143 base_url = str (kwargs ["request" ].base_url )
142144 try :
143- item = self .client .get (index = "stac_items" , id = item_id )
145+ item = self .client .get (index = ITEMS_INDEX , id = item_id )
144146 except elasticsearch .exceptions .NotFoundError :
145147 raise NotFoundError (
146148 f"Item { item_id } does not exist in Collection { collection_id } "
@@ -171,6 +173,7 @@ def _return_date(interval_str):
171173
172174 return {"lte" : end_date , "gte" : start_date }
173175
176+ @overrides
174177 def get_search (
175178 self ,
176179 collections : Optional [List [str ]] = None ,
@@ -234,15 +237,13 @@ def bbox2poly(b0, b1, b2, b3):
234237 poly = [[[b0 , b1 ], [b2 , b1 ], [b2 , b3 ], [b0 , b3 ], [b0 , b1 ]]]
235238 return poly
236239
237- def post_search (
238- self , search_request : BaseSearchPostRequest , ** kwargs
239- ) -> ItemCollection :
240+ def post_search (self , search_request : Search , ** kwargs ) -> ItemCollection :
240241 """POST search catalog."""
241242 base_url = str (kwargs ["request" ].base_url )
242243 search = (
243244 Search ()
244245 .using (self .client )
245- .index ("stac_items" )
246+ .index (ITEMS_INDEX )
246247 .sort (
247248 {"properties.datetime" : {"order" : "desc" }},
248249 {"id" : {"order" : "desc" }},
0 commit comments