das-cli 1.5.7__tar.gz → 1.5.11__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.7/das_cli.egg-info → das_cli-1.5.11}/PKG-INFO +1 -1
- {das_cli-1.5.7 → das_cli-1.5.11}/das/managers/digital_objects_manager.py +37 -15
- {das_cli-1.5.7 → das_cli-1.5.11}/das/services/digital_objects.py +34 -15
- {das_cli-1.5.7 → das_cli-1.5.11/das_cli.egg-info}/PKG-INFO +1 -1
- {das_cli-1.5.7 → das_cli-1.5.11}/pyproject.toml +1 -1
- {das_cli-1.5.7 → das_cli-1.5.11}/LICENSE +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/MANIFEST.in +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/README.md +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/__init__.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/ai/plugins/dasai.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/ai/plugins/entries/entries_plugin.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/app.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/authentication/auth.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/authentication/oauth.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/authentication/secure_input.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/cli.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/common/api.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/common/config.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/common/entry_fields_constants.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/common/enums.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/common/file_utils.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/managers/__init__.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/managers/download_manager.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/managers/entries_manager.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/managers/search_manager.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/services/attributes.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/services/cache.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/services/das_elastic_search.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/services/downloads.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/services/entries.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/services/entry_fields.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/services/hangfire.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/services/search.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/services/service_base.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das/services/users.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das_cli.egg-info/SOURCES.txt +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das_cli.egg-info/dependency_links.txt +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das_cli.egg-info/entry_points.txt +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das_cli.egg-info/requires.txt +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/das_cli.egg-info/top_level.txt +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/setup.cfg +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/tests/__init__.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/tests/attributes_test.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/tests/download_manager_test.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/tests/entries_manager_test.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/tests/entries_service_test.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/tests/entries_test.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/tests/file_utils_test.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/tests/run_tests.py +0 -0
- {das_cli-1.5.7 → das_cli-1.5.11}/tests/search_manager_test.py +0 -0
|
@@ -51,34 +51,56 @@ class DigitalObjectsManager:
|
|
|
51
51
|
|
|
52
52
|
return result
|
|
53
53
|
|
|
54
|
-
def
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
entry_response = self.entry_service.get_entry(entry_code)
|
|
64
|
-
if entry_response is None:
|
|
65
|
-
raise ValueError(f"Entry with code '{entry_code}' not found")
|
|
59
|
+
skipCount=0,
|
|
60
|
+
)
|
|
66
61
|
|
|
67
|
-
if response.get(
|
|
62
|
+
if response.get("totalCount", 0) == 0:
|
|
68
63
|
raise ValueError(f"Digital object type '{digital_object_type}' not found")
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
|
|
65
|
+
return response.get("items", [])[0].get("entry").get("id")
|
|
66
|
+
|
|
67
|
+
def upload_file(
|
|
68
|
+
self, file_description: str, digital_object_type: str, file_path: str
|
|
69
|
+
) -> str:
|
|
70
|
+
"""Upload a file as a digital object without linking it to an entry."""
|
|
71
|
+
digital_object_type_id = self._resolve_digital_object_type_id(digital_object_type)
|
|
72
|
+
digital_object_id = self.digital_objects_service.upload_digital_object(
|
|
73
|
+
file_description, digital_object_type_id, file_path
|
|
74
|
+
)
|
|
72
75
|
|
|
73
76
|
if not digital_object_id:
|
|
74
77
|
raise ValueError(f"Upload did not return a digital object id for '{file_path}'")
|
|
75
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")
|
|
89
|
+
|
|
90
|
+
entry_payload = entry_response.get("entry")
|
|
91
|
+
if entry_payload is None:
|
|
92
|
+
raise ValueError(f"Entry with code '{entry_code}' not found")
|
|
93
|
+
|
|
76
94
|
self.digital_objects_service.link_existing_digital_objects(
|
|
77
|
-
attribute_id=entry_response.get(
|
|
78
|
-
entry_id=
|
|
79
|
-
digital_object_id_list=
|
|
95
|
+
attribute_id=entry_response.get("attributeId"),
|
|
96
|
+
entry_id=entry_payload.get("id"),
|
|
97
|
+
digital_object_id_list=digital_object_ids,
|
|
80
98
|
)
|
|
81
99
|
|
|
100
|
+
def upload_digital_object(self, entry_code: str, file_description: str, digital_object_type: str, file_path: str):
|
|
101
|
+
"""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])
|
|
82
104
|
return digital_object_id
|
|
83
105
|
|
|
84
106
|
def download_digital_object(self, output_path: str, digital_object_id: str = None, digital_object_code: str = None):
|
|
@@ -41,7 +41,15 @@ class DigitalObjectsService(ServiceBase):
|
|
|
41
41
|
f"{self.base_url}/LinkExistingDigitalObject", data=payload, headers=headers
|
|
42
42
|
)
|
|
43
43
|
|
|
44
|
-
|
|
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,6 +60,14 @@ class DigitalObjectsService(ServiceBase):
|
|
|
52
60
|
yield data
|
|
53
61
|
|
|
54
62
|
|
|
63
|
+
def _extract_upload_result_id(self, response: dict | None) -> str | None:
|
|
64
|
+
if not response:
|
|
65
|
+
return None
|
|
66
|
+
result = response.get("result", response)
|
|
67
|
+
if isinstance(result, dict):
|
|
68
|
+
return result.get("id")
|
|
69
|
+
return None
|
|
70
|
+
|
|
55
71
|
def upload_digital_object(self, file_description: str, digital_object_type_id: str, file_path: str):
|
|
56
72
|
|
|
57
73
|
if not exists(file_path):
|
|
@@ -67,6 +83,7 @@ class DigitalObjectsService(ServiceBase):
|
|
|
67
83
|
"id": str(uuid.uuid4()).lower(),
|
|
68
84
|
"totalCount": ceil(os.path.getsize(file_path) / CHUNK_SIZE),
|
|
69
85
|
"index": 0,
|
|
86
|
+
"chunkStart": 0,
|
|
70
87
|
}
|
|
71
88
|
|
|
72
89
|
byte_offset = 0
|
|
@@ -78,30 +95,32 @@ class DigitalObjectsService(ServiceBase):
|
|
|
78
95
|
try:
|
|
79
96
|
for chunk in self.__read_in_chunks(binary_file, CHUNK_SIZE):
|
|
80
97
|
chunk_end = byte_offset + len(chunk)
|
|
81
|
-
|
|
98
|
+
metadata["index"] = chunk_index
|
|
99
|
+
metadata["chunkStart"] = byte_offset
|
|
100
|
+
headers["Content-Range"] = "bytes %s-%s/%s" % (
|
|
82
101
|
byte_offset,
|
|
83
102
|
chunk_end - 1,
|
|
84
|
-
metadata.get(
|
|
103
|
+
metadata.get("fileSize"),
|
|
85
104
|
)
|
|
86
|
-
byte_offset = chunk_end
|
|
87
|
-
metadata['index'] = chunk_index
|
|
88
105
|
json_metadata = json.dumps(metadata)
|
|
89
|
-
base654_bytes = b64encode(json_metadata.encode(
|
|
90
|
-
headers[
|
|
106
|
+
base654_bytes = b64encode(json_metadata.encode("utf-8")).decode("ascii")
|
|
107
|
+
headers["metadata"] = base654_bytes
|
|
91
108
|
|
|
92
109
|
r = self.upload_file(chunk, metadata, headers)
|
|
93
110
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
raise ValueError(
|
|
98
|
-
f"Upload failed for '{file_path}': no result on final chunk"
|
|
99
|
-
)
|
|
100
|
-
continue
|
|
111
|
+
uploaded_id = self._extract_upload_result_id(r)
|
|
112
|
+
if uploaded_id:
|
|
113
|
+
digital_object_id = uploaded_id
|
|
101
114
|
|
|
102
|
-
|
|
115
|
+
byte_offset = chunk_end
|
|
103
116
|
chunk_index += 1
|
|
104
117
|
|
|
118
|
+
is_final_chunk = chunk_index >= metadata["totalCount"]
|
|
119
|
+
if is_final_chunk and digital_object_id is None:
|
|
120
|
+
raise ValueError(
|
|
121
|
+
f"Upload failed for '{file_path}': no digital object id on final chunk"
|
|
122
|
+
)
|
|
123
|
+
|
|
105
124
|
except Exception as e:
|
|
106
125
|
raise ValueError(f"Error uploading file '{file_path}': {str(e)}")
|
|
107
126
|
|
|
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
|