Skip to content
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
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
ij_kotlin_allow_trailing_comma = false
ij_kotlin_allow_trailing_comma_on_call_site = false
ktlint_code_style = intellij_idea
ktlint_standard_no-unused-imports = enabled
ktlint_standard_no-unused-imports = enabled
ktlint_standard_blank-line-between-when-conditions = disabled
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: setup java
uses: graalvm/setup-graalvm@v1
with:
java-version: "21"
java-version: "25"
distribution: graalvm
cache: "gradle"
- name: Publish
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: setup java
uses: graalvm/setup-graalvm@v1
with:
java-version: "21"
java-version: "25"
distribution: graalvm
cache: "gradle"
- name: Lint
Expand All @@ -27,7 +27,7 @@ jobs:
- name: setup java
uses: graalvm/setup-graalvm@v1
with:
java-version: "21"
java-version: "25"
distribution: graalvm
cache: "gradle"
- name: Test
Expand Down
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
}

group = "com.valensas"
java.sourceCompatibility = JavaVersion.VERSION_21
java.sourceCompatibility = JavaVersion.VERSION_25

repositories {
mavenCentral()
Expand All @@ -24,7 +24,7 @@ dependencies {
compileOnly("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.data:spring-data-commons")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("com.valensas:exception:2.5.0")
implementation("com.valensas:exception:3.0.0")
compileOnly("io.micrometer:micrometer-core")
api("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:1.11.0")
testImplementation("org.springframework.boot:spring-boot-starter-webflux")
Expand All @@ -35,15 +35,15 @@ dependencies {
tasks.withType<KotlinCompile> {
compilerOptions {
freeCompilerArgs.addAll("-Xjsr305=strict")
jvmTarget = JvmTarget.JVM_21
jvmTarget = JvmTarget.JVM_25
}
}

extra["kotlin.version"] = "2.4.0"

dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:3.5.15")
mavenBom("org.springframework.boot:spring-boot-dependencies:4.1.0")
}
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.0-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
15 changes: 7 additions & 8 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 12 additions & 22 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/main/kotlin/com/valensas/util/Monitoring.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ fun measure(
if (exception == null) {
mapOf("exception" to "none")
} else {
mapOf("exception" to exception!!.javaClass.canonicalName)
mapOf("exception" to exception.javaClass.canonicalName)
}

meterRegistry.timer(name, (tags + extraTags).map { Tag.of(it.key, it.value) }).record(nanoDuration, TimeUnit.NANOSECONDS)
if (exception != null) throw exception!!
if (exception != null) throw exception
}

fun runScheduledTask(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
package com.valensas.util.autoconfigure

import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.SerializationFeature
import com.valensas.util.serializer.BigDecimalMoneyDeserializer
import com.valensas.util.serializer.InstantSerializer
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.jackson.autoconfigure.JsonMapperBuilderCustomizer
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
import tools.jackson.databind.DeserializationFeature
import tools.jackson.databind.cfg.DateTimeFeature
import tools.jackson.databind.cfg.EnumFeature
import tools.jackson.databind.module.SimpleModule
import java.math.BigDecimal
import java.time.Instant

@Configuration
class JacksonConfiguration {
@Bean
@Primary
fun jackson2ObjectMapperBuilder(
fun valensasJsonMapperBuilderCustomizer(
@Value("\${valensas.server.bigdecimal.scale:8}")
scale: Int
): Jackson2ObjectMapperBuilder = Jackson2ObjectMapperBuilder()
.deserializerByType(BigDecimal::class.java, BigDecimalMoneyDeserializer(scale))
.serializerByType(Instant::class.java, InstantSerializer())
.createXmlMapper(false)
.featuresToDisable(
SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS,
SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS
).featuresToEnable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
): JsonMapperBuilderCustomizer = JsonMapperBuilderCustomizer { builder ->
val module = SimpleModule()
.addDeserializer(BigDecimal::class.java, BigDecimalMoneyDeserializer(scale))
.addSerializer(Instant::class.java, InstantSerializer())
builder
.addModule(module)
.disable(
DateTimeFeature.WRITE_DATES_AS_TIMESTAMPS,
DateTimeFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS,
DateTimeFeature.WRITE_DURATIONS_AS_TIMESTAMPS
).enable(EnumFeature.WRITE_ENUMS_USING_TO_STRING)
.enable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import kotlinx.coroutines.reactor.mono
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono

suspend fun <T> Collection<T>.parallelForEach(mapper: suspend (T) -> Unit) {
suspend fun <T : Any> Collection<T>.parallelForEach(mapper: suspend (T) -> Unit) {
if (this.isEmpty()) return
Flux.fromIterable(this).parallelForEach(mapper)
}

suspend fun <T, U> Collection<T>.parallelMap(mapper: suspend (T) -> U): List<U> {
suspend fun <T : Any, U : Any> Collection<T>.parallelMap(mapper: suspend (T) -> U): List<U> {
if (this.isEmpty()) return emptyList()
return Flux
.fromIterable(this)
Expand All @@ -23,6 +23,6 @@ suspend fun <T, U> Collection<T>.parallelMap(mapper: suspend (T) -> U): List<U>
.awaitSingle()
}

suspend fun <T> Flux<T>.parallelForEach(function: suspend (T) -> Unit) {
suspend fun <T : Any> Flux<T>.parallelForEach(function: suspend (T) -> Unit) {
this.flatMap { mono { function(it) } }.switchIfEmpty(Mono.just(Unit)).awaitLast()
}
7 changes: 4 additions & 3 deletions src/main/kotlin/com/valensas/util/pagination/Pageable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.springframework.util.StringUtils
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.util.UriBuilder
import java.io.Serializable
import java.util.Optional

class Pageable(
@RequestParam(required = false) var page: Int?,
Expand Down Expand Up @@ -65,6 +66,6 @@ private fun parseParameterIntoSort(sort: String?): Sort {
}

fun UriBuilder.pageable(pageable: Pageable) = this
.queryParam("page", pageable.page)
.queryParam("sort", pageable.sort)
.queryParam("size", pageable.size)
.queryParamIfPresent("page", Optional.ofNullable(pageable.page))
.queryParamIfPresent("sort", Optional.ofNullable(pageable.sort))
.queryParamIfPresent("size", Optional.ofNullable(pageable.size))
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.valensas.util.serializer

import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JsonDeserializer
import java.io.IOException
import tools.jackson.core.JsonParser
import tools.jackson.databind.DeserializationContext
import tools.jackson.databind.ValueDeserializer
import java.math.BigDecimal
import java.math.RoundingMode

class BigDecimalMoneyDeserializer(
private val scale: Int
) : JsonDeserializer<BigDecimal>() {
@Throws(IOException::class, JsonProcessingException::class)
) : ValueDeserializer<BigDecimal>() {
override fun deserialize(
jp: JsonParser,
ctx: DeserializationContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.valensas.util.serializer

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.JsonSerializer
import com.fasterxml.jackson.databind.SerializerProvider
import tools.jackson.core.JsonGenerator
import tools.jackson.databind.SerializationContext
import tools.jackson.databind.ValueSerializer
import java.time.Instant
import java.time.format.DateTimeFormatter
import java.time.format.DateTimeFormatterBuilder

class InstantSerializer : JsonSerializer<Instant>() {
class InstantSerializer : ValueSerializer<Instant>() {
private val dateTimeFormatter: DateTimeFormatter = DateTimeFormatterBuilder().appendInstant(3).toFormatter()

override fun serialize(
value: Instant?,
gen: JsonGenerator?,
serializers: SerializerProvider?
value: Instant,
gen: JsonGenerator,
ctxt: SerializationContext
) {
gen?.writeString(dateTimeFormatter.format(value))
gen.writeString(dateTimeFormatter.format(value))
}
}
Loading
Loading