Skip to content

Commit

Permalink
fix(core): allows to check existence of an attribute whatever its dat…
Browse files Browse the repository at this point in the history
…asetId (#1284)
  • Loading branch information
bobeal authored Dec 13, 2024
1 parent c1c9f8f commit b7d18a2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,12 @@ class EntityAttributeService(
suspend fun checkEntityAndAttributeExistence(
entityId: URI,
attributeName: ExpandedTerm,
datasetId: URI? = null
datasetId: URI? = null,
anyAttributeInstance: Boolean = false
): Either<APIException, Unit> {
val datasetIdFilter =
if (anyAttributeInstance) ""
else datasetId.toDatasetIdFilter()
val selectQuery =
"""
select
Expand All @@ -560,7 +564,7 @@ class EntityAttributeService(
from temporal_entity_attribute
where entity_id = :entity_id
and attribute_name = :attribute_name
${datasetId.toDatasetIdFilter()}
$datasetIdFilter
) as attributeNameExists;
""".trimIndent()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ class EntityService(
entityAttributeService.checkEntityAndAttributeExistence(
entityId,
attributeName,
datasetId
datasetId,
deleteAll
).bind()
entityAttributeService.deleteAttribute(
entityId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,18 @@ class EntityAttributeServiceTests : WithTimescaleContainer, WithKafkaContainer {
.shouldSucceed()
}

@Test
fun `it should return a right unit if entiy and attribute exist whatever its datasetId`() = runTest {
val rawEntity = loadSampleData("beehive_multi_instance_property.jsonld")

coEvery { attributeInstanceService.create(any()) } returns Unit.right()

entityAttributeService.createAttributes(rawEntity, APIC_COMPOUND_CONTEXTS)

entityAttributeService.checkEntityAndAttributeExistence(beehiveTestCId, INCOMING_PROPERTY, null, true)
.shouldSucceed()
}

@Test
fun `it should return a left attribute not found if entity exists but not the attribute`() = runTest {
val rawEntity = loadSampleData()
Expand Down

0 comments on commit b7d18a2

Please sign in to comment.