|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
| 5 | +from uuid import UUID |
| 6 | + |
5 | 7 | from dataconnect.exceptions import ( |
6 | 8 | AuthenticationError, |
7 | 9 | AuthorizationError, |
|
12 | 14 | ServerError, |
13 | 15 | ValidationError, |
14 | 16 | ) |
15 | | -from dataconnect.models import Study |
| 17 | +from dataconnect.models import DatasetVersion, Study |
16 | 18 | from dataconnect.service.base import DataConnectService |
17 | | -from dataconnect.service.mappers import resource_to_study |
| 19 | +from dataconnect.service.mappers import resource_to_dataset_version, resource_to_study |
18 | 20 | from dataconnect.transport.base import Transport |
19 | 21 | from dataconnect.transport.errors import ( |
20 | 22 | TransportAuthenticationError, |
|
29 | 31 |
|
30 | 32 | # Server action identifiers |
31 | 33 | _ACTION_LIST_STUDIES = "studies.list" |
| 34 | +_ACTION_LIST_DATASET_VERSIONS = "dataset_versions.list" |
32 | 35 |
|
33 | 36 |
|
34 | 37 | def _translate_error(ex: TransportError) -> DataConnectError: |
@@ -69,9 +72,22 @@ def get_studies(self) -> list[Study]: |
69 | 72 |
|
70 | 73 | try: |
71 | 74 | return [resource_to_study(r) for r in resources] |
72 | | - except (KeyError, TypeError, ValueError) as ex: |
| 75 | + except (IndexError, KeyError, TypeError, ValueError) as ex: |
73 | 76 | raise ValidationError(f"Unexpected studies response format: {ex}") from ex |
74 | 77 |
|
| 78 | + def get_dataset_versions(self, dataset_uuid: UUID) -> list[DatasetVersion]: |
| 79 | + request = ResourceQuery(action=_ACTION_LIST_DATASET_VERSIONS).append_body({"dataset_uuid": str(dataset_uuid)}) |
| 80 | + |
| 81 | + try: |
| 82 | + resources = self._transport.list_resources(request) |
| 83 | + except TransportError as ex: |
| 84 | + raise _translate_error(ex) from ex |
| 85 | + |
| 86 | + try: |
| 87 | + return [resource_to_dataset_version(r) for r in resources] |
| 88 | + except (IndexError, KeyError, TypeError, ValueError) as ex: |
| 89 | + raise ValidationError(f"Unexpected dataset versions response format: {ex}") from ex |
| 90 | + |
75 | 91 | def close(self) -> None: |
76 | 92 |
|
77 | 93 | try: |
|
0 commit comments