diff --git a/search-service/src/main/kotlin/com/egm/stellio/search/authorization/EnabledAuthorizationService.kt b/search-service/src/main/kotlin/com/egm/stellio/search/authorization/EnabledAuthorizationService.kt index b0b910814..9d3b109ea 100644 --- a/search-service/src/main/kotlin/com/egm/stellio/search/authorization/EnabledAuthorizationService.kt +++ b/search-service/src/main/kotlin/com/egm/stellio/search/authorization/EnabledAuthorizationService.kt @@ -128,7 +128,7 @@ class EnabledAuthorizationService( } else entityAccessControl } .map { it.serializeProperties(contexts) } - .map { ExpandedEntity(it, contexts) } + .map { ExpandedEntity(it) } val count = entityAccessRightsService.getSubjectAccessRightsCount( sub, @@ -162,7 +162,7 @@ class EnabledAuthorizationService( } val jsonLdEntities = groups.second.map { - ExpandedEntity(it.serializeProperties(), contexts) + ExpandedEntity(it.serializeProperties()) } Pair(groups.first, jsonLdEntities) @@ -177,7 +177,7 @@ class EnabledAuthorizationService( val usersCount = subjectReferentialService.getUsersCount().bind() val jsonLdEntities = users.map { - ExpandedEntity(it.serializeProperties(contexts), contexts) + ExpandedEntity(it.serializeProperties(contexts)) } Pair(usersCount, jsonLdEntities) diff --git a/search-service/src/main/kotlin/com/egm/stellio/search/service/QueryService.kt b/search-service/src/main/kotlin/com/egm/stellio/search/service/QueryService.kt index 16f04f396..9c57ab62f 100644 --- a/search-service/src/main/kotlin/com/egm/stellio/search/service/QueryService.kt +++ b/search-service/src/main/kotlin/com/egm/stellio/search/service/QueryService.kt @@ -26,13 +26,10 @@ class QueryService( private val attributeInstanceService: AttributeInstanceService, private val temporalEntityAttributeService: TemporalEntityAttributeService ) { - suspend fun queryEntity( - entityId: URI, - contexts: List - ): Either = + suspend fun queryEntity(entityId: URI): Either = either { val entityPayload = entityPayloadService.retrieve(entityId).bind() - toJsonLdEntity(entityPayload, contexts) + toJsonLdEntity(entityPayload) } suspend fun queryEntities( @@ -46,17 +43,14 @@ class QueryService( if (entitiesIds.isEmpty()) return@either Pair, Int>(emptyList(), count) - val entitiesPayloads = - entityPayloadService.retrieve(entitiesIds) - .map { toJsonLdEntity(it, entitiesQuery.contexts) } + val entitiesPayloads = entityPayloadService.retrieve(entitiesIds).map { toJsonLdEntity(it) } Pair(entitiesPayloads, count).right().bind() } suspend fun queryTemporalEntity( entityId: URI, - temporalEntitiesQuery: TemporalEntitiesQuery, - contexts: List + temporalEntitiesQuery: TemporalEntitiesQuery ): Either = either { val attrs = temporalEntitiesQuery.entitiesQuery.attrs val temporalEntityAttributes = temporalEntityAttributeService.getForEntity(entityId, attrs).let { @@ -83,8 +77,7 @@ class QueryService( TemporalEntityBuilder.buildTemporalEntity( EntityTemporalResult(entityPayload, scopeHistory, temporalEntityAttributesWithInstances), - temporalEntitiesQuery, - contexts + temporalEntitiesQuery ) } @@ -175,8 +168,7 @@ class QueryService( Pair( TemporalEntityBuilder.buildTemporalEntities( attributeInstancesPerEntityAndAttribute, - temporalEntitiesQuery, - temporalEntitiesQuery.entitiesQuery.contexts + temporalEntitiesQuery ), count ) @@ -235,11 +227,8 @@ class QueryService( ) } - private fun toJsonLdEntity( - entityPayload: EntityPayload, - contexts: List - ): ExpandedEntity { + private fun toJsonLdEntity(entityPayload: EntityPayload): ExpandedEntity { val deserializedEntity = entityPayload.payload.deserializeAsMap() - return ExpandedEntity(deserializedEntity, contexts) + return ExpandedEntity(deserializedEntity) } } 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 afc1d03c2..b2dfa564a 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 @@ -593,12 +593,12 @@ class TemporalEntityAttributeService( val currentTea = getForEntityAndAttribute(entityUri, ngsiLdAttribute.name, ngsiLdAttributeInstance.datasetId) .fold({ null }, { it }) + val attributeMetadata = ngsiLdAttributeInstance.toTemporalAttributeMetadata().bind() + val attributePayload = expandedAttributes.getAttributeFromExpandedAttributes( + ngsiLdAttribute.name, + ngsiLdAttributeInstance.datasetId + )!! if (currentTea != null) { - val attributeMetadata = ngsiLdAttributeInstance.toTemporalAttributeMetadata().bind() - val attributePayload = expandedAttributes.getAttributeFromExpandedAttributes( - ngsiLdAttribute.name, - ngsiLdAttributeInstance.datasetId - )!! replaceAttribute( currentTea, ngsiLdAttribute, @@ -615,17 +615,21 @@ class TemporalEntityAttributeService( ) }.bind() } else { - val message = if (ngsiLdAttributeInstance.datasetId != null) - "Attribute (datasetId: ${ngsiLdAttributeInstance.datasetId}) does not exist" - else - "Attribute (default instance) does not exist" - logger.info(message) - UpdateAttributeResult( + addAttribute( + entityUri, ngsiLdAttribute.name, - ngsiLdAttributeInstance.datasetId, - UpdateOperationResult.IGNORED, - message - ).right().bind() + attributeMetadata, + createdAt, + attributePayload, + sub + ).map { + UpdateAttributeResult( + ngsiLdAttribute.name, + ngsiLdAttributeInstance.datasetId, + UpdateOperationResult.APPENDED, + null + ) + }.bind() } } }.fold({ it.left() }, { updateResultFromDetailedResult(it).right() }) diff --git a/search-service/src/main/kotlin/com/egm/stellio/search/util/TemporalEntityBuilder.kt b/search-service/src/main/kotlin/com/egm/stellio/search/util/TemporalEntityBuilder.kt index 0017e7515..91f9adfb7 100644 --- a/search-service/src/main/kotlin/com/egm/stellio/search/util/TemporalEntityBuilder.kt +++ b/search-service/src/main/kotlin/com/egm/stellio/search/util/TemporalEntityBuilder.kt @@ -29,17 +29,15 @@ object TemporalEntityBuilder { fun buildTemporalEntities( queryResult: List, - temporalEntitiesQuery: TemporalEntitiesQuery, - contexts: List + temporalEntitiesQuery: TemporalEntitiesQuery ): List = queryResult.map { - buildTemporalEntity(it, temporalEntitiesQuery, contexts) + buildTemporalEntity(it, temporalEntitiesQuery) } fun buildTemporalEntity( entityTemporalResult: EntityTemporalResult, - temporalEntitiesQuery: TemporalEntitiesQuery, - contexts: List + temporalEntitiesQuery: TemporalEntitiesQuery ): ExpandedEntity { val temporalAttributes = buildTemporalAttributes( entityTemporalResult.teaInstancesResult, @@ -55,7 +53,7 @@ object TemporalEntityBuilder { val expandedTemporalEntity = entityTemporalResult.entityPayload.serializeProperties() .plus(temporalAttributes) .plus(scopeAttributeInstances) - return ExpandedEntity(expandedTemporalEntity, contexts) + return ExpandedEntity(expandedTemporalEntity) } private fun buildTemporalAttributes( 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 4f7d7d619..9f0d59ff1 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 @@ -243,13 +243,12 @@ class EntityHandler( authorizationService.userCanReadEntity(entityId, sub).bind() - val expandedEntity = queryService.queryEntity(entityId, contexts).bind() + val expandedEntity = queryService.queryEntity(entityId).bind() expandedEntity.checkContainsAnyOf(queryParams.attrs).bind() val filteredExpandedEntity = ExpandedEntity( - expandedEntity.filterOnAttributes(queryParams.attrs), - expandedEntity.contexts + expandedEntity.filterOnAttributes(queryParams.attrs) ) val compactedEntity = compactEntity(filteredExpandedEntity, contexts) diff --git a/search-service/src/main/kotlin/com/egm/stellio/search/web/TemporalEntityHandler.kt b/search-service/src/main/kotlin/com/egm/stellio/search/web/TemporalEntityHandler.kt index 99a0b44cd..cab98293d 100644 --- a/search-service/src/main/kotlin/com/egm/stellio/search/web/TemporalEntityHandler.kt +++ b/search-service/src/main/kotlin/com/egm/stellio/search/web/TemporalEntityHandler.kt @@ -66,8 +66,7 @@ class TemporalEntityHandler( val expandedEntity = ExpandedEntity( sortedJsonLdInstances .keepFirstInstances() - .addCoreMembers(jsonLdTemporalEntity.id, jsonLdTemporalEntity.types), - contexts + .addCoreMembers(jsonLdTemporalEntity.id, jsonLdTemporalEntity.types) ) val ngsiLdEntity = expandedEntity.toNgsiLdEntity().bind() @@ -193,11 +192,7 @@ class TemporalEntityHandler( val temporalEntitiesQuery = composeTemporalEntitiesQuery(applicationProperties.pagination, params, contexts).bind() - val temporalEntity = queryService.queryTemporalEntity( - entityId, - temporalEntitiesQuery, - contexts - ).bind() + val temporalEntity = queryService.queryTemporalEntity(entityId, temporalEntitiesQuery).bind() val compactedEntity = compactEntity(temporalEntity, contexts) diff --git a/search-service/src/main/kotlin/db/migration/V0_29__JsonLd_migration.kt b/search-service/src/main/kotlin/db/migration/V0_29__JsonLd_migration.kt index f5fda8d2d..5f595e5cf 100644 --- a/search-service/src/main/kotlin/db/migration/V0_29__JsonLd_migration.kt +++ b/search-service/src/main/kotlin/db/migration/V0_29__JsonLd_migration.kt @@ -133,7 +133,7 @@ class V0_29__JsonLd_migration : BaseJavaMigration() { """.trimIndent() ) - val jsonLdEntity = ExpandedEntity(expandedEntity, contexts) + val jsonLdEntity = ExpandedEntity(expandedEntity) val ngsiLdEntity = runBlocking { jsonLdEntity.toNgsiLdEntity() } diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/service/QueryServiceTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/service/QueryServiceTests.kt index fa53a9398..5c80ec8fc 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/service/QueryServiceTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/service/QueryServiceTests.kt @@ -56,7 +56,7 @@ class QueryServiceTests { fun `it should return a JSON-LD entity when querying by id`() = runTest { coEvery { entityPayloadService.retrieve(any()) } returns gimmeEntityPayload().right() - queryService.queryEntity(entityUri, APIC_COMPOUND_CONTEXTS) + queryService.queryEntity(entityUri) .shouldSucceedWith { assertEquals(entityUri.toString(), it.id) assertEquals(listOf(BEEHIVE_TYPE), it.types) @@ -68,7 +68,7 @@ class QueryServiceTests { fun `it should return an API exception if no entity exists with the given id`() = runTest { coEvery { entityPayloadService.retrieve(any()) } returns ResourceNotFoundException("").left() - queryService.queryEntity(entityUri, APIC_COMPOUND_CONTEXTS) + queryService.queryEntity(entityUri) .shouldFail { assertTrue(it is ResourceNotFoundException) } @@ -120,8 +120,7 @@ class QueryServiceTests { withTemporalValues = false, withAudit = false, withAggregatedValues = false - ), - APIC_COMPOUND_CONTEXTS + ) ).fold({ assertInstanceOf(ResourceNotFoundException::class.java, it) assertEquals( @@ -172,8 +171,7 @@ class QueryServiceTests { withTemporalValues = false, withAudit = false, withAggregatedValues = false - ), - APIC_COMPOUND_CONTEXTS + ) ) coVerify { diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/util/TemporalEntityBuilderTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/util/TemporalEntityBuilderTests.kt index f03433213..7933511b4 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/util/TemporalEntityBuilderTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/util/TemporalEntityBuilderTests.kt @@ -47,8 +47,7 @@ class TemporalEntityBuilderTests { withTemporalValues = false, withAudit = false, withAggregatedValues = false - ), - APIC_COMPOUND_CONTEXTS + ) ) assertJsonPayloadsAreEqual( loadSampleData("expectations/beehive_empty_outgoing.jsonld"), @@ -81,8 +80,7 @@ class TemporalEntityBuilderTests { withTemporalValues, withAudit, false - ), - APIC_COMPOUND_CONTEXTS + ) ) assertJsonPayloadsAreEqual( expectation, @@ -107,8 +105,7 @@ class TemporalEntityBuilderTests { withTemporalValues, withAudit, false - ), - APIC_COMPOUND_CONTEXTS + ) ) assertJsonPayloadsAreEqual( expectation, @@ -186,8 +183,7 @@ class TemporalEntityBuilderTests { withTemporalValues = false, withAudit = false, withAggregatedValues = true - ), - APIC_COMPOUND_CONTEXTS + ) ) assertJsonPayloadsAreEqual( diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityAccessControlHandlerTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityAccessControlHandlerTests.kt index 1845d72d7..9c65ab365 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityAccessControlHandlerTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityAccessControlHandlerTests.kt @@ -690,8 +690,7 @@ class EntityAccessControlHandlerTests { "@id" to "urn:ngsi-ld:group:1", "@type" to listOf(GROUP_TYPE), NGSILD_NAME_PROPERTY to buildExpandedPropertyValue("egm") - ), - listOf(NGSILD_TEST_CORE_CONTEXT) + ) ) ) ).right() @@ -731,8 +730,7 @@ class EntityAccessControlHandlerTests { "@type" to listOf(GROUP_TYPE), NGSILD_NAME_PROPERTY to buildExpandedPropertyValue("egm"), AuthContextModel.AUTH_REL_IS_MEMBER_OF to buildExpandedPropertyValue("true") - ), - listOf(AUTHZ_TEST_COMPOUND_CONTEXT) + ) ) ) ).right() @@ -835,8 +833,7 @@ class EntityAccessControlHandlerTests { "givenName", "familyName", mapOf("profile" to "stellio-user", "username" to "username") - ).serializeProperties(AUTHZ_TEST_COMPOUND_CONTEXTS), - listOf(NGSILD_TEST_CORE_CONTEXT) + ).serializeProperties(AUTHZ_TEST_COMPOUND_CONTEXTS) ) ) ).right() @@ -866,12 +863,9 @@ class EntityAccessControlHandlerTests { .jsonPath("[0].modifiedAt").doesNotExist() } - private suspend fun createJsonLdEntity( - entityAccessRights: EntityAccessRights, - context: String = NGSILD_TEST_CORE_CONTEXT - ): ExpandedEntity { + private suspend fun createJsonLdEntity(entityAccessRights: EntityAccessRights): ExpandedEntity { val earSerialized = entityAccessRights.serializeProperties(AUTHZ_TEST_COMPOUND_CONTEXTS) - return ExpandedEntity(earSerialized, listOf(context)) + return ExpandedEntity(earSerialized) } private fun createEntityAccessRight( diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityHandlerTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityHandlerTests.kt index 9a5c4de9e..4d64afe79 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityHandlerTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityHandlerTests.kt @@ -285,7 +285,7 @@ class EntityHandlerTests { mockkDefaultBehaviorForGetEntityById() val returnedExpandedEntity = mockkClass(ExpandedEntity::class, relaxed = true) - coEvery { queryService.queryEntity(any(), any()) } returns returnedExpandedEntity.right() + coEvery { queryService.queryEntity(any()) } returns returnedExpandedEntity.right() every { returnedExpandedEntity.checkContainsAnyOf(any()) } returns Unit.right() webClient.get() @@ -299,7 +299,7 @@ class EntityHandlerTests { fun `get entity by id should correctly serialize temporal properties`() { mockkDefaultBehaviorForGetEntityById() - coEvery { queryService.queryEntity(any(), any()) } returns ExpandedEntity( + coEvery { queryService.queryEntity(any()) } returns ExpandedEntity( mapOf( NGSILD_CREATED_AT_PROPERTY to mapOf( @@ -308,8 +308,7 @@ class EntityHandlerTests { ), "@id" to beehiveId.toString(), "@type" to listOf("Beehive") - ), - listOf(NGSILD_TEST_CORE_CONTEXT) + ) ).right() webClient.get() @@ -331,7 +330,7 @@ class EntityHandlerTests { fun `get entity by id should correctly filter the asked attributes`() { mockkDefaultBehaviorForGetEntityById() - coEvery { queryService.queryEntity(any(), any()) } returns ExpandedEntity( + coEvery { queryService.queryEntity(any()) } returns ExpandedEntity( mapOf( "@id" to beehiveId.toString(), "@type" to listOf("Beehive"), @@ -347,8 +346,7 @@ class EntityHandlerTests { "@value" to "some value 2" ) ) - ), - listOf(NGSILD_TEST_CORE_CONTEXT) + ) ).right() webClient.get() @@ -365,7 +363,7 @@ class EntityHandlerTests { fun `get entity by id should correctly return the simplified representation of an entity`() { mockkDefaultBehaviorForGetEntityById() - coEvery { queryService.queryEntity(any(), any()) } returns ExpandedEntity( + coEvery { queryService.queryEntity(any()) } returns ExpandedEntity( mapOf( "@id" to beehiveId.toString(), "@type" to listOf("Beehive"), @@ -381,8 +379,7 @@ class EntityHandlerTests { JSONLD_ID to "urn:ngsi-ld:Entity:1234" ) ) - ), - listOf(NGSILD_TEST_CORE_CONTEXT) + ) ).right() webClient.get() @@ -408,12 +405,11 @@ class EntityHandlerTests { fun `get entity by id should return 404 if the entity has none of the requested attributes`() { mockkDefaultBehaviorForGetEntityById() - coEvery { queryService.queryEntity(any(), any()) } returns ExpandedEntity( + coEvery { queryService.queryEntity(any()) } returns ExpandedEntity( mapOf( "@id" to beehiveId.toString(), "@type" to listOf(BEEHIVE_TYPE) - ), - listOf(NGSILD_TEST_CORE_CONTEXT) + ) ).right() val expectedMessage = entityOrAttrsNotFoundMessage( @@ -440,12 +436,11 @@ class EntityHandlerTests { fun `get entity by id should not include temporal properties if optional query param sysAttrs is not present`() { mockkDefaultBehaviorForGetEntityById() - coEvery { queryService.queryEntity(any(), any()) } returns ExpandedEntity( + coEvery { queryService.queryEntity(any()) } returns ExpandedEntity( mapOf( "@id" to beehiveId.toString(), "@type" to listOf("Beehive") - ), - listOf(NGSILD_TEST_CORE_CONTEXT) + ) ).right() webClient.get() @@ -461,7 +456,7 @@ class EntityHandlerTests { @Test fun `get entity by id should correctly serialize properties of type DateTime and display sysAttrs asked`() { mockkDefaultBehaviorForGetEntityById() - coEvery { queryService.queryEntity(any(), any()) } returns ExpandedEntity( + coEvery { queryService.queryEntity(any()) } returns ExpandedEntity( mapOf( NGSILD_CREATED_AT_PROPERTY to mapOf( @@ -487,8 +482,7 @@ class EntityHandlerTests { ), "@id" to beehiveId.toString(), "@type" to listOf("Beehive") - ), - listOf(NGSILD_TEST_CORE_CONTEXT) + ) ).right() webClient.get() @@ -519,7 +513,7 @@ class EntityHandlerTests { fun `get entity by id should correctly serialize properties of type Date`() { mockkDefaultBehaviorForGetEntityById() - coEvery { queryService.queryEntity(any(), any()) } returns ExpandedEntity( + coEvery { queryService.queryEntity(any()) } returns ExpandedEntity( mapOf( "https://uri.etsi.org/ngsi-ld/default-context/testedAt" to mapOf( "@type" to "https://uri.etsi.org/ngsi-ld/Property", @@ -530,8 +524,7 @@ class EntityHandlerTests { ), "@id" to beehiveId.toString(), "@type" to listOf("Beehive") - ), - listOf(NGSILD_TEST_CORE_CONTEXT) + ) ).right() webClient.get() @@ -559,7 +552,7 @@ class EntityHandlerTests { fun `get entity by id should correctly serialize properties of type Time`() { mockkDefaultBehaviorForGetEntityById() - coEvery { queryService.queryEntity(any(), any()) } returns ExpandedEntity( + coEvery { queryService.queryEntity(any()) } returns ExpandedEntity( mapOf( "https://uri.etsi.org/ngsi-ld/default-context/testedAt" to mapOf( "@type" to "https://uri.etsi.org/ngsi-ld/Property", @@ -570,8 +563,7 @@ class EntityHandlerTests { ), "@id" to "urn:ngsi-ld:Beehive:4567", "@type" to listOf("Beehive") - ), - listOf(NGSILD_TEST_CORE_CONTEXT) + ) ).right() webClient.get() @@ -599,7 +591,7 @@ class EntityHandlerTests { fun `get entity by id should correctly serialize multi-attribute property having one instance`() { mockkDefaultBehaviorForGetEntityById() - coEvery { queryService.queryEntity(any(), any()) } returns ExpandedEntity( + coEvery { queryService.queryEntity(any()) } returns ExpandedEntity( mapOf( "https://uri.etsi.org/ngsi-ld/default-context/name" to mapOf( @@ -611,8 +603,7 @@ class EntityHandlerTests { ), JSONLD_ID to "urn:ngsi-ld:Beehive:4567", JSONLD_TYPE to listOf("Beehive") - ), - listOf(NGSILD_TEST_CORE_CONTEXT) + ) ).right() webClient.get() @@ -636,7 +627,7 @@ class EntityHandlerTests { fun `get entity by id should correctly serialize multi-attribute property having more than one instance`() { mockkDefaultBehaviorForGetEntityById() - coEvery { queryService.queryEntity(any(), any()) } returns ExpandedEntity( + coEvery { queryService.queryEntity(any()) } returns ExpandedEntity( mapOf( "https://uri.etsi.org/ngsi-ld/default-context/name" to listOf( @@ -657,8 +648,7 @@ class EntityHandlerTests { ), JSONLD_ID to "urn:ngsi-ld:Beehive:4567", JSONLD_TYPE to listOf("Beehive") - ), - listOf(NGSILD_TEST_CORE_CONTEXT) + ) ).right() webClient.get() @@ -689,7 +679,7 @@ class EntityHandlerTests { fun `get entity by id should correctly serialize multi-attribute relationship having one instance`() { mockkDefaultBehaviorForGetEntityById() - coEvery { queryService.queryEntity(any(), any()) } returns ExpandedEntity( + coEvery { queryService.queryEntity(any()) } returns ExpandedEntity( mapOf( "https://uri.etsi.org/ngsi-ld/default-context/managedBy" to mapOf( @@ -703,8 +693,7 @@ class EntityHandlerTests { ), JSONLD_ID to "urn:ngsi-ld:Beehive:4567", JSONLD_TYPE to listOf("Beehive") - ), - listOf(NGSILD_TEST_CORE_CONTEXT) + ) ).right() webClient.get() @@ -732,7 +721,7 @@ class EntityHandlerTests { fun `get entity by id should include createdAt & modifiedAt if query param sysAttrs is present`() { mockkDefaultBehaviorForGetEntityById() - coEvery { queryService.queryEntity(any(), any()) } returns ExpandedEntity( + coEvery { queryService.queryEntity(any()) } returns ExpandedEntity( mapOf( "https://uri.etsi.org/ngsi-ld/default-context/managedBy" to mapOf( @@ -756,8 +745,7 @@ class EntityHandlerTests { ), JSONLD_ID to "urn:ngsi-ld:Beehive:4567", JSONLD_TYPE to listOf("Beehive") - ), - listOf(NGSILD_TEST_CORE_CONTEXT) + ) ).right() webClient.get() @@ -774,7 +762,7 @@ class EntityHandlerTests { fun `get entity by id should correctly serialize multi-attribute relationship having more than one instance`() { mockkDefaultBehaviorForGetEntityById() - coEvery { queryService.queryEntity(any(), any()) } returns ExpandedEntity( + coEvery { queryService.queryEntity(any()) } returns ExpandedEntity( mapOf( "https://uri.etsi.org/ngsi-ld/default-context/managedBy" to listOf( @@ -796,8 +784,7 @@ class EntityHandlerTests { ), JSONLD_ID to "urn:ngsi-ld:Beehive:4567", JSONLD_TYPE to listOf("Beehive") - ), - listOf(NGSILD_TEST_CORE_CONTEXT) + ) ).right() webClient.get() @@ -877,8 +864,7 @@ class EntityHandlerTests { mapOf( "@id" to beehiveId.toString(), "@type" to listOf("Beehive") - ), - listOf(NGSILD_TEST_CORE_CONTEXT) + ) ) ), 1 @@ -926,8 +912,7 @@ class EntityHandlerTests { ), "@id" to beehiveId.toString(), "@type" to listOf("Beehive") - ), - listOf(NGSILD_TEST_CORE_CONTEXT) + ) ) ), 1 @@ -957,8 +942,7 @@ class EntityHandlerTests { coEvery { queryService.queryEntities(any(), any()) } returns Pair( listOf( ExpandedEntity( - mapOf("@id" to "urn:ngsi-ld:Beehive:TESTC", "@type" to listOf("Beehive")), - listOf(NGSILD_TEST_CORE_CONTEXT) + mapOf("@id" to "urn:ngsi-ld:Beehive:TESTC", "@type" to listOf("Beehive")) ) ), 3 @@ -1056,8 +1040,7 @@ class EntityHandlerTests { mapOf( "@id" to beehiveId.toString(), "@type" to listOf("Beehive") - ), - APIC_COMPOUND_CONTEXTS + ) ) ), 1 diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityOperationHandlerTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityOperationHandlerTests.kt index b6287aae2..961c7fb1c 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityOperationHandlerTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/web/EntityOperationHandlerTests.kt @@ -92,7 +92,6 @@ class EntityOperationHandlerTests { mockedTemperatureSensorExpandedEntity = mockkClass(ExpandedEntity::class) { every { id } returns temperatureSensorUri.toString() every { members } returns emptyMap() - every { contexts } returns listOf(AQUAC_COMPOUND_CONTEXT) } mockedDissolvedOxygenSensorEntity = mockkClass(NgsiLdEntity::class) { every { id } returns dissolvedOxygenSensorUri @@ -101,7 +100,6 @@ class EntityOperationHandlerTests { mockedDissolvedOxygenSensorExpandedEntity = mockkClass(ExpandedEntity::class) { every { id } returns dissolvedOxygenSensorUri.toString() every { members } returns emptyMap() - every { contexts } returns listOf(AQUAC_COMPOUND_CONTEXT) } mockedDeviceEntity = mockkClass(NgsiLdEntity::class) { every { id } returns deviceUri @@ -110,7 +108,6 @@ class EntityOperationHandlerTests { mockedDeviceExpandedEntity = mockkClass(ExpandedEntity::class) { every { id } returns deviceUri.toString() every { members } returns emptyMap() - every { contexts } returns listOf(AQUAC_COMPOUND_CONTEXT) } } diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/web/TemporalEntityHandlerTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/web/TemporalEntityHandlerTests.kt index c669cc883..5b41d1eef 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/web/TemporalEntityHandlerTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/web/TemporalEntityHandlerTests.kt @@ -364,7 +364,7 @@ class TemporalEntityHandlerTests { val returnedExpandedEntity = mockkClass(ExpandedEntity::class, relaxed = true) coEvery { - queryService.queryTemporalEntity(any(), any(), any()) + queryService.queryTemporalEntity(any(), any()) } returns returnedExpandedEntity.right() webClient.get() @@ -527,7 +527,7 @@ class TemporalEntityHandlerTests { buildDefaultMockResponsesForGetEntity() coEvery { - queryService.queryTemporalEntity(any(), any(), any()) + queryService.queryTemporalEntity(any(), any()) } throws ResourceNotFoundException("Entity urn:ngsi-ld:BeeHive:TESTC was not found") webClient.get() @@ -554,7 +554,7 @@ class TemporalEntityHandlerTests { val returnedExpandedEntity = mockkClass(ExpandedEntity::class, relaxed = true) coEvery { - queryService.queryTemporalEntity(any(), any(), any()) + queryService.queryTemporalEntity(any(), any()) } returns returnedExpandedEntity.right() webClient.get() @@ -576,8 +576,7 @@ class TemporalEntityHandlerTests { ) && !temporalEntitiesQuery.withTemporalValues && !temporalEntitiesQuery.withAudit - }, - eq(APIC_COMPOUND_CONTEXTS) + } ) } confirmVerified(queryService) @@ -589,7 +588,7 @@ class TemporalEntityHandlerTests { val returnedExpandedEntity = mockkClass(ExpandedEntity::class, relaxed = true) coEvery { - queryService.queryTemporalEntity(any(), any(), any()) + queryService.queryTemporalEntity(any(), any()) } returns returnedExpandedEntity.right() webClient.get() @@ -610,7 +609,7 @@ class TemporalEntityHandlerTests { val returnedExpandedEntity = mockkClass(ExpandedEntity::class, relaxed = true) coEvery { - queryService.queryTemporalEntity(any(), any(), any()) + queryService.queryTemporalEntity(any(), any()) } returns returnedExpandedEntity.right() webClient.get() @@ -734,7 +733,7 @@ class TemporalEntityHandlerTests { } coEvery { - queryService.queryTemporalEntity(any(), any(), any()) + queryService.queryTemporalEntity(any(), any()) } returns entityWith2temporalEvolutions.right() } diff --git a/shared/src/main/kotlin/com/egm/stellio/shared/model/ExpandedEntity.kt b/shared/src/main/kotlin/com/egm/stellio/shared/model/ExpandedEntity.kt index 0893f678e..d82347b90 100644 --- a/shared/src/main/kotlin/com/egm/stellio/shared/model/ExpandedEntity.kt +++ b/shared/src/main/kotlin/com/egm/stellio/shared/model/ExpandedEntity.kt @@ -14,8 +14,7 @@ import com.egm.stellio.shared.util.entityOrAttrsNotFoundMessage import java.time.ZonedDateTime data class ExpandedEntity( - val members: Map, - val contexts: List + val members: Map ) { fun containsAnyOf(expandedAttributes: Set): Boolean = expandedAttributes.isEmpty() || members.keys.any { expandedAttributes.contains(it) } @@ -50,8 +49,7 @@ data class ExpandedEntity( createdAt ) as ExpandedAttributeInstance } - }.addDateTimeProperty(NGSILD_CREATED_AT_PROPERTY, createdAt), - contexts = contexts + }.addDateTimeProperty(NGSILD_CREATED_AT_PROPERTY, createdAt) ) /** @@ -71,8 +69,7 @@ data class ExpandedEntity( } } .addDateTimeProperty(NGSILD_CREATED_AT_PROPERTY, createdAt) - .addDateTimeProperty(NGSILD_MODIFIED_AT_PROPERTY, replacedAt), - contexts = contexts + .addDateTimeProperty(NGSILD_MODIFIED_AT_PROPERTY, replacedAt) ) val id by lazy { @@ -111,5 +108,5 @@ data class ExpandedEntity( fun List.filterOnAttributes(includedAttributes: Set): List = this.filter { it.containsAnyOf(includedAttributes) } .map { - ExpandedEntity(it.filterOnAttributes(includedAttributes), it.contexts) + ExpandedEntity(it.filterOnAttributes(includedAttributes)) } diff --git a/shared/src/main/kotlin/com/egm/stellio/shared/util/JsonLdUtils.kt b/shared/src/main/kotlin/com/egm/stellio/shared/util/JsonLdUtils.kt index ee27cf3b6..c8d70714e 100644 --- a/shared/src/main/kotlin/com/egm/stellio/shared/util/JsonLdUtils.kt +++ b/shared/src/main/kotlin/com/egm/stellio/shared/util/JsonLdUtils.kt @@ -135,14 +135,14 @@ object JsonLdUtils { runCatching { doJsonLdExpansion(input, contexts) }.fold({ - ExpandedEntity(it, contexts).right() + ExpandedEntity(it).right() }, { if (it is APIException) it.left() else it.toAPIException().left() }) suspend fun expandJsonLdEntity(input: Map, contexts: List): ExpandedEntity = - ExpandedEntity(doJsonLdExpansion(input, contexts), contexts) + ExpandedEntity(doJsonLdExpansion(input, contexts)) suspend fun expandJsonLdEntity(input: String, contexts: List): ExpandedEntity = expandJsonLdEntity(input.deserializeAsMap(), contexts) diff --git a/shared/src/test/kotlin/com/egm/stellio/shared/model/ExpandedEntityTests.kt b/shared/src/test/kotlin/com/egm/stellio/shared/model/ExpandedEntityTests.kt index e935f63af..112a4c24f 100644 --- a/shared/src/test/kotlin/com/egm/stellio/shared/model/ExpandedEntityTests.kt +++ b/shared/src/test/kotlin/com/egm/stellio/shared/model/ExpandedEntityTests.kt @@ -12,8 +12,7 @@ class ExpandedEntityTests { @Test fun `it should find an expanded attribute contained in the entity`() { val expandedEntity = ExpandedEntity( - mapOf(INCOMING_PROPERTY to "", OUTGOING_PROPERTY to ""), - NGSILD_TEST_CORE_CONTEXTS + mapOf(INCOMING_PROPERTY to "", OUTGOING_PROPERTY to "") ) val checkResult = expandedEntity.checkContainsAnyOf(setOf(TEMPERATURE_PROPERTY, INCOMING_PROPERTY)) @@ -26,8 +25,7 @@ class ExpandedEntityTests { @Test fun `it should not find an expanded attribute contained in the entity`() { val expandedEntity = ExpandedEntity( - mapOf(INCOMING_PROPERTY to "", OUTGOING_PROPERTY to "", JSONLD_ID to "urn:ngsi-ld:Entity:01"), - NGSILD_TEST_CORE_CONTEXTS + mapOf(INCOMING_PROPERTY to "", OUTGOING_PROPERTY to "", JSONLD_ID to "urn:ngsi-ld:Entity:01") ) val checkResult = expandedEntity.checkContainsAnyOf(setOf(TEMPERATURE_PROPERTY, NGSILD_NAME_PROPERTY)) diff --git a/subscription-service/src/main/kotlin/com/egm/stellio/subscription/listener/EntityEventListenerService.kt b/subscription-service/src/main/kotlin/com/egm/stellio/subscription/listener/EntityEventListenerService.kt index f01218ea3..b8eb686a8 100644 --- a/subscription-service/src/main/kotlin/com/egm/stellio/subscription/listener/EntityEventListenerService.kt +++ b/subscription-service/src/main/kotlin/com/egm/stellio/subscription/listener/EntityEventListenerService.kt @@ -52,59 +52,51 @@ class EntityEventListenerService( tenantName, entityEvent.operationPayload.getUpdatedAttributes(), entityEvent.getEntity(), - NotificationTrigger.ENTITY_CREATED, - entityEvent.contexts + NotificationTrigger.ENTITY_CREATED ) is EntityReplaceEvent -> entityEvent.operationPayload.getUpdatedAttributes().forEach { attribute -> handleEntityEvent( tenantName, setOf(attribute), entityEvent.getEntity(), - NotificationTrigger.ATTRIBUTE_CREATED, - entityEvent.contexts + NotificationTrigger.ATTRIBUTE_CREATED ) } is EntityDeleteEvent -> handleEntityEvent( tenantName, entityEvent.deletedEntity?.getUpdatedAttributes() ?: emptySet(), entityEvent.getEntity() ?: serializeObject(emptyMap()), - NotificationTrigger.ENTITY_DELETED, - entityEvent.contexts + NotificationTrigger.ENTITY_DELETED ) is AttributeAppendEvent -> handleEntityEvent( tenantName, setOf(entityEvent.attributeName), entityEvent.getEntity(), - NotificationTrigger.ATTRIBUTE_CREATED, - entityEvent.contexts + NotificationTrigger.ATTRIBUTE_CREATED ) is AttributeReplaceEvent -> handleEntityEvent( tenantName, setOf(entityEvent.attributeName), entityEvent.getEntity(), - NotificationTrigger.ATTRIBUTE_UPDATED, - entityEvent.contexts + NotificationTrigger.ATTRIBUTE_UPDATED ) is AttributeUpdateEvent -> handleEntityEvent( tenantName, setOf(entityEvent.attributeName), entityEvent.getEntity(), - NotificationTrigger.ATTRIBUTE_UPDATED, - entityEvent.contexts + NotificationTrigger.ATTRIBUTE_UPDATED ) is AttributeDeleteEvent -> handleEntityEvent( tenantName, setOf(entityEvent.attributeName), entityEvent.getEntity(), - NotificationTrigger.ATTRIBUTE_DELETED, - entityEvent.contexts + NotificationTrigger.ATTRIBUTE_DELETED ) is AttributeDeleteAllInstancesEvent -> handleEntityEvent( tenantName, setOf(entityEvent.attributeName), entityEvent.getEntity(), - NotificationTrigger.ATTRIBUTE_DELETED, - entityEvent.contexts + NotificationTrigger.ATTRIBUTE_DELETED ) } }.onFailure { @@ -116,11 +108,10 @@ class EntityEventListenerService( tenantName: String, updatedAttributes: Set, entityPayload: String, - notificationTrigger: NotificationTrigger, - contexts: List + notificationTrigger: NotificationTrigger ): Either = either { logger.debug("Attributes considered in the event: {}", updatedAttributes) - val expandedEntity = ExpandedEntity(entityPayload.deserializeAsMap(), contexts) + val expandedEntity = ExpandedEntity(entityPayload.deserializeAsMap()) mono { notificationService.notifyMatchingSubscribers( expandedEntity, diff --git a/subscription-service/src/main/kotlin/com/egm/stellio/subscription/service/NotificationService.kt b/subscription-service/src/main/kotlin/com/egm/stellio/subscription/service/NotificationService.kt index 22ab43996..bef5e5799 100644 --- a/subscription-service/src/main/kotlin/com/egm/stellio/subscription/service/NotificationService.kt +++ b/subscription-service/src/main/kotlin/com/egm/stellio/subscription/service/NotificationService.kt @@ -44,7 +44,7 @@ class NotificationService( else AttributeRepresentation.NORMALIZED val compactedEntity = compactEntity( - ExpandedEntity(filteredEntity, it.contexts), + ExpandedEntity(filteredEntity), it.contexts ).toFinalRepresentation( NgsiLdDataRepresentation(