Skip to content

Commit

Permalink
fix(subscription): expand watchedAttributes when updating a subscript…
Browse files Browse the repository at this point in the history
…ion (#1039)
  • Loading branch information
bobeal authored Nov 6, 2023
1 parent d43c28e commit ddabfc4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.egm.stellio.shared.util.*
import com.egm.stellio.shared.util.JsonLdUtils.JSONLD_TYPE_TERM
import com.egm.stellio.shared.util.JsonLdUtils.NGSILD_LOCATION_PROPERTY
import com.egm.stellio.shared.util.JsonLdUtils.NGSILD_SUBSCRIPTION_TERM
import com.egm.stellio.shared.util.JsonLdUtils.expandJsonLdTerm
import com.egm.stellio.subscription.config.SubscriptionProperties
import com.egm.stellio.subscription.model.*
import com.egm.stellio.subscription.model.GeoQ
Expand Down Expand Up @@ -270,7 +271,7 @@ class SubscriptionService(
input: Map<String, Any>,
contexts: List<String>
): Either<APIException, Unit> = either {
val subscriptionInputWithModifiedAt = input.plus("modifiedAt" to Instant.now().atZone(ZoneOffset.UTC))
val subscriptionInputWithModifiedAt = input.plus("modifiedAt" to ngsiLdDateTime())

if (!subscriptionInputWithModifiedAt.containsKey(JSONLD_TYPE_TERM) ||
subscriptionInputWithModifiedAt[JSONLD_TYPE_TERM]!! != NGSILD_SUBSCRIPTION_TERM
Expand Down Expand Up @@ -301,10 +302,16 @@ class SubscriptionService(
updateSubscriptionAttribute(subscriptionId, columnName, expiresAt).bind()
}

it.key == "watchedAttributes" -> {
val value = (it.value as List<String>).map { watchedAttribute ->
expandJsonLdTerm(watchedAttribute, contexts)
}.toSqlValue(it.key)
updateSubscriptionAttribute(subscriptionId, it.key.toSqlColumnName(), value).bind()
}

listOf(
"subscriptionName",
"description",
"watchedAttributes",
"timeInterval",
"q",
"scopeQ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,13 +770,13 @@ class SubscriptionServiceTests : WithTimescaleContainer {
}

@Test
fun `it should update a subscription watched attributes`() = runTest {
fun `it should update and expand watched attributes of a subscription`() = runTest {
val parsedInput = mapOf(
"type" to NGSILD_SUBSCRIPTION_TERM,
"watchedAttributes" to arrayListOf(INCOMING_PROPERTY, TEMPERATURE_PROPERTY)
"watchedAttributes" to arrayListOf(INCOMING_COMPACT_PROPERTY, TEMPERATURE_COMPACT_PROPERTY)
)

subscriptionService.update(subscription5Id, parsedInput, listOf(APIC_COMPOUND_CONTEXT))
subscriptionService.update(subscription5Id, parsedInput, listOf(APIC_COMPOUND_CONTEXT)).shouldSucceed()

val subscription = subscriptionService.getById(subscription5Id)

Expand Down

0 comments on commit ddabfc4

Please sign in to comment.