Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(subscription): expand watchedAttributes when updating a subscription #1039

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading