Skip to content

Commit

Permalink
Merge pull request #473 from navikt/jpa
Browse files Browse the repository at this point in the history
Rewrite to JPA and refactor.
  • Loading branch information
flexable777 authored Feb 16, 2024
2 parents 25a4e2c + ea2b855 commit 9f808b5
Show file tree
Hide file tree
Showing 58 changed files with 1,865 additions and 1,921 deletions.
21 changes: 15 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val exposedVersion = "0.45.0"
val mockkVersion = "1.13.8"
val h2Version = "2.2.224"
val pamGeographyVersion = "2.9"
val tokenValidationVersion = "1.3.0"
Expand All @@ -14,9 +13,12 @@ val resilience4jVersion = "2.2.0"
val problemSpringWebStartVersion = "0.27.0"
val shedlockVersion = "5.10.2"
val springDocVersion = "2.3.0"
val kodeverkVersion = "1.5.5"
val kodeverkVersion = "1.7.28"
val simpleSlackPosterVersion = "0.1.4"
val mockitoInlineVersion = "5.2.0"
val testContainersVersion = "1.19.3"
val mockkVersion = "1.13.8"
val springMockkVersion = "4.0.2"

val githubUser: String by project
val githubPassword: String by project
Expand All @@ -33,6 +35,7 @@ plugins {
id("org.jetbrains.kotlin.jvm") version kotlinVersion
id("org.springframework.boot") version "3.2.1"
id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
kotlin("plugin.jpa") version kotlinVersion
idea
}

Expand All @@ -45,6 +48,7 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")

implementation("io.micrometer:micrometer-registry-prometheus")
implementation("io.micrometer:micrometer-tracing-bridge-brave")
Expand All @@ -53,8 +57,6 @@ dependencies {

implementation("org.flywaydb:flyway-core")
implementation("com.zaxxer:HikariCP")
implementation("org.jetbrains.exposed:exposed-spring-boot-starter:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-java-time:$exposedVersion")
implementation("org.postgresql:postgresql")

implementation("io.github.resilience4j:resilience4j-retry:$resilience4jVersion")
Expand Down Expand Up @@ -84,12 +86,19 @@ dependencies {

implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:$springDocVersion")

testImplementation("io.mockk:mockk:$mockkVersion")
testImplementation("org.testcontainers:testcontainers:$testContainersVersion")
testImplementation("org.testcontainers:junit-jupiter:$testContainersVersion")
testImplementation("org.testcontainers:postgresql:$testContainersVersion")

testImplementation("com.h2database:h2:$h2Version")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage")
exclude(group = "org.mockito")
}
testImplementation("org.mockito:mockito-inline:$mockitoInlineVersion")

testImplementation("io.mockk:mockk:$mockkVersion")
testImplementation("com.ninja-squad:springmockk:$springMockkVersion")

testImplementation("no.nav.security:token-validation-spring-test:$tokenSupportVersion")
}

Expand Down
4 changes: 3 additions & 1 deletion deploy/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ kafka_pool: nav-dev

db_tier: db-f1-micro
db_type: POSTGRES_15
db_high_availability: false
db_high_availability: false

max_replicas: 2
2 changes: 1 addition & 1 deletion deploy/nais.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
memory: 2048Mi
replicas:
min: 2
max: 4
max: {{max_replicas}}
cpuThresholdPercentage: 80
prometheus:
enabled: true
Expand Down
4 changes: 3 additions & 1 deletion deploy/prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ kafka_pool: nav-prod

db_tier: db-custom-1-3840
db_type: POSTGRES_15
db_high_availability: true
db_high_availability: true

max_replicas: 4
13 changes: 1 addition & 12 deletions src/main/kotlin/no/nav/klage/Application.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
package no.nav.klage

import no.nav.security.token.support.client.spring.oauth2.EnableOAuth2Client
import no.nav.security.token.support.spring.api.EnableJwtTokenValidation
import org.jetbrains.exposed.spring.autoconfigure.ExposedAutoConfiguration
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Import
import org.springframework.scheduling.annotation.EnableScheduling

@SpringBootApplication(exclude = [DataSourceTransactionManagerAutoConfiguration::class])
@EnableJwtTokenValidation(ignore = ["org.springdoc", "org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController"])
@EnableOAuth2Client(cacheEnabled = true)
@Import(value = [ExposedAutoConfiguration::class])
@EnableScheduling
@SpringBootApplication
class Application

//TODO: EnableOAuth er nødvendig for ny, sjekk om kompatibelt med gammel.
fun main() {
runApplication<Application>()
}
12 changes: 6 additions & 6 deletions src/main/kotlin/no/nav/klage/clients/KlageDittnavPdfgenClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ class KlageDittnavPdfgenClient(
private val logger = getLogger(javaClass.enclosingClass)
}

fun getKlagePDF(input: PDFInput): ByteArray {
logger.debug("Creating PDF from klage.")
fun getKlageAnkePDF(input: PDFInput): ByteArray {
logger.debug("Creating PDF for ${input.type}.")
return klageDittnavPdfgenWebClient.post()
.uri { it.path("/klage").build() }
.uri { it.path("/klageanke").build() }
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(input)
.retrieve()
.bodyToMono<ByteArray>()
.block() ?: throw RuntimeException("PDF could not be generated")
}

fun getAnkePDF(input: PDFInput): ByteArray {
logger.debug("Creating PDF from anke.")
fun getEttersendelsePDF(input: PDFInput): ByteArray {
logger.debug("Creating PDF for ettersendelse for ${input.type}")
return klageDittnavPdfgenWebClient.post()
.uri { it.path("/anke").build() }
.uri { it.path("/ettersendelse").build() }
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(input)
.retrieve()
Expand Down
12 changes: 2 additions & 10 deletions src/main/kotlin/no/nav/klage/common/KlageAnkeMetrics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import no.nav.klage.domain.klage.CheckboxEnum
import no.nav.klage.domain.titles.Innsendingsytelse
import no.nav.klage.util.getLogger
import org.springframework.stereotype.Component

@Component
class KlageAnkeMetrics(private val meterRegistry: MeterRegistry) {

Expand All @@ -15,7 +16,6 @@ class KlageAnkeMetrics(private val meterRegistry: MeterRegistry) {
private const val COUNTER_KLAGER_FINALIZED = "klager_finalized"
private const val COUNTER_KLAGER_INITIALIZED = "klager_initialized"
private const val COUNTER_KLAGER_FINALIZED_GRUNN = "klager_finalized_grunn"
private const val COUNTER_KLAGER_FINALIZED_FULLMAKT = "klager_finalized_fullmakt"
private const val COUNTER_KLAGER_OPTIONAL_SAKSNUMMER = "klager_optional_saksnummer"
private const val COUNTER_KLAGER_OPTIONAL_VEDTAKSDATO = "klager_optional_vedtaksdato"
private const val COUNTER_KLAGER_FINALIZED_TITLE = "klager_finalized_title"
Expand All @@ -40,7 +40,7 @@ class KlageAnkeMetrics(private val meterRegistry: MeterRegistry) {
}
}

fun incrementKlagerGrunn(ytelse: String, checkboxesSelected: Set<CheckboxEnum>) {
fun incrementKlagerGrunn(ytelse: String, checkboxesSelected: List<CheckboxEnum>) {
try {
checkboxesSelected.forEach {
meterRegistry.counter(COUNTER_KLAGER_FINALIZED_GRUNN, "ytelse", ytelse, "grunn", it.name).increment()
Expand All @@ -50,14 +50,6 @@ class KlageAnkeMetrics(private val meterRegistry: MeterRegistry) {
}
}

fun incrementFullmakt(ytelse: String) {
try {
meterRegistry.counter(COUNTER_KLAGER_FINALIZED_FULLMAKT, "ytelse", ytelse).increment()
} catch (e: Exception) {
logger.warn("incrementFullmakt failed", e)
}
}

fun incrementOptionalSaksnummer(ytelse: String) {
try {
meterRegistry.counter(COUNTER_KLAGER_OPTIONAL_SAKSNUMMER, "ytelse", ytelse).increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.jdbc.core.JdbcTemplate
import org.springframework.scheduling.annotation.EnableAsync
import org.springframework.scheduling.annotation.EnableScheduling
import javax.sql.DataSource


@Configuration
@EnableSchedulerLock(defaultLockAtMostFor = "10m")
@EnableAsync
@EnableScheduling
class SchedulingConfiguration {

@Bean
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/no/nav/klage/config/SecurityConfiguration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package no.nav.klage.config

import no.nav.security.token.support.client.spring.oauth2.EnableOAuth2Client
import no.nav.security.token.support.spring.api.EnableJwtTokenValidation
import org.springframework.context.annotation.Configuration

@EnableJwtTokenValidation(ignore = ["org.springdoc", "org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController"])
@EnableOAuth2Client(cacheEnabled = true)
@Configuration
internal class SecurityConfiguration {

}
Loading

0 comments on commit 9f808b5

Please sign in to comment.