Skip to content

Commit

Permalink
Fixes dataset service to handle both jsonld and ssm json formats
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallmcdonnell committed Aug 16, 2024
1 parent c822a60 commit 475c82e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/ssm_client/services/dataset_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit 475c82e

Please sign in to comment.