links¶
Replicate of
LinksMapper
in OPTIMADE Python tools.
LinksMapper (BaseResourceMapper)
¶
Replicate of
LinksMapper
in OPTIMADE Python tools.
This is based on the OPTIMADE Gateway
BaseResourceMapper
however.
ENTRY_RESOURCE_CLASS (EntryResource)
pydantic-model
¶
A Links endpoint resource object
map_back(doc)
classmethod
¶
Map properties from MongoDB to OPTIMADE.
Starting from a MongoDB document doc
, map the DB fields to the corresponding OPTIMADE fields.
Then, the fields are all added to the top-level field "attributes",
with the exception of other top-level fields, defined in cls.TOP_LEVEL_NON_ATTRIBUTES_FIELDS
.
All fields not in cls.TOP_LEVEL_NON_ATTRIBUTES_FIELDS
+ "attributes" will be removed.
Finally, the type
is given the value of the specified cls.ENDPOINT
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc |
dict |
A resource object in MongoDB format. |
required |
Returns:
Type | Description |
---|---|
dict |
A resource object in OPTIMADE format. |
Source code in optimade_gateway/mappers/links.py
@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