Skip to content

rs_server_common/stac_sortables.md

<< Back to index

Sortables extension for RS-Server.

RSSortablesClient

Bases: BaseSortablesClient

Sortables exposed by RS-Server.

Source code in docs/rs-server/services/common/rs_server_common/stac_sortables.py
class RSSortablesClient(BaseSortablesClient):
    """Sortables exposed by RS-Server."""

    SCHEMA_URL = "https://json-schema.org/draft/2020-12/schema"
    SCHEMA_TITLE = "Sortables"
    SORTABLES_BASE_URL = "https://example.org"

    COMMON_PROPERTIES = {
        "id": {
            "title": "Identifier",
            "type": "string",
        },
        "file:size": {
            "title": "File size",
            "type": "number",
        },
        "type": {
            "title": "Type",
            "type": "string",
        },
        "eviction_datetime": {
            "title": "Eviction datetime",
            "type": "string",
            "format": "date-time",
        },
        "created": {
            "title": "Created",
            "type": "string",
            "format": "date-time",
        },
        "start_datetime": {
            "title": "Start datetime",
            "type": "string",
            "format": "date-time",
        },
        "end_datetime": {
            "title": "End datetime",
            "type": "string",
            "format": "date-time",
        },
    }

    PROPERTIES = {
        "cadip": {
            "id": {
                "title": "Identifier",
                "type": "string",
            },
            "datetime": {
                "title": "Datetime",
                "type": "string",
                "format": "date-time",
            },
            "published": {
                "title": "Published",
                "type": "string",
                "format": "date-time",
            },
        },
        "auxip": {
            **COMMON_PROPERTIES,
        },
        "prip": {
            **COMMON_PROPERTIES,
            "published": {
                "title": "Published",
                "type": "string",
                "format": "date-time",
            },
        },
    }

    def __init__(self, router_prefix: str):
        self.router_prefix = router_prefix.strip("/")

    def _build_schema(self, path: str) -> dict[str, Any]:
        """Build a Sortables JSON Schema."""
        return {
            "$id": f"{self.SORTABLES_BASE_URL}/{path}",
            "$schema": self.SCHEMA_URL,
            "type": "object",
            "title": self.SCHEMA_TITLE,
            "properties": self.PROPERTIES.get(self.router_prefix, {}),
        }

    # pylint: disable = unused-argument
    def get_sortables(
        self,
        request=None,
        **kwargs: Any,
    ) -> dict[str, Any]:
        """Return sortables for the /search endpoint."""
        return self._build_schema(
            f"{self.router_prefix}/sortables",
        )

    # pylint: disable = unused-argument
    def get_collection_sortables(
        self,
        collection_id: str,
        request=None,
        **kwargs: Any,
    ) -> dict[str, Any]:
        """Return sortables for the /collections/{collection_id}/items endpoint."""
        return self._build_schema(
            f"{self.router_prefix}/collections/{collection_id}/sortables",
        )

get_collection_sortables(collection_id, request=None, **kwargs)

Return sortables for the /collections/{collection_id}/items endpoint.

Source code in docs/rs-server/services/common/rs_server_common/stac_sortables.py
def get_collection_sortables(
    self,
    collection_id: str,
    request=None,
    **kwargs: Any,
) -> dict[str, Any]:
    """Return sortables for the /collections/{collection_id}/items endpoint."""
    return self._build_schema(
        f"{self.router_prefix}/collections/{collection_id}/sortables",
    )

get_sortables(request=None, **kwargs)

Return sortables for the /search endpoint.

Source code in docs/rs-server/services/common/rs_server_common/stac_sortables.py
def get_sortables(
    self,
    request=None,
    **kwargs: Any,
) -> dict[str, Any]:
    """Return sortables for the /search endpoint."""
    return self._build_schema(
        f"{self.router_prefix}/sortables",
    )