Skip to content

Commit

Permalink
fixup: clear the replace attribute logic
Browse files Browse the repository at this point in the history
- do not delete the previous attribute
- create only a modifiedAt trace
- do again a replace in update entity attributes (a partial update patch at the Entity level, not at the Attribute level as in 5.6.4)
  • Loading branch information
bobeal committed Jan 9, 2025
1 parent 655717f commit a6b8b37
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
1 change: 0 additions & 1 deletion search-service/config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<ID>LongParameterList:EntityAttributeService.kt$EntityAttributeService$( attribute: Attribute, attributeName: ExpandedTerm, attributeMetadata: AttributeMetadata, mergedAt: ZonedDateTime, observedAt: ZonedDateTime?, attributePayload: ExpandedAttributeInstance, sub: Sub? )</ID>
<ID>LongParameterList:EntityAttributeService.kt$EntityAttributeService$( attribute: Attribute, ngsiLdAttribute: NgsiLdAttribute, attributeMetadata: AttributeMetadata, createdAt: ZonedDateTime, attributePayload: ExpandedAttributeInstance, sub: Sub? )</ID>
<ID>LongParameterList:EntityAttributeService.kt$EntityAttributeService$( entityId: URI, attributeName: ExpandedTerm, attributeMetadata: AttributeMetadata, createdAt: ZonedDateTime, attributePayload: ExpandedAttributeInstance, sub: Sub? )</ID>
<ID>LongParameterList:EntityAttributeService.kt$EntityAttributeService$( entityId: URI, attributeName: ExpandedTerm, datasetId: URI?, attributeValues: ExpandedAttributeInstance, modifiedAt: ZonedDateTime, sub: Sub? )</ID>
<ID>LongParameterList:EntityAttributeService.kt$EntityAttributeService$( entityUri: URI, ngsiLdAttributes: List&lt;NgsiLdAttribute&gt;, expandedAttributes: ExpandedAttributes, createdAt: ZonedDateTime, observedAt: ZonedDateTime?, sub: Sub? )</ID>
<ID>LongParameterList:EntityAttributeService.kt$EntityAttributeService$( entityUri: URI, ngsiLdAttributes: List&lt;NgsiLdAttribute&gt;, expandedAttributes: ExpandedAttributes, disallowOverwrite: Boolean, createdAt: ZonedDateTime, sub: Sub? )</ID>
<ID>LongParameterList:TemporalEntityHandler.kt$TemporalEntityHandler$( @RequestHeader httpHeaders: HttpHeaders, @PathVariable entityId: URI, @PathVariable attrId: String, @PathVariable instanceId: URI, @RequestBody requestBody: Mono&lt;String&gt;, @AllowedParameters(notImplemented = [QP.LOCAL, QP.VIA]) @RequestParam queryParams: MultiValueMap&lt;String, String&gt; )</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,15 @@ class EntityAttributeService(
)
val attributeUuid = create(attribute).bind()

// if the temporal property existed before, the create operation returned a different id than the one
// in the attribute object
val timeProperty =
if (attributeUuid != attribute.id) AttributeInstance.TemporalProperty.MODIFIED_AT
else AttributeInstance.TemporalProperty.CREATED_AT

val attributeInstance = AttributeInstance(
attributeUuid = attributeUuid,
timeProperty = AttributeInstance.TemporalProperty.CREATED_AT,
timeProperty = timeProperty,
time = createdAt,
attributeMetadata = attributeMetadata,
payload = attributePayload,
Expand Down Expand Up @@ -254,7 +260,6 @@ class EntityAttributeService(
attributeMetadata.datasetId,
attribute.entityId
)
deleteAttribute(attribute.entityId, attribute.attributeName, attribute.datasetId, false, createdAt).bind()
addAttribute(
attribute.entityId,
attribute.attributeName,
Expand Down Expand Up @@ -705,14 +710,21 @@ class EntityAttributeService(
createdAt
).bind().first()
} else {
applyPartialUpdatePatchOperation(
entityUri,
ngsiLdAttribute.name,
ngsiLdAttributeInstance.datasetId,
attributePayload,
replaceAttribute(
currentAttribute,
ngsiLdAttribute,
attributeMetadata,
createdAt,
attributePayload,
sub
).bind()
).map {
SucceededAttributeOperationResult(
ngsiLdAttribute.name,
ngsiLdAttributeInstance.datasetId,
OperationStatus.REPLACED,
attributePayload
)
}.bind()
}
}
}.fold({ it.left() }, { it.right() })
Expand Down Expand Up @@ -748,9 +760,7 @@ class EntityAttributeService(
).bind().first()
} else {
applyPartialUpdatePatchOperation(
entityId,
attributeName,
datasetId,
currentAttribute,
attributeValues,
modifiedAt,
sub
Expand All @@ -761,16 +771,13 @@ class EntityAttributeService(
}

@Transactional
suspend fun applyPartialUpdatePatchOperation(
entityId: URI,
attributeName: ExpandedTerm,
datasetId: URI?,
internal suspend fun applyPartialUpdatePatchOperation(
attribute: Attribute,
attributeValues: ExpandedAttributeInstance,
modifiedAt: ZonedDateTime,
sub: Sub?
): Either<APIException, SucceededAttributeOperationResult> = either {
// first update payload in temporal entity attribute
val attribute = getForEntityAndAttribute(entityId, attributeName, datasetId).bind()
attributeValues[JSONLD_TYPE]?.let {
ensure(isAttributeOfType(attributeValues, AttributeType(NGSILD_PREFIX + attribute.attributeType))) {
BadRequestDataException("The type of the attribute has to be the same as the existing one")
Expand All @@ -793,8 +800,8 @@ class EntityAttributeService(
attributeInstanceService.create(attributeInstance).bind()

SucceededAttributeOperationResult(
attributeName,
datasetId,
attribute.attributeName,
attribute.datasetId,
OperationStatus.UPDATED,
updatedAttributeInstance
)
Expand Down

0 comments on commit a6b8b37

Please sign in to comment.