Skip to content

Commit

Permalink
API update
Browse files Browse the repository at this point in the history
  • Loading branch information
sdRDM Bot authored and sdRDM Bot committed May 13, 2024
1 parent b4e182c commit da3f3fa
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 91 deletions.
3 changes: 1 addition & 2 deletions FAIRDaRUS/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from .tools import DaRUS_upload

__URL__ = "https://github.com/FAIRChemistry/FAIRDaRUS"
__COMMIT__ = "65a354f35f9dd007471dce7138d159343f49cad5"
__COMMIT__ = "b4e182c6ea23841a0256d49c102fb1f1ff0530d9"
28 changes: 19 additions & 9 deletions FAIRDaRUS/core/author.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import sdRDM

from typing import Optional
from pydantic import PrivateAttr
from typing import Dict, Optional
from pydantic import PrivateAttr, model_validator
from uuid import uuid4
from pydantic_xml import attr, element
from lxml.etree import _Element
from sdRDM.base.listplus import ListPlus
from sdRDM.base.utils import forge_signature
from sdRDM.tools.utils import elem2dict


@forge_signature
class Author(
sdRDM.DataModel,
nsmap={
"": "https://github.com/FAIRChemistry/FAIRDaRUS@65a354f35f9dd007471dce7138d159343f49cad5#Author"
},
):
class Author(sdRDM.DataModel, search_mode="unordered"):
""""""

id: Optional[str] = attr(
Expand Down Expand Up @@ -57,5 +55,17 @@ class Author(
default="https://github.com/FAIRChemistry/FAIRDaRUS"
)
_commit: Optional[str] = PrivateAttr(
default="65a354f35f9dd007471dce7138d159343f49cad5"
default="b4e182c6ea23841a0256d49c102fb1f1ff0530d9"
)
_raw_xml_data: Dict = PrivateAttr(default_factory=dict)

@model_validator(mode="after")
def _parse_raw_xml_data(self):
for attr, value in self:
if isinstance(value, (ListPlus, list)) and all(
(isinstance(i, _Element) for i in value)
):
self._raw_xml_data[attr] = [elem2dict(i) for i in value]
elif isinstance(value, _Element):
self._raw_xml_data[attr] = elem2dict(value)
return self
113 changes: 60 additions & 53 deletions FAIRDaRUS/core/citation.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import sdRDM

from typing import List, Optional
from pydantic import PrivateAttr
from typing import Dict, List, Optional
from pydantic import PrivateAttr, model_validator
from uuid import uuid4
from pydantic_xml import attr, element, wrapped
from pydantic_xml import attr, element
from lxml.etree import _Element
from sdRDM.base.listplus import ListPlus
from sdRDM.base.utils import forge_signature
from sdRDM.tools.utils import elem2dict
from .topicclassification import TopicClassification
from .author import Author
from .relatedpublication import RelatedPublication
from .keyword import Keyword
from .author import Author
from .topicclassification import TopicClassification


@forge_signature
class Contact(
sdRDM.DataModel,
nsmap={
"": "https://github.com/FAIRChemistry/FAIRDaRUS@65a354f35f9dd007471dce7138d159343f49cad5#Contact"
},
):
class Contact(sdRDM.DataModel, search_mode="unordered"):
"""Small type for attribute 'contact'"""

id: Optional[str] = attr(
Expand All @@ -36,17 +33,24 @@ class Contact(
default="https://github.com/FAIRChemistry/FAIRDaRUS"
)
_commit: Optional[str] = PrivateAttr(
default="65a354f35f9dd007471dce7138d159343f49cad5"
default="b4e182c6ea23841a0256d49c102fb1f1ff0530d9"
)
_raw_xml_data: Dict = PrivateAttr(default_factory=dict)

@model_validator(mode="after")
def _parse_raw_xml_data(self):
for attr, value in self:
if isinstance(value, (ListPlus, list)) and all(
(isinstance(i, _Element) for i in value)
):
self._raw_xml_data[attr] = [elem2dict(i) for i in value]
elif isinstance(value, _Element):
self._raw_xml_data[attr] = elem2dict(value)
return self


@forge_signature
class Citation(
sdRDM.DataModel,
nsmap={
"": "https://github.com/FAIRChemistry/FAIRDaRUS@65a354f35f9dd007471dce7138d159343f49cad5#Citation"
},
):
class Citation(sdRDM.DataModel, search_mode="unordered"):
""""""

id: Optional[str] = attr(
Expand Down Expand Up @@ -77,14 +81,11 @@ class Citation(
json_schema_extra=dict(),
)

authors: List[Author] = wrapped(
"authors",
element(
description="authors of this dataset.",
default_factory=ListPlus,
tag="Author",
json_schema_extra=dict(multiple=True),
),
authors: List[Author] = element(
description="authors of this dataset.",
default_factory=ListPlus,
tag="authors",
json_schema_extra=dict(multiple=True),
)

contact: Optional[Contact] = element(
Expand All @@ -94,17 +95,14 @@ class Citation(
json_schema_extra=dict(),
)

subject: List[str] = wrapped(
"subject",
element(
description=(
"domain specific subject categories that are topically relevant to the"
" dataset."
),
default_factory=ListPlus,
tag="string",
json_schema_extra=dict(multiple=True),
subject: List[str] = element(
description=(
"domain specific subject categories that are topically relevant to the"
" dataset."
),
default_factory=ListPlus,
tag="subject",
json_schema_extra=dict(multiple=True),
)

related_publication: Optional[RelatedPublication] = element(
Expand All @@ -114,31 +112,37 @@ class Citation(
json_schema_extra=dict(),
)

keywords: List[Keyword] = wrapped(
"keywords",
element(
description="keywords and url related to the project.",
default_factory=ListPlus,
tag="Keyword",
json_schema_extra=dict(multiple=True),
),
keywords: List[Keyword] = element(
description="keywords and url related to the project.",
default_factory=ListPlus,
tag="keywords",
json_schema_extra=dict(multiple=True),
)

topic_classification: List[TopicClassification] = wrapped(
"topic_classification",
element(
description="topic classification.",
default_factory=ListPlus,
tag="TopicClassification",
json_schema_extra=dict(multiple=True),
),
topic_classification: List[TopicClassification] = element(
description="topic classification.",
default_factory=ListPlus,
tag="topic_classification",
json_schema_extra=dict(multiple=True),
)
_repo: Optional[str] = PrivateAttr(
default="https://github.com/FAIRChemistry/FAIRDaRUS"
)
_commit: Optional[str] = PrivateAttr(
default="65a354f35f9dd007471dce7138d159343f49cad5"
default="b4e182c6ea23841a0256d49c102fb1f1ff0530d9"
)
_raw_xml_data: Dict = PrivateAttr(default_factory=dict)

@model_validator(mode="after")
def _parse_raw_xml_data(self):
for attr, value in self:
if isinstance(value, (ListPlus, list)) and all(
(isinstance(i, _Element) for i in value)
):
self._raw_xml_data[attr] = [elem2dict(i) for i in value]
elif isinstance(value, _Element):
self._raw_xml_data[attr] = elem2dict(value)
return self

def add_to_authors(
self,
Expand All @@ -147,6 +151,7 @@ def add_to_authors(
identifier_scheme: Optional[str] = None,
identifier: Optional[str] = None,
id: Optional[str] = None,
**kwargs
) -> Author:
"""
This method adds an object of type 'Author' to attribute authors
Expand Down Expand Up @@ -175,6 +180,7 @@ def add_to_keywords(
vocabulary: Optional[str] = None,
vocabulary_uri: Optional[str] = None,
id: Optional[str] = None,
**kwargs
) -> Keyword:
"""
This method adds an object of type 'Keyword' to attribute keywords
Expand All @@ -201,6 +207,7 @@ def add_to_topic_classification(
vocab: Optional[str] = None,
vocab_uri: Optional[str] = None,
id: Optional[str] = None,
**kwargs
) -> TopicClassification:
"""
This method adds an object of type 'TopicClassification' to attribute topic_classification
Expand Down
28 changes: 19 additions & 9 deletions FAIRDaRUS/core/keyword.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import sdRDM

from typing import Optional
from pydantic import PrivateAttr
from typing import Dict, Optional
from pydantic import PrivateAttr, model_validator
from uuid import uuid4
from pydantic_xml import attr, element
from lxml.etree import _Element
from sdRDM.base.listplus import ListPlus
from sdRDM.base.utils import forge_signature
from sdRDM.tools.utils import elem2dict


@forge_signature
class Keyword(
sdRDM.DataModel,
nsmap={
"": "https://github.com/FAIRChemistry/FAIRDaRUS@65a354f35f9dd007471dce7138d159343f49cad5#Keyword"
},
):
class Keyword(sdRDM.DataModel, search_mode="unordered"):
""""""

id: Optional[str] = attr(
Expand Down Expand Up @@ -53,5 +51,17 @@ class Keyword(
default="https://github.com/FAIRChemistry/FAIRDaRUS"
)
_commit: Optional[str] = PrivateAttr(
default="65a354f35f9dd007471dce7138d159343f49cad5"
default="b4e182c6ea23841a0256d49c102fb1f1ff0530d9"
)
_raw_xml_data: Dict = PrivateAttr(default_factory=dict)

@model_validator(mode="after")
def _parse_raw_xml_data(self):
for attr, value in self:
if isinstance(value, (ListPlus, list)) and all(
(isinstance(i, _Element) for i in value)
):
self._raw_xml_data[attr] = [elem2dict(i) for i in value]
elif isinstance(value, _Element):
self._raw_xml_data[attr] = elem2dict(value)
return self
28 changes: 19 additions & 9 deletions FAIRDaRUS/core/relatedpublication.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import sdRDM

from typing import Optional
from pydantic import PrivateAttr
from typing import Dict, Optional
from pydantic import PrivateAttr, model_validator
from uuid import uuid4
from pydantic_xml import attr, element
from lxml.etree import _Element
from sdRDM.base.listplus import ListPlus
from sdRDM.base.utils import forge_signature
from sdRDM.tools.utils import elem2dict


@forge_signature
class RelatedPublication(
sdRDM.DataModel,
nsmap={
"": "https://github.com/FAIRChemistry/FAIRDaRUS@65a354f35f9dd007471dce7138d159343f49cad5#RelatedPublication"
},
):
class RelatedPublication(sdRDM.DataModel, search_mode="unordered"):
""""""

id: Optional[str] = attr(
Expand Down Expand Up @@ -60,5 +58,17 @@ class RelatedPublication(
default="https://github.com/FAIRChemistry/FAIRDaRUS"
)
_commit: Optional[str] = PrivateAttr(
default="65a354f35f9dd007471dce7138d159343f49cad5"
default="b4e182c6ea23841a0256d49c102fb1f1ff0530d9"
)
_raw_xml_data: Dict = PrivateAttr(default_factory=dict)

@model_validator(mode="after")
def _parse_raw_xml_data(self):
for attr, value in self:
if isinstance(value, (ListPlus, list)) and all(
(isinstance(i, _Element) for i in value)
):
self._raw_xml_data[attr] = [elem2dict(i) for i in value]
elif isinstance(value, _Element):
self._raw_xml_data[attr] = elem2dict(value)
return self
28 changes: 19 additions & 9 deletions FAIRDaRUS/core/topicclassification.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import sdRDM

from typing import Optional
from pydantic import PrivateAttr
from typing import Dict, Optional
from pydantic import PrivateAttr, model_validator
from uuid import uuid4
from pydantic_xml import attr, element
from lxml.etree import _Element
from sdRDM.base.listplus import ListPlus
from sdRDM.base.utils import forge_signature
from sdRDM.tools.utils import elem2dict


@forge_signature
class TopicClassification(
sdRDM.DataModel,
nsmap={
"": "https://github.com/FAIRChemistry/FAIRDaRUS@65a354f35f9dd007471dce7138d159343f49cad5#TopicClassification"
},
):
class TopicClassification(sdRDM.DataModel, search_mode="unordered"):
""""""

id: Optional[str] = attr(
Expand Down Expand Up @@ -50,5 +48,17 @@ class TopicClassification(
default="https://github.com/FAIRChemistry/FAIRDaRUS"
)
_commit: Optional[str] = PrivateAttr(
default="65a354f35f9dd007471dce7138d159343f49cad5"
default="b4e182c6ea23841a0256d49c102fb1f1ff0530d9"
)
_raw_xml_data: Dict = PrivateAttr(default_factory=dict)

@model_validator(mode="after")
def _parse_raw_xml_data(self):
for attr, value in self:
if isinstance(value, (ListPlus, list)) and all(
(isinstance(i, _Element) for i in value)
):
self._raw_xml_data[attr] = [elem2dict(i) for i in value]
elif isinstance(value, _Element):
self._raw_xml_data[attr] = elem2dict(value)
return self

0 comments on commit da3f3fa

Please sign in to comment.