-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from Materials-Consortia/issue_66_pagination
Minor re-design. Remove the gateway-as-an-OPTIMADE-DB concept. This concept introduced a lot of edge-cases for the base code and in general didn't provide much benefit, other than being able to validate. Responses can still be returned as proper OPTIMADE responses by using the `as_optimade=True` query parameter in the `GET /search` endpoint. Furthermore, this PR represents updates to the code as a result of updates in OPTIMADE Python tools and its public Python API, as well as updated ways of extending the various functional classes. Finally, a more modularized query processing has been introduced. The queries here being the actual gateway queries; preparation, handling, and processing.
- Loading branch information
Showing
52 changed files
with
1,211 additions
and
1,990 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from typing import Iterable, List, Union | ||
|
||
from optimade.models import EntryResource | ||
from optimade.server.mappers.entries import ( | ||
BaseResourceMapper as OptimadeBaseResourceMapper, | ||
) | ||
|
||
|
||
class BaseResourceMapper(OptimadeBaseResourceMapper): | ||
""" | ||
Generic Resource Mapper that defines and performs the mapping | ||
between objects in the database and the resource objects defined by | ||
the specification. | ||
Note: | ||
This is a "wrapped" sub-class to make certain methods asynchronous. | ||
Attributes: | ||
ALIASES: a tuple of aliases between | ||
OPTIMADE field names and the field names in the database , | ||
e.g. `(("elements", "custom_elements_field"))`. | ||
LENGTH_ALIASES: a tuple of aliases between | ||
a field name and another field that defines its length, to be used | ||
when querying, e.g. `(("elements", "nelements"))`. | ||
e.g. `(("elements", "custom_elements_field"))`. | ||
ENTRY_RESOURCE_CLASS: The entry type that this mapper corresponds to. | ||
PROVIDER_FIELDS: a tuple of extra field names that this | ||
mapper should support when querying with the database prefix. | ||
TOP_LEVEL_NON_ATTRIBUTES_FIELDS: the set of top-level | ||
field names common to all endpoints. | ||
SUPPORTED_PREFIXES: The set of prefixes registered by this mapper. | ||
ALL_ATTRIBUTES: The set of attributes defined across the entry | ||
resource class and the server configuration. | ||
ENTRY_RESOURCE_ATTRIBUTES: A dictionary of attributes and their definitions | ||
defined by the schema of the entry resource class. | ||
ENDPOINT: The expected endpoint name for this resource, as defined by | ||
the `type` in the schema of the entry resource class. | ||
""" | ||
|
||
@classmethod | ||
async def deserialize( | ||
cls, results: Union[dict, Iterable[dict]] | ||
) -> Union[List[EntryResource], EntryResource]: | ||
return super(BaseResourceMapper, cls).deserialize(results) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from optimade.models.links import LinksResource | ||
|
||
from optimade_gateway.mappers.base import BaseResourceMapper | ||
|
||
__all__ = ("LinksMapper",) | ||
|
||
|
||
class LinksMapper(BaseResourceMapper): | ||
|
||
ENDPOINT = "links" | ||
ENTRY_RESOURCE_CLASS = LinksResource | ||
|
||
@classmethod | ||
def map_back(cls, doc: dict) -> dict: | ||
type_ = doc.get("type", None) or "links" | ||
newdoc = super().map_back(doc) | ||
newdoc["type"] = type_ | ||
return newdoc |
Oops, something went wrong.