Skip to content

Commit

Permalink
refacto: rename EntityPayloadService -> EntityService
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasBousselin authored and bobeal committed Aug 11, 2024
1 parent fd62885 commit 2ff1f3b
Show file tree
Hide file tree
Showing 30 changed files with 453 additions and 453 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 @@ -5,7 +5,7 @@
<ID>ClassNaming:V0_29_JsonLd_migrationTests.kt$V0_29_JsonLd_migrationTests</ID>
<ID>ClassNaming:V0_29__JsonLd_migration.kt$V0_29__JsonLd_migration : BaseJavaMigration</ID>
<ID>ComplexCondition:EntitiesQueryUtils.kt$geoQuery == null &amp;&amp; q.isNullOrEmpty() &amp;&amp; typeSelection.isNullOrEmpty() &amp;&amp; attrs.isEmpty()</ID>
<ID>ComplexCondition:EntityPayloadService.kt$EntityPayloadService$it &amp;&amp; !inverse || !it &amp;&amp; inverse</ID>
<ID>ComplexCondition:EntityService.kt$EntityService$it &amp;&amp; !inverse || !it &amp;&amp; inverse</ID>
<ID>Filename:V0_29__JsonLd_migration.kt$db.migration.V0_29__JsonLd_migration.kt</ID>
<ID>LongMethod:AttributeInstanceService.kt$AttributeInstanceService$@Transactional suspend fun create(attributeInstance: AttributeInstance): Either&lt;APIException, Unit&gt;</ID>
<ID>LongMethod:EnabledAuthorizationServiceTests.kt$EnabledAuthorizationServiceTests$@Test fun `it should return serialized access control entities with other rigths if user is owner`()</ID>
Expand All @@ -31,6 +31,6 @@
<ID>MaximumLineLength:TemporalEntityOperationsHandlerTests.kt$TemporalEntityOperationsHandlerTests$ </ID>
<ID>NestedBlockDepth:V0_29__JsonLd_migration.kt$V0_29__JsonLd_migration$override fun migrate(context: Context)</ID>
<ID>SwallowedException:TemporalQueryUtils.kt$e: IllegalArgumentException</ID>
<ID>TooManyFunctions:EntityPayloadService.kt$EntityPayloadService</ID>
<ID>TooManyFunctions:EntityService.kt$EntityService</ID>
</CurrentIssues>
</SmellBaseline>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.egm.stellio.search.authorization.service.EntityAccessRightsService
import com.egm.stellio.search.authorization.service.SubjectReferentialService
import com.egm.stellio.search.common.config.SearchProperties
import com.egm.stellio.search.entity.service.EntityEventService
import com.egm.stellio.search.entity.service.EntityPayloadService
import com.egm.stellio.search.entity.service.EntityService
import com.egm.stellio.shared.model.*
import com.egm.stellio.shared.util.AuthContextModel.AUTH_TERM_IS_MEMBER_OF
import com.egm.stellio.shared.util.AuthContextModel.AUTH_TERM_ROLES
Expand Down Expand Up @@ -39,7 +39,7 @@ class IAMListener(
private val subjectReferentialService: SubjectReferentialService,
private val searchProperties: SearchProperties,
private val entityAccessRightsService: EntityAccessRightsService,
private val entityPayloadService: EntityPayloadService,
private val entityService: EntityService,
private val entityEventService: EntityEventService
) {

Expand Down Expand Up @@ -120,7 +120,7 @@ class IAMListener(
val entitiesIds = entityAccessRightsService.getEntitiesIdsOwnedBySubject(sub).getOrNull()
entitiesIds?.let { entityAccessRightsService.deleteAllAccessRightsOnEntities(it) }
entitiesIds?.forEach { entityId ->
entityPayloadService.deleteEntity(entityId).getOrNull()?.also {
entityService.deleteEntity(entityId).getOrNull()?.also {
entityEventService.publishEntityDeleteEvent(null, it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import arrow.core.raise.either
import com.egm.stellio.search.authorization.model.EntityAccessRights
import com.egm.stellio.search.authorization.model.EntityAccessRights.SubjectRightInfo
import com.egm.stellio.search.common.util.*
import com.egm.stellio.search.entity.service.EntityPayloadService
import com.egm.stellio.search.entity.service.EntityService
import com.egm.stellio.shared.config.ApplicationProperties
import com.egm.stellio.shared.model.*
import com.egm.stellio.shared.util.*
Expand All @@ -32,7 +32,7 @@ class EntityAccessRightsService(
private val applicationProperties: ApplicationProperties,
private val databaseClient: DatabaseClient,
private val subjectReferentialService: SubjectReferentialService,
private val entityPayloadService: EntityPayloadService
private val entityService: EntityService
) {
@Transactional
suspend fun setReadRoleOnEntity(sub: Sub, entityId: URI): Either<APIException, Unit> =
Expand Down Expand Up @@ -144,7 +144,7 @@ class EntityAccessRightsService(
subjectReferentialService.hasStellioAdminRole(subjectUuids)
.flatMap {
if (!it)
entityPayloadService.hasSpecificAccessPolicies(entityId, specificAccessPolicies)
entityService.hasSpecificAccessPolicies(entityId, specificAccessPolicies)
else true.right()
}.flatMap {
if (!it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.egm.stellio.search.entity.model.NotUpdatedDetails
import com.egm.stellio.search.entity.model.UpdateAttributeResult
import com.egm.stellio.search.entity.model.UpdateOperationResult
import com.egm.stellio.search.entity.model.updateResultFromDetailedResult
import com.egm.stellio.search.entity.service.EntityPayloadService
import com.egm.stellio.search.entity.service.EntityService
import com.egm.stellio.search.entity.util.composeEntitiesQuery
import com.egm.stellio.shared.config.ApplicationProperties
import com.egm.stellio.shared.model.*
Expand Down Expand Up @@ -40,7 +40,7 @@ import kotlin.collections.flatten
class EntityAccessControlHandler(
private val applicationProperties: ApplicationProperties,
private val entityAccessRightsService: EntityAccessRightsService,
private val entityPayloadService: EntityPayloadService,
private val entityService: EntityService,
private val authorizationService: AuthorizationService
) : BaseHandler() {

Expand Down Expand Up @@ -302,7 +302,7 @@ class EntityAccessControlHandler(

val ngsiLdAttribute = expandedAttribute.toNgsiLdAttribute().bind()

entityPayloadService.updateSpecificAccessPolicy(entityId, ngsiLdAttribute).bind()
entityService.updateSpecificAccessPolicy(entityId, ngsiLdAttribute).bind()

ResponseEntity.status(HttpStatus.NO_CONTENT).build<String>()
}.fold(
Expand All @@ -318,7 +318,7 @@ class EntityAccessControlHandler(

authorizationService.userCanAdminEntity(entityId, sub).bind()

entityPayloadService.removeSpecificAccessPolicy(entityId).bind()
entityService.removeSpecificAccessPolicy(entityId).bind()

ResponseEntity.status(HttpStatus.NO_CONTENT).build<String>()
}.fold(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import arrow.core.Either
import arrow.core.left
import arrow.core.raise.either
import com.egm.stellio.search.entity.service.EntityEventService
import com.egm.stellio.search.entity.service.EntityPayloadService
import com.egm.stellio.search.entity.service.EntityService
import com.egm.stellio.shared.model.*
import com.egm.stellio.shared.util.JsonLdUtils.expandAttribute
import com.egm.stellio.shared.util.JsonLdUtils.expandJsonLdEntity
Expand All @@ -23,7 +23,7 @@ import reactor.core.publisher.Mono

@Component
class ObservationEventListener(
private val entityPayloadService: EntityPayloadService,
private val entityService: EntityService,
private val entityEventService: EntityEventService
) {
private val logger = LoggerFactory.getLogger(javaClass)
Expand Down Expand Up @@ -70,7 +70,7 @@ class ObservationEventListener(
val ngsiLdEntity = expandedEntity.toNgsiLdEntity().bind()

mono {
entityPayloadService.createEntity(
entityService.createEntity(
ngsiLdEntity,
expandedEntity,
observationEvent.sub
Expand All @@ -95,7 +95,7 @@ class ObservationEventListener(
)

mono {
entityPayloadService.partialUpdateAttribute(
entityService.partialUpdateAttribute(
observationEvent.entityId,
expandedAttribute,
observationEvent.sub
Expand Down Expand Up @@ -132,7 +132,7 @@ class ObservationEventListener(
)

mono {
entityPayloadService.appendAttributes(
entityService.appendAttributes(
observationEvent.entityId,
expandedAttribute.toExpandedAttributes(),
!observationEvent.overwrite,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.net.URI
@Component
class EntityEventService(
private val kafkaTemplate: KafkaTemplate<String, String>,
private val entityPayloadService: EntityPayloadService
private val entityService: EntityService
) {

private val catchAllTopic = "cim.entity._CatchAll"
Expand Down Expand Up @@ -232,7 +232,7 @@ class EntityEventService(
internal suspend fun getSerializedEntity(
entityId: URI
): Either<APIException, Pair<List<ExpandedTerm>, String>> =
entityPayloadService.retrieve(entityId)
entityService.retrieve(entityId)
.map {
Pair(it.types, it.payload.asString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import java.net.URI
*/
@Component
class EntityOperationService(
private val entityPayloadService: EntityPayloadService,
private val entityService: EntityService,
private val entityAttributeService: EntityAttributeService,
private val authorizationService: AuthorizationService,
private val entityEventService: EntityEventService
Expand Down Expand Up @@ -49,7 +49,7 @@ class EntityOperationService(
extractIdFunc: (T) -> URI
): Pair<List<T>, List<T>> {
val existingEntitiesIds =
entityPayloadService.filterExistingEntitiesAsIds(entities.map { extractIdFunc.invoke(it) })
entityService.filterExistingEntitiesAsIds(entities.map { extractIdFunc.invoke(it) })
return entities.partition { existingEntitiesIds.contains(extractIdFunc.invoke(it)) }
}

Expand Down Expand Up @@ -86,7 +86,7 @@ class EntityOperationService(
): BatchOperationResult {
val creationResults = entities.map { jsonLdNgsiLdEntity ->
either {
entityPayloadService.createEntity(jsonLdNgsiLdEntity.second, jsonLdNgsiLdEntity.first, sub)
entityService.createEntity(jsonLdNgsiLdEntity.second, jsonLdNgsiLdEntity.first, sub)
.onRight {
entityEventService.publishEntityCreateEvent(
sub,
Expand Down Expand Up @@ -116,7 +116,7 @@ class EntityOperationService(
val deletionResults = entities.map { entity ->
val entityId = entity.entityId
either {
entityPayloadService.deleteEntity(entityId)
entityService.deleteEntity(entityId)
.onRight {
authorizationService.removeRightsOnEntity(entityId)
}
Expand Down Expand Up @@ -235,7 +235,7 @@ class EntityOperationService(
): Either<APIException, UpdateResult> = either {
val (jsonLdEntity, ngsiLdEntity) = entity
entityAttributeService.deleteTemporalAttributesOfEntity(ngsiLdEntity.id).bind()
entityPayloadService.appendAttributes(
entityService.appendAttributes(
ngsiLdEntity.id,
jsonLdEntity.getModifiableMembers(),
disallowOverwrite,
Expand All @@ -255,7 +255,7 @@ class EntityOperationService(
sub: Sub?
): Either<APIException, UpdateResult> = either {
val (jsonLdEntity, ngsiLdEntity) = entity
entityPayloadService.appendAttributes(
entityService.appendAttributes(
ngsiLdEntity.id,
jsonLdEntity.getModifiableMembers(),
disallowOverwrite,
Expand All @@ -278,7 +278,7 @@ class EntityOperationService(
sub: Sub?
): Either<APIException, UpdateResult> = either {
val (jsonLdEntity, ngsiLdEntity) = entity
entityPayloadService.mergeEntity(
entityService.mergeEntity(
ngsiLdEntity.id,
jsonLdEntity.getModifiableMembers(),
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ import java.net.URI

@Service
class EntityQueryService(
private val entityPayloadService: EntityPayloadService,
private val entityService: EntityService,
) {
suspend fun queryEntity(entityId: URI): Either<APIException, ExpandedEntity> =
either {
val entityPayload = entityPayloadService.retrieve(entityId).bind()
val entityPayload = entityService.retrieve(entityId).bind()
toJsonLdEntity(entityPayload)
}

suspend fun queryEntities(
entitiesQuery: EntitiesQuery,
accessRightFilter: () -> String?
): Either<APIException, Pair<List<ExpandedEntity>, Int>> = either {
val entitiesIds = entityPayloadService.queryEntities(entitiesQuery, accessRightFilter)
val count = entityPayloadService.queryEntitiesCount(entitiesQuery, accessRightFilter).bind()
val entitiesIds = entityService.queryEntities(entitiesQuery, accessRightFilter)
val count = entityService.queryEntitiesCount(entitiesQuery, accessRightFilter).bind()

// we can have an empty list of entities with a non-zero count (e.g., offset too high)
if (entitiesIds.isEmpty())
return@either Pair<List<ExpandedEntity>, Int>(emptyList(), count)

val entitiesPayloads = entityPayloadService.retrieve(entitiesIds).map { toJsonLdEntity(it) }
val entitiesPayloads = entityService.retrieve(entitiesIds).map { toJsonLdEntity(it) }

Pair(entitiesPayloads, count).right().bind()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import java.time.ZoneOffset
import java.time.ZonedDateTime

@Service
class EntityPayloadService(
class EntityService(
private val databaseClient: DatabaseClient,
private val entityAttributeService: EntityAttributeService,
private val scopeService: ScopeService
Expand Down
Loading

0 comments on commit 2ff1f3b

Please sign in to comment.