diff --git a/search-service/config/detekt/baseline.xml b/search-service/config/detekt/baseline.xml index f467d3c62..1d258d355 100644 --- a/search-service/config/detekt/baseline.xml +++ b/search-service/config/detekt/baseline.xml @@ -26,6 +26,7 @@ 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 f020f47b0..84431d6b0 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 @@ -705,21 +705,14 @@ class EntityAttributeService( createdAt ).bind().first() } else { - replaceAttribute( - currentAttribute, - ngsiLdAttribute, - attributeMetadata, - createdAt, + applyPartialUpdatePatchOperation( + entityUri, + ngsiLdAttribute.name, + ngsiLdAttributeInstance.datasetId, attributePayload, + createdAt, sub - ).map { - SucceededAttributeOperationResult( - ngsiLdAttribute.name, - ngsiLdAttributeInstance.datasetId, - OperationStatus.REPLACED, - attributePayload - ) - }.bind() + ).bind() } } }.fold({ it.left() }, { it.right() }) @@ -754,40 +747,59 @@ class EntityAttributeService( modifiedAt ).bind().first() } else { - // 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") - } - } - val (jsonTargetObject, updatedAttributeInstance) = - partialUpdatePatch(attribute.payload.toExpandedAttributeInstance(), attributeValues) - val value = getValueFromPartialAttributePayload(attribute, updatedAttributeInstance) - val attributeValueType = guessAttributeValueType(attribute.attributeType, attributeValues) - updateOnUpdate(attribute.id, attributeValueType, modifiedAt, jsonTargetObject).bind() - - // then update attribute instance - val attributeInstance = createContextualAttributeInstance( - attribute, - updatedAttributeInstance, - value, - modifiedAt, - sub - ) - attributeInstanceService.create(attributeInstance).bind() - - SucceededAttributeOperationResult( + applyPartialUpdatePatchOperation( + entityId, attributeName, datasetId, - OperationStatus.UPDATED, - updatedAttributeInstance - ) + attributeValues, + modifiedAt, + sub + ).bind() } attributeOperationResult } + @Transactional + suspend fun applyPartialUpdatePatchOperation( + entityId: URI, + attributeName: ExpandedTerm, + datasetId: URI?, + 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") + } + } + val (jsonTargetObject, updatedAttributeInstance) = + partialUpdatePatch(attribute.payload.toExpandedAttributeInstance(), attributeValues) + val value = getValueFromPartialAttributePayload(attribute, updatedAttributeInstance) + val attributeValueType = guessAttributeValueType(attribute.attributeType, attributeValues) + updateOnUpdate(attribute.id, attributeValueType, modifiedAt, jsonTargetObject).bind() + + // then update attribute instance + val attributeInstance = createContextualAttributeInstance( + attribute, + updatedAttributeInstance, + value, + modifiedAt, + sub + ) + attributeInstanceService.create(attributeInstance).bind() + + SucceededAttributeOperationResult( + attributeName, + datasetId, + OperationStatus.UPDATED, + updatedAttributeInstance + ) + } + @Transactional suspend fun upsertAttributes( entityUri: URI,