Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/sap_cloud_sdk/adms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,20 @@
)
from sap_cloud_sdk.adms._models import (
AllowedDomain,
ApplicationTenant,
BaseType,
BusinessObjectNodeChangeLog,
BusinessObjectNodeType,
ChangeLog,
CreateAllowedDomainInput,
CreateApplicationTenantInput,
CreateBusinessObjectNodeTypeInput,
CreateDocumentTypeBoTypeMapInput,
CreateDocumentInput,
CreateDocumentRelationInput,
CreateDocumentTypeInput,
CreateFileExtensionPolicyInput,
DeleteBusinessObjectNodeResult,
DeleteUserDataJobParameters,
Document,
DocumentContentVersion,
Expand All @@ -74,6 +80,7 @@
DraftActivateInput,
DraftAdministrativeData,
DraftInput,
FileExtensionPolicy,
JobInput,
JobOutput,
JobStatus,
Expand Down Expand Up @@ -113,8 +120,11 @@
"ScanNotCleanError",
# models — core
"BaseType",
"ChangeLog",
"BusinessObjectNodeChangeLog",
"CreateDocumentInput",
"CreateDocumentRelationInput",
"DeleteBusinessObjectNodeResult",
"DeleteUserDataJobParameters",
"Document",
"DocumentContentVersion",
Expand All @@ -131,17 +141,21 @@
"ZipDownloadJobParameters",
# models — config
"AllowedDomain",
"ApplicationTenant",
"BusinessObjectNodeType",
"CreateAllowedDomainInput",
"CreateApplicationTenantInput",
"CreateBusinessObjectNodeTypeInput",
"UpdateAllowedDomainInput",
"UpdateBusinessObjectNodeTypeInput",
"UpdateDocumentTypeInput",
"CreateDocumentTypeBoTypeMapInput",
"CreateDocumentTypeInput",
"CreateFileExtensionPolicyInput",
"DocumentType",
"DocumentTypeBusinessObjectTypeMap",
"DocumentTypeText",
"FileExtensionPolicy",
"UpdateAllowedDomainInput",
"UpdateBusinessObjectNodeTypeInput",
"UpdateDocumentTypeInput",
# query options
"ConfigQueryOptions",
"DocumentQueryOptions",
Expand Down
195 changes: 134 additions & 61 deletions src/sap_cloud_sdk/adms/_configuration_api.py

Large diffs are not rendered by default.

60 changes: 27 additions & 33 deletions src/sap_cloud_sdk/adms/_document_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def get_download_url(
document_relation_id: str,
*,
is_active_entity: bool = True,
doc_content_version_id: str,
doc_content_version_id: str | None = None,
) -> str:
"""Return a time-limited presigned download URL for a document.

Expand All @@ -125,6 +125,7 @@ def get_download_url(
document_relation_id: UUID of the parent DocumentRelation.
is_active_entity: Active vs draft entity flag.
doc_content_version_id: Content version to download (e.g. ``"1.0"``).
If ``None``, the latest version is downloaded.

Returns:
Presigned URL string.
Expand Down Expand Up @@ -153,10 +154,13 @@ def get_download_url(
f"Downloads are only permitted when state is CLEAN."
)

fn_key = (
f"{rel_key}/DownloadDocument("
f"DocContentVersionID={quote_odata_string_key(doc_content_version_id)})"
)
if doc_content_version_id is not None:
fn_key = (
f"{rel_key}/com.sap.adm.DocumentService.DownloadDocument("
f"DocContentVersionID={quote_odata_string_key(doc_content_version_id)})"
)
else:
fn_key = f"{rel_key}/com.sap.adm.DocumentService.DownloadDocument()"
resp = self._http.get(fn_key, service_base=_SERVICE_PATH)
return resp.json().get("value", "")

Expand All @@ -170,29 +174,21 @@ def update(
) -> Document:
"""Update document metadata via the bound ``UpdateDocument`` action.

ADM's UpdateDocument action returns only the changed fields. This
method transparently follows up with a GET to return the full Document.

Args:
document_relation_id: UUID of the parent DocumentRelation.
update_input: Fields to update (only non-None fields are sent).
is_active_entity: Active vs draft entity flag.

Returns:
Full updated :class:`~sap_cloud_sdk.adms._models.Document`.
Partial :class:`~sap_cloud_sdk.adms._models.Document` as returned
by the ADM ``UpdateDocument`` action (only changed fields populated).
"""
path = (
build_relation_key_path(document_relation_id, is_active_entity)
+ "/UpdateDocument"
+ "/com.sap.adm.DocumentService.UpdateDocument"
)
payload = {"Document": update_input.to_odata_dict()}
self._http.post(path, json=payload, service_base=_SERVICE_PATH)
# UpdateDocument returns only changed fields — fetch the full entity.
full_path = (
build_relation_key_path(document_relation_id, is_active_entity)
+ "/Document"
)
resp = self._http.get(full_path, service_base=_SERVICE_PATH)
resp = self._http.post(path, json=payload, service_base=_SERVICE_PATH)
return Document.from_dict(resp.json())

@record_metrics(Module.ADMS, Operation.ADMS_DOCUMENTS_RESTORE_CONTENT_VERSION)
Expand All @@ -217,7 +213,7 @@ def restore_content_version(
"""
path = (
build_relation_key_path(document_relation_id, is_active_entity)
+ "/RestoreDocumentContentVersion"
+ "/com.sap.adm.DocumentService.RestoreDocumentContentVersion"
)
payload: dict = {
"DocumentContentVersion": {
Expand Down Expand Up @@ -246,7 +242,7 @@ def delete_content_version(
"""
path = (
build_relation_key_path(document_relation_id, is_active_entity)
+ "/DeleteDocumentContentVersion"
+ "/com.sap.adm.DocumentService.DeleteDocumentContentVersion"
)
self._http.post(
path,
Expand Down Expand Up @@ -316,7 +312,7 @@ async def get_download_url(
document_relation_id: str,
*,
is_active_entity: bool = True,
doc_content_version_id: str,
doc_content_version_id: str | None = None,
) -> str:
"""Async download URL fetch with scan-state gate."""
rel_key = build_relation_key_path(document_relation_id, is_active_entity)
Expand All @@ -339,10 +335,13 @@ async def get_download_url(
f"Downloads are only permitted when state is CLEAN."
)

fn_key = (
f"{rel_key}/DownloadDocument("
f"DocContentVersionID={quote_odata_string_key(doc_content_version_id)})"
)
if doc_content_version_id is not None:
fn_key = (
f"{rel_key}/com.sap.adm.DocumentService.DownloadDocument("
f"DocContentVersionID={quote_odata_string_key(doc_content_version_id)})"
)
else:
fn_key = f"{rel_key}/com.sap.adm.DocumentService.DownloadDocument()"
resp = await self._http.get(fn_key, service_base=_SERVICE_PATH)
return resp.json().get("value", "")

Expand All @@ -357,15 +356,10 @@ async def update(
"""Async variant of :meth:`_DocumentApi.update` — same semantics."""
path = (
build_relation_key_path(document_relation_id, is_active_entity)
+ "/UpdateDocument"
+ "/com.sap.adm.DocumentService.UpdateDocument"
)
payload = {"Document": update.to_odata_dict()}
await self._http.post(path, json=payload, service_base=_SERVICE_PATH)
full_path = (
build_relation_key_path(document_relation_id, is_active_entity)
+ "/Document"
)
resp = await self._http.get(full_path, service_base=_SERVICE_PATH)
resp = await self._http.post(path, json=payload, service_base=_SERVICE_PATH)
return Document.from_dict(resp.json())

@record_metrics(Module.ADMS, Operation.ADMS_DOCUMENTS_DELETE_CONTENT_VERSION)
Expand All @@ -379,7 +373,7 @@ async def delete_content_version(
"""Async variant of :meth:`_DocumentApi.delete_content_version` — same semantics."""
path = (
build_relation_key_path(document_relation_id, is_active_entity)
+ "/DeleteDocumentContentVersion"
+ "/com.sap.adm.DocumentService.DeleteDocumentContentVersion"
)
await self._http.post(
path,
Expand All @@ -399,7 +393,7 @@ async def restore_content_version(
"""Async variant of :meth:`_DocumentApi.restore_content_version` — same semantics."""
path = (
build_relation_key_path(document_relation_id, is_active_entity)
+ "/RestoreDocumentContentVersion"
+ "/com.sap.adm.DocumentService.RestoreDocumentContentVersion"
)
payload: dict = {
"DocumentContentVersion": {
Expand Down
Loading