-
Notifications
You must be signed in to change notification settings - Fork 40
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 #95 from Materials-Consortia/close_89_add_links
Add /links endpoint
- Loading branch information
Showing
17 changed files
with
1,014 additions
and
176 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,3 @@ index_base_url = http://example.com/optimade/index | |
[structures] | ||
band_gap : | ||
_mp_chemsys : | ||
|
||
[references] |
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# pylint: disable=undefined-variable | ||
from .entries import * | ||
from .links import * | ||
from .references import * | ||
from .structures import * | ||
|
||
__all__ = entries.__all__ + references.__all__ + structures.__all__ # noqa | ||
__all__ = ( | ||
entries.__all__ + links.__all__ + references.__all__ + structures.__all__ # noqa | ||
) |
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,23 @@ | ||
from .entries import ResourceMapper | ||
|
||
__all__ = ("LinksMapper",) | ||
|
||
|
||
class LinksMapper(ResourceMapper): | ||
|
||
ENDPOINT = "links" | ||
|
||
@classmethod | ||
def map_back(cls, doc: dict) -> dict: | ||
"""Map properties from MongoDB to OPTiMaDe | ||
:param doc: A resource object in MongoDB format | ||
:type doc: dict | ||
:return: A resource object in OPTiMaDe format | ||
:rtype: dict | ||
""" | ||
type_ = doc["type"] | ||
newdoc = super().map_back(doc) | ||
newdoc["type"] = type_ | ||
return newdoc |
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 |
---|---|---|
@@ -1,45 +1,8 @@ | ||
from .entries import ResourceMapper | ||
|
||
|
||
__all__ = ("ReferenceMapper",) | ||
|
||
|
||
class ReferenceMapper(ResourceMapper): | ||
|
||
ENDPOINT = "references" | ||
ALIASES = (("id", "task_id"),) | ||
|
||
@classmethod | ||
def map_back(cls, doc: dict) -> dict: | ||
"""Map properties from MongoDB to OPTiMaDe | ||
:param doc: A resource object in MongoDB format | ||
:type doc: dict | ||
:return: A resource object in OPTiMaDe format | ||
:rtype: dict | ||
""" | ||
if "_id" in doc: | ||
del doc["_id"] | ||
# print(doc) | ||
mapping = ((real, alias) for alias, real in cls.all_aliases()) | ||
newdoc = {} | ||
reals = {real for alias, real in cls.all_aliases()} | ||
for k in doc: | ||
if k not in reals: | ||
newdoc[k] = doc[k] | ||
for real, alias in mapping: | ||
if real in doc: | ||
newdoc[alias] = doc[real] | ||
|
||
# print(newdoc) | ||
if "attributes" in newdoc: | ||
raise Exception("Will overwrite doc field!") | ||
newdoc["attributes"] = newdoc.copy() | ||
for k in {"id", "type"}: | ||
newdoc["attributes"].pop(k, None) | ||
for k in list(newdoc.keys()): | ||
if k not in ("id", "attributes"): | ||
del newdoc[k] | ||
newdoc["type"] = cls.ENDPOINT | ||
return newdoc |
Oops, something went wrong.