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.
- {das_cli-1.5.11/das_cli.egg-info → das_cli-1.5.17}/PKG-INFO +1 -1
- {das_cli-1.5.11 → das_cli-1.5.17}/das/managers/digital_objects_manager.py +29 -25
- {das_cli-1.5.11 → das_cli-1.5.17}/das/services/digital_objects.py +12 -12
- {das_cli-1.5.11 → das_cli-1.5.17/das_cli.egg-info}/PKG-INFO +1 -1
- {das_cli-1.5.11 → das_cli-1.5.17}/pyproject.toml +1 -1
- {das_cli-1.5.11 → das_cli-1.5.17}/LICENSE +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/MANIFEST.in +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/README.md +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/__init__.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/ai/plugins/dasai.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/ai/plugins/entries/entries_plugin.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/app.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/authentication/auth.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/authentication/oauth.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/authentication/secure_input.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/cli.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/common/api.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/common/config.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/common/entry_fields_constants.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/common/enums.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/common/file_utils.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/managers/__init__.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/managers/download_manager.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/managers/entries_manager.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/managers/search_manager.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/services/attributes.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/services/cache.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/services/das_elastic_search.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/services/downloads.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/services/entries.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/services/entry_fields.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/services/hangfire.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/services/search.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/services/service_base.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das/services/users.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das_cli.egg-info/SOURCES.txt +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das_cli.egg-info/dependency_links.txt +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das_cli.egg-info/entry_points.txt +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das_cli.egg-info/requires.txt +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/das_cli.egg-info/top_level.txt +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/setup.cfg +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/tests/__init__.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/tests/attributes_test.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/tests/download_manager_test.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/tests/entries_manager_test.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/tests/entries_service_test.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/tests/entries_test.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/tests/file_utils_test.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/tests/run_tests.py +0 -0
- {das_cli-1.5.11 → das_cli-1.5.17}/tests/search_manager_test.py +0 -0
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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.
|
|
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
|
-
|
|
103
|
-
self.link_to_entry(entry_code, [
|
|
104
|
-
return
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
112
|
-
if
|
|
113
|
-
|
|
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
|
|
119
|
+
if is_final_chunk and upload_result is None:
|
|
120
120
|
raise ValueError(
|
|
121
|
-
f"Upload failed for '{file_path}': no digital object
|
|
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
|
|
128
|
-
raise ValueError(f"Upload did not return a digital object
|
|
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
|
|
130
|
+
return upload_result
|
|
131
131
|
|
|
132
132
|
|
|
133
133
|
def upload_file(self, file, body, headers):
|
|
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
|
|
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
|
|
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
|