Skip to content

Commit fa9dc39

Browse files
committed
* Oppdaterte ktlint slik at den er kompatibel med nyeste kotlin-versjon.
* Endret oppførsel til å være lik andre ef-repos ved at det ktlint autoformatterer koden i stedet for å bare validere. * Endret compile-task for å gå vekk fra kotlinOptions som er deprecated
1 parent fb40197 commit fa9dc39

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+238
-209
lines changed

build.gradle.kts

+18-34
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
23

34
val mockkVersion = "1.13.16"
45
val tokenSupportVersion = "5.0.16"
56
val springdocVersion = "1.8.0"
67
val navFoedselsnummerVersion = "1.0-SNAPSHOT.6"
78
val kontrakterVersion = "3.0_20250113155636_bb71360"
89
val mainClass = "no.nav.familie.ef.infotrygd.Main"
9-
val ktlint by configurations.creating
1010

1111
plugins {
1212
val kotlinVersion = "2.1.10"
@@ -17,6 +17,7 @@ plugins {
1717
kotlin("plugin.spring") version kotlinVersion
1818
kotlin("plugin.jpa") version kotlinVersion
1919
id("org.cyclonedx.bom") version "2.1.0"
20+
id("org.jlleitschuh.gradle.ktlint") version "12.1.2"
2021
}
2122

2223
group = "no.nav"
@@ -35,21 +36,14 @@ repositories {
3536
name = "Github"
3637
url = uri("https://maven.pkg.github.com/navikt/nav-foedselsnummer")
3738
credentials {
38-
username = "x-access-token" //project.findProperty("gpr.user") as String? ?: System.getenv("GPR_USER")
39+
username = "x-access-token" // project.findProperty("gpr.user") as String? ?: System.getenv("GPR_USER")
3940
password = System.getenv("GPR_API_KEY") ?: System.getenv("GITHUB_TOKEN") ?: project.findProperty("gpr.key") as String?
4041
}
4142
}
4243
}
4344

44-
4545
dependencies {
4646

47-
48-
ktlint("com.pinterest:ktlint:0.51.0-FINAL") {
49-
attributes {
50-
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
51-
}
52-
}
5347
implementation("nav-foedselsnummer:core:$navFoedselsnummerVersion")
5448
testImplementation("nav-foedselsnummer:testutils:$navFoedselsnummerVersion")
5549
implementation("org.springframework.boot:spring-boot-starter-actuator")
@@ -81,40 +75,31 @@ dependencies {
8175
testImplementation("com.h2database:h2")
8276
testImplementation("org.flywaydb:flyway-core")
8377
testImplementation("io.mockk:mockk-jvm:$mockkVersion")
84-
85-
8678
}
8779

8880
val inputFiles = project.fileTree(mapOf("dir" to "src", "include" to "**/*.kt"))
8981

90-
val ktlintCheck by tasks.creating(JavaExec::class) {
91-
inputs.files(inputFiles)
92-
// outputs.dir(outputDir)
82+
allprojects {
83+
apply(plugin = "org.jlleitschuh.gradle.ktlint")
84+
}
9385

94-
description = "Check Kotlin code style."
95-
classpath = ktlint
96-
mainClass.set("com.pinterest.ktlint.Main")
97-
args = listOf("src/**/*.kt")
86+
ktlint {
87+
version = "1.5.0"
9888
}
9989

100-
val ktlintFormat by tasks.creating(JavaExec::class) {
101-
inputs.files(inputFiles)
102-
// outputs.dir(outputDir)
90+
tasks.ktlintMainSourceSetCheck {
91+
enabled = false
92+
}
10393

104-
description = "Fix Kotlin code style deviations."
105-
classpath = ktlint
106-
mainClass.set("com.pinterest.ktlint.Main")
107-
args = listOf("-F", "src/**/*.kt")
108-
jvmArgs = listOf("--add-opens", "java.base/java.lang=ALL-UNNAMED")
94+
tasks.ktlintKotlinScriptCheck {
95+
enabled = false
10996
}
11097

111-
tasks.withType<KotlinCompile> {
112-
dependsOn("ktlintFormat")
113-
dependsOn("ktlintCheck")
114-
tasks.findByName("ktlintCheck")?.mustRunAfter("ktlintFormat")
115-
kotlinOptions {
98+
tasks.withType<KotlinJvmCompile> {
99+
dependsOn(tasks.ktlintFormat)
100+
compilerOptions {
116101
freeCompilerArgs = listOf("-Xjsr305=strict")
117-
jvmTarget = "21"
102+
jvmTarget.set(JvmTarget.JVM_21)
118103
}
119104
}
120105

@@ -130,4 +115,3 @@ tasks.test {
130115
tasks.cyclonedxBom {
131116
setIncludeConfigs(listOf("runtimeClasspath", "compileClasspath"))
132117
}
133-
// tasks.findByName('publish').mustRunAfter 'build'

settings.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ pluginManagement {
33
gradlePluginPortal()
44
}
55
}
6-
rootProject.name = "familie-ef-infotrygd"
6+
rootProject.name = "familie-ef-infotrygd"

src/main/kotlin/no/nav/familie/ef/infotrygd/SwaggerConfig.kt

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@ class SwaggerConfig {
1313
private val bearer = "Bearer"
1414

1515
@Bean
16-
fun openApi(): OpenAPI {
17-
return OpenAPI().info(Info().title("Familie ef infotrygd api"))
16+
fun openApi(): OpenAPI =
17+
OpenAPI()
18+
.info(Info().title("Familie ef infotrygd api"))
1819
.components(Components().addSecuritySchemes(bearer, bearerTokenSecurityScheme()))
1920
.addSecurityItem(SecurityRequirement().addList(bearer, listOf("read", "write")))
20-
}
2121

22-
private fun bearerTokenSecurityScheme(): SecurityScheme {
23-
return SecurityScheme()
22+
private fun bearerTokenSecurityScheme(): SecurityScheme =
23+
SecurityScheme()
2424
.type(SecurityScheme.Type.APIKEY)
2525
.scheme(bearer)
2626
.bearerFormat("JWT")
2727
.`in`(SecurityScheme.In.HEADER)
2828
.name("Authorization")
29-
}
3029
}

src/main/kotlin/no/nav/familie/ef/infotrygd/config/JacksonJsonConfig.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,5 @@ class JacksonJsonConfig {
2828
}
2929

3030
@Bean
31-
fun objectMapper(): ObjectMapper {
32-
return OM
33-
}
31+
fun objectMapper(): ObjectMapper = OM
3432
}

src/main/kotlin/no/nav/familie/ef/infotrygd/exception/UkjentDatabaseverdiException.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ package no.nav.familie.ef.infotrygd.exception
22

33
import java.lang.RuntimeException
44

5-
class UkjentDatabaseverdiException(val verdi: String, gyldigeVerdier: List<String>) :
6-
RuntimeException("Ukjent databaseverdi '$verdi'. Tillatte verdier er: ${gyldigeVerdier.joinToString()}")
5+
class UkjentDatabaseverdiException(
6+
val verdi: String,
7+
gyldigeVerdier: List<String>,
8+
) : RuntimeException("Ukjent databaseverdi '$verdi'. Tillatte verdier er: ${gyldigeVerdier.joinToString()}")

src/main/kotlin/no/nav/familie/ef/infotrygd/integration/TableIntegrator.kt

+7-5
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,16 @@ class TableIntegrator : Integrator {
4747
}
4848

4949
@Component
50-
class TableIntegratorProvider(private val tableIntegrator: TableIntegrator) : IntegratorProvider {
51-
override fun getIntegrators(): MutableList<Integrator> {
52-
return mutableListOf(tableIntegrator)
53-
}
50+
class TableIntegratorProvider(
51+
private val tableIntegrator: TableIntegrator,
52+
) : IntegratorProvider {
53+
override fun getIntegrators(): MutableList<Integrator> = mutableListOf(tableIntegrator)
5454
}
5555

5656
@Component
57-
class HibernateConfig(private val tableIntegratorProvider: TableIntegratorProvider) : HibernatePropertiesCustomizer {
57+
class HibernateConfig(
58+
private val tableIntegratorProvider: TableIntegratorProvider,
59+
) : HibernatePropertiesCustomizer {
5860
override fun customize(hibernateProperties: MutableMap<String, Any>) {
5961
hibernateProperties["hibernate.integrator_provider"] = tableIntegratorProvider
6062
}

src/main/kotlin/no/nav/familie/ef/infotrygd/model/StønadType.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ package no.nav.familie.ef.infotrygd.model
44
* @param kodeRutine Verdi fra kode_rutine fra v_vedtak
55
* @param saS10Valg Verdi fra s10_valg fra sa_sak_10
66
*/
7-
enum class StønadType(val kodeRutine: String, val saS10Valg: String) {
7+
enum class StønadType(
8+
val kodeRutine: String,
9+
val saS10Valg: String,
10+
) {
811
OVERGANGSSTØNAD("EO", "OG"),
912
BARNETILSYN("EB", "BT"),
1013
SKOLEPENGER("EU", "UT"),

src/main/kotlin/no/nav/familie/ef/infotrygd/model/converters/AbstractCharConverter.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package no.nav.familie.ef.infotrygd.model.converters
33
import jakarta.persistence.AttributeConverter
44
import jakarta.persistence.Converter
55

6-
abstract class AbstractCharConverter(private val size: Int) : AttributeConverter<String?, String?> {
6+
abstract class AbstractCharConverter(
7+
private val size: Int,
8+
) : AttributeConverter<String?, String?> {
79
override fun convertToDatabaseColumn(attribute: String?): String? {
810
val str = attribute ?: ""
911
return str.padEnd(size, ' ')

src/main/kotlin/no/nav/familie/ef/infotrygd/model/converters/AbstractNavLocalDateConverter.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import org.slf4j.LoggerFactory
55
import java.time.LocalDate
66
import java.time.format.DateTimeFormatter
77

8-
open class AbstractNavLocalDateConverter(datePattern: String) : AttributeConverter<LocalDate?, Int?> {
8+
open class AbstractNavLocalDateConverter(
9+
datePattern: String,
10+
) : AttributeConverter<LocalDate?, Int?> {
911
private val logger = LoggerFactory.getLogger(javaClass)
1012

1113
private val formatter = DateTimeFormatter.ofPattern(datePattern)
1214

13-
override fun convertToDatabaseColumn(attribute: LocalDate?): Int? {
14-
return attribute?.format(formatter)?.toInt()
15-
}
15+
override fun convertToDatabaseColumn(attribute: LocalDate?): Int? = attribute?.format(formatter)?.toInt()
1616

1717
override fun convertToEntityAttribute(dbData: Int?): LocalDate? {
1818
if (dbData == null || dbData == NULL_VALUE) {

src/main/kotlin/no/nav/familie/ef/infotrygd/model/converters/FoedselNrConverter.kt

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import jakarta.persistence.AttributeConverter
44
import no.nav.commons.foedselsnummer.FoedselsNr
55

66
class FoedselNrConverter : AttributeConverter<FoedselsNr?, String?> {
7-
override fun convertToDatabaseColumn(attribute: FoedselsNr?): String? {
8-
return attribute?.asString
9-
}
7+
override fun convertToDatabaseColumn(attribute: FoedselsNr?): String? = attribute?.asString
108

11-
override fun convertToEntityAttribute(dbData: String?): FoedselsNr? {
12-
return dbData?.let { FoedselsNr(it) }
13-
}
9+
override fun convertToEntityAttribute(dbData: String?): FoedselsNr? = dbData?.let { FoedselsNr(it) }
1410
}

src/main/kotlin/no/nav/familie/ef/infotrygd/model/converters/NavCharDateConverter.kt

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import java.time.LocalDate
88
class NavCharDateConverter : AttributeConverter<LocalDate?, String?> {
99
private val converter = NavLocalDateConverter()
1010

11-
override fun convertToDatabaseColumn(attribute: LocalDate?): String? {
12-
return converter.convertToDatabaseColumn(attribute)?.toString()
13-
}
11+
override fun convertToDatabaseColumn(attribute: LocalDate?): String? = converter.convertToDatabaseColumn(attribute)?.toString()
1412

15-
override fun convertToEntityAttribute(dbData: String?): LocalDate? {
16-
return dbData?.let { converter.convertToEntityAttribute(it.toInt()) }
17-
}
13+
override fun convertToEntityAttribute(dbData: String?): LocalDate? = dbData?.let { converter.convertToEntityAttribute(it.toInt()) }
1814
}

src/main/kotlin/no/nav/familie/ef/infotrygd/model/converters/ReversedFoedselNrConverter.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import jakarta.persistence.AttributeConverter
44
import no.nav.familie.ef.infotrygd.utils.reverserFnr
55

66
class ReversedFoedselNrConverter : AttributeConverter<String?, String?> {
7-
override fun convertToDatabaseColumn(attribute: String?): String? {
8-
return attribute?.reverserFnr() ?: "00000000000"
9-
}
7+
override fun convertToDatabaseColumn(attribute: String?): String? = attribute?.reverserFnr() ?: "00000000000"
108

119
override fun convertToEntityAttribute(dbData: String?): String? {
1210
if (dbData == null) {

src/main/kotlin/no/nav/familie/ef/infotrygd/model/converters/ReversedLongFoedselNrConverter.kt

+3-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import jakarta.persistence.AttributeConverter
55
class ReversedLongFoedselNrConverter : AttributeConverter<String?, Long?> {
66
private val converter = ReversedFoedselNrConverter()
77

8-
override fun convertToDatabaseColumn(attribute: String?): Long? {
9-
return converter.convertToDatabaseColumn(attribute)?.toLong() ?: 0
10-
}
8+
override fun convertToDatabaseColumn(attribute: String?): Long? = converter.convertToDatabaseColumn(attribute)?.toLong() ?: 0
119

12-
override fun convertToEntityAttribute(dbData: Long?): String? {
13-
return converter.convertToEntityAttribute(dbData?.toString()?.padStart(11, '0'))
14-
}
10+
override fun convertToEntityAttribute(dbData: Long?): String? =
11+
converter.convertToEntityAttribute(dbData?.toString()?.padStart(11, '0'))
1512
}

src/main/kotlin/no/nav/familie/ef/infotrygd/repository/InfotrygdRepository.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import org.springframework.stereotype.Repository
77
import java.time.LocalDate
88

99
@Repository
10-
class InfotrygdRepository(private val jdbcTemplate: NamedParameterJdbcTemplate) {
10+
class InfotrygdRepository(
11+
private val jdbcTemplate: NamedParameterJdbcTemplate,
12+
) {
1113
fun harAktivStønad(personIdenter: Set<String>) = harStønad(personIdenter, kunAktive = true)
1214

1315
fun harStønad(

src/main/kotlin/no/nav/familie/ef/infotrygd/repository/PeriodeRepository.kt

+12-10
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import java.time.YearMonth
2525
* UA: Uavklart
2626
*/
2727
@Repository
28-
class PeriodeRepository(private val jdbcTemplate: NamedParameterJdbcTemplate) {
28+
class PeriodeRepository(
29+
private val jdbcTemplate: NamedParameterJdbcTemplate,
30+
) {
2931
fun hentPerioder(request: PeriodeRequest): List<Pair<StønadType, Periode>> {
3032
val values =
3133
MapSqlParameterSource()
@@ -170,13 +172,13 @@ class PeriodeRepository(private val jdbcTemplate: NamedParameterJdbcTemplate) {
170172
.takeIf(String::isNotEmpty)
171173
?.let(mapper)
172174

173-
private fun mapStønadskoder(request: PeriodeRequest): List<String> {
174-
return request.stønadstyper.ifEmpty {
175-
setOf(
176-
StønadType.OVERGANGSSTØNAD,
177-
StønadType.SKOLEPENGER,
178-
StønadType.BARNETILSYN,
179-
)
180-
}.map { it.kodeRutine }
181-
}
175+
private fun mapStønadskoder(request: PeriodeRequest): List<String> =
176+
request.stønadstyper
177+
.ifEmpty {
178+
setOf(
179+
StønadType.OVERGANGSSTØNAD,
180+
StønadType.SKOLEPENGER,
181+
StønadType.BARNETILSYN,
182+
)
183+
}.map { it.kodeRutine }
182184
}

src/main/kotlin/no/nav/familie/ef/infotrygd/repository/SakRepository.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ import org.springframework.jdbc.core.namedparam.MapSqlParameterSource
1313
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
1414
import org.springframework.stereotype.Repository
1515

16-
data class ÅpnesakerRapport(val typeMedAntall: Map<String, Int>)
16+
data class ÅpnesakerRapport(
17+
val typeMedAntall: Map<String, Int>,
18+
)
1719

1820
@Repository
19-
class SakRepository(private val jdbcTemplate: NamedParameterJdbcTemplate) {
21+
class SakRepository(
22+
private val jdbcTemplate: NamedParameterJdbcTemplate,
23+
) {
2024
private val datoConverter = NavReversedLocalDateConverter()
2125

2226
fun hentÅpneSaker(): ÅpnesakerRapport {

src/main/kotlin/no/nav/familie/ef/infotrygd/rest/ApiExceptionHandler.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ class ApiExceptionHandler : ResponseEntityExceptionHandler() {
2121
private val logger = LoggerFactory.getLogger(ApiExceptionHandler::class.java)
2222
private val secureLogger = LoggerFactory.getLogger("secureLogger")
2323

24-
private fun rootCause(throwable: Throwable): Throwable {
25-
return NestedExceptionUtils.getMostSpecificCause(throwable)
26-
}
24+
private fun rootCause(throwable: Throwable): Throwable = NestedExceptionUtils.getMostSpecificCause(throwable)
2725

2826
override fun handleExceptionInternal(
2927
ex: Exception,
@@ -90,5 +88,7 @@ class ApiExceptionHandler : ResponseEntityExceptionHandler() {
9088
}
9189
}
9290

93-
data class ErrorResponse(val errorMessage: String)
91+
data class ErrorResponse(
92+
val errorMessage: String,
93+
)
9494
}

src/main/kotlin/no/nav/familie/ef/infotrygd/rest/api/InfotrygdFinnesResponse.kt

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ data class InfotrygdFinnesResponse(
77
val saker: List<Saktreff>,
88
)
99

10-
data class Vedtakstreff(val personIdent: String, val stønadType: StønadType, val harLøpendeVedtak: Boolean)
10+
data class Vedtakstreff(
11+
val personIdent: String,
12+
val stønadType: StønadType,
13+
val harLøpendeVedtak: Boolean,
14+
)
1115

12-
data class Saktreff(val personIdent: String, val stønadType: StønadType)
16+
data class Saktreff(
17+
val personIdent: String,
18+
val stønadType: StønadType,
19+
)

0 commit comments

Comments
 (0)