22
33from __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
68from sap_cloud_sdk .core .odata ._transport import ODataHttpTransport
79from sap_cloud_sdk .core .odata ._async_transport import AsyncODataHttpTransport
810from 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 )
0 commit comments