diff --git a/search-service/src/main/kotlin/com/egm/stellio/search/model/UpdateResult.kt b/search-service/src/main/kotlin/com/egm/stellio/search/model/UpdateResult.kt index 4127d15bf0..ddb61f626e 100644 --- a/search-service/src/main/kotlin/com/egm/stellio/search/model/UpdateResult.kt +++ b/search-service/src/main/kotlin/com/egm/stellio/search/model/UpdateResult.kt @@ -20,6 +20,10 @@ data class UpdateResult( updated = this.updated.plus(other.updated), notUpdated = this.notUpdated.plus(other.notUpdated) ) + + @JsonIgnore + fun hasSuccessfulUpdate(): Boolean = + this.updated.isNotEmpty() } val EMPTY_UPDATE_RESULT: UpdateResult = UpdateResult(emptyList(), emptyList()) @@ -48,7 +52,8 @@ data class UpdateAttributeResult( this.updateOperationResult in listOf( UpdateOperationResult.APPENDED, UpdateOperationResult.REPLACED, - UpdateOperationResult.UPDATED + UpdateOperationResult.UPDATED, + UpdateOperationResult.IGNORED ) } @@ -62,9 +67,6 @@ enum class UpdateOperationResult { fun isSuccessResult(): Boolean = listOf(APPENDED, REPLACED, UPDATED).contains(this) } -fun UpdateResult.hasSuccessfulUpdate(): Boolean = - this.updated.isNotEmpty() - fun updateResultFromDetailedResult(updateStatuses: List): UpdateResult { val updated = updateStatuses.filter { it.isSuccessfullyUpdated() } .map { UpdatedDetails(it.attributeName, it.datasetId, it.updateOperationResult) } diff --git a/search-service/src/main/kotlin/com/egm/stellio/search/service/EntityPayloadService.kt b/search-service/src/main/kotlin/com/egm/stellio/search/service/EntityPayloadService.kt index 541406daf3..2f5f335523 100644 --- a/search-service/src/main/kotlin/com/egm/stellio/search/service/EntityPayloadService.kt +++ b/search-service/src/main/kotlin/com/egm/stellio/search/service/EntityPayloadService.kt @@ -492,33 +492,32 @@ class EntityPayloadService( expandedAttributes: ExpandedAttributes, disallowOverwrite: Boolean, sub: Sub? - ): Either = - either { - val (coreAttrs, otherAttrs) = - expandedAttributes.toList().partition { JSONLD_EXPANDED_ENTITY_SPECIFIC_MEMBERS.contains(it.first) } - val createdAt = ZonedDateTime.now(ZoneOffset.UTC) + ): Either = either { + val (coreAttrs, otherAttrs) = + expandedAttributes.toList().partition { JSONLD_EXPANDED_ENTITY_SPECIFIC_MEMBERS.contains(it.first) } + val createdAt = ZonedDateTime.now(ZoneOffset.UTC) - val operationType = - if (disallowOverwrite) APPEND_ATTRIBUTES - else APPEND_ATTRIBUTES_OVERWRITE_ALLOWED - val coreUpdateResult = updateCoreAttributes(entityUri, coreAttrs, createdAt, operationType).bind() - val attrsUpdateResult = temporalEntityAttributeService.appendEntityAttributes( - entityUri, - otherAttrs.toMap().toNgsiLdAttributes().bind(), - expandedAttributes, - disallowOverwrite, - createdAt, - sub - ).bind() + val operationType = + if (disallowOverwrite) APPEND_ATTRIBUTES + else APPEND_ATTRIBUTES_OVERWRITE_ALLOWED + val coreUpdateResult = updateCoreAttributes(entityUri, coreAttrs, createdAt, operationType).bind() + val attrsUpdateResult = temporalEntityAttributeService.appendEntityAttributes( + entityUri, + otherAttrs.toMap().toNgsiLdAttributes().bind(), + expandedAttributes, + disallowOverwrite, + createdAt, + sub + ).bind() - val updateResult = coreUpdateResult.mergeWith(attrsUpdateResult) - // update modifiedAt in entity if at least one attribute has been added - if (updateResult.hasSuccessfulUpdate()) { - val teas = temporalEntityAttributeService.getForEntity(entityUri, emptySet()) - updateState(entityUri, createdAt, teas).bind() - } - updateResult + val updateResult = coreUpdateResult.mergeWith(attrsUpdateResult) + // update modifiedAt in entity if at least one attribute has been added + if (updateResult.hasSuccessfulUpdate()) { + val teas = temporalEntityAttributeService.getForEntity(entityUri, emptySet()) + updateState(entityUri, createdAt, teas).bind() } + updateResult + } @Transactional suspend fun updateAttributes( diff --git a/search-service/src/main/kotlin/com/egm/stellio/search/service/TemporalEntityAttributeService.kt b/search-service/src/main/kotlin/com/egm/stellio/search/service/TemporalEntityAttributeService.kt index b450a38d17..96a6e4130c 100644 --- a/search-service/src/main/kotlin/com/egm/stellio/search/service/TemporalEntityAttributeService.kt +++ b/search-service/src/main/kotlin/com/egm/stellio/search/service/TemporalEntityAttributeService.kt @@ -689,7 +689,7 @@ class TemporalEntityAttributeService( UpdateAttributeResult( attributeName, datasetId, - UpdateOperationResult.IGNORED, + UpdateOperationResult.FAILED, "Unknown attribute $attributeName with datasetId $datasetId in entity $entityId" ) } @@ -819,7 +819,7 @@ class TemporalEntityAttributeService( UpdateAttributeResult( attributeName, datasetId, - UpdateOperationResult.IGNORED, + UpdateOperationResult.FAILED, "Unknown attribute $attributeName with datasetId $datasetId in entity $entityId" ) } else { diff --git a/search-service/src/main/kotlin/com/egm/stellio/search/web/EntityHandler.kt b/search-service/src/main/kotlin/com/egm/stellio/search/web/EntityHandler.kt index fc15e68d94..d51a080b31 100644 --- a/search-service/src/main/kotlin/com/egm/stellio/search/web/EntityHandler.kt +++ b/search-service/src/main/kotlin/com/egm/stellio/search/web/EntityHandler.kt @@ -5,7 +5,6 @@ import arrow.core.left import arrow.core.raise.either import arrow.core.right import com.egm.stellio.search.authorization.AuthorizationService -import com.egm.stellio.search.model.hasSuccessfulUpdate import com.egm.stellio.search.service.EntityEventService import com.egm.stellio.search.service.EntityPayloadService import com.egm.stellio.search.service.QueryService