diff --git a/api/serialization/_retrieval/datasets.py b/api/serialization/_retrieval/datasets.py index 9777dc4..92d113e 100644 --- a/api/serialization/_retrieval/datasets.py +++ b/api/serialization/_retrieval/datasets.py @@ -1,6 +1,7 @@ -from api.serialization.util.siibra import EbrainsBaseDataset +from api.serialization.util.siibra import EbrainsBaseDataset, GenericDataset from api.serialization.util import serialize from api.models._retrieval.datasets import EbrainsDatasetModel, EbrainsDsPerson, EbrainsDsUrl +from hashlib import md5 @serialize(EbrainsBaseDataset) def ebrains_dataset_to_model(ds: EbrainsBaseDataset, **kwargs) -> EbrainsDatasetModel: @@ -21,3 +22,19 @@ def ebrains_dataset_to_model(ds: EbrainsBaseDataset, **kwargs) -> EbrainsDataset ebrains_page=ds.ebrains_page, custodians=[EbrainsDsPerson(**person) for person in ds.custodians] ) + +@serialize(GenericDataset) +def generic_dataset_to_model(ds: GenericDataset, **kwargs) -> EbrainsDatasetModel: + """Serialize generic dataset""" + return EbrainsDatasetModel( + id=md5(ds.name).hexdigest(), + name=ds.name, + urls=[EbrainsDsUrl(**url) for url in ds.urls], + description=ds.description, + contributors=[EbrainsDsPerson(id=person.get("name"), + identifier=person.get("name"), + shortName=person.get("name"), + name=person.get("name")) + for person in ds.contributors], + custodians=[], + ) diff --git a/api/serialization/util/siibra.py b/api/serialization/util/siibra.py index eed0489..8ca2976 100644 --- a/api/serialization/util/siibra.py +++ b/api/serialization/util/siibra.py @@ -16,7 +16,7 @@ from siibra.volumes.parcellationmap import Map from siibra.volumes.volume import Volume -from siibra.retrieval.datasets import EbrainsBaseDataset +from siibra.retrieval.datasets import EbrainsBaseDataset, GenericDataset from siibra.features.feature import Feature from siibra.features.connectivity.regional_connectivity import RegionalConnectivity