Skip to content

Commit

Permalink
chore: upgrade Kotlin 2.1 / fix deprecations and upgrades (#1275)
Browse files Browse the repository at this point in the history
* chore: upgrade Kotlin 2.1 / fix deprecations and upgrades
* chore: update actuator config
  • Loading branch information
bobeal authored Dec 1, 2024
1 parent e6fe9f9 commit f3d668b
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 113 deletions.
7 changes: 4 additions & 3 deletions api-gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ application:

management:
endpoints:
enabled-by-default: false
web:
exposure:
include: health,info
access:
default: none
endpoint:
info:
enabled: false
access: none
health:
enabled: true
access: read_only

logbook:
format.style: http
Expand Down
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ plugins {
id("org.springframework.boot") version "3.4.0" apply false
id("io.spring.dependency-management") version "1.1.6" apply false
id("org.graalvm.buildtools.native") version "0.10.3"
kotlin("jvm") version "2.0.21" apply false
kotlin("plugin.spring") version "2.0.21" apply false
kotlin("jvm") version "2.1.0" apply false
kotlin("plugin.spring") version "2.1.0" apply false
id("com.google.cloud.tools.jib") version "3.4.4" apply false
id("io.gitlab.arturbosch.detekt") version "1.23.7" apply false
id("org.sonarqube") version "6.0.1.5171"
Expand Down Expand Up @@ -86,7 +86,8 @@ subprojects {

kotlin {
compilerOptions {
freeCompilerArgs.add("-Xjsr305=strict")
// https://kotlinlang.org/docs/whatsnew2020.html#data-class-copy-function-to-have-the-same-visibility-as-constructor
freeCompilerArgs.addAll("-Xjsr305=strict", "-Xconsistent-data-class-copy-visibility")
apiVersion.set(KotlinVersion.KOTLIN_2_0)
jvmTarget.set(JvmTarget.JVM_21)
}
Expand Down
1 change: 1 addition & 0 deletions search-service/config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<ID>LongMethod:V0_29__JsonLd_migration.kt$V0_29__JsonLd_migration$override fun migrate(context: Context)</ID>
<ID>LongParameterList:AttributeInstance.kt$AttributeInstance.Companion$( attributeUuid: UUID, instanceId: URI = generateRandomInstanceId(), timeAndProperty: Pair&lt;ZonedDateTime, TemporalProperty&gt;, value: Triple&lt;String?, Double?, WKTCoordinates?&gt;, payload: ExpandedAttributeInstance, sub: String? )</ID>
<ID>LongParameterList:AttributeInstance.kt$AttributeInstance.Companion$( attributeUuid: UUID, instanceId: URI = generateRandomInstanceId(), timeProperty: TemporalProperty? = TemporalProperty.OBSERVED_AT, modifiedAt: ZonedDateTime? = null, attributeMetadata: AttributeMetadata, payload: ExpandedAttributeInstance, time: ZonedDateTime, sub: String? = null )</ID>
<ID>LongParameterList:BusinessObjectsFactory.kt$( attributeUuid: UUID, timeProperty: AttributeInstance.TemporalProperty = AttributeInstance.TemporalProperty.OBSERVED_AT, measuredValue: Double? = Random.nextDouble(), value: String? = null, time: ZonedDateTime = ngsiLdDateTime(), sub: Sub? = null )</ID>
<ID>LongParameterList:EntitiesQuery.kt$EntitiesQuery$( open val q: String?, open val scopeQ: String?, open val paginationQuery: PaginationQuery, open val attrs: Set&lt;ExpandedTerm&gt;, open val datasetId: Set&lt;String&gt;, open val geoQuery: GeoQuery?, open val linkedEntityQuery: LinkedEntityQuery?, open val contexts: List&lt;String&gt; )</ID>
<ID>LongParameterList:EntityAttributeService.kt$EntityAttributeService$( attribute: Attribute, attributeName: ExpandedTerm, attributeMetadata: AttributeMetadata, mergedAt: ZonedDateTime, observedAt: ZonedDateTime?, attributePayload: ExpandedAttributeInstance, sub: Sub? )</ID>
<ID>LongParameterList:EntityAttributeService.kt$EntityAttributeService$( attribute: Attribute, ngsiLdAttribute: NgsiLdAttribute, attributeMetadata: AttributeMetadata, createdAt: ZonedDateTime, attributePayload: ExpandedAttributeInstance, sub: Sub? )</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ data class MiscellaneousPersistentWarning(
override val csr: ContextSourceRegistration
) : NGSILDWarning(MISCELLANEOUS_PERSISTENT_WARNING_CODE, message, csr)

fun ResponseEntity<*>.addWarnings(warnings: List<NGSILDWarning>?): ResponseEntity<*> {
val headers = HttpHeaders.writableHttpHeaders(this.headers)
if (!warnings.isNullOrEmpty())
headers.addAll(NGSILDWarning.HEADER_NAME, warnings.map { it.getHeaderMessage() })

return ResponseEntity.status(this.statusCode)
.headers(headers)
.body(this.body)
}
fun ResponseEntity<*>.addWarnings(warnings: List<NGSILDWarning>?): ResponseEntity<*> =
if (!warnings.isNullOrEmpty()) {
val headers = HttpHeaders(this.headers).apply {
addAll(NGSILDWarning.HEADER_NAME, warnings.map { it.getHeaderMessage() })
}

ResponseEntity.status(this.statusCode)
.headers(headers)
.body(this.body)
} else this
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import com.egm.stellio.shared.model.getSingleEntry
import com.egm.stellio.shared.util.APIC_COMPOUND_CONTEXTS
import com.egm.stellio.shared.util.BEEHIVE_TYPE
import com.egm.stellio.shared.util.JsonLdUtils
import com.egm.stellio.shared.util.Sub
import com.egm.stellio.shared.util.ngsiLdDateTime
import com.egm.stellio.shared.util.toUri
import io.r2dbc.postgresql.codec.Json
import java.net.URI
import java.time.ZonedDateTime
import java.util.UUID
import kotlin.random.Random

Expand All @@ -42,16 +44,20 @@ fun gimmeEntityPayload(

fun gimmeNumericPropertyAttributeInstance(
attributeUuid: UUID,
timeProperty: AttributeInstance.TemporalProperty = AttributeInstance.TemporalProperty.OBSERVED_AT
timeProperty: AttributeInstance.TemporalProperty = AttributeInstance.TemporalProperty.OBSERVED_AT,
measuredValue: Double? = Random.nextDouble(),
value: String? = null,
time: ZonedDateTime = ngsiLdDateTime(),
sub: Sub? = null
): AttributeInstance {
val attributeMetadata = AttributeMetadata(
measuredValue = Random.nextDouble(),
value = null,
measuredValue = measuredValue,
value = value,
geoValue = null,
valueType = Attribute.AttributeValueType.NUMBER,
datasetId = null,
type = Attribute.AttributeType.Property,
observedAt = ngsiLdDateTime()
observedAt = time
)
val payload = JsonLdUtils.buildExpandedPropertyValue(attributeMetadata.measuredValue!!)
.addNonReifiedTemporalProperty(JsonLdUtils.NGSILD_OBSERVED_AT_PROPERTY, attributeMetadata.observedAt!!)
Expand All @@ -62,7 +68,8 @@ fun gimmeNumericPropertyAttributeInstance(
time = attributeMetadata.observedAt,
attributeMetadata = attributeMetadata,
timeProperty = timeProperty,
payload = payload
payload = payload,
sub = sub
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ class AggregatedTemporalQueryServiceTests : WithTimescaleContainer, WithKafkaCon
fun `it should correctly aggregate on JSON Number values`(aggrMethod: String, expectedValue: String) = runTest {
val attribute = createAttribute(Attribute.AttributeValueType.NUMBER)
(1..10).forEach { i ->
val attributeInstance = gimmeNumericPropertyAttributeInstance(attributeUuid)
.copy(measuredValue = i.toDouble())
val attributeInstance = gimmeNumericPropertyAttributeInstance(
attributeUuid = attributeUuid,
measuredValue = i.toDouble()
)
attributeInstanceService.create(attributeInstance)
}

Expand Down Expand Up @@ -126,8 +128,10 @@ class AggregatedTemporalQueryServiceTests : WithTimescaleContainer, WithKafkaCon
fun `it should correctly aggregate on JSON String values`(aggrMethod: String, expectedValue: String?) = runTest {
val attribute = createAttribute(Attribute.AttributeValueType.STRING)
(1..10).forEach { i ->
val attributeInstance = gimmeNumericPropertyAttributeInstance(attributeUuid)
.copy(measuredValue = null, value = "a$i")
val attributeInstance = gimmeNumericPropertyAttributeInstance(
attributeUuid = attributeUuid,
value = "a$i"
)
attributeInstanceService.create(attributeInstance)
}

Expand Down Expand Up @@ -155,15 +159,10 @@ class AggregatedTemporalQueryServiceTests : WithTimescaleContainer, WithKafkaCon
fun `it should correctly aggregate on JSON Object values`(aggrMethod: String, expectedValue: String?) = runTest {
val attribute = createAttribute(Attribute.AttributeValueType.OBJECT)
(1..10).forEach { i ->
val attributeInstance = gimmeNumericPropertyAttributeInstance(attributeUuid)
.copy(
measuredValue = null,
value = """
{
"a": $i
}
""".trimIndent()
)
val attributeInstance = gimmeNumericPropertyAttributeInstance(
attributeUuid = attributeUuid,
value = """{ "a": $i }"""
)
attributeInstanceService.create(attributeInstance)
}

Expand Down Expand Up @@ -191,13 +190,10 @@ class AggregatedTemporalQueryServiceTests : WithTimescaleContainer, WithKafkaCon
fun `it should correctly aggregate on JSON Array values`(aggrMethod: String, expectedValue: String?) = runTest {
val attribute = createAttribute(Attribute.AttributeValueType.ARRAY)
(1..10).forEach { i ->
val attributeInstance = gimmeNumericPropertyAttributeInstance(attributeUuid)
.copy(
measuredValue = null,
value = """
[ $i ]
""".trimIndent()
)
val attributeInstance = gimmeNumericPropertyAttributeInstance(
attributeUuid = attributeUuid,
value = """[ $i ]"""
)
attributeInstanceService.create(attributeInstance)
}

Expand Down Expand Up @@ -225,11 +221,10 @@ class AggregatedTemporalQueryServiceTests : WithTimescaleContainer, WithKafkaCon
fun `it should correctly aggregate on JSON Boolean values`(aggrMethod: String, expectedValue: String?) = runTest {
val attribute = createAttribute(Attribute.AttributeValueType.BOOLEAN)
(1..10).forEach { i ->
val attributeInstance = gimmeNumericPropertyAttributeInstance(attributeUuid)
.copy(
measuredValue = null,
value = if (i % 2 == 0) "true" else "false"
)
val attributeInstance = gimmeNumericPropertyAttributeInstance(
attributeUuid = attributeUuid,
value = if (i % 2 == 0) "true" else "false"
)
attributeInstanceService.create(attributeInstance)
}

Expand Down Expand Up @@ -258,11 +253,10 @@ class AggregatedTemporalQueryServiceTests : WithTimescaleContainer, WithKafkaCon
val attribute = createAttribute(Attribute.AttributeValueType.DATETIME)
val baseDateTime = ZonedDateTime.parse("2023-03-05T00:01:01Z")
(1..10).forEach { i ->
val attributeInstance = gimmeNumericPropertyAttributeInstance(attributeUuid)
.copy(
measuredValue = null,
value = baseDateTime.plusHours(i.toLong()).toString()
)
val attributeInstance = gimmeNumericPropertyAttributeInstance(
attributeUuid = attributeUuid,
value = baseDateTime.plusHours(i.toLong()).toString()
)
attributeInstanceService.create(attributeInstance)
}

Expand Down Expand Up @@ -291,11 +285,10 @@ class AggregatedTemporalQueryServiceTests : WithTimescaleContainer, WithKafkaCon
val attribute = createAttribute(Attribute.AttributeValueType.DATE)
val baseDateTime = LocalDate.parse("2023-03-05")
(1..10).forEach { i ->
val attributeInstance = gimmeNumericPropertyAttributeInstance(attributeUuid)
.copy(
measuredValue = null,
value = baseDateTime.plusDays(i.toLong()).toString()
)
val attributeInstance = gimmeNumericPropertyAttributeInstance(
attributeUuid = attributeUuid,
value = baseDateTime.plusDays(i.toLong()).toString()
)
attributeInstanceService.create(attributeInstance)
}

Expand Down Expand Up @@ -324,11 +317,10 @@ class AggregatedTemporalQueryServiceTests : WithTimescaleContainer, WithKafkaCon
val attribute = createAttribute(Attribute.AttributeValueType.TIME)
val baseDateTime = OffsetTime.parse("00:00:01Z")
(1..10).forEach { i ->
val attributeInstance = gimmeNumericPropertyAttributeInstance(attributeUuid)
.copy(
measuredValue = null,
value = baseDateTime.plusHours(i.toLong()).toString()
)
val attributeInstance = gimmeNumericPropertyAttributeInstance(
attributeUuid = attributeUuid,
value = baseDateTime.plusHours(i.toLong()).toString()
)
attributeInstanceService.create(attributeInstance)
}

Expand Down Expand Up @@ -356,11 +348,10 @@ class AggregatedTemporalQueryServiceTests : WithTimescaleContainer, WithKafkaCon
fun `it should correctly aggregate on URI values`(aggrMethod: String, expectedValue: String?) = runTest {
val attribute = createAttribute(Attribute.AttributeValueType.URI)
(1..10).forEach { i ->
val attributeInstance = gimmeNumericPropertyAttributeInstance(attributeUuid)
.copy(
measuredValue = null,
value = "urn:ngsi-ld:Entity:$i"
)
val attributeInstance = gimmeNumericPropertyAttributeInstance(
attributeUuid = attributeUuid,
value = "urn:ngsi-ld:Entity:$i"
)
attributeInstanceService.create(attributeInstance)
}

Expand All @@ -378,8 +369,10 @@ class AggregatedTemporalQueryServiceTests : WithTimescaleContainer, WithKafkaCon
fun `it should aggregate on the whole time range if no aggrPeriodDuration is given`() = runTest {
val attribute = createAttribute(Attribute.AttributeValueType.NUMBER)
(1..10).forEach { i ->
val attributeInstance = gimmeNumericPropertyAttributeInstance(attributeUuid)
.copy(measuredValue = i.toDouble())
val attributeInstance = gimmeNumericPropertyAttributeInstance(
attributeUuid = attributeUuid,
measuredValue = i.toDouble()
)
attributeInstanceService.create(attributeInstance)
}

Expand Down Expand Up @@ -415,8 +408,10 @@ class AggregatedTemporalQueryServiceTests : WithTimescaleContainer, WithKafkaCon
val attribute = createAttribute(Attribute.AttributeValueType.NUMBER)
val startTimestamp = ZonedDateTime.parse("2023-12-28T12:00:00Z")
(1..10).forEach { i ->
val attributeInstance = gimmeNumericPropertyAttributeInstance(attributeUuid)
.copy(time = startTimestamp.plusDays(i.toLong()))
val attributeInstance = gimmeNumericPropertyAttributeInstance(
attributeUuid = attributeUuid,
time = startTimestamp.plusDays(i.toLong())
)
attributeInstanceService.create(attributeInstance)
}

Expand All @@ -437,11 +432,15 @@ class AggregatedTemporalQueryServiceTests : WithTimescaleContainer, WithKafkaCon
fun `it should handle aggregates for an attribute having different types of values in history`() = runTest {
val attribute = createAttribute(Attribute.AttributeValueType.ARRAY)
(1..10).forEach { i ->
val attributeInstanceWithArrayValue = gimmeNumericPropertyAttributeInstance(attributeUuid)
.copy(measuredValue = null, value = "[ $i ]")
val attributeInstanceWithArrayValue = gimmeNumericPropertyAttributeInstance(
attributeUuid = attributeUuid,
value = "[ $i ]"
)
attributeInstanceService.create(attributeInstanceWithArrayValue)
val attributeInstanceWithStringValue = gimmeNumericPropertyAttributeInstance(attributeUuid)
.copy(measuredValue = null, value = "$i")
val attributeInstanceWithStringValue = gimmeNumericPropertyAttributeInstance(
attributeUuid = attributeUuid,
value = "$i"
)
attributeInstanceService.create(attributeInstanceWithStringValue)
}

Expand All @@ -461,11 +460,11 @@ class AggregatedTemporalQueryServiceTests : WithTimescaleContainer, WithKafkaCon
val attribute = createAttribute(Attribute.AttributeValueType.NUMBER)
val startTimestamp = ZonedDateTime.parse("2023-12-31T23:00:00Z")
(0..9).forEach { i ->
val attributeInstance = gimmeNumericPropertyAttributeInstance(attributeUuid)
.copy(
time = startTimestamp.plusHours(i.toLong()),
measuredValue = 1.0
)
val attributeInstance = gimmeNumericPropertyAttributeInstance(
attributeUuid = attributeUuid,
measuredValue = 1.0,
time = startTimestamp.plusHours(i.toLong())
)
attributeInstanceService.create(attributeInstance)
}

Expand Down
Loading

0 comments on commit f3d668b

Please sign in to comment.