diff --git a/subscription-service/src/main/kotlin/com/egm/stellio/subscription/service/SubscriptionService.kt b/subscription-service/src/main/kotlin/com/egm/stellio/subscription/service/SubscriptionService.kt index 63ac66c61..00ad77bfc 100644 --- a/subscription-service/src/main/kotlin/com/egm/stellio/subscription/service/SubscriptionService.kt +++ b/subscription-service/src/main/kotlin/com/egm/stellio/subscription/service/SubscriptionService.kt @@ -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 @@ -270,7 +271,7 @@ class SubscriptionService( input: Map, contexts: List ): Either = 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 @@ -301,10 +302,16 @@ class SubscriptionService( updateSubscriptionAttribute(subscriptionId, columnName, expiresAt).bind() } + it.key == "watchedAttributes" -> { + val value = (it.value as List).map { watchedAttribute -> + expandJsonLdTerm(watchedAttribute, contexts) + }.toSqlValue(it.key) + updateSubscriptionAttribute(subscriptionId, it.key.toSqlColumnName(), value).bind() + } + listOf( "subscriptionName", "description", - "watchedAttributes", "timeInterval", "q", "scopeQ", diff --git a/subscription-service/src/test/kotlin/com/egm/stellio/subscription/service/SubscriptionServiceTests.kt b/subscription-service/src/test/kotlin/com/egm/stellio/subscription/service/SubscriptionServiceTests.kt index cb91f5d03..24c197ff3 100644 --- a/subscription-service/src/test/kotlin/com/egm/stellio/subscription/service/SubscriptionServiceTests.kt +++ b/subscription-service/src/test/kotlin/com/egm/stellio/subscription/service/SubscriptionServiceTests.kt @@ -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)