das-cli 1.5.11__tar.gz → 1.5.17__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. {das_cli-1.5.11/das_cli.egg-info → das_cli-1.5.17}/PKG-INFO +1 -1
  2. {das_cli-1.5.11 → das_cli-1.5.17}/das/managers/digital_objects_manager.py +29 -25
  3. {das_cli-1.5.11 → das_cli-1.5.17}/das/services/digital_objects.py +12 -12
  4. {das_cli-1.5.11 → das_cli-1.5.17/das_cli.egg-info}/PKG-INFO +1 -1
  5. {das_cli-1.5.11 → das_cli-1.5.17}/pyproject.toml +1 -1
  6. {das_cli-1.5.11 → das_cli-1.5.17}/LICENSE +0 -0
  7. {das_cli-1.5.11 → das_cli-1.5.17}/MANIFEST.in +0 -0
  8. {das_cli-1.5.11 → das_cli-1.5.17}/README.md +0 -0
  9. {das_cli-1.5.11 → das_cli-1.5.17}/das/__init__.py +0 -0
  10. {das_cli-1.5.11 → das_cli-1.5.17}/das/ai/plugins/dasai.py +0 -0
  11. {das_cli-1.5.11 → das_cli-1.5.17}/das/ai/plugins/entries/entries_plugin.py +0 -0
  12. {das_cli-1.5.11 → das_cli-1.5.17}/das/app.py +0 -0
  13. {das_cli-1.5.11 → das_cli-1.5.17}/das/authentication/auth.py +0 -0
  14. {das_cli-1.5.11 → das_cli-1.5.17}/das/authentication/oauth.py +0 -0
  15. {das_cli-1.5.11 → das_cli-1.5.17}/das/authentication/secure_input.py +0 -0
  16. {das_cli-1.5.11 → das_cli-1.5.17}/das/cli.py +0 -0
  17. {das_cli-1.5.11 → das_cli-1.5.17}/das/common/api.py +0 -0
  18. {das_cli-1.5.11 → das_cli-1.5.17}/das/common/config.py +0 -0
  19. {das_cli-1.5.11 → das_cli-1.5.17}/das/common/entry_fields_constants.py +0 -0
  20. {das_cli-1.5.11 → das_cli-1.5.17}/das/common/enums.py +0 -0
  21. {das_cli-1.5.11 → das_cli-1.5.17}/das/common/file_utils.py +0 -0
  22. {das_cli-1.5.11 → das_cli-1.5.17}/das/managers/__init__.py +0 -0
  23. {das_cli-1.5.11 → das_cli-1.5.17}/das/managers/download_manager.py +0 -0
  24. {das_cli-1.5.11 → das_cli-1.5.17}/das/managers/entries_manager.py +0 -0
  25. {das_cli-1.5.11 → das_cli-1.5.17}/das/managers/search_manager.py +0 -0
  26. {das_cli-1.5.11 → das_cli-1.5.17}/das/services/attributes.py +0 -0
  27. {das_cli-1.5.11 → das_cli-1.5.17}/das/services/cache.py +0 -0
  28. {das_cli-1.5.11 → das_cli-1.5.17}/das/services/das_elastic_search.py +0 -0
  29. {das_cli-1.5.11 → das_cli-1.5.17}/das/services/downloads.py +0 -0
  30. {das_cli-1.5.11 → das_cli-1.5.17}/das/services/entries.py +0 -0
  31. {das_cli-1.5.11 → das_cli-1.5.17}/das/services/entry_fields.py +0 -0
  32. {das_cli-1.5.11 → das_cli-1.5.17}/das/services/hangfire.py +0 -0
  33. {das_cli-1.5.11 → das_cli-1.5.17}/das/services/search.py +0 -0
  34. {das_cli-1.5.11 → das_cli-1.5.17}/das/services/service_base.py +0 -0
  35. {das_cli-1.5.11 → das_cli-1.5.17}/das/services/users.py +0 -0
  36. {das_cli-1.5.11 → das_cli-1.5.17}/das_cli.egg-info/SOURCES.txt +0 -0
  37. {das_cli-1.5.11 → das_cli-1.5.17}/das_cli.egg-info/dependency_links.txt +0 -0
  38. {das_cli-1.5.11 → das_cli-1.5.17}/das_cli.egg-info/entry_points.txt +0 -0
  39. {das_cli-1.5.11 → das_cli-1.5.17}/das_cli.egg-info/requires.txt +0 -0
  40. {das_cli-1.5.11 → das_cli-1.5.17}/das_cli.egg-info/top_level.txt +0 -0
  41. {das_cli-1.5.11 → das_cli-1.5.17}/setup.cfg +0 -0
  42. {das_cli-1.5.11 → das_cli-1.5.17}/tests/__init__.py +0 -0
  43. {das_cli-1.5.11 → das_cli-1.5.17}/tests/attributes_test.py +0 -0
  44. {das_cli-1.5.11 → das_cli-1.5.17}/tests/download_manager_test.py +0 -0
  45. {das_cli-1.5.11 → das_cli-1.5.17}/tests/entries_manager_test.py +0 -0
  46. {das_cli-1.5.11 → das_cli-1.5.17}/tests/entries_service_test.py +0 -0
  47. {das_cli-1.5.11 → das_cli-1.5.17}/tests/entries_test.py +0 -0
  48. {das_cli-1.5.11 → das_cli-1.5.17}/tests/file_utils_test.py +0 -0
  49. {das_cli-1.5.11 → das_cli-1.5.17}/tests/run_tests.py +0 -0
  50. {das_cli-1.5.11 → das_cli-1.5.17}/tests/search_manager_test.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: das-cli
3
- Version: 1.5.11
3
+ Version: 1.5.17
4
4
  Summary: DAS api client.
5
5
  Author: Royal Netherlands Institute for Sea Research
6
6
  License-Expression: MIT
@@ -64,44 +64,48 @@ class DigitalObjectsManager:
64
64
 
65
65
  return response.get("items", [])[0].get("entry").get("id")
66
66
 
67
+ def _resolve_digital_object_code(self, upload_result: dict) -> str:
68
+ code = upload_result.get("code")
69
+ if code:
70
+ return code
71
+
72
+ object_id = upload_result.get("id")
73
+ if not object_id:
74
+ raise ValueError("Upload result is missing digital object id and code")
75
+
76
+ entry_response = self.entry_service.get(id=object_id)
77
+ if entry_response is None:
78
+ raise ValueError(f"Digital object with id '{object_id}' not found")
79
+
80
+ code = (entry_response.get("entry") or {}).get("code")
81
+ if not code:
82
+ raise ValueError(f"Digital object with id '{object_id}' has no code")
83
+
84
+ return code
85
+
67
86
  def upload_file(
68
87
  self, file_description: str, digital_object_type: str, file_path: str
69
88
  ) -> str:
70
89
  """Upload a file as a digital object without linking it to an entry."""
71
90
  digital_object_type_id = self._resolve_digital_object_type_id(digital_object_type)
72
- digital_object_id = self.digital_objects_service.upload_digital_object(
91
+ upload_result = self.digital_objects_service.upload_digital_object(
73
92
  file_description, digital_object_type_id, file_path
74
93
  )
75
94
 
76
- if not digital_object_id:
77
- raise ValueError(f"Upload did not return a digital object id for '{file_path}'")
78
-
79
- return digital_object_id
80
-
81
- def link_to_entry(self, entry_code: str, digital_object_ids: list[str]) -> None:
82
- """Link one or more uploaded digital objects to an entry."""
83
- if not digital_object_ids:
84
- raise ValueError("At least one digital object id is required")
85
-
86
- entry_response = self.entry_service.get_entry(entry_code)
87
- if entry_response is None:
88
- raise ValueError(f"Entry with code '{entry_code}' not found")
95
+ return self._resolve_digital_object_code(upload_result)
89
96
 
90
- entry_payload = entry_response.get("entry")
91
- if entry_payload is None:
92
- raise ValueError(f"Entry with code '{entry_code}' not found")
97
+ def link_to_entry(self, entry_code: str, digital_object_codes: list[str]) -> None:
98
+ """Link one or more uploaded digital objects to an entry using their codes."""
99
+ if not digital_object_codes:
100
+ raise ValueError("At least one digital object code is required")
93
101
 
94
- self.digital_objects_service.link_existing_digital_objects(
95
- attribute_id=entry_response.get("attributeId"),
96
- entry_id=entry_payload.get("id"),
97
- digital_object_id_list=digital_object_ids,
98
- )
102
+ self.link_existing_digital_objects(entry_code, digital_object_codes)
99
103
 
100
104
  def upload_digital_object(self, entry_code: str, file_description: str, digital_object_type: str, file_path: str):
101
105
  """Upload a digital object and link it to an entry."""
102
- digital_object_id = self.upload_file(file_description, digital_object_type, file_path)
103
- self.link_to_entry(entry_code, [digital_object_id])
104
- return digital_object_id
106
+ digital_object_code = self.upload_file(file_description, digital_object_type, file_path)
107
+ self.link_to_entry(entry_code, [digital_object_code])
108
+ return digital_object_code
105
109
 
106
110
  def download_digital_object(self, output_path: str, digital_object_id: str = None, digital_object_code: str = None):
107
111
  """Download a digital object from the digital object service."""
@@ -60,15 +60,15 @@ class DigitalObjectsService(ServiceBase):
60
60
  yield data
61
61
 
62
62
 
63
- def _extract_upload_result_id(self, response: dict | None) -> str | None:
63
+ def _extract_upload_result(self, response: dict | None) -> dict | None:
64
64
  if not response:
65
65
  return None
66
66
  result = response.get("result", response)
67
67
  if isinstance(result, dict):
68
- return result.get("id")
68
+ return result
69
69
  return None
70
70
 
71
- def upload_digital_object(self, file_description: str, digital_object_type_id: str, file_path: str):
71
+ def upload_digital_object(self, file_description: str, digital_object_type_id: str, file_path: str) -> dict:
72
72
 
73
73
  if not exists(file_path):
74
74
  raise ValueError(f"File '{file_path}' does not exist")
@@ -88,7 +88,7 @@ class DigitalObjectsService(ServiceBase):
88
88
 
89
89
  byte_offset = 0
90
90
  chunk_index = 0
91
- digital_object_id = None
91
+ upload_result: dict | None = None
92
92
  headers = {}
93
93
 
94
94
  with open(file_path, "rb") as binary_file:
@@ -108,26 +108,26 @@ class DigitalObjectsService(ServiceBase):
108
108
 
109
109
  r = self.upload_file(chunk, metadata, headers)
110
110
 
111
- uploaded_id = self._extract_upload_result_id(r)
112
- if uploaded_id:
113
- digital_object_id = uploaded_id
111
+ chunk_result = self._extract_upload_result(r)
112
+ if chunk_result:
113
+ upload_result = chunk_result
114
114
 
115
115
  byte_offset = chunk_end
116
116
  chunk_index += 1
117
117
 
118
118
  is_final_chunk = chunk_index >= metadata["totalCount"]
119
- if is_final_chunk and digital_object_id is None:
119
+ if is_final_chunk and upload_result is None:
120
120
  raise ValueError(
121
- f"Upload failed for '{file_path}': no digital object id on final chunk"
121
+ f"Upload failed for '{file_path}': no digital object returned on final chunk"
122
122
  )
123
123
 
124
124
  except Exception as e:
125
125
  raise ValueError(f"Error uploading file '{file_path}': {str(e)}")
126
126
 
127
- if digital_object_id is None:
128
- raise ValueError(f"Upload did not return a digital object id for '{file_path}'")
127
+ if upload_result is None or not upload_result.get("id"):
128
+ raise ValueError(f"Upload did not return a digital object for '{file_path}'")
129
129
 
130
- return digital_object_id
130
+ return upload_result
131
131
 
132
132
 
133
133
  def upload_file(self, file, body, headers):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: das-cli
3
- Version: 1.5.11
3
+ Version: 1.5.17
4
4
  Summary: DAS api client.
5
5
  Author: Royal Netherlands Institute for Sea Research
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "das-cli"
7
- version = "1.5.11"
7
+ version = "1.5.17"
8
8
  authors = [
9
9
  { name="Royal Netherlands Institute for Sea Research" },
10
10
  ]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes