Skip to content

Commit dab0a75

Browse files
committed
Refactor get by id
1 parent ee9c588 commit dab0a75

23 files changed

Lines changed: 854 additions & 346 deletions

‎src/sap_cloud_sdk/adms/_configuration_api.py‎

Lines changed: 133 additions & 57 deletions
Large diffs are not rendered by default.

‎src/sap_cloud_sdk/adms/_document_api.py‎

Lines changed: 95 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
from __future__ import annotations
44

5-
from sap_cloud_sdk.adms._keys import build_relation_key_path, quote_odata_string_key
5+
import uuid
6+
7+
from sap_cloud_sdk.core.odata._entity_key import EntityKey
68
from sap_cloud_sdk.core.odata._transport import ODataHttpTransport
79
from sap_cloud_sdk.core.odata._async_transport import AsyncODataHttpTransport
810
from sap_cloud_sdk.adms._models import (
@@ -86,9 +88,13 @@ def get(
8688
Raises:
8789
DocumentNotFoundError: If no relation with this ID exists.
8890
"""
89-
path = (
90-
build_relation_key_path(document_relation_id, is_active_entity)
91-
+ "/Document"
91+
path = str(
92+
EntityKey(
93+
"DocumentRelation",
94+
DocumentRelationID=uuid.UUID(document_relation_id),
95+
IsActiveEntity=is_active_entity,
96+
)
97+
/ "Document"
9298
)
9399
return Document.from_dict(self._http.get(path))
94100

@@ -116,7 +122,11 @@ def get_download_url(
116122
ScanNotCleanError: If the document is not in ``CLEAN`` scan state.
117123
DocumentNotFoundError: If the relation/document cannot be found.
118124
"""
119-
rel_key = build_relation_key_path(document_relation_id, is_active_entity)
125+
rel_key = EntityKey(
126+
"DocumentRelation",
127+
DocumentRelationID=uuid.UUID(document_relation_id),
128+
IsActiveEntity=is_active_entity,
129+
)
120130
data = self._http.get(f"{rel_key}?$expand=Document")
121131
doc_data = data.get("Document") or {}
122132
state_raw = doc_data.get("DocumentState", ScanStatus.PENDING.value)
@@ -132,9 +142,8 @@ def get_download_url(
132142
f"Downloads are only permitted when state is CLEAN."
133143
)
134144

135-
fn_key = (
136-
f"{rel_key}/DownloadDocument("
137-
f"DocContentVersionID={quote_odata_string_key(doc_content_version_id)})"
145+
fn_key = f"{rel_key}/DownloadDocument" + EntityKey.segment(
146+
DocContentVersionID=doc_content_version_id
138147
)
139148
return self._http.get(fn_key).get("value", "")
140149

@@ -160,14 +169,26 @@ def update(
160169
Full updated :class:`~sap_cloud_sdk.adms._models.Document`.
161170
"""
162171
self._http.post(
163-
build_relation_key_path(document_relation_id, is_active_entity)
164-
+ "/UpdateDocument",
172+
str(
173+
EntityKey(
174+
"DocumentRelation",
175+
DocumentRelationID=uuid.UUID(document_relation_id),
176+
IsActiveEntity=is_active_entity,
177+
)
178+
/ "UpdateDocument"
179+
),
165180
json={"Document": update_input.to_odata_dict()},
166181
)
167182
return Document.from_dict(
168183
self._http.get(
169-
build_relation_key_path(document_relation_id, is_active_entity)
170-
+ "/Document"
184+
str(
185+
EntityKey(
186+
"DocumentRelation",
187+
DocumentRelationID=uuid.UUID(document_relation_id),
188+
IsActiveEntity=is_active_entity,
189+
)
190+
/ "Document"
191+
)
171192
)
172193
)
173194

@@ -198,8 +219,14 @@ def restore_content_version(
198219
payload["DocumentContentVersion"]["DocContentVersionComment"] = comment
199220
return Document.from_dict(
200221
self._http.post(
201-
build_relation_key_path(document_relation_id, is_active_entity)
202-
+ "/RestoreDocumentContentVersion",
222+
str(
223+
EntityKey(
224+
"DocumentRelation",
225+
DocumentRelationID=uuid.UUID(document_relation_id),
226+
IsActiveEntity=is_active_entity,
227+
)
228+
/ "RestoreDocumentContentVersion"
229+
),
203230
json=payload,
204231
)
205232
)
@@ -220,8 +247,14 @@ def delete_content_version(
220247
is_active_entity: Active vs draft entity flag.
221248
"""
222249
self._http.post(
223-
build_relation_key_path(document_relation_id, is_active_entity)
224-
+ "/DeleteDocumentContentVersion",
250+
str(
251+
EntityKey(
252+
"DocumentRelation",
253+
DocumentRelationID=uuid.UUID(document_relation_id),
254+
IsActiveEntity=is_active_entity,
255+
)
256+
/ "DeleteDocumentContentVersion"
257+
),
225258
json={"DocContentVersionID": doc_content_version_id},
226259
)
227260

@@ -270,9 +303,13 @@ async def get(
270303
is_active_entity: bool = True,
271304
) -> Document:
272305
"""Async variant of :meth:`_DocumentApi.get` — same semantics."""
273-
path = (
274-
build_relation_key_path(document_relation_id, is_active_entity)
275-
+ "/Document"
306+
path = str(
307+
EntityKey(
308+
"DocumentRelation",
309+
DocumentRelationID=uuid.UUID(document_relation_id),
310+
IsActiveEntity=is_active_entity,
311+
)
312+
/ "Document"
276313
)
277314
return Document.from_dict(await self._http.get(path))
278315

@@ -285,7 +322,11 @@ async def get_download_url(
285322
doc_content_version_id: str,
286323
) -> str:
287324
"""Async download URL fetch with scan-state gate."""
288-
rel_key = build_relation_key_path(document_relation_id, is_active_entity)
325+
rel_key = EntityKey(
326+
"DocumentRelation",
327+
DocumentRelationID=uuid.UUID(document_relation_id),
328+
IsActiveEntity=is_active_entity,
329+
)
289330
data = await self._http.get(f"{rel_key}?$expand=Document")
290331
doc_data = data.get("Document") or {}
291332
state_raw = doc_data.get("DocumentState", ScanStatus.PENDING.value)
@@ -301,9 +342,8 @@ async def get_download_url(
301342
f"Downloads are only permitted when state is CLEAN."
302343
)
303344

304-
fn_key = (
305-
f"{rel_key}/DownloadDocument("
306-
f"DocContentVersionID={quote_odata_string_key(doc_content_version_id)})"
345+
fn_key = f"{rel_key}/DownloadDocument" + EntityKey.segment(
346+
DocContentVersionID=doc_content_version_id
307347
)
308348
return (await self._http.get(fn_key)).get("value", "")
309349

@@ -317,14 +357,26 @@ async def update(
317357
) -> Document:
318358
"""Async variant of :meth:`_DocumentApi.update` — same semantics."""
319359
await self._http.post(
320-
build_relation_key_path(document_relation_id, is_active_entity)
321-
+ "/UpdateDocument",
360+
str(
361+
EntityKey(
362+
"DocumentRelation",
363+
DocumentRelationID=uuid.UUID(document_relation_id),
364+
IsActiveEntity=is_active_entity,
365+
)
366+
/ "UpdateDocument"
367+
),
322368
json={"Document": update.to_odata_dict()},
323369
)
324370
return Document.from_dict(
325371
await self._http.get(
326-
build_relation_key_path(document_relation_id, is_active_entity)
327-
+ "/Document"
372+
str(
373+
EntityKey(
374+
"DocumentRelation",
375+
DocumentRelationID=uuid.UUID(document_relation_id),
376+
IsActiveEntity=is_active_entity,
377+
)
378+
/ "Document"
379+
)
328380
)
329381
)
330382

@@ -338,8 +390,14 @@ async def delete_content_version(
338390
) -> None:
339391
"""Async variant of :meth:`_DocumentApi.delete_content_version` — same semantics."""
340392
await self._http.post(
341-
build_relation_key_path(document_relation_id, is_active_entity)
342-
+ "/DeleteDocumentContentVersion",
393+
str(
394+
EntityKey(
395+
"DocumentRelation",
396+
DocumentRelationID=uuid.UUID(document_relation_id),
397+
IsActiveEntity=is_active_entity,
398+
)
399+
/ "DeleteDocumentContentVersion"
400+
),
343401
json={"DocContentVersionID": doc_content_version_id},
344402
)
345403

@@ -360,8 +418,14 @@ async def restore_content_version(
360418
payload["DocumentContentVersion"]["DocContentVersionComment"] = comment
361419
return Document.from_dict(
362420
await self._http.post(
363-
build_relation_key_path(document_relation_id, is_active_entity)
364-
+ "/RestoreDocumentContentVersion",
421+
str(
422+
EntityKey(
423+
"DocumentRelation",
424+
DocumentRelationID=uuid.UUID(document_relation_id),
425+
IsActiveEntity=is_active_entity,
426+
)
427+
/ "RestoreDocumentContentVersion"
428+
),
365429
json=payload,
366430
)
367431
)

‎src/sap_cloud_sdk/adms/_job_api.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from sap_cloud_sdk.adms._keys import build_job_status_key_path
5+
from sap_cloud_sdk.core.odata._entity_key import EntityKey
66
from sap_cloud_sdk.core.odata._transport import ODataHttpTransport
77
from sap_cloud_sdk.core.odata._async_transport import AsyncODataHttpTransport
88
from sap_cloud_sdk.adms._models import (
@@ -80,7 +80,9 @@ def get_status(
8080
Current :class:`~sap_cloud_sdk.adms._models.JobOutput`.
8181
"""
8282
transport = self._admin_http if use_admin_service else self._http
83-
return JobOutput.from_dict(transport.get(build_job_status_key_path(job_id)))
83+
return JobOutput.from_dict(
84+
transport.get(str(EntityKey("JobStatus", JobID=job_id)))
85+
)
8486

8587

8688
class _AsyncJobApi:
@@ -131,5 +133,5 @@ async def get_status(
131133
"""Poll the status of a running job (async)."""
132134
transport = self._admin_http if use_admin_service else self._http
133135
return JobOutput.from_dict(
134-
await transport.get(build_job_status_key_path(job_id))
136+
await transport.get(str(EntityKey("JobStatus", JobID=job_id)))
135137
)

‎src/sap_cloud_sdk/adms/_keys.py‎

Lines changed: 0 additions & 46 deletions
This file was deleted.

‎src/sap_cloud_sdk/adms/_models.py‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
from __future__ import annotations
1818

19+
from sap_cloud_sdk.core.odata._models import ODataEntity
20+
1921
from dataclasses import dataclass, field
2022
from enum import Enum
2123
from typing import Any
@@ -390,7 +392,7 @@ def from_dict(cls, data: dict) -> DraftAdministrativeData:
390392

391393

392394
@dataclass
393-
class DocumentRelation:
395+
class DocumentRelation(ODataEntity):
394396
"""Represents the link between a business object node and a stored document.
395397
396398
A DocumentRelation is the *link* between a business object node
@@ -558,7 +560,7 @@ def to_odata_dict(self) -> dict:
558560

559561

560562
@dataclass
561-
class AllowedDomain:
563+
class AllowedDomain(ODataEntity):
562564
"""Tenant-level domain allow-list for external URL documents.
563565
564566
Controls which hostnames are permitted as targets when a document
@@ -688,7 +690,7 @@ def to_odata_dict(self) -> dict:
688690

689691

690692
@dataclass
691-
class DocumentType:
693+
class DocumentType(ODataEntity):
692694
"""Tenant-configured document type (classification for documents).
693695
694696
ADM enforces AMS policies per document type. Each
@@ -787,7 +789,7 @@ def to_odata_dict(self) -> dict:
787789

788790

789791
@dataclass
790-
class BusinessObjectNodeType:
792+
class BusinessObjectNodeType(ODataEntity):
791793
"""Tenant-configured business object node type.
792794
793795
Each :class:`DocumentRelation` is anchored to a
@@ -877,7 +879,7 @@ def to_odata_dict(self) -> dict:
877879

878880

879881
@dataclass
880-
class DocumentTypeBusinessObjectTypeMap:
882+
class DocumentTypeBusinessObjectTypeMap(ODataEntity):
881883
"""Mapping that controls which document types are allowed for a business object node type.
882884
883885
Must be created before consumers can attach documents of a given type
@@ -1217,7 +1219,7 @@ class MimeTypePolicy(str, Enum):
12171219

12181220

12191221
@dataclass
1220-
class FileExtensionPolicy:
1222+
class FileExtensionPolicy(ODataEntity):
12211223
"""Tenant-level file extension allow/block policy.
12221224
12231225
ADM checks this list before accepting an upload.
@@ -1277,7 +1279,7 @@ def to_odata_dict(self) -> dict:
12771279

12781280

12791281
@dataclass
1280-
class ApplicationTenant:
1282+
class ApplicationTenant(ODataEntity):
12811283
"""Tenant-level application configuration.
12821284
12831285
Attributes:
@@ -1314,3 +1316,20 @@ def to_odata_dict(self) -> dict:
13141316
"ApplicationTenantID": self.application_tenant_id,
13151317
"ApplicationTenantName": self.application_tenant_name,
13161318
}
1319+
1320+
1321+
# OData entity metadata (set after class definition to avoid Python 3.14 dataclass issues)
1322+
AllowedDomain._entity_set = "AllowedDomainSet"
1323+
AllowedDomain._key_fields = ("AllowedDomainID",)
1324+
DocumentType._entity_set = "DocumentTypeSet"
1325+
DocumentType._key_fields = ("DocumentTypeID",)
1326+
BusinessObjectNodeType._entity_set = "BusinessObjectNodeTypeSet"
1327+
BusinessObjectNodeType._key_fields = ("BusinessObjectNodeTypeUniqueID",)
1328+
DocumentTypeBusinessObjectTypeMap._entity_set = "DocumentTypeBusinessObjectTypeMapSet"
1329+
DocumentTypeBusinessObjectTypeMap._key_fields = ("DocumentTypeBOTypeMapID",)
1330+
FileExtensionPolicy._entity_set = "FileExtensionPolicySet"
1331+
FileExtensionPolicy._key_fields = ("FileExtensionPolicyID",)
1332+
ApplicationTenant._entity_set = "ApplicationTenantSet"
1333+
ApplicationTenant._key_fields = ("ApplicationTenantID",)
1334+
DocumentRelation._entity_set = "DocumentRelation"
1335+
DocumentRelation._key_fields = ("DocumentRelationID", "IsActiveEntity")

0 commit comments

Comments
 (0)