Skip to content

Commit

Permalink
Ktlint 1.3.0 (#5099)
Browse files Browse the repository at this point in the history
* Bump gradle to 8.8

* ktlint 1.3.0

* Update jar
  • Loading branch information
chrissearle authored Jun 11, 2024
1 parent 796d5c1 commit 900ad3d
Show file tree
Hide file tree
Showing 625 changed files with 9,581 additions and 7,322 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ root = true
[*.{kt,kts}]
ktlint_code_style = ktlint_official
ktlint_standard_if-else-wrapping = disabled
ktlint_standard_discouraged-comment-location = disabled # Vi har mange kommentarer i discouraged location per nå. Se jira for teknisk-gjeld task for å fjerne denne
ktlint_standard_discouraged-comment-location = disabled # Vi har mange kommentarer i discouraged location per nå. Se jira for teknisk-gjeld task for å fjerne denne
4 changes: 3 additions & 1 deletion apps/etterlatte-behandling/src/main/kotlin/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ fun main() {
Server(ApplicationContext()).run()
}

private class Server(private val context: ApplicationContext) {
private class Server(
private val context: ApplicationContext,
) {
init {
sikkerLoggOppstartOgAvslutning("etterlatte-behandling")
}
Expand Down
32 changes: 17 additions & 15 deletions apps/etterlatte-behandling/src/main/kotlin/Contekst.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,32 @@ class Context(
val databasecontxt: DatabaseKontekst,
val sakTilgangDao: SakTilgangDao,
) {
fun appUserAsSaksbehandler(): SaksbehandlerMedEnheterOgRoller {
return this.AppUser as SaksbehandlerMedEnheterOgRoller
}
fun appUserAsSaksbehandler(): SaksbehandlerMedEnheterOgRoller = this.AppUser as SaksbehandlerMedEnheterOgRoller
}

interface User {
fun name(): String
}

abstract class ExternalUser(val identifiedBy: TokenValidationContext) : User
abstract class ExternalUser(
val identifiedBy: TokenValidationContext,
) : User

class Self(private val prosess: String) : User {
class Self(
private val prosess: String,
) : User {
override fun name() = prosess
}

class SystemUser(identifiedBy: TokenValidationContext, val brukerTokenInfo: BrukerTokenInfo) : ExternalUser(identifiedBy) {
override fun name(): String {
return identifiedBy.hentTokenClaims(AZURE_ISSUER)
class SystemUser(
identifiedBy: TokenValidationContext,
val brukerTokenInfo: BrukerTokenInfo,
) : ExternalUser(identifiedBy) {
override fun name(): String =
identifiedBy
.hentTokenClaims(AZURE_ISSUER)
?.getStringClaim("azp_name") // format=cluster:namespace:app-name
?: throw IllegalArgumentException("Støtter ikke navn på systembruker")
}
}

class SaksbehandlerMedEnheterOgRoller(
Expand All @@ -56,9 +61,7 @@ class SaksbehandlerMedEnheterOgRoller(
private fun saksbehandlersEnheter() =
saksbehandlerService.hentEnheterForSaksbehandlerIdentWrapper(name()).map { it.enhetsNummer }.toSet()

override fun name(): String {
return identifiedBy.hentTokenClaims(AZURE_ISSUER)!!.getStringClaim("NAVident")
}
override fun name(): String = identifiedBy.hentTokenClaims(AZURE_ISSUER)!!.getStringClaim("NAVident")

private fun harKjentEnhet(saksbehandlersEnheter: Set<String>) = Enheter.kjenteEnheter().intersect(saksbehandlersEnheter).isNotEmpty()

Expand Down Expand Up @@ -97,8 +100,8 @@ fun decideUser(
saksbehandlerGroupIdsByKey: Map<AzureGroup, String>,
saksbehandlerService: SaksbehandlerService,
brukerTokenInfo: BrukerTokenInfo,
): ExternalUser {
return if (principal.context.issuers.contains(AZURE_ISSUER)) {
): ExternalUser =
if (principal.context.issuers.contains(AZURE_ISSUER)) {
if (brukerTokenInfo is Systembruker) {
SystemUser(principal.context, brukerTokenInfo)
} else {
Expand All @@ -112,7 +115,6 @@ fun decideUser(
} else {
throw IllegalStateException("no token from preapproved issuers")
}
}

interface DatabaseKontekst {
fun activeTx(): Connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class BehandlingDao(
INNER JOIN sak s ON b.sak_id = s.id
""".trimIndent()

fun hentBehandling(id: UUID): Behandling? {
return connectionAutoclosing.hentConnection {
fun hentBehandling(id: UUID): Behandling? =
connectionAutoclosing.hentConnection {
with(it) {
val stmt =
prepareStatement(
Expand All @@ -69,10 +69,9 @@ class BehandlingDao(
}
}
}
}

fun alleBehandlingerISak(sakid: Long): List<Behandling> {
return connectionAutoclosing.hentConnection {
fun alleBehandlingerISak(sakid: Long): List<Behandling> =
connectionAutoclosing.hentConnection {
with(it) {
val stmt =
prepareStatement(
Expand All @@ -86,13 +85,12 @@ class BehandlingDao(
stmt.executeQuery().behandlingsListe()
}
}
}

fun hentAlleRevurderingerISakMedAarsak(
sakid: Long,
revurderingaarsak: Revurderingaarsak,
): List<Revurdering> {
return connectionAutoclosing.hentConnection {
): List<Revurdering> =
connectionAutoclosing.hentConnection {
with(it) {
val stmt =
prepareStatement(
Expand All @@ -110,10 +108,9 @@ class BehandlingDao(
stmt.executeQuery().toListPassesRsToBlock { rs -> asRevurdering(rs) }
}
}
}

fun migrerStatusPaaAlleBehandlingerSomTrengerNyBeregning(saker: Saker): List<BehandlingOgSak> {
return connectionAutoclosing.hentConnection { connection ->
fun migrerStatusPaaAlleBehandlingerSomTrengerNyBeregning(saker: Saker): List<BehandlingOgSak> =
connectionAutoclosing.hentConnection { connection ->
with(connection) {
val stmt =
prepareStatement(
Expand All @@ -131,10 +128,9 @@ class BehandlingDao(
stmt.executeQuery().toList { BehandlingOgSak(getUUID("id"), getLong("sak_id")) }
}
}
}

fun hentAapneBehandlinger(saker: Saker): List<BehandlingOgSak> {
return connectionAutoclosing.hentConnection { connection ->
fun hentAapneBehandlinger(saker: Saker): List<BehandlingOgSak> =
connectionAutoclosing.hentConnection { connection ->
with(connection) {
val stmt =
prepareStatement(
Expand All @@ -150,7 +146,6 @@ class BehandlingDao(
stmt.executeQuery().toList { BehandlingOgSak(getUUID("id"), getLong("sak_id")) }
}
}
}

private fun asFoerstegangsbehandling(rs: ResultSet): Foerstegangsbehandling {
val id = rs.getUUID("id")
Expand All @@ -164,10 +159,12 @@ class BehandlingDao(
status = rs.getString("status").let { BehandlingStatus.valueOf(it) },
virkningstidspunkt = rs.getString("virkningstidspunkt")?.let { objectMapper.readValue(it) },
utlandstilknytning =
rs.getString("utlandstilknytning")
rs
.getString("utlandstilknytning")
?.let { objectMapper.readValue(it) },
boddEllerArbeidetUtlandet =
rs.getString("bodd_eller_arbeidet_utlandet")
rs
.getString("bodd_eller_arbeidet_utlandet")
?.let { objectMapper.readValue(it) },
kommerBarnetTilgode = kommerBarnetTilGodeDao.hentKommerBarnetTilGode(id),
prosesstype = rs.getString("prosesstype").let { Prosesstype.valueOf(it) },
Expand All @@ -190,8 +187,8 @@ class BehandlingDao(
enhet = rs.getString("enhet"),
)

fun opprettBehandling(behandling: OpprettBehandling) {
return connectionAutoclosing.hentConnection {
fun opprettBehandling(behandling: OpprettBehandling) =
connectionAutoclosing.hentConnection {
with(it) {
val stmt =
prepareStatement(
Expand Down Expand Up @@ -227,10 +224,9 @@ class BehandlingDao(
require(stmt.executeUpdate() == 1)
}
}
}

fun lagreGyldighetsproving(behandling: Foerstegangsbehandling) {
return connectionAutoclosing.hentConnection {
fun lagreGyldighetsproving(behandling: Foerstegangsbehandling) =
connectionAutoclosing.hentConnection {
with(it) {
val stmt =
prepareStatement(
Expand All @@ -247,7 +243,6 @@ class BehandlingDao(
require(stmt.executeUpdate() == 1)
}
}
}

fun lagreStatus(lagretBehandling: Behandling) {
lagreStatus(lagretBehandling.id, lagretBehandling.status, lagretBehandling.sistEndret)
Expand All @@ -257,45 +252,39 @@ class BehandlingDao(
behandlingId: UUID,
status: BehandlingStatus,
sistEndret: LocalDateTime,
) {
return connectionAutoclosing.hentConnection {
with(it) {
val stmt = prepareStatement("UPDATE behandling SET status = ?, sist_endret = ? WHERE id = ?")
) = connectionAutoclosing.hentConnection {
with(it) {
val stmt = prepareStatement("UPDATE behandling SET status = ?, sist_endret = ? WHERE id = ?")

stmt.setString(1, status.name)
stmt.setTidspunkt(2, sistEndret.toTidspunkt())
stmt.setObject(3, behandlingId)
require(stmt.executeUpdate() == 1)
}
stmt.setString(1, status.name)
stmt.setTidspunkt(2, sistEndret.toTidspunkt())
stmt.setObject(3, behandlingId)
require(stmt.executeUpdate() == 1)
}
}

fun lagreBoddEllerArbeidetUtlandet(
behandlingId: UUID,
boddEllerArbeidetUtlandet: BoddEllerArbeidetUtlandet,
) {
return connectionAutoclosing.hentConnection {
with(it) {
val stmt = prepareStatement("UPDATE behandling SET bodd_eller_arbeidet_utlandet = ? WHERE id = ?")
) = connectionAutoclosing.hentConnection {
with(it) {
val stmt = prepareStatement("UPDATE behandling SET bodd_eller_arbeidet_utlandet = ? WHERE id = ?")

stmt.setString(1, objectMapper.writeValueAsString(boddEllerArbeidetUtlandet))
stmt.setObject(2, behandlingId)
require(stmt.executeUpdate() == 1)
}
stmt.setString(1, objectMapper.writeValueAsString(boddEllerArbeidetUtlandet))
stmt.setObject(2, behandlingId)
require(stmt.executeUpdate() == 1)
}
}

fun lagreUtlandstilknytning(
behandlingId: UUID,
utlandstilknytning: Utlandstilknytning,
) {
return connectionAutoclosing.hentConnection {
with(it) {
val statement = prepareStatement("UPDATE behandling set utlandstilknytning = ? where id = ?")
statement.setJsonb(1, utlandstilknytning)
statement.setObject(2, behandlingId)
require(statement.executeUpdate() == 1)
}
) = connectionAutoclosing.hentConnection {
with(it) {
val statement = prepareStatement("UPDATE behandling set utlandstilknytning = ? where id = ?")
statement.setJsonb(1, utlandstilknytning)
statement.setObject(2, behandlingId)
require(statement.executeUpdate() == 1)
}
}

Expand Down Expand Up @@ -332,14 +321,12 @@ class BehandlingDao(
fun lagreNyttVirkningstidspunkt(
behandlingId: UUID,
virkningstidspunkt: Virkningstidspunkt,
) {
return connectionAutoclosing.hentConnection {
with(it) {
val statement = prepareStatement("UPDATE behandling SET virkningstidspunkt = ? where id = ?")
statement.setString(1, objectMapper.writeValueAsString(virkningstidspunkt))
statement.setObject(2, behandlingId)
statement.executeUpdate()
}
) = connectionAutoclosing.hentConnection {
with(it) {
val statement = prepareStatement("UPDATE behandling SET virkningstidspunkt = ? where id = ?")
statement.setString(1, objectMapper.writeValueAsString(virkningstidspunkt))
statement.setObject(2, behandlingId)
statement.executeUpdate()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,15 @@ class BehandlingFactory(
request = hentDataForOpprettBehandling(sak.id),
).also {
if (request.kilde == Vedtaksloesning.GJENOPPRETTA) {
oppgaveService.hentOppgaverForSak(sak.id)
.find { it.type == OppgaveType.GJENOPPRETTING_ALDERSOVERGANG && !it.erAvsluttet() }?.let {
oppgaveService
.hentOppgaverForSak(sak.id)
.find { it.type == OppgaveType.GJENOPPRETTING_ALDERSOVERGANG && !it.erAvsluttet() }
?.let {
oppgaveService.ferdigstillOppgave(it.id, brukerTokenInfo)
}
}
} ?: throw IllegalStateException("Kunne ikke opprette behandling")
}
.also { it.sendMeldingForHendelse() }
}.also { it.sendMeldingForHendelse() }
.behandling

val gyldighetsvurdering =
Expand Down Expand Up @@ -175,14 +176,16 @@ class BehandlingFactory(
throw ManuellMigreringHarEksisterendeIverksattBehandling()
}
val forrigeBehandling = request.iverksatteEllerAttesterteBehandlinger.maxBy { it.behandlingOpprettet }
revurderingService.opprettAutomatiskRevurdering(
sakId = sakId,
persongalleri = persongalleri,
forrigeBehandling = forrigeBehandling,
mottattDato = mottattDato,
kilde = kilde,
revurderingAarsak = Revurderingaarsak.NY_SOEKNAD,
).oppdater().let { BehandlingOgOppgave(it, null) }
revurderingService
.opprettAutomatiskRevurdering(
sakId = sakId,
persongalleri = persongalleri,
forrigeBehandling = forrigeBehandling,
mottattDato = mottattDato,
kilde = kilde,
revurderingAarsak = Revurderingaarsak.NY_SOEKNAD,
).oppdater()
.let { BehandlingOgOppgave(it, null) }
} else {
val harBehandlingUnderbehandling =
request.alleBehandlingerISak.filter { behandling ->
Expand Down Expand Up @@ -269,17 +272,23 @@ class BehandlingFactory(
}
}

data class BehandlingOgOppgave(val behandling: Behandling, val oppgave: OppgaveIntern?, val sendMeldingForHendelse: () -> Unit = {})

class ManuellMigreringHarEksisterendeIverksattBehandling : UgyldigForespoerselException(
code = "MANUELL_MIGRERING_EKSISTERENDE_IVERKSATT",
detail = "Det eksisterer allerede en sak med en iverksatt behandling for angitt søker",
data class BehandlingOgOppgave(
val behandling: Behandling,
val oppgave: OppgaveIntern?,
val sendMeldingForHendelse: () -> Unit = {},
)

class UgyldigEnhetException : UgyldigForespoerselException(
code = "UGYLDIG-ENHET",
detail = "Enhet brukt i form er matcher ingen gyldig enhet",
)
class ManuellMigreringHarEksisterendeIverksattBehandling :
UgyldigForespoerselException(
code = "MANUELL_MIGRERING_EKSISTERENDE_IVERKSATT",
detail = "Det eksisterer allerede en sak med en iverksatt behandling for angitt søker",
)

class UgyldigEnhetException :
UgyldigForespoerselException(
code = "UGYLDIG-ENHET",
detail = "Enhet brukt i form er matcher ingen gyldig enhet",
)

fun Vedtaksloesning.foerstOpprettaIPesys() = this == Vedtaksloesning.PESYS || this == Vedtaksloesning.GJENOPPRETTA

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import no.nav.etterlatte.libs.sporingslogg.HttpMethod
import no.nav.etterlatte.libs.sporingslogg.Sporingslogg
import no.nav.etterlatte.libs.sporingslogg.Sporingsrequest

class BehandlingRequestLogger(private val sporingslogg: Sporingslogg) {
class BehandlingRequestLogger(
private val sporingslogg: Sporingslogg,
) {
fun loggRequest(
brukerTokenInfo: BrukerTokenInfo,
fnr: Folkeregisteridentifikator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@ internal fun Route.behandlingRoutes(
Vedtaksloesning.GJENNY,
request = request,
)
}
?.also { it.sendMeldingForHendelse() }
}?.also { it.sendMeldingForHendelse() }
?.behandling
) {
null -> call.respond(HttpStatusCode.NotFound)
Expand Down
Loading

0 comments on commit 900ad3d

Please sign in to comment.