Skip to content

Commit ab64bc0

Browse files
committed
fix(dpi_ng/consent): correct entity schemas, primary keys, OData query, and mutation headers
1 parent bbd9c55 commit ab64bc0

13 files changed

Lines changed: 267 additions & 293 deletions

src/sap_cloud_sdk/core/dpi_ng/consent/client.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,44 @@ def save(self, entity: Any) -> None:
156156
entity: A python-odata entity instance to create or update.
157157
"""
158158
logger.info("Invoked ODataClient.save")
159-
entity.__odata_service__.save(entity)
159+
if entity.__odata__.persisted:
160+
self._session.headers["If-Match"] = "*"
161+
try:
162+
entity.__odata_service__.save(entity)
163+
finally:
164+
self._session.headers.pop("If-Match", None)
160165
logger.info("Exiting ODataClient.save")
161166

167+
@staticmethod
168+
def _apply_body(entity: Any, body: dict[str, Any]) -> None:
169+
"""Set fields from *body* on *entity* and force-mark each as dirty.
170+
171+
The odata library only marks a field dirty when the value changes, so
172+
fields already matching their current value are silently dropped from
173+
the PATCH body. Forcing dirty ensures the server always receives every
174+
field the caller explicitly provided.
175+
176+
Unknown keys (not mapped as odata property descriptors on the entity
177+
class) are silently ignored and never sent in the request.
178+
"""
179+
for k, v in body.items():
180+
prop = getattr(type(entity), k, None)
181+
if prop is not None:
182+
setattr(entity, k, v)
183+
entity.__odata__.set_property_dirty(prop)
184+
162185
def delete_entity(self, entity: Any) -> None:
163186
"""Send a DELETE request for the given entity.
164187
165188
Args:
166189
entity: A python-odata entity instance to delete.
167190
"""
168191
logger.info("Invoked ODataClient.delete_entity")
169-
entity.__odata_service__.delete(entity)
192+
self._session.headers["If-Match"] = "*"
193+
try:
194+
entity.__odata_service__.delete(entity)
195+
finally:
196+
self._session.headers.pop("If-Match", None)
170197
logger.info("Exiting ODataClient.delete_entity")
171198

172199
# ------------------------------------------------------------------

src/sap_cloud_sdk/core/dpi_ng/consent/dtos/consent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class CreateConsentRequest(_CamelSerializable):
6464
template_name: str
6565
language_code: str
6666
data_subject_type_name: str
67-
jurisdiction_code: str
67+
jurisdiction_code: str | None = None
6868
data_subject_description: str | None = None
6969
outbound_channel_type_name: str | None = None
7070
outbound_channel: str | None = None
@@ -88,5 +88,5 @@ class WithdrawConsentRequest(_CamelSerializable):
8888
"""
8989

9090
consent_id: str
91-
withdrawn_by: str
91+
withdrawn_by: str | None = None
9292
withdrawn_at: str | None = None

src/sap_cloud_sdk/core/dpi_ng/consent/entities/consent.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ class Consent(Service.Entity):
4646
third_party_function_code = StringProperty("thirdPartyFunctionCode")
4747
consent_status_code = StringProperty("consentStatusCode")
4848
lifecycle_status_code = StringProperty("lifecycleStatusCode")
49-
purpose_description_text_id = StringProperty("purposeDescriptionTextId")
50-
purpose_explanatory_text_id = StringProperty("purposeExplanatoryTextId")
51-
template_description_text_id = StringProperty("templateDescriptionTextId")
52-
template_explanatory_text_id = StringProperty("templateExplanatoryTextId")
53-
template_question_text_id = StringProperty("templateQuestionTextId")
54-
template_consequence_text_id = StringProperty("templateConsequenceTextId")
55-
template_data_privacy_statement_text_id = StringProperty(
49+
purpose_description_text_id = UUIDProperty("purposeDescriptionTextId")
50+
purpose_explanatory_text_id = UUIDProperty("purposeExplanatoryTextId")
51+
template_description_text_id = UUIDProperty("templateDescriptionTextId")
52+
template_explanatory_text_id = UUIDProperty("templateExplanatoryTextId")
53+
template_question_text_id = UUIDProperty("templateQuestionTextId")
54+
template_consequence_text_id = UUIDProperty("templateConsequenceTextId")
55+
template_data_privacy_statement_text_id = UUIDProperty(
5656
"templateDataPrivacyStatementTextId"
5757
)
5858
purpose_sensitive_data_flag = BooleanProperty("purposeSensitiveDataFlag")

src/sap_cloud_sdk/core/dpi_ng/consent/entities/consent_configuration.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class Jurisdiction(Service.Entity):
3030
tenant = StringProperty("tenant")
3131
jurisdiction_id = UUIDProperty("jurisdictionId", primary_key=True)
3232
jurisdiction_code = StringProperty("jurisdictionCode")
33-
description = StringProperty("description")
3433
created_at = DatetimeProperty("createdAt")
3534
created_by = StringProperty("createdBy")
3635
changed_at = DatetimeProperty("changedAt")
@@ -40,8 +39,10 @@ class JurisdictionText(Service.Entity):
4039
"""OData entity representing a localised description for a jurisdiction."""
4140

4241
__odata_collection__ = "jurisdictionTexts"
43-
jurisdiction_id = UUIDProperty("jurisdictionId", primary_key=True)
44-
language_code = StringProperty("languageCode", primary_key=True)
42+
jurisdiction_text_id = UUIDProperty("jurisdictionTextId", primary_key=True)
43+
jurisdiction_code = StringProperty("jurisdictionCode")
44+
jurisdiction_id = UUIDProperty("jurisdictionId")
45+
language_code = StringProperty("languageCode")
4546
description = StringProperty("description")
4647

4748
class Language(Service.Entity):
@@ -59,7 +60,9 @@ class LanguageDescription(Service.Entity):
5960
"""OData entity representing an additional description for a language."""
6061

6162
__odata_collection__ = "languageDescriptions"
62-
language_code = StringProperty("languageCode", primary_key=True)
63+
language_desc_id = UUIDProperty("languageDescId", primary_key=True)
64+
language_code = StringProperty("languageCode")
65+
description_language_code = StringProperty("descriptionLanguageCode")
6366
description = StringProperty("description")
6467

6568
class SourceInfo(Service.Entity):
@@ -144,7 +147,9 @@ class OutboundChannelType(Service.Entity):
144147
outbound_channel_type_name = StringProperty("outboundChannelTypeName")
145148
description = StringProperty("description")
146149
created_at = DatetimeProperty("createdAt")
150+
created_by = StringProperty("createdBy")
147151
changed_at = DatetimeProperty("changedAt")
152+
changed_by = StringProperty("changedBy")
148153

149154
return (
150155
ThirdParty,

src/sap_cloud_sdk/core/dpi_ng/consent/entities/consent_purpose.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ class ConsentPurpose(Service.Entity):
2323
purpose_id = UUIDProperty("purposeId", primary_key=True)
2424
purpose_name = StringProperty("purposeName")
2525
lifecycle_status_code = StringProperty("lifecycleStatusCode")
26-
lifecycle_status_domain_description = StringProperty(
27-
"lifecycleStatusDomainDescription"
28-
)
2926
sensitive_data_flag = BooleanProperty("sensitiveDataFlag")
3027
created_at = DatetimeProperty("createdAt")
3128
created_by = StringProperty("createdBy")
@@ -37,9 +34,10 @@ class ConsentPurposeText(Service.Entity):
3734

3835
__odata_collection__ = "consentPurposeTexts"
3936
tenant = StringProperty("tenant")
40-
purpose_id = UUIDProperty("purposeId", primary_key=True)
41-
type_code = StringProperty("typeCode", primary_key=True)
42-
language_code = StringProperty("languageCode", primary_key=True)
37+
purpose_text_id = UUIDProperty("purposeTextId", primary_key=True)
38+
purpose_id = UUIDProperty("purposeId")
39+
language_code = StringProperty("languageCode")
40+
type_code = StringProperty("typeCode")
4341
text = StringProperty("text")
4442
changed_at = DatetimeProperty("changedAt")
4543

src/sap_cloud_sdk/core/dpi_ng/consent/entities/consent_retention.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ConsentRetentionRule(Service.Entity):
2727
controller_id = UUIDProperty("controllerId")
2828
jurisdiction_code = StringProperty("jurisdictionCode")
2929
consent_model_code = StringProperty("consentModelCode")
30+
retention_period = IntegerProperty("retentionPeriod")
3031
retention_years = IntegerProperty("retentionYears")
3132
retention_months = IntegerProperty("retentionMonths")
3233
retention_days = IntegerProperty("retentionDays")

src/sap_cloud_sdk/core/dpi_ng/consent/entities/consent_template.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from odata.property import (
88
BooleanProperty,
99
DatetimeProperty,
10+
IntegerProperty,
1011
StringProperty,
1112
UUIDProperty,
1213
)
@@ -28,8 +29,8 @@ class ConsentTemplate(Service.Entity):
2829
jurisdiction_code = StringProperty("jurisdictionCode")
2930
consent_model_code = StringProperty("consentModelCode")
3031
application_template_id = StringProperty("applicationTemplateId")
31-
validity_period = StringProperty("validityPeriod")
32-
expiring_period = StringProperty("expiringPeriod")
32+
validity_period = IntegerProperty("validityPeriod")
33+
expiring_period = IntegerProperty("expiringPeriod")
3334
lifecycle_status_code = StringProperty("lifecycleStatusCode")
3435
purpose_name = StringProperty("purposeName")
3536
controller_name = StringProperty("controllerName")
@@ -44,9 +45,10 @@ class ConsentTemplateText(Service.Entity):
4445

4546
__odata_collection__ = "consentTemplateTexts"
4647
tenant = StringProperty("tenant")
47-
template_id = UUIDProperty("templateId", primary_key=True)
48-
type_code = StringProperty("typeCode", primary_key=True)
49-
language_code = StringProperty("languageCode", primary_key=True)
48+
template_text_id = UUIDProperty("templatTextId", primary_key=True)
49+
template_id = UUIDProperty("templateId")
50+
language_code = StringProperty("languageCode")
51+
type_code = StringProperty("typeCode")
5052
text = StringProperty("text")
5153
changed_at = DatetimeProperty("changedAt")
5254

@@ -55,11 +57,12 @@ class TemplateThirdPartyPersData(Service.Entity):
5557

5658
__odata_collection__ = "templateThirdPartyPersDatas"
5759
tenant = StringProperty("tenant")
60+
third_party_assignment_id = UUIDProperty("thirdPartyAssignmentId", primary_key=True)
5861
template_id = UUIDProperty("templateId", primary_key=True)
59-
third_party_id = UUIDProperty("thirdPartyId", primary_key=True)
62+
third_party_id = UUIDProperty("thirdPartyId")
63+
third_party_name = StringProperty("thirdPartyName")
6064
third_party_function_code = StringProperty("thirdPartyFunctionCode")
6165
sensitive_data_flag = BooleanProperty("sensitiveDataFlag")
62-
created_at = DatetimeProperty("createdAt")
6366
changed_at = DatetimeProperty("changedAt")
6467

6568
return (

src/sap_cloud_sdk/core/dpi_ng/consent/services/_query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def _apply_query(q: Any, params: dict[str, Any]) -> Any:
1919
The Query instance with all supported options applied.
2020
"""
2121
if "filter" in params:
22-
q = q.raw({"$filter": params["filter"]})
22+
q = q.filter(params["filter"])
2323
if "top" in params:
2424
q = q.limit(int(params["top"]))
2525
if "skip" in params:
2626
q = q.offset(int(params["skip"]))
2727
if "orderby" in params:
28-
q = q.raw({"$orderby": params["orderby"]})
28+
q = q.order_by(params["orderby"])
2929
return q

0 commit comments

Comments
 (0)