das-cli 1.5.9__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.9/das_cli.egg-info → das_cli-1.5.17}/PKG-INFO +1 -1
  2. {das_cli-1.5.9 → das_cli-1.5.17}/das/managers/digital_objects_manager.py +44 -18
  3. {das_cli-1.5.9 → das_cli-1.5.17}/das/services/digital_objects.py +21 -13
  4. {das_cli-1.5.9 → das_cli-1.5.17/das_cli.egg-info}/PKG-INFO +1 -1
  5. {das_cli-1.5.9 → das_cli-1.5.17}/pyproject.toml +1 -1
  6. {das_cli-1.5.9 → das_cli-1.5.17}/LICENSE +0 -0
  7. {das_cli-1.5.9 → das_cli-1.5.17}/MANIFEST.in +0 -0
  8. {das_cli-1.5.9 → das_cli-1.5.17}/README.md +0 -0
  9. {das_cli-1.5.9 → das_cli-1.5.17}/das/__init__.py +0 -0
  10. {das_cli-1.5.9 → das_cli-1.5.17}/das/ai/plugins/dasai.py +0 -0
  11. {das_cli-1.5.9 → das_cli-1.5.17}/das/ai/plugins/entries/entries_plugin.py +0 -0
  12. {das_cli-1.5.9 → das_cli-1.5.17}/das/app.py +0 -0
  13. {das_cli-1.5.9 → das_cli-1.5.17}/das/authentication/auth.py +0 -0
  14. {das_cli-1.5.9 → das_cli-1.5.17}/das/authentication/oauth.py +0 -0
  15. {das_cli-1.5.9 → das_cli-1.5.17}/das/authentication/secure_input.py +0 -0
  16. {das_cli-1.5.9 → das_cli-1.5.17}/das/cli.py +0 -0
  17. {das_cli-1.5.9 → das_cli-1.5.17}/das/common/api.py +0 -0
  18. {das_cli-1.5.9 → das_cli-1.5.17}/das/common/config.py +0 -0
  19. {das_cli-1.5.9 → das_cli-1.5.17}/das/common/entry_fields_constants.py +0 -0
  20. {das_cli-1.5.9 → das_cli-1.5.17}/das/common/enums.py +0 -0
  21. {das_cli-1.5.9 → das_cli-1.5.17}/das/common/file_utils.py +0 -0
  22. {das_cli-1.5.9 → das_cli-1.5.17}/das/managers/__init__.py +0 -0
  23. {das_cli-1.5.9 → das_cli-1.5.17}/das/managers/download_manager.py +0 -0
  24. {das_cli-1.5.9 → das_cli-1.5.17}/das/managers/entries_manager.py +0 -0
  25. {das_cli-1.5.9 → das_cli-1.5.17}/das/managers/search_manager.py +0 -0
  26. {das_cli-1.5.9 → das_cli-1.5.17}/das/services/attributes.py +0 -0
  27. {das_cli-1.5.9 → das_cli-1.5.17}/das/services/cache.py +0 -0
  28. {das_cli-1.5.9 → das_cli-1.5.17}/das/services/das_elastic_search.py +0 -0
  29. {das_cli-1.5.9 → das_cli-1.5.17}/das/services/downloads.py +0 -0
  30. {das_cli-1.5.9 → das_cli-1.5.17}/das/services/entries.py +0 -0
  31. {das_cli-1.5.9 → das_cli-1.5.17}/das/services/entry_fields.py +0 -0
  32. {das_cli-1.5.9 → das_cli-1.5.17}/das/services/hangfire.py +0 -0
  33. {das_cli-1.5.9 → das_cli-1.5.17}/das/services/search.py +0 -0
  34. {das_cli-1.5.9 → das_cli-1.5.17}/das/services/service_base.py +0 -0
  35. {das_cli-1.5.9 → das_cli-1.5.17}/das/services/users.py +0 -0
  36. {das_cli-1.5.9 → das_cli-1.5.17}/das_cli.egg-info/SOURCES.txt +0 -0
  37. {das_cli-1.5.9 → das_cli-1.5.17}/das_cli.egg-info/dependency_links.txt +0 -0
  38. {das_cli-1.5.9 → das_cli-1.5.17}/das_cli.egg-info/entry_points.txt +0 -0
  39. {das_cli-1.5.9 → das_cli-1.5.17}/das_cli.egg-info/requires.txt +0 -0
  40. {das_cli-1.5.9 → das_cli-1.5.17}/das_cli.egg-info/top_level.txt +0 -0
  41. {das_cli-1.5.9 → das_cli-1.5.17}/setup.cfg +0 -0
  42. {das_cli-1.5.9 → das_cli-1.5.17}/tests/__init__.py +0 -0
  43. {das_cli-1.5.9 → das_cli-1.5.17}/tests/attributes_test.py +0 -0
  44. {das_cli-1.5.9 → das_cli-1.5.17}/tests/download_manager_test.py +0 -0
  45. {das_cli-1.5.9 → das_cli-1.5.17}/tests/entries_manager_test.py +0 -0
  46. {das_cli-1.5.9 → das_cli-1.5.17}/tests/entries_service_test.py +0 -0
  47. {das_cli-1.5.9 → das_cli-1.5.17}/tests/entries_test.py +0 -0
  48. {das_cli-1.5.9 → das_cli-1.5.17}/tests/file_utils_test.py +0 -0
  49. {das_cli-1.5.9 → das_cli-1.5.17}/tests/run_tests.py +0 -0
  50. {das_cli-1.5.9 → 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.9
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
@@ -51,35 +51,61 @@ class DigitalObjectsManager:
51
51
 
52
52
  return result
53
53
 
54
- def upload_digital_object(self, entry_code: str, file_description: str, digital_object_type: str, file_path: str):
55
- """Upload a digital object to the digital object service."""
54
+ def _resolve_digital_object_type_id(self, digital_object_type: str) -> str:
56
55
  response = self.search_service.search_entries(
57
56
  queryString=f"displayname({digital_object_type})",
58
57
  attributeId=self.__attribute_id_digital_object_type,
59
58
  maxResultCount=1,
60
- skipCount=0
61
- )
59
+ skipCount=0,
60
+ )
62
61
 
63
- entry_response = self.entry_service.get_entry(entry_code)
62
+ if response.get("totalCount", 0) == 0:
63
+ raise ValueError(f"Digital object type '{digital_object_type}' not found")
64
+
65
+ return response.get("items", [])[0].get("entry").get("id")
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)
64
77
  if entry_response is None:
65
- raise ValueError(f"Entry with code '{entry_code}' not found")
78
+ raise ValueError(f"Digital object with id '{object_id}' not found")
66
79
 
67
- if response.get('totalCount', 0) == 0:
68
- raise ValueError(f"Digital object type '{digital_object_type}' not found")
69
-
70
- digital_object_type_id = response.get('items', [])[0].get('entry').get('id')
71
- digital_object_id = self.digital_objects_service.upload_digital_object(file_description, digital_object_type_id, file_path)
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")
72
83
 
73
- if not digital_object_id:
74
- raise ValueError(f"Upload did not return a digital object id for '{file_path}'")
84
+ return code
75
85
 
76
- self.digital_objects_service.link_existing_digital_objects(
77
- attribute_id=entry_response.get('attributeId'),
78
- entry_id=entry_response.get('entry').get('id'),
79
- digital_object_id_list=[digital_object_id]
86
+ def upload_file(
87
+ self, file_description: str, digital_object_type: str, file_path: str
88
+ ) -> str:
89
+ """Upload a file as a digital object without linking it to an entry."""
90
+ digital_object_type_id = self._resolve_digital_object_type_id(digital_object_type)
91
+ upload_result = self.digital_objects_service.upload_digital_object(
92
+ file_description, digital_object_type_id, file_path
80
93
  )
81
94
 
82
- return digital_object_id
95
+ return self._resolve_digital_object_code(upload_result)
96
+
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")
101
+
102
+ self.link_existing_digital_objects(entry_code, digital_object_codes)
103
+
104
+ def upload_digital_object(self, entry_code: str, file_description: str, digital_object_type: str, file_path: str):
105
+ """Upload a digital object and link it to an entry."""
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
83
109
 
84
110
  def download_digital_object(self, output_path: str, digital_object_id: str = None, digital_object_code: str = None):
85
111
  """Download a digital object from the digital object service."""
@@ -41,7 +41,15 @@ class DigitalObjectsService(ServiceBase):
41
41
  f"{self.base_url}/LinkExistingDigitalObject", data=payload, headers=headers
42
42
  )
43
43
 
44
- return response.get("success")
44
+ if response.get("success") is not True:
45
+ error = response.get("error") or {}
46
+ if isinstance(error, dict):
47
+ message = (error.get("message") or "Failed to link digital objects").strip()
48
+ else:
49
+ message = str(error).strip() or "Failed to link digital objects"
50
+ raise ValueError(message)
51
+
52
+ return True
45
53
 
46
54
  # This is our chunk reader. This is what gets the next chunk of data ready to send.
47
55
  def __read_in_chunks(self, file_object, chunk_size):
@@ -52,15 +60,15 @@ class DigitalObjectsService(ServiceBase):
52
60
  yield data
53
61
 
54
62
 
55
- def _extract_upload_result_id(self, response: dict | None) -> str | None:
63
+ def _extract_upload_result(self, response: dict | None) -> dict | None:
56
64
  if not response:
57
65
  return None
58
66
  result = response.get("result", response)
59
67
  if isinstance(result, dict):
60
- return result.get("id")
68
+ return result
61
69
  return None
62
70
 
63
- 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:
64
72
 
65
73
  if not exists(file_path):
66
74
  raise ValueError(f"File '{file_path}' does not exist")
@@ -80,7 +88,7 @@ class DigitalObjectsService(ServiceBase):
80
88
 
81
89
  byte_offset = 0
82
90
  chunk_index = 0
83
- digital_object_id = None
91
+ upload_result: dict | None = None
84
92
  headers = {}
85
93
 
86
94
  with open(file_path, "rb") as binary_file:
@@ -100,26 +108,26 @@ class DigitalObjectsService(ServiceBase):
100
108
 
101
109
  r = self.upload_file(chunk, metadata, headers)
102
110
 
103
- uploaded_id = self._extract_upload_result_id(r)
104
- if uploaded_id:
105
- digital_object_id = uploaded_id
111
+ chunk_result = self._extract_upload_result(r)
112
+ if chunk_result:
113
+ upload_result = chunk_result
106
114
 
107
115
  byte_offset = chunk_end
108
116
  chunk_index += 1
109
117
 
110
118
  is_final_chunk = chunk_index >= metadata["totalCount"]
111
- if is_final_chunk and digital_object_id is None:
119
+ if is_final_chunk and upload_result is None:
112
120
  raise ValueError(
113
- 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"
114
122
  )
115
123
 
116
124
  except Exception as e:
117
125
  raise ValueError(f"Error uploading file '{file_path}': {str(e)}")
118
126
 
119
- if digital_object_id is None:
120
- 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}'")
121
129
 
122
- return digital_object_id
130
+ return upload_result
123
131
 
124
132
 
125
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.9
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.9"
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
File without changes