Skip to content

Commit

Permalink
refactor: some final missing points
Browse files Browse the repository at this point in the history
  • Loading branch information
bobeal committed Aug 11, 2024
1 parent 1ef77f9 commit d419088
Show file tree
Hide file tree
Showing 29 changed files with 514 additions and 476 deletions.
4 changes: 2 additions & 2 deletions search-service/config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<ID>LongMethod:TemporalQueryServiceTests.kt$TemporalQueryServiceTests$@Test fun `it should return an empty list for an attribute if it has no temporal values`()</ID>
<ID>LongMethod:TemporalScopeBuilderTests.kt$TemporalScopeBuilderTests$@Test fun `it should build an aggregated temporal representation of scopes`()</ID>
<ID>LongMethod:V0_29__JsonLd_migration.kt$V0_29__JsonLd_migration$override fun migrate(context: Context)</ID>
<ID>LongParameterList:AttributeInstance.kt$AttributeInstance.Companion$( attribute: UUID, instanceId: URI = generateRandomInstanceId(), timeAndProperty: Pair&lt;ZonedDateTime, TemporalProperty&gt;, value: Triple&lt;String?, Double?, WKTCoordinates?&gt;, payload: ExpandedAttributeInstance, sub: String? )</ID>
<ID>LongParameterList:AttributeInstance.kt$AttributeInstance.Companion$( attribute: UUID, instanceId: URI = generateRandomInstanceId(), timeProperty: TemporalProperty? = TemporalProperty.OBSERVED_AT, modifiedAt: ZonedDateTime? = null, attributeMetadata: AttributeMetadata, payload: ExpandedAttributeInstance, time: ZonedDateTime, sub: String? = null )</ID>
<ID>LongParameterList:AttributeInstance.kt$AttributeInstance.Companion$( attributeUuid: UUID, instanceId: URI = generateRandomInstanceId(), timeAndProperty: Pair&lt;ZonedDateTime, TemporalProperty&gt;, value: Triple&lt;String?, Double?, WKTCoordinates?&gt;, payload: ExpandedAttributeInstance, sub: String? )</ID>
<ID>LongParameterList:AttributeInstance.kt$AttributeInstance.Companion$( attributeUuid: UUID, instanceId: URI = generateRandomInstanceId(), timeProperty: TemporalProperty? = TemporalProperty.OBSERVED_AT, modifiedAt: ZonedDateTime? = null, attributeMetadata: AttributeMetadata, payload: ExpandedAttributeInstance, time: ZonedDateTime, sub: String? = null )</ID>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import arrow.fx.coroutines.parMap
import com.egm.stellio.search.common.util.*
import com.egm.stellio.search.entity.model.*
import com.egm.stellio.search.entity.model.Attribute
import com.egm.stellio.search.entity.util.guessAttributeValueType
import com.egm.stellio.search.entity.util.mergePatch
import com.egm.stellio.search.entity.util.partialUpdatePatch
import com.egm.stellio.search.entity.util.prepareAttributes
import com.egm.stellio.search.entity.util.toAttributeMetadata
import com.egm.stellio.search.entity.util.toExpandedAttributeInstance
import com.egm.stellio.search.temporal.model.AttributeInstance
import com.egm.stellio.search.temporal.service.AttributeInstanceService
import com.egm.stellio.search.temporal.util.*
import com.egm.stellio.shared.model.*
import com.egm.stellio.shared.util.*
import com.egm.stellio.shared.util.AttributeType
Expand Down Expand Up @@ -121,7 +126,7 @@ class EntityAttributeService(
* To be removed at some point later.
*/
@Transactional
suspend fun createEntityAttributes(
suspend fun createAttributes(
payload: String,
contexts: List<String>,
sub: String? = null
Expand All @@ -131,12 +136,12 @@ class EntityAttributeService(
val ngsiLdEntity = expandedEntity.toNgsiLdEntity().bind()
ngsiLdEntity.prepareAttributes()
.map {
createEntityAttributes(ngsiLdEntity, expandedEntity, it, createdAt, sub).bind()
createAttributes(ngsiLdEntity, expandedEntity, it, createdAt, sub).bind()
}.bind()
}

@Transactional
suspend fun createEntityAttributes(
suspend fun createAttributes(
ngsiLdEntity: NgsiLdEntity,
expandedEntity: ExpandedEntity,
attributesMetadata: List<Pair<ExpandedTerm, AttributeMetadata>>,
Expand Down Expand Up @@ -190,7 +195,7 @@ class EntityAttributeService(
create(attribute).bind()

val attributeInstance = AttributeInstance(
attribute = attribute.id,
attributeUuid = attribute.id,
timeProperty = AttributeInstance.TemporalProperty.CREATED_AT,
time = createdAt,
attributeMetadata = attributeMetadata,
Expand All @@ -201,7 +206,7 @@ class EntityAttributeService(

if (attributeMetadata.observedAt != null) {
val attributeObservedAtInstance = AttributeInstance(
attribute = attribute.id,
attributeUuid = attribute.id,
time = attributeMetadata.observedAt,
attributeMetadata = attributeMetadata,
payload = attributePayload
Expand Down Expand Up @@ -233,7 +238,7 @@ class EntityAttributeService(
).bind()

val attributeInstance = AttributeInstance(
attribute = attribute.id,
attributeUuid = attribute.id,
timeProperty = AttributeInstance.TemporalProperty.MODIFIED_AT,
time = createdAt,
attributeMetadata = attributeMetadata,
Expand All @@ -244,7 +249,7 @@ class EntityAttributeService(

if (attributeMetadata.observedAt != null) {
val attributeObservedAtInstance = AttributeInstance(
attribute = attribute.id,
attributeUuid = attribute.id,
time = attributeMetadata.observedAt,
attributeMetadata = attributeMetadata,
payload = attributePayload
Expand Down Expand Up @@ -286,7 +291,7 @@ class EntityAttributeService(
}

@Transactional
suspend fun deleteTemporalAttributesOfEntity(entityId: URI): Either<APIException, Unit> {
suspend fun deleteAttributes(entityId: URI): Either<APIException, Unit> {
val uuids = databaseClient.sql(
"""
DELETE FROM temporal_entity_attribute
Expand All @@ -305,7 +310,7 @@ class EntityAttributeService(
}

@Transactional
suspend fun deleteTemporalAttribute(
suspend fun deleteAttribute(
entityId: URI,
attributeName: String,
datasetId: URI?,
Expand All @@ -315,15 +320,15 @@ class EntityAttributeService(
logger.debug("Deleting attribute {} from entity {} (all: {})", attributeName, entityId, deleteAll)
if (deleteAll) {
attributeInstanceService.deleteAllInstancesOfAttribute(entityId, attributeName).bind()
deleteTemporalAttributeAllInstancesReferences(entityId, attributeName).bind()
deleteAllInstances(entityId, attributeName).bind()
} else {
attributeInstanceService.deleteInstancesOfAttribute(entityId, attributeName, datasetId).bind()
deleteTemporalAttributeReferences(entityId, attributeName, datasetId).bind()
deleteSpecificInstance(entityId, attributeName, datasetId).bind()
}
}

@Transactional
suspend fun deleteTemporalAttributeReferences(
suspend fun deleteSpecificInstance(
entityId: URI,
attributeName: String,
datasetId: URI?
Expand All @@ -345,7 +350,7 @@ class EntityAttributeService(
.execute()

@Transactional
suspend fun deleteTemporalAttributeAllInstancesReferences(
suspend fun deleteAllInstances(
entityId: URI,
attributeName: String
): Either<APIException, Unit> =
Expand All @@ -360,7 +365,7 @@ class EntityAttributeService(
.bind("attribute_name", attributeName)
.execute()

suspend fun getForTemporalEntities(
suspend fun getForEntities(
entitiesIds: List<URI>,
entitiesQuery: EntitiesQuery
): List<Attribute> {
Expand Down Expand Up @@ -540,7 +545,7 @@ class EntityAttributeService(
}

@Transactional
suspend fun appendEntityAttributes(
suspend fun appendAttributes(
entityUri: URI,
ngsiLdAttributes: List<NgsiLdAttribute>,
expandedAttributes: ExpandedAttributes,
Expand Down Expand Up @@ -605,7 +610,7 @@ class EntityAttributeService(
}.fold({ it.left() }, { updateResultFromDetailedResult(it).right() })

@Transactional
suspend fun updateEntityAttributes(
suspend fun updateAttributes(
entityUri: URI,
ngsiLdAttributes: List<NgsiLdAttribute>,
expandedAttributes: ExpandedAttributes,
Expand Down Expand Up @@ -660,7 +665,7 @@ class EntityAttributeService(
}.fold({ it.left() }, { updateResultFromDetailedResult(it).right() })

@Transactional
suspend fun partialUpdateEntityAttribute(
suspend fun partialUpdateAttribute(
entityId: URI,
expandedAttribute: ExpandedAttribute,
modifiedAt: ZonedDateTime,
Expand Down Expand Up @@ -721,7 +726,7 @@ class EntityAttributeService(
}

@Transactional
suspend fun upsertEntityAttributes(
suspend fun upsertAttributes(
entityUri: URI,
ngsiLdAttribute: NgsiLdAttribute,
expandedAttributes: ExpandedAttributes,
Expand Down Expand Up @@ -764,7 +769,7 @@ class EntityAttributeService(
}

@Transactional
suspend fun mergeEntityAttributes(
suspend fun mergeAttributes(
entityUri: URI,
ngsiLdAttributes: List<NgsiLdAttribute>,
expandedAttributes: ExpandedAttributes,
Expand Down Expand Up @@ -822,7 +827,7 @@ class EntityAttributeService(
}.fold({ it.left() }, { updateResultFromDetailedResult(it).right() })

@Transactional
suspend fun replaceEntityAttribute(
suspend fun replaceAttribute(
entityId: URI,
ngsiLdAttribute: NgsiLdAttribute,
expandedAttribute: ExpandedAttribute,
Expand Down Expand Up @@ -924,7 +929,7 @@ class EntityAttributeService(
Pair(modifiedAt, AttributeInstance.TemporalProperty.MODIFIED_AT)

return AttributeInstance(
attribute = attribute.id,
attributeUuid = attribute.id,
timeAndProperty = timeAndProperty,
value = value,
payload = expandedAttributeInstance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class EntityOperationService(
sub: Sub?
): Either<APIException, UpdateResult> = either {
val (jsonLdEntity, ngsiLdEntity) = entity
entityAttributeService.deleteTemporalAttributesOfEntity(ngsiLdEntity.id).bind()
entityAttributeService.deleteAttributes(ngsiLdEntity.id).bind()
entityService.appendAttributes(
ngsiLdEntity.id,
jsonLdEntity.getModifiableMembers(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import com.egm.stellio.search.common.util.*
import com.egm.stellio.search.entity.model.*
import com.egm.stellio.search.entity.model.Attribute
import com.egm.stellio.search.entity.model.OperationType.*
import com.egm.stellio.search.entity.util.prepareAttributes
import com.egm.stellio.search.scope.ScopeService
import com.egm.stellio.search.temporal.util.prepareAttributes
import com.egm.stellio.shared.model.*
import com.egm.stellio.shared.util.*
import com.egm.stellio.shared.util.AuthContextModel.SpecificAccessPolicy
Expand Down Expand Up @@ -47,7 +47,7 @@ class EntityService(
logger.debug("Creating entity {}", ngsiLdEntity.id)

createEntityPayload(ngsiLdEntity, expandedEntity, createdAt, sub = sub).bind()
entityAttributeService.createEntityAttributes(
entityAttributeService.createAttributes(
ngsiLdEntity,
expandedEntity,
attributesMetadata,
Expand Down Expand Up @@ -96,7 +96,7 @@ class EntityService(
val mergedAt = ngsiLdDateTime()

val coreUpdateResult = updateCoreAttributes(entityId, coreAttrs, mergedAt, MERGE_ENTITY).bind()
val attrsUpdateResult = entityAttributeService.mergeEntityAttributes(
val attrsUpdateResult = entityAttributeService.mergeAttributes(
entityId,
otherAttrs.toMap().toNgsiLdAttributes().bind(),
expandedAttributes,
Expand Down Expand Up @@ -125,10 +125,10 @@ class EntityService(
val attributesMetadata = ngsiLdEntity.prepareAttributes().bind()
logger.debug("Replacing entity {}", ngsiLdEntity.id)

entityAttributeService.deleteTemporalAttributesOfEntity(entityId)
entityAttributeService.deleteAttributes(entityId)

replaceEntityPayload(ngsiLdEntity, expandedEntity, replacedAt, sub).bind()
entityAttributeService.createEntityAttributes(
entityAttributeService.createAttributes(
ngsiLdEntity,
expandedEntity,
attributesMetadata,
Expand Down Expand Up @@ -481,7 +481,7 @@ class EntityService(
if (disallowOverwrite) APPEND_ATTRIBUTES
else APPEND_ATTRIBUTES_OVERWRITE_ALLOWED
val coreUpdateResult = updateCoreAttributes(entityUri, coreAttrs, createdAt, operationType).bind()
val attrsUpdateResult = entityAttributeService.appendEntityAttributes(
val attrsUpdateResult = entityAttributeService.appendAttributes(
entityUri,
otherAttrs.toMap().toNgsiLdAttributes().bind(),
expandedAttributes,
Expand Down Expand Up @@ -510,7 +510,7 @@ class EntityService(
val createdAt = ngsiLdDateTime()

val coreUpdateResult = updateCoreAttributes(entityUri, coreAttrs, createdAt, UPDATE_ATTRIBUTES).bind()
val attrsUpdateResult = entityAttributeService.updateEntityAttributes(
val attrsUpdateResult = entityAttributeService.updateAttributes(
entityUri,
otherAttrs.toMap().toNgsiLdAttributes().bind(),
expandedAttributes,
Expand All @@ -534,7 +534,7 @@ class EntityService(
sub: Sub?
): Either<APIException, UpdateResult> = either {
val modifiedAt = ngsiLdDateTime()
val updateResult = entityAttributeService.partialUpdateEntityAttribute(
val updateResult = entityAttributeService.partialUpdateAttribute(
entityId,
expandedAttribute,
modifiedAt,
Expand All @@ -560,7 +560,7 @@ class EntityService(
val jsonLdAttribute = mapOf(attributeName to listOf(expandedAttributeInstance))
val ngsiLdAttribute = jsonLdAttribute.toNgsiLdAttributes().bind()[0]

entityAttributeService.upsertEntityAttributes(
entityAttributeService.upsertAttributes(
entityId,
ngsiLdAttribute,
jsonLdAttribute,
Expand All @@ -585,7 +585,7 @@ class EntityService(
val ngsiLdAttribute = listOf(expandedAttribute).toMap().toNgsiLdAttributes().bind()[0]
val replacedAt = ngsiLdDateTime()

val updateResult = entityAttributeService.replaceEntityAttribute(
val updateResult = entityAttributeService.replaceAttribute(
entityId,
ngsiLdAttribute,
expandedAttribute,
Expand Down Expand Up @@ -675,7 +675,7 @@ class EntityService(
}
.bind()

entityAttributeService.deleteTemporalAttributesOfEntity(entityId).bind()
entityAttributeService.deleteAttributes(entityId).bind()
scopeService.deleteHistory(entityId).bind()
entity
}
Expand All @@ -695,7 +695,7 @@ class EntityService(
attributeName,
datasetId
).bind()
entityAttributeService.deleteTemporalAttribute(
entityAttributeService.deleteAttribute(
entityId,
attributeName,
datasetId,
Expand Down
Loading

0 comments on commit d419088

Please sign in to comment.