From 48585badbf4beabfc19983fe1d1dcf0af3e1c156 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 27 May 2024 16:53:39 -0400 Subject: [PATCH 1/7] landing page queryable link --- stac_fastapi/core/stac_fastapi/core/core.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/stac_fastapi/core/stac_fastapi/core/core.py b/stac_fastapi/core/stac_fastapi/core/core.py index 5469bf10..9cf9d4ec 100644 --- a/stac_fastapi/core/stac_fastapi/core/core.py +++ b/stac_fastapi/core/stac_fastapi/core/core.py @@ -153,6 +153,19 @@ async def landing_page(self, **kwargs) -> stac_types.LandingPage: conformance_classes=self.conformance_classes(), extension_schemas=[], ) + + if self.extension_is_enabled("FilterExtension"): + landing_page["links"].append( + { + # TODO: replace this with Relations.queryables.value, + "rel": "http://www.opengis.net/def/rel/ogc/1.0/queryables", + # TODO: replace this with MimeTypes.jsonschema, + "type": "application/schema+json", + "title": "Queryables", + "href": urljoin(base_url, "queryables") + } + ) + collections = await self.all_collections(request=kwargs["request"]) for collection in collections["collections"]: landing_page["links"].append( From 67c0f347d97413b23a7bb5966cba34cad0b250ad Mon Sep 17 00:00:00 2001 From: James Date: Tue, 28 May 2024 13:45:12 -0400 Subject: [PATCH 2/7] landing page link test --- stac_fastapi/core/stac_fastapi/core/core.py | 2 +- stac_fastapi/tests/extensions/test_filter.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/stac_fastapi/core/stac_fastapi/core/core.py b/stac_fastapi/core/stac_fastapi/core/core.py index 9cf9d4ec..bd9d1d2d 100644 --- a/stac_fastapi/core/stac_fastapi/core/core.py +++ b/stac_fastapi/core/stac_fastapi/core/core.py @@ -158,7 +158,7 @@ async def landing_page(self, **kwargs) -> stac_types.LandingPage: landing_page["links"].append( { # TODO: replace this with Relations.queryables.value, - "rel": "http://www.opengis.net/def/rel/ogc/1.0/queryables", + "rel": "queryables", # TODO: replace this with MimeTypes.jsonschema, "type": "application/schema+json", "title": "Queryables", diff --git a/stac_fastapi/tests/extensions/test_filter.py b/stac_fastapi/tests/extensions/test_filter.py index edff5c1a..32f7e4a4 100644 --- a/stac_fastapi/tests/extensions/test_filter.py +++ b/stac_fastapi/tests/extensions/test_filter.py @@ -8,6 +8,17 @@ THIS_DIR = os.path.dirname(os.path.abspath(__file__)) +@pytest.mark.asyncio +async def test_filter_extension_landing_page_link(app_client, ctx): + resp = await app_client.get( + "/" + ) + assert resp.status_code == 200 + resp_json = resp.json() + keys = [link["rel"] for link in resp_json["links"]] + assert "queryables" in keys + + @pytest.mark.asyncio async def test_search_filters_post(app_client, ctx): From 64adf74f04cf9aff1d6a724a5756b427eb242f7a Mon Sep 17 00:00:00 2001 From: James Date: Wed, 29 May 2024 18:50:46 -0400 Subject: [PATCH 3/7] collection db_to_stac input request --- stac_fastapi/core/stac_fastapi/core/core.py | 18 ++++++------- .../core/stac_fastapi/core/models/links.py | 26 +++++++++++++++++++ .../core/stac_fastapi/core/serializers.py | 10 ++++--- .../stac_fastapi/opensearch/database_logic.py | 5 ++-- stac_fastapi/tests/conftest.py | 1 + 5 files changed, 45 insertions(+), 15 deletions(-) diff --git a/stac_fastapi/core/stac_fastapi/core/core.py b/stac_fastapi/core/stac_fastapi/core/core.py index bd9d1d2d..ab534ff6 100644 --- a/stac_fastapi/core/stac_fastapi/core/core.py +++ b/stac_fastapi/core/stac_fastapi/core/core.py @@ -218,7 +218,7 @@ async def all_collections(self, **kwargs) -> stac_types.Collections: token = request.query_params.get("token") collections, next_token = await self.database.get_all_collections( - token=token, limit=limit, base_url=base_url + token=token, limit=limit, request=request ) links = [ @@ -252,10 +252,10 @@ async def get_collection( Raises: NotFoundError: If the collection with the given id cannot be found in the database. """ - base_url = str(kwargs["request"].base_url) + request = kwargs["request"] collection = await self.database.find_collection(collection_id=collection_id) return self.collection_serializer.db_to_stac( - collection=collection, base_url=base_url + collection=collection, request=request ) async def item_collection( @@ -761,12 +761,12 @@ async def create_collection( ConflictError: If the collection already exists. """ collection = collection.model_dump(mode="json") - base_url = str(kwargs["request"].base_url) + request = kwargs["request"] collection = self.database.collection_serializer.stac_to_db( - collection, base_url + collection, request ) await self.database.create_collection(collection=collection) - return CollectionSerializer.db_to_stac(collection, base_url) + return CollectionSerializer.db_to_stac(collection, request) @overrides async def update_collection( @@ -793,16 +793,16 @@ async def update_collection( """ collection = collection.model_dump(mode="json") - base_url = str(kwargs["request"].base_url) + request = kwargs["request"] collection = self.database.collection_serializer.stac_to_db( - collection, base_url + collection, request ) await self.database.update_collection( collection_id=collection_id, collection=collection ) - return CollectionSerializer.db_to_stac(collection, base_url) + return CollectionSerializer.db_to_stac(collection, request) @overrides async def delete_collection( diff --git a/stac_fastapi/core/stac_fastapi/core/models/links.py b/stac_fastapi/core/stac_fastapi/core/models/links.py index 725dc5c0..14c37d58 100644 --- a/stac_fastapi/core/stac_fastapi/core/models/links.py +++ b/stac_fastapi/core/stac_fastapi/core/models/links.py @@ -105,6 +105,32 @@ async def get_links( ] return links + +@attr.s +class CollectionLinks(BaseLinks): + """Create inferred links specific to collections.""" + + collection_id: str = attr.ib() + + def link_parent(self) -> Dict[str, Any]: + """Create the `parent` link.""" + return dict(rel=Relations.parent, type=MimeTypes.json.value, href=self.base_url) + + def link_items(self) -> Dict[str, Any]: + """Create the `items` link.""" + return dict( + rel="items", + type=MimeTypes.geojson.value, + href=urljoin(self.base_url, f"collections/{self.collection_id}/items"), + ) + + def link_queryables(self) -> Dict[str, Any]: + """create the `queryables` link.""" + return dict( + rel="queryables", + type=MimeTypes.json.value, + href=urljoin(self.base_url, f"collections/{self.collection_id}/quaryables"), + ) @attr.s diff --git a/stac_fastapi/core/stac_fastapi/core/serializers.py b/stac_fastapi/core/stac_fastapi/core/serializers.py index ba588025..4aba53f2 100644 --- a/stac_fastapi/core/stac_fastapi/core/serializers.py +++ b/stac_fastapi/core/stac_fastapi/core/serializers.py @@ -7,7 +7,9 @@ from stac_fastapi.core.datetime_utils import now_to_rfc3339_str from stac_fastapi.types import stac as stac_types -from stac_fastapi.types.links import CollectionLinks, ItemLinks, resolve_links +from stac_fastapi.core.models.links import CollectionLinks +from stac_fastapi.types.links import ItemLinks, resolve_links +from starlette.requests import Request @attr.s @@ -126,7 +128,7 @@ def stac_to_db( return collection @classmethod - def db_to_stac(cls, collection: dict, base_url: str) -> stac_types.Collection: + def db_to_stac(cls, collection: dict, request: Request) -> stac_types.Collection: """Transform database model to STAC collection. Args: @@ -157,13 +159,13 @@ def db_to_stac(cls, collection: dict, base_url: str) -> stac_types.Collection: # Create the collection links using CollectionLinks collection_links = CollectionLinks( - collection_id=collection_id, base_url=base_url + collection_id=collection_id, request=request ).create_links() # Add any additional links from the collection dictionary original_links = collection.get("links") if original_links: - collection_links += resolve_links(original_links, base_url) + collection_links += resolve_links(original_links, str(request.base_url)) collection["links"] = collection_links # Return the stac_types.Collection object diff --git a/stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py b/stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py index 5a320d8f..933ffc59 100644 --- a/stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py +++ b/stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py @@ -20,6 +20,7 @@ from stac_fastapi.opensearch.config import OpensearchSettings as SyncSearchSettings from stac_fastapi.types.errors import ConflictError, NotFoundError from stac_fastapi.types.stac import Collection, Item +from starlette.requests import Request logger = logging.getLogger(__name__) @@ -336,7 +337,7 @@ class DatabaseLogic: """CORE LOGIC""" async def get_all_collections( - self, token: Optional[str], limit: int, base_url: str + self, token: Optional[str], limit: int, request: Request ) -> Tuple[List[Dict[str, Any]], Optional[str]]: """ Retrieve a list of all collections from Opensearch, supporting pagination. @@ -366,7 +367,7 @@ async def get_all_collections( hits = response["hits"]["hits"] collections = [ self.collection_serializer.db_to_stac( - collection=hit["_source"], base_url=base_url + collection=hit["_source"], request=request ) for hit in hits ] diff --git a/stac_fastapi/tests/conftest.py b/stac_fastapi/tests/conftest.py index 21380494..619a257c 100644 --- a/stac_fastapi/tests/conftest.py +++ b/stac_fastapi/tests/conftest.py @@ -58,6 +58,7 @@ def __init__(self, item, collection): class MockRequest: base_url = "http://test-server" + url = "http://test-server/test" query_params = {} def __init__( From b9656d0f6331b0958c869cebca903e2c03aa2c0a Mon Sep 17 00:00:00 2001 From: James Date: Sun, 2 Jun 2024 05:56:43 -0400 Subject: [PATCH 4/7] Landing page and collection links --- stac_fastapi/core/stac_fastapi/core/core.py | 12 ++++------ .../core/stac_fastapi/core/models/links.py | 5 ++-- .../core/stac_fastapi/core/serializers.py | 14 ++++++----- .../elasticsearch/database_logic.py | 5 ++-- .../stac_fastapi/opensearch/database_logic.py | 2 +- stac_fastapi/tests/extensions/test_filter.py | 24 ++++++++++++++++--- 6 files changed, 40 insertions(+), 22 deletions(-) diff --git a/stac_fastapi/core/stac_fastapi/core/core.py b/stac_fastapi/core/stac_fastapi/core/core.py index ab534ff6..01f4c67f 100644 --- a/stac_fastapi/core/stac_fastapi/core/core.py +++ b/stac_fastapi/core/stac_fastapi/core/core.py @@ -162,10 +162,10 @@ async def landing_page(self, **kwargs) -> stac_types.LandingPage: # TODO: replace this with MimeTypes.jsonschema, "type": "application/schema+json", "title": "Queryables", - "href": urljoin(base_url, "queryables") + "href": urljoin(base_url, "queryables"), } ) - + collections = await self.all_collections(request=kwargs["request"]) for collection in collections["collections"]: landing_page["links"].append( @@ -762,9 +762,7 @@ async def create_collection( """ collection = collection.model_dump(mode="json") request = kwargs["request"] - collection = self.database.collection_serializer.stac_to_db( - collection, request - ) + collection = self.database.collection_serializer.stac_to_db(collection, request) await self.database.create_collection(collection=collection) return CollectionSerializer.db_to_stac(collection, request) @@ -795,9 +793,7 @@ async def update_collection( request = kwargs["request"] - collection = self.database.collection_serializer.stac_to_db( - collection, request - ) + collection = self.database.collection_serializer.stac_to_db(collection, request) await self.database.update_collection( collection_id=collection_id, collection=collection ) diff --git a/stac_fastapi/core/stac_fastapi/core/models/links.py b/stac_fastapi/core/stac_fastapi/core/models/links.py index 14c37d58..9d9841bb 100644 --- a/stac_fastapi/core/stac_fastapi/core/models/links.py +++ b/stac_fastapi/core/stac_fastapi/core/models/links.py @@ -105,7 +105,8 @@ async def get_links( ] return links - + + @attr.s class CollectionLinks(BaseLinks): """Create inferred links specific to collections.""" @@ -125,7 +126,7 @@ def link_items(self) -> Dict[str, Any]: ) def link_queryables(self) -> Dict[str, Any]: - """create the `queryables` link.""" + """Create the `queryables` link.""" return dict( rel="queryables", type=MimeTypes.json.value, diff --git a/stac_fastapi/core/stac_fastapi/core/serializers.py b/stac_fastapi/core/stac_fastapi/core/serializers.py index 4aba53f2..47d01f47 100644 --- a/stac_fastapi/core/stac_fastapi/core/serializers.py +++ b/stac_fastapi/core/stac_fastapi/core/serializers.py @@ -4,12 +4,12 @@ from typing import Any import attr +from starlette.requests import Request from stac_fastapi.core.datetime_utils import now_to_rfc3339_str -from stac_fastapi.types import stac as stac_types from stac_fastapi.core.models.links import CollectionLinks +from stac_fastapi.types import stac as stac_types from stac_fastapi.types.links import ItemLinks, resolve_links -from starlette.requests import Request @attr.s @@ -111,20 +111,22 @@ class CollectionSerializer(Serializer): @classmethod def stac_to_db( - cls, collection: stac_types.Collection, base_url: str + cls, collection: stac_types.Collection, request: Request ) -> stac_types.Collection: """ Transform STAC Collection to database-ready STAC collection. Args: stac_data: the STAC Collection object to be transformed - base_url: the base URL for the STAC API + starlette.requests.Request: the API request Returns: stac_types.Collection: The database-ready STAC Collection object. """ collection = deepcopy(collection) - collection["links"] = resolve_links(collection.get("links", []), base_url) + collection["links"] = resolve_links( + collection.get("links", []), str(request.base_url) + ) return collection @classmethod @@ -133,7 +135,7 @@ def db_to_stac(cls, collection: dict, request: Request) -> stac_types.Collection Args: collection (dict): The collection data in dictionary form, extracted from the database. - base_url (str): The base URL for the collection. + bstarlette.requests.Request: the API request Returns: stac_types.Collection: The STAC collection object. diff --git a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py index ddb6648b..8225854b 100644 --- a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py +++ b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py @@ -7,6 +7,7 @@ import attr from elasticsearch_dsl import Q, Search +from starlette.requests import Request from elasticsearch import exceptions, helpers # type: ignore from stac_fastapi.core.extensions import filter @@ -315,7 +316,7 @@ class DatabaseLogic: """CORE LOGIC""" async def get_all_collections( - self, token: Optional[str], limit: int, base_url: str + self, token: Optional[str], limit: int, request: Request ) -> Tuple[List[Dict[str, Any]], Optional[str]]: """Retrieve a list of all collections from Elasticsearch, supporting pagination. @@ -342,7 +343,7 @@ async def get_all_collections( hits = response["hits"]["hits"] collections = [ self.collection_serializer.db_to_stac( - collection=hit["_source"], base_url=base_url + collection=hit["_source"], request=request ) for hit in hits ] diff --git a/stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py b/stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py index 933ffc59..db089f92 100644 --- a/stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py +++ b/stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py @@ -10,6 +10,7 @@ from opensearchpy.exceptions import TransportError from opensearchpy.helpers.query import Q from opensearchpy.helpers.search import Search +from starlette.requests import Request from stac_fastapi.core import serializers from stac_fastapi.core.extensions import filter @@ -20,7 +21,6 @@ from stac_fastapi.opensearch.config import OpensearchSettings as SyncSearchSettings from stac_fastapi.types.errors import ConflictError, NotFoundError from stac_fastapi.types.stac import Collection, Item -from starlette.requests import Request logger = logging.getLogger(__name__) diff --git a/stac_fastapi/tests/extensions/test_filter.py b/stac_fastapi/tests/extensions/test_filter.py index 32f7e4a4..8f4fa5ee 100644 --- a/stac_fastapi/tests/extensions/test_filter.py +++ b/stac_fastapi/tests/extensions/test_filter.py @@ -10,15 +10,33 @@ @pytest.mark.asyncio async def test_filter_extension_landing_page_link(app_client, ctx): - resp = await app_client.get( - "/" - ) + resp = await app_client.get("/") assert resp.status_code == 200 + resp_json = resp.json() keys = [link["rel"] for link in resp_json["links"]] + assert "queryables" in keys +@pytest.mark.asyncio +async def test_filter_extension_collection_link(app_client, load_test_data): + """Test creation and deletion of a collection""" + test_collection = load_test_data("test_collection.json") + test_collection["id"] = "test" + + resp = await app_client.post("/collections", json=test_collection) + assert resp.status_code == 201 + + resp = await app_client.get(f"/collections/{test_collection['id']}") + resp_json = resp.json() + keys = [link["rel"] for link in resp_json["links"]] + assert "queryables" in keys + + resp = await app_client.delete(f"/collections/{test_collection['id']}") + assert resp.status_code == 204 + + @pytest.mark.asyncio async def test_search_filters_post(app_client, ctx): From 9e59aca6adc52380671c8d66b712b8e3758a128c Mon Sep 17 00:00:00 2001 From: James Date: Sun, 2 Jun 2024 16:34:54 -0400 Subject: [PATCH 5/7] add condition for filter extension not-enabled --- data_loader.py | 7 ++++++- sample_data/collection.json | 1 + stac_fastapi/core/stac_fastapi/core/core.py | 16 +++++++++++++--- .../core/stac_fastapi/core/models/links.py | 16 +++++++++++----- .../core/stac_fastapi/core/serializers.py | 8 +++++--- .../stac_fastapi/elasticsearch/database_logic.py | 4 +++- .../opensearch/stac_fastapi/opensearch/app.py | 2 ++ .../stac_fastapi/opensearch/database_logic.py | 4 +++- 8 files changed, 44 insertions(+), 14 deletions(-) diff --git a/data_loader.py b/data_loader.py index 1cccffd5..7d157e40 100644 --- a/data_loader.py +++ b/data_loader.py @@ -22,12 +22,17 @@ def load_collection(base_url, collection_id, data_dir): collection["id"] = collection_id try: resp = requests.post(f"{base_url}/collections", json=collection) - if resp.status_code == 200: + if resp.status_code == 200 or resp.status_code == 201: click.echo(f"Status code: {resp.status_code}") click.echo(f"Added collection: {collection['id']}") elif resp.status_code == 409: click.echo(f"Status code: {resp.status_code}") click.echo(f"Collection: {collection['id']} already exists") + else: + click.echo(f"Status code: {resp.status_code}") + click.echo( + f"Error writing {collection['id']} collection. Message: {resp.text}" + ) except requests.ConnectionError: click.secho("Failed to connect", fg="red", err=True) diff --git a/sample_data/collection.json b/sample_data/collection.json index dd68234d..bafd3ea2 100644 --- a/sample_data/collection.json +++ b/sample_data/collection.json @@ -1,6 +1,7 @@ { "id":"sentinel-s2-l2a-cogs-test", "stac_version":"1.0.0", + "type": "Collection", "description":"Sentinel-2a and Sentinel-2b imagery, processed to Level 2A (Surface Reflectance) and converted to Cloud-Optimized GeoTIFFs", "links":[ {"rel":"self","href":"https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs"}, diff --git a/stac_fastapi/core/stac_fastapi/core/core.py b/stac_fastapi/core/stac_fastapi/core/core.py index 01f4c67f..984b2e0a 100644 --- a/stac_fastapi/core/stac_fastapi/core/core.py +++ b/stac_fastapi/core/stac_fastapi/core/core.py @@ -255,7 +255,9 @@ async def get_collection( request = kwargs["request"] collection = await self.database.find_collection(collection_id=collection_id) return self.collection_serializer.db_to_stac( - collection=collection, request=request + collection=collection, + request=request, + extensions=[type(ext).__name__ for ext in self.extensions], ) async def item_collection( @@ -764,7 +766,11 @@ async def create_collection( request = kwargs["request"] collection = self.database.collection_serializer.stac_to_db(collection, request) await self.database.create_collection(collection=collection) - return CollectionSerializer.db_to_stac(collection, request) + return CollectionSerializer.db_to_stac( + collection, + request, + extensions=[type(ext).__name__ for ext in self.database.extensions], + ) @overrides async def update_collection( @@ -798,7 +804,11 @@ async def update_collection( collection_id=collection_id, collection=collection ) - return CollectionSerializer.db_to_stac(collection, request) + return CollectionSerializer.db_to_stac( + collection, + request, + extensions=[type(ext).__name__ for ext in self.database.extensions], + ) @overrides async def delete_collection( diff --git a/stac_fastapi/core/stac_fastapi/core/models/links.py b/stac_fastapi/core/stac_fastapi/core/models/links.py index 9d9841bb..7a12b1c4 100644 --- a/stac_fastapi/core/stac_fastapi/core/models/links.py +++ b/stac_fastapi/core/stac_fastapi/core/models/links.py @@ -112,6 +112,7 @@ class CollectionLinks(BaseLinks): """Create inferred links specific to collections.""" collection_id: str = attr.ib() + extensions: List[str] = attr.ib(default=attr.Factory(list)) def link_parent(self) -> Dict[str, Any]: """Create the `parent` link.""" @@ -127,11 +128,16 @@ def link_items(self) -> Dict[str, Any]: def link_queryables(self) -> Dict[str, Any]: """Create the `queryables` link.""" - return dict( - rel="queryables", - type=MimeTypes.json.value, - href=urljoin(self.base_url, f"collections/{self.collection_id}/quaryables"), - ) + if "FilterExtension" in self.extensions: + return dict( + rel="queryables", + type=MimeTypes.json.value, + href=urljoin( + self.base_url, f"collections/{self.collection_id}/queryables" + ), + ) + else: + return None @attr.s diff --git a/stac_fastapi/core/stac_fastapi/core/serializers.py b/stac_fastapi/core/stac_fastapi/core/serializers.py index 47d01f47..c78501fe 100644 --- a/stac_fastapi/core/stac_fastapi/core/serializers.py +++ b/stac_fastapi/core/stac_fastapi/core/serializers.py @@ -1,7 +1,7 @@ """Serializers.""" import abc from copy import deepcopy -from typing import Any +from typing import Any, List, Optional import attr from starlette.requests import Request @@ -130,7 +130,9 @@ def stac_to_db( return collection @classmethod - def db_to_stac(cls, collection: dict, request: Request) -> stac_types.Collection: + def db_to_stac( + cls, collection: dict, request: Request, extensions: Optional[List[str]] = [] + ) -> stac_types.Collection: """Transform database model to STAC collection. Args: @@ -161,7 +163,7 @@ def db_to_stac(cls, collection: dict, request: Request) -> stac_types.Collection # Create the collection links using CollectionLinks collection_links = CollectionLinks( - collection_id=collection_id, request=request + collection_id=collection_id, request=request, extensions=extensions ).create_links() # Add any additional links from the collection dictionary diff --git a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py index 8225854b..a4b40325 100644 --- a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py +++ b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py @@ -313,6 +313,8 @@ class DatabaseLogic: default=CollectionSerializer ) + extensions: List[str] = attr.ib(default=attr.Factory(list)) + """CORE LOGIC""" async def get_all_collections( @@ -343,7 +345,7 @@ async def get_all_collections( hits = response["hits"]["hits"] collections = [ self.collection_serializer.db_to_stac( - collection=hit["_source"], request=request + collection=hit["_source"], request=request, extensions=self.extensions ) for hit in hits ] diff --git a/stac_fastapi/opensearch/stac_fastapi/opensearch/app.py b/stac_fastapi/opensearch/stac_fastapi/opensearch/app.py index 4cd38c20..d06b0f29 100644 --- a/stac_fastapi/opensearch/stac_fastapi/opensearch/app.py +++ b/stac_fastapi/opensearch/stac_fastapi/opensearch/app.py @@ -59,6 +59,8 @@ filter_extension, ] +database_logic.extensions = [type(ext).__name__ for ext in extensions] + post_request_model = create_post_request_model(extensions) api = StacApi( diff --git a/stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py b/stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py index db089f92..841d5e27 100644 --- a/stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py +++ b/stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py @@ -334,6 +334,8 @@ class DatabaseLogic: default=serializers.CollectionSerializer ) + extensions: List[str] = attr.ib(default=attr.Factory(list)) + """CORE LOGIC""" async def get_all_collections( @@ -367,7 +369,7 @@ async def get_all_collections( hits = response["hits"]["hits"] collections = [ self.collection_serializer.db_to_stac( - collection=hit["_source"], request=request + collection=hit["_source"], request=request, extensions=self.extensions ) for hit in hits ] From ac232ef5588b321a49312c7af79c8b3ffc553966 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 2 Jun 2024 16:48:53 -0400 Subject: [PATCH 6/7] cleanup --- stac_fastapi/core/stac_fastapi/core/serializers.py | 3 ++- stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/stac_fastapi/core/stac_fastapi/core/serializers.py b/stac_fastapi/core/stac_fastapi/core/serializers.py index c78501fe..9b0d36d4 100644 --- a/stac_fastapi/core/stac_fastapi/core/serializers.py +++ b/stac_fastapi/core/stac_fastapi/core/serializers.py @@ -137,7 +137,8 @@ def db_to_stac( Args: collection (dict): The collection data in dictionary form, extracted from the database. - bstarlette.requests.Request: the API request + starlette.requests.Request: the API request + extensions: A list of the extension class names (`ext.__name__`) or all enabled STAC API extensions. Returns: stac_types.Collection: The STAC collection object. diff --git a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py index c0d4aaea..6a5ee006 100644 --- a/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py +++ b/stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py @@ -59,6 +59,8 @@ filter_extension, ] +database_logic.extensions = [type(ext).__name__ for ext in extensions] + post_request_model = create_post_request_model(extensions) api = StacApi( From ace6649469fb268d5a6efd5ae28f703e77c6ced8 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 3 Jun 2024 03:06:45 -0400 Subject: [PATCH 7/7] changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c763b4aa..c1a4829f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added + - Queryables landing page and collection links when the Filter Extension is enabled [#267](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/267) + ## [v3.0.0a1] ### Changed