113
113
"id" : {"type" : "keyword" },
114
114
"collection" : {"type" : "keyword" },
115
115
"geometry" : {"type" : "geo_shape" },
116
- "assets" : {"type" : "object" , "enabled" : False },
116
+ "assets" : {"type" : "object" },
117
117
"links" : {"type" : "object" , "enabled" : False },
118
118
"properties" : {
119
119
"type" : "object" ,
@@ -324,9 +324,7 @@ class DatabaseLogic:
324
324
sync_client = SyncElasticsearchSettings ().create_client
325
325
326
326
item_serializer : Type [ItemSerializer ] = attr .ib (default = ItemSerializer )
327
- collection_serializer : Type [CollectionSerializer ] = attr .ib (
328
- default = CollectionSerializer
329
- )
327
+ collection_serializer : Type [CollectionSerializer ] = attr .ib (default = CollectionSerializer )
330
328
331
329
extensions : List [str ] = attr .ib (default = attr .Factory (list ))
332
330
@@ -360,15 +358,9 @@ class DatabaseLogic:
360
358
"size" : 10000 ,
361
359
}
362
360
},
363
- "sun_elevation_frequency" : {
364
- "histogram" : {"field" : "properties.view:sun_elevation" , "interval" : 5 }
365
- },
366
- "sun_azimuth_frequency" : {
367
- "histogram" : {"field" : "properties.view:sun_azimuth" , "interval" : 5 }
368
- },
369
- "off_nadir_frequency" : {
370
- "histogram" : {"field" : "properties.view:off_nadir" , "interval" : 5 }
371
- },
361
+ "sun_elevation_frequency" : {"histogram" : {"field" : "properties.view:sun_elevation" , "interval" : 5 }},
362
+ "sun_azimuth_frequency" : {"histogram" : {"field" : "properties.view:sun_azimuth" , "interval" : 5 }},
363
+ "off_nadir_frequency" : {"histogram" : {"field" : "properties.view:off_nadir" , "interval" : 5 }},
372
364
"centroid_geohash_grid_frequency" : {
373
365
"geohash_grid" : {
374
366
"field" : "properties.proj:centroid" ,
@@ -465,9 +457,7 @@ async def get_one_item(self, collection_id: str, item_id: str) -> Dict:
465
457
id = mk_item_id (item_id , collection_id ),
466
458
)
467
459
except exceptions .NotFoundError :
468
- raise NotFoundError (
469
- f"Item { item_id } does not exist in Collection { collection_id } "
470
- )
460
+ raise NotFoundError (f"Item { item_id } does not exist in Collection { collection_id } " )
471
461
return item ["_source" ]
472
462
473
463
@staticmethod
@@ -497,16 +487,10 @@ def apply_datetime_filter(search: Search, datetime_search):
497
487
Search: The filtered search object.
498
488
"""
499
489
if "eq" in datetime_search :
500
- search = search .filter (
501
- "term" , ** {"properties__datetime" : datetime_search ["eq" ]}
502
- )
490
+ search = search .filter ("term" , ** {"properties__datetime" : datetime_search ["eq" ]})
503
491
else :
504
- search = search .filter (
505
- "range" , properties__datetime = {"lte" : datetime_search ["lte" ]}
506
- )
507
- search = search .filter (
508
- "range" , properties__datetime = {"gte" : datetime_search ["gte" ]}
509
- )
492
+ search = search .filter ("range" , properties__datetime = {"lte" : datetime_search ["lte" ]})
493
+ search = search .filter ("range" , properties__datetime = {"gte" : datetime_search ["gte" ]})
510
494
return search
511
495
512
496
@staticmethod
@@ -600,9 +584,7 @@ def apply_free_text_filter(search: Search, free_text_queries: Optional[List[str]
600
584
"""Database logic to perform query for search endpoint."""
601
585
if free_text_queries is not None :
602
586
free_text_query_string = '" OR properties.\\ *:"' .join (free_text_queries )
603
- search = search .query (
604
- "query_string" , query = f'properties.\\ *:"{ free_text_query_string } "'
605
- )
587
+ search = search .query ("query_string" , query = f'properties.\\ *:"{ free_text_query_string } "' )
606
588
607
589
return search
608
590
@@ -715,11 +697,7 @@ async def execute_search(
715
697
if hits and (sort_array := hits [limit - 1 ].get ("sort" )):
716
698
next_token = urlsafe_b64encode (json .dumps (sort_array ).encode ()).decode ()
717
699
718
- matched = (
719
- es_response ["hits" ]["total" ]["value" ]
720
- if es_response ["hits" ]["total" ]["relation" ] == "eq"
721
- else None
722
- )
700
+ matched = es_response ["hits" ]["total" ]["value" ] if es_response ["hits" ]["total" ]["relation" ] == "eq" else None
723
701
if count_task .done ():
724
702
try :
725
703
matched = count_task .result ().get ("count" )
@@ -799,9 +777,7 @@ async def check_collection_exists(self, collection_id: str):
799
777
if not await self .client .exists (index = COLLECTIONS_INDEX , id = collection_id ):
800
778
raise NotFoundError (f"Collection { collection_id } does not exist" )
801
779
802
- async def prep_create_item (
803
- self , item : Item , base_url : str , exist_ok : bool = False
804
- ) -> Item :
780
+ async def prep_create_item (self , item : Item , base_url : str , exist_ok : bool = False ) -> Item :
805
781
"""
806
782
Preps an item for insertion into the database.
807
783
@@ -823,15 +799,11 @@ async def prep_create_item(
823
799
index = index_alias_by_collection_id (item ["collection" ]),
824
800
id = mk_item_id (item ["id" ], item ["collection" ]),
825
801
):
826
- raise ConflictError (
827
- f"Item { item ['id' ]} in collection { item ['collection' ]} already exists"
828
- )
802
+ raise ConflictError (f"Item { item ['id' ]} in collection { item ['collection' ]} already exists" )
829
803
830
804
return self .item_serializer .stac_to_db (item , base_url )
831
805
832
- def sync_prep_create_item (
833
- self , item : Item , base_url : str , exist_ok : bool = False
834
- ) -> Item :
806
+ def sync_prep_create_item (self , item : Item , base_url : str , exist_ok : bool = False ) -> Item :
835
807
"""
836
808
Prepare an item for insertion into the database.
837
809
@@ -860,9 +832,7 @@ def sync_prep_create_item(
860
832
index = index_alias_by_collection_id (collection_id ),
861
833
id = mk_item_id (item_id , collection_id ),
862
834
):
863
- raise ConflictError (
864
- f"Item { item_id } in collection { collection_id } already exists"
865
- )
835
+ raise ConflictError (f"Item { item_id } in collection { collection_id } already exists" )
866
836
867
837
return self .item_serializer .stac_to_db (item , base_url )
868
838
@@ -890,13 +860,9 @@ async def create_item(self, item: Item, refresh: bool = False):
890
860
)
891
861
892
862
if (meta := es_resp .get ("meta" )) and meta .get ("status" ) == 409 :
893
- raise ConflictError (
894
- f"Item { item_id } in collection { collection_id } already exists"
895
- )
863
+ raise ConflictError (f"Item { item_id } in collection { collection_id } already exists" )
896
864
897
- async def delete_item (
898
- self , item_id : str , collection_id : str , refresh : bool = False
899
- ):
865
+ async def delete_item (self , item_id : str , collection_id : str , refresh : bool = False ):
900
866
"""Delete a single item from the database.
901
867
902
868
Args:
@@ -914,9 +880,7 @@ async def delete_item(
914
880
refresh = refresh ,
915
881
)
916
882
except exceptions .NotFoundError :
917
- raise NotFoundError (
918
- f"Item { item_id } in collection { collection_id } not found"
919
- )
883
+ raise NotFoundError (f"Item { item_id } in collection { collection_id } not found" )
920
884
921
885
async def create_collection (self , collection : Collection , refresh : bool = False ):
922
886
"""Create a single collection in the database.
@@ -963,17 +927,13 @@ async def find_collection(self, collection_id: str) -> Collection:
963
927
collection as a `Collection` object. If the collection is not found, a `NotFoundError` is raised.
964
928
"""
965
929
try :
966
- collection = await self .client .get (
967
- index = COLLECTIONS_INDEX , id = collection_id
968
- )
930
+ collection = await self .client .get (index = COLLECTIONS_INDEX , id = collection_id )
969
931
except exceptions .NotFoundError :
970
932
raise NotFoundError (f"Collection { collection_id } not found" )
971
933
972
934
return collection ["_source" ]
973
935
974
- async def update_collection (
975
- self , collection_id : str , collection : Collection , refresh : bool = False
976
- ):
936
+ async def update_collection (self , collection_id : str , collection : Collection , refresh : bool = False ):
977
937
"""Update a collection from the database.
978
938
979
939
Args:
@@ -1035,14 +995,10 @@ async def delete_collection(self, collection_id: str, refresh: bool = False):
1035
995
function also calls `delete_item_index` to delete the index for the items in the collection.
1036
996
"""
1037
997
await self .find_collection (collection_id = collection_id )
1038
- await self .client .delete (
1039
- index = COLLECTIONS_INDEX , id = collection_id , refresh = refresh
1040
- )
998
+ await self .client .delete (index = COLLECTIONS_INDEX , id = collection_id , refresh = refresh )
1041
999
await delete_item_index (collection_id )
1042
1000
1043
- async def bulk_async (
1044
- self , collection_id : str , processed_items : List [Item ], refresh : bool = False
1045
- ) -> None :
1001
+ async def bulk_async (self , collection_id : str , processed_items : List [Item ], refresh : bool = False ) -> None :
1046
1002
"""Perform a bulk insert of items into the database asynchronously.
1047
1003
1048
1004
Args:
@@ -1064,9 +1020,7 @@ async def bulk_async(
1064
1020
raise_on_error = False ,
1065
1021
)
1066
1022
1067
- def bulk_sync (
1068
- self , collection_id : str , processed_items : List [Item ], refresh : bool = False
1069
- ) -> None :
1023
+ def bulk_sync (self , collection_id : str , processed_items : List [Item ], refresh : bool = False ) -> None :
1070
1024
"""Perform a bulk insert of items into the database synchronously.
1071
1025
1072
1026
Args:
0 commit comments