From 475c82e4cea9c57bf94c2c4a9ff7b9b18310f220 Mon Sep 17 00:00:00 2001 From: "McDonnell, Marshall" Date: Fri, 16 Aug 2024 13:00:37 -0400 Subject: [PATCH] Fixes dataset service to handle both jsonld and ssm json formats --- src/ssm_client/services/dataset_service.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ssm_client/services/dataset_service.py b/src/ssm_client/services/dataset_service.py index be5c576..fd55211 100644 --- a/src/ssm_client/services/dataset_service.py +++ b/src/ssm_client/services/dataset_service.py @@ -5,7 +5,10 @@ from .collection_service import _COLLECTION_ENDPOINT _DATASETS_ENDPOINT = "datasets" -_DATASET_FORMAT_CHOICES = ["jsonld", "json"] + +_FORMAT_JSONLD = "jsonld" +_FORMAT_SSM_JSON = "json" +_DATASET_FORMAT_CHOICES = [_FORMAT_JSONLD, _FORMAT_SSM_JSON] class MismatchedCollectionException(Exception): @@ -103,7 +106,7 @@ def create(self, dataset): response.raise_for_status() return DatasetContainer(**response.json()) - def get_by_uuid(self, uuid, format: str = "jsonld"): + def get_by_uuid(self, uuid, format: str = _FORMAT_JSONLD): """ Get dataset for given UUID at SSM Catalog API @@ -132,7 +135,12 @@ def get_by_uuid(self, uuid, format: str = "jsonld"): response = requests.get(self._endpoint(uuid), params=params) response.raise_for_status() - return DatasetContainer(**response.json()) + output = DatasetContainer() + if format is _FORMAT_JSONLD: + output = DatasetContainer(**response.json()) + elif format is _FORMAT_SSM_JSON: + output = DatasetContainer(dataset=response.json()) + return output def replace_dataset_for_uuid(self, uuid, dataset): """