Commit eca1a760 authored by parciak's avatar parciak
Browse files

Updates to hardcoded localhost reference. Updatest to missing date parsing for...


Updates to hardcoded localhost reference. Updatest to missing date parsing for python < 3.7. Base url of ids is now settable in metadata templates. Removed unused models_metadata.py
Signed-off-by: parciak's avatarMarcel Parciak <marcel.parciak@gmail.com>
parent 26fbf7f6
Pipeline #148053 failed with stage
in 7 minutes and 20 seconds
......@@ -31,6 +31,10 @@ class ArchiveInfo(BaseModel):
created: datetime.datetime = Field(None, example="2020-07-24T09:40:10.548+0000")
modified: datetime.datetime = Field(None, example="2020-07-24T09:41:05.881+0000")
file_count: int = Field(None, example=1)
base_uri: str = Field(
os.path.join(config.BasicSettings().couch_uri, config.BasicSettings().couch_db),
example="https://localhost:5984/medic",
)
def to_jsonld(self) -> Dict[str, Any]:
with open(
......@@ -62,6 +66,10 @@ class FileInfo(BaseModel):
"sha256": "2a57d4a5d06599f9ea4df8bfdaaa7c57b3a6755ba8c445147f8911972cd58441",
},
)
base_uri: str = Field(
os.path.join(config.BasicSettings().couch_uri, config.BasicSettings().couch_db),
example="https://localhost:5984/medic",
)
def to_jsonld(self) -> Dict[str, Any]:
with open(
......
from __future__ import annotations
from pydantic import BaseModel, Field
from typing import ForwardRef, List
class MetadataBase(BaseModel):
context: str = Field(
"http://schema.org/",
example="http://schema.org/",
alias="@context",
const="http://schema.org/",
)
type: str = Field("Thing", example="Thing", alias="@type", const="Thing")
id: str = Field(None, example="some_id", alias="@id")
name: str = Field(None, example="Some Name")
url: str = Field(None, example="www.example.org")
def schema_org_ref(self) -> dict:
""" Creates a Schema.org valid JSON-LD reference (i.e. only the type and @id) from the pydantic model. It can be used to refer to linked JSON-LD elements.
Returns
-------
dict
A dictionary according to the JSON-LD reference the pydantic model contains.
"""
return {"@type": self.type, "@id": self.id}
class Config:
allow_population_by_alias = True
class MetadataOrganization(MetadataBase):
type: str = Field(
"Organization", example="Organization", alias="@type", const="Organization"
)
email: str = Field(None, example="medic@umg.eu")
location: str = Field(
None, example="Von-Siebold-Straße 3, 37075 Göttingen, Germany"
)
member: MetadataOrganization = Field(None, example=MetadataBase(id="umg_medic"))
memberOf: MetadataOrganization = Field(None, example=MetadataBase(id="umg"))
telephone: str = Field(None, example="+49 551 39 0")
MetadataOrganization.update_forward_refs()
class MetadataCreativeWork(MetadataBase):
type: str = Field(
"CreativeWork", example="CreativeWork", alias="@type", const="CreativeWork"
)
abstract: str = Field(None, example="A generic dataset.")
accessibilityAPI: str = Field(None, example="https://cdstar.gwdg.de/docs/dev/")
acquireLicensePage: str = Field(None, example="mailto:medic@umg.eu")
author: MetadataOrganization = Field(
None, example=MetadataOrganization(id="umg_medic")
)
creator: MetadataOrganization = Field(
None, example=MetadataOrganization(id="umg_medic")
)
dateCreated: str = Field(None, example="2020-01-01T12:00:05")
datePublished: str = Field(None, example="2020-01-01T12:00:05")
encodingFormat: str = Field(None, example="text/plain")
maintainer: MetadataOrganization = Field(
None, example=MetadataOrganization(id="umg_medic")
)
sourceOrganization: MetadataOrganization = Field(
None, example=MetadataOrganization(id="umg_medic")
)
MetadataArchive = ForwardRef("MetadataArchive")
class MetadataFile(MetadataCreativeWork):
type: str = Field(
"DataDownload", example="DataDownload", alias="@type", const="DataDownload"
)
contentSize: str = Field(None, example="12345")
contentUrl: str = Field(
None, example="http://cdstar.example.com/v3/sources/abcdefg1234/filename.ext"
)
description: str = Field(
None, example="Error happened, this field holds the information for that."
)
encodingFormat: str = Field(None, example="text/plain")
isPartOf: MetadataArchive = Field(None, example=MetadataBase(id="SomeDataset"))
uploadDate: str = Field(None, example="2020-01-01T12:00:05")
MetadataArchive = ForwardRef("MetadataArchive")
class MetadataDataCatalog(MetadataCreativeWork):
type: str = Field(
"DataCatalog", example="DataCatalog", alias="@type", const="DataCatalog"
)
dataset: List[MetadataArchive] = Field(
[], example=[MetadataCreativeWork(id="SomeDataset")]
)
class MetadataArchive(MetadataCreativeWork):
type: str = Field("Dataset", example="Dataset", alias="@type", const="Dataset")
includedInDataCatalog: MetadataDataCatalog = Field(
None, example=MetadataCreativeWork(id="umg_medic")
)
distribution: List[MetadataFile] = Field(
None,
example=[
MetadataCreativeWork(id="somefile.csv"),
MetadataCreativeWork(id="anotherfile.csv"),
],
)
hasPart: List[MetadataFile] = Field(
[],
example=[
MetadataCreativeWork(id="somefile.csv"),
MetadataCreativeWork(id="anotherfile.csv"),
],
)
MetadataDataCatalog.update_forward_refs()
MetadataFile.update_forward_refs()
{
"@context": "http://schema.org/",
"@type": "Dataset",
"@id": "http://localhost:5984/medic/{{ model.id }}",
"@id": "{{ model.base_uri }}/{{ model.id }}",
"identifier": "{{ model.id }}",
{% if model.file_count is defined %}
"size": {
......
{
"@context": "http://schema.org/",
"@type": "DataDownload",
"@id": "http://localhost:5984/medic/{{ model.id }}",
"@id": "{{ model.base_uri }}/{{ model.id }}",
"identifier": "{{ model.id }}",
{% if model.size is defined %}
"size": {
......
......@@ -166,10 +166,10 @@ def test_receive_02(cdstar_archive):
assert meta_json["identifier"] == archive_id
assert datetime.datetime.strptime(
cdstar_json["created"], "%Y-%m-%dT%H:%M:%S.%f%z"
) == datetime.datetime.strptime(meta_json["dateCreated"], "%Y-%m-%dT%H:%M:%S.%f")
) == datetime.datetime.strptime(meta_json["dateCreated"], "%Y-%m-%dT%H:%M:%S.%f%z")
assert datetime.datetime.strptime(
cdstar_json["modified"], "%Y-%m-%dT%H:%M:%S.%f%z"
) == datetime.datetime.strptime(meta_json["dateModified"], "%Y-%m-%dT%H:%M:%S.%f")
) == datetime.datetime.strptime(meta_json["dateModified"], "%Y-%m-%dT%H:%M:%S.%f%z")
assert int(cdstar_json["file_count"]) == int(meta_json["size"]["value"])
assert int(cdstar_json["file_count"]) == len(meta_json["hasPart"])
......@@ -214,10 +214,14 @@ def test_receive_03(cdstar_archive):
assert int(file_info["size"]) == int(meta_json["contentSize"])
assert datetime.datetime.strptime(
file_info["created"], "%Y-%m-%dT%H:%M:%S.%f%z"
) == datetime.datetime.fromisoformat(meta_json["dateCreated"])
) == datetime.datetime.strptime(
meta_json["dateCreated"], "%Y-%m-%dT%H:%M:%S.%f%z"
)
assert datetime.datetime.strptime(
file_info["modified"], "%Y-%m-%dT%H:%M:%S.%f%z"
) == datetime.datetime.fromisoformat(meta_json["dateModified"])
) == datetime.datetime.strptime(
meta_json["dateModified"], "%Y-%m-%dT%H:%M:%S.%f%z"
)
test_utils.cleanup_metafile(vault_id, archive_id)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment