diff --git a/search-service/config/detekt/baseline.xml b/search-service/config/detekt/baseline.xml index 1d258d355..f467d3c62 100644 --- a/search-service/config/detekt/baseline.xml +++ b/search-service/config/detekt/baseline.xml @@ -26,7 +26,6 @@ LongParameterList:EntityAttributeService.kt$EntityAttributeService$( attribute: Attribute, attributeName: ExpandedTerm, attributeMetadata: AttributeMetadata, mergedAt: ZonedDateTime, observedAt: ZonedDateTime?, attributePayload: ExpandedAttributeInstance, sub: Sub? ) LongParameterList:EntityAttributeService.kt$EntityAttributeService$( attribute: Attribute, ngsiLdAttribute: NgsiLdAttribute, attributeMetadata: AttributeMetadata, createdAt: ZonedDateTime, attributePayload: ExpandedAttributeInstance, sub: Sub? ) LongParameterList:EntityAttributeService.kt$EntityAttributeService$( entityId: URI, attributeName: ExpandedTerm, attributeMetadata: AttributeMetadata, createdAt: ZonedDateTime, attributePayload: ExpandedAttributeInstance, sub: Sub? ) - LongParameterList:EntityAttributeService.kt$EntityAttributeService$( entityId: URI, attributeName: ExpandedTerm, datasetId: URI?, attributeValues: ExpandedAttributeInstance, modifiedAt: ZonedDateTime, sub: Sub? ) LongParameterList:EntityAttributeService.kt$EntityAttributeService$( entityUri: URI, ngsiLdAttributes: List<NgsiLdAttribute>, expandedAttributes: ExpandedAttributes, createdAt: ZonedDateTime, observedAt: ZonedDateTime?, sub: Sub? ) LongParameterList:EntityAttributeService.kt$EntityAttributeService$( entityUri: URI, ngsiLdAttributes: List<NgsiLdAttribute>, expandedAttributes: ExpandedAttributes, disallowOverwrite: Boolean, createdAt: ZonedDateTime, sub: Sub? ) LongParameterList:TemporalEntityHandler.kt$TemporalEntityHandler$( @RequestHeader httpHeaders: HttpHeaders, @PathVariable entityId: URI, @PathVariable attrId: String, @PathVariable instanceId: URI, @RequestBody requestBody: Mono<String>, @AllowedParameters(notImplemented = [QP.LOCAL, QP.VIA]) @RequestParam queryParams: MultiValueMap<String, String> ) diff --git a/search-service/src/main/kotlin/com/egm/stellio/search/entity/service/EntityAttributeService.kt b/search-service/src/main/kotlin/com/egm/stellio/search/entity/service/EntityAttributeService.kt index 84431d6b0..71ac72612 100644 --- a/search-service/src/main/kotlin/com/egm/stellio/search/entity/service/EntityAttributeService.kt +++ b/search-service/src/main/kotlin/com/egm/stellio/search/entity/service/EntityAttributeService.kt @@ -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, @@ -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, @@ -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() }) @@ -748,9 +760,7 @@ class EntityAttributeService( ).bind().first() } else { applyPartialUpdatePatchOperation( - entityId, - attributeName, - datasetId, + currentAttribute, attributeValues, modifiedAt, sub @@ -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 = 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") @@ -793,8 +800,8 @@ class EntityAttributeService( attributeInstanceService.create(attributeInstance).bind() SucceededAttributeOperationResult( - attributeName, - datasetId, + attribute.attributeName, + attribute.datasetId, OperationStatus.UPDATED, updatedAttributeInstance )