Skip to content

Commit

Permalink
Merge branch 'master' into utsatt-oppgave-normal-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
bjerga committed Dec 17, 2024
2 parents 19b3e19 + 6698663 commit f6125b9
Show file tree
Hide file tree
Showing 57 changed files with 423 additions and 363 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ktlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
- name: "Install ktlint"
uses: nbadal/action-ktlint-setup@v1
with:
ktlint_version: '1.2.1'
ktlint_version: '1.5.0'
- run: ktlint
shell: bash
6 changes: 5 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ tasks.jar {
}
doLast {
configurations.runtimeClasspath.get().forEach {
val file = layout.buildDirectory.file("libs/${it.name}").get().asFile
val file =
layout.buildDirectory
.file("libs/${it.name}")
.get()
.asFile
if (!file.exists()) {
it.copyTo(file)
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kotlin.code.style=official

# Plugin versions
kotlinVersion=2.0.21
kotlinterVersion=4.3.0
kotlinterVersion=5.0.1
versionsVersion=0.50.0

# Dependency versions
Expand Down
8 changes: 6 additions & 2 deletions src/main/kotlin/no/nav/syfo/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import org.koin.core.context.stopKoin
import org.slf4j.Logger
import kotlin.concurrent.thread

class SpinnApplication(val port: Int = 8080) : KoinComponent {
class SpinnApplication(
val port: Int = 8080,
) : KoinComponent {
private val logger: Logger = this.logger()
private var webserver: NettyApplicationEngine? = null
private var appConfig: HoconApplicationConfig = HoconApplicationConfig(ConfigFactory.load())
Expand Down Expand Up @@ -127,7 +129,9 @@ class SpinnApplication(val port: Int = 8080) : KoinComponent {
private fun migrateDatabase() {
logger.info("Starter databasemigrering")

Flyway.configure().baselineOnMigrate(true)
Flyway
.configure()
.baselineOnMigrate(true)
.dataSource(GlobalContext.getKoinApplicationOrNull()?.koin?.get())
.load()
.migrate()
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/no/nav/syfo/Metrikker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class MetrikkVarsler : Bakgrunnsvarsler {
}

val FEILET_JOBB_COUNTER =
Counter.build()
Counter
.build()
.namespace(METRICS_NS)
.name("feilet_jobb")
.help("Counts the number of permanently failed jobs")
Expand Down
42 changes: 32 additions & 10 deletions src/main/kotlin/no/nav/syfo/behandling/BehandlingException.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
package no.nav.syfo.behandling

open class BehandlingException(val feiltype: Feiltype, message: String, cause: Exception?) : RuntimeException(message, cause)
open class BehandlingException(
val feiltype: Feiltype,
message: String,
cause: Exception?,
) : RuntimeException(message, cause)

// AktorClient
open class AktørException(feiltype: Feiltype, message: String, causedBy: Exception?) : BehandlingException(feiltype, message, causedBy)
open class AktørException(
feiltype: Feiltype,
message: String,
causedBy: Exception?,
) : BehandlingException(feiltype, message, causedBy)

open class FantIkkeAktørException(causedBy: java.lang.Exception?) : AktørException(
Feiltype.AKTØR_IKKE_FUNNET,
"Fant ikke aktørId",
causedBy,
)
open class FantIkkeAktørException(
causedBy: java.lang.Exception?,
) : AktørException(
Feiltype.AKTØR_IKKE_FUNNET,
"Fant ikke aktørId",
causedBy,
)

// OppgaveClient
open class OppgaveException(feiltype: Feiltype, message: String, causedBy: Exception?) : BehandlingException(feiltype, message, causedBy)
open class OppgaveException(
feiltype: Feiltype,
message: String,
causedBy: Exception?,
) : BehandlingException(feiltype, message, causedBy)

open class HentOppgaveException(
journalpostId: String,
Expand All @@ -35,7 +49,11 @@ open class OpprettFordelingsOppgaveException(
) : OppgaveException(Feiltype.OPPGAVE_OPPRETT_FORDELING, "Klarte ikke opprette fordelingsoppgave for journalpostId $journalpostId!", cause)

// BehandlendeEnhetConsumer
open class BehandlendeEnhetException(feiltype: Feiltype, message: String, cause: Exception?) : BehandlingException(feiltype, message, cause)
open class BehandlendeEnhetException(
feiltype: Feiltype,
message: String,
cause: Exception?,
) : BehandlingException(feiltype, message, cause)

open class IngenAktivEnhetException(
geografiskTilknytning: String?,
Expand All @@ -47,7 +65,11 @@ open class BehandlendeEnhetFeiletException(
) : BehandlendeEnhetException(Feiltype.BEHANDLENDE_FEILET, "Feil ved henting av geografisk tilknytning", cause)

// JournalConsumer
open class JournalException(feiltype: Feiltype, message: String, cause: Exception?) : BehandlingException(feiltype, message, cause)
open class JournalException(
feiltype: Feiltype,
message: String,
cause: Exception?,
) : BehandlingException(feiltype, message, cause)

open class HentDokumentFeiletException(
journalpostId: String,
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/no/nav/syfo/behandling/Feiltype.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package no.nav.syfo.behandling

enum class Feiltype(var navn: String) {
enum class Feiltype(
var navn: String,
) {
USPESIFISERT("uspesifisert"),
AKTØR_IKKE_FUNNET("aktor_ikkefunnet"),
DOKUMENT_FEILET("dokument_feilet"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package no.nav.syfo.client.dokarkiv
fun mapFeilregistrertRequest(
fnr: String,
dokumentId: String,
): OppdaterJournalpostRequest {
return OppdaterJournalpostRequest(
): OppdaterJournalpostRequest =
OppdaterJournalpostRequest(
bruker =
Bruker(
fnr,
Expand All @@ -14,4 +14,3 @@ fun mapFeilregistrertRequest(
tema = "SYK",
dokumenter = listOf(Dokument(dokumentId, "Inntektsmelding duplikat")),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ data class Sak(
val arkivsaksystem: String? = null,
)

fun mapOppdaterRequest(fnr: String): OppdaterJournalpostRequest {
return OppdaterJournalpostRequest(
fun mapOppdaterRequest(fnr: String): OppdaterJournalpostRequest =
OppdaterJournalpostRequest(
bruker =
Bruker(
fnr,
Expand All @@ -51,4 +51,3 @@ fun mapOppdaterRequest(fnr: String): OppdaterJournalpostRequest {
sak = Sak("GENERELL_SAK"),
tema = "SYK",
)
}
5 changes: 2 additions & 3 deletions src/main/kotlin/no/nav/syfo/client/saf/LagQuery.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.nav.syfo.client.saf

fun lagQuery(journalpostId: String): String {
return """query {
fun lagQuery(journalpostId: String): String =
"""query {
journalpost(journalpostId: "$journalpostId") {
tittel,
journalstatus,
Expand All @@ -12,4 +12,3 @@ fun lagQuery(journalpostId: String): String {
}
}
}""".trim()
}
39 changes: 25 additions & 14 deletions src/main/kotlin/no/nav/syfo/client/saf/SafJournalpostClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ class SafJournalpostClient(
try {
val response: JournalResponse =
runBlocking {
httpClient.post(basePath) {
contentType(ContentType.Application.Json)
header("Authorization", "Bearer $accessToken")
header("X-Correlation-ID", journalpostId)
setBody(GetJournalpostRequest(query = lagQuery(journalpostId)))
}.call.response.body<JournalResponse>()
httpClient
.post(basePath) {
contentType(ContentType.Application.Json)
header("Authorization", "Bearer $accessToken")
header("X-Correlation-ID", journalpostId)
setBody(GetJournalpostRequest(query = lagQuery(journalpostId)))
}.call.response
.body<JournalResponse>()
}
if (response.errors != null && response.errors.isNotEmpty()) {
throw ErrorException(journalpostId, response.errors.toString())
Expand All @@ -51,14 +53,23 @@ class SafJournalpostClient(
}
}

open class SafJournalpostException(journalpostId: String) : Exception(journalpostId)
open class SafJournalpostException(
journalpostId: String,
) : Exception(journalpostId)

open class NotAuthorizedException(journalpostId: String) : SafJournalpostException(
"SAF ga ikke tilgang til å lese ut journalpost '$journalpostId'",
)
open class NotAuthorizedException(
journalpostId: String,
) : SafJournalpostException(
"SAF ga ikke tilgang til å lese ut journalpost '$journalpostId'",
)

open class ErrorException(journalpostId: String, errors: String) : SafJournalpostException(
"SAF returnerte feil journalpost '$journalpostId': $errors",
)
open class ErrorException(
journalpostId: String,
errors: String,
) : SafJournalpostException(
"SAF returnerte feil journalpost '$journalpostId': $errors",
)

open class EmptyException(journalpostId: String) : SafJournalpostException("SAF returnerte tom journalpost '$journalpostId'")
open class EmptyException(
journalpostId: String,
) : SafJournalpostException("SAF returnerte tom journalpost '$journalpostId'")
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ data class Inntektsmelding(
val rapportertInntekt: RapportertInntekt? = null,
val vedtaksperiodeId: UUID? = null,
) {
fun isDuplicate(inntektsmelding: Inntektsmelding): Boolean {
return this.equals(
fun isDuplicate(inntektsmelding: Inntektsmelding): Boolean =
this.equals(
inntektsmelding.copy(
id = this.id,
fnr = this.fnr,
Expand All @@ -57,10 +57,9 @@ data class Inntektsmelding(
avsenderSystem = this.avsenderSystem,
),
)
}

fun isDuplicateExclusiveArsakInnsending(inntektsmelding: Inntektsmelding): Boolean {
return this.equals(
fun isDuplicateExclusiveArsakInnsending(inntektsmelding: Inntektsmelding): Boolean =
this.equals(
inntektsmelding.copy(
id = this.id,
fnr = this.fnr,
Expand All @@ -75,10 +74,7 @@ data class Inntektsmelding(
arsakTilInnsending = this.arsakTilInnsending,
),
)
}

// TODO: kanskje kan vi fjerne dette, hvis vedtaksperiodeId *alltid* skal komme i selvbestemtIM
fun matcherSpleis(): Boolean {
return !(avsenderSystem.navn == NAV_NO_SELVBESTEMT && vedtaksperiodeId == null)
}
fun matcherSpleis(): Boolean = !(avsenderSystem.navn == NAV_NO_SELVBESTEMT && vedtaksperiodeId == null)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class UtsattOppgaveConsumer(
val om: ObjectMapper,
val utsattOppgaveService: UtsattOppgaveService,
val bakgrunnsjobbRepo: BakgrunnsjobbRepository,
) : ReadynessComponent, LivenessComponent {
) : ReadynessComponent,
LivenessComponent {
private val consumer: KafkaConsumer<String, String> = KafkaConsumer(props, StringDeserializer(), StringDeserializer())
private val logger = this.logger()
private val sikkerlogger = sikkerLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class JournalpostHendelseConsumer(
topicName: String,
private val bakgrunnsjobbRepo: BakgrunnsjobbRepository,
private val om: ObjectMapper,
) : ReadynessComponent, LivenessComponent {
) : ReadynessComponent,
LivenessComponent {
private val log = LoggerFactory.getLogger(JournalpostHendelseConsumer::class.java)
private val sikkerlogger = sikkerLogger()
private val consumer: KafkaConsumer<String, GenericRecord> = KafkaConsumer(props)
Expand Down Expand Up @@ -113,5 +114,4 @@ class JournalpostHendelseConsumer(
}
}

fun isInntektsmelding(hendelse: InngaaendeJournalpostDTO): Boolean =
hendelse.temaNytt == "SYK" && hendelse.mottaksKanal == "ALTINN" && hendelse.journalpostStatus == "MOTTATT"
fun isInntektsmelding(hendelse: InngaaendeJournalpostDTO): Boolean = hendelse.temaNytt == "SYK" && hendelse.mottaksKanal == "ALTINN" && hendelse.journalpostStatus == "MOTTATT"
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package no.nav.syfo.integration.kafka.journalpost
import no.nav.syfo.kafkamottak.InngaaendeJournalpostDTO
import org.apache.avro.generic.GenericRecord

fun mapJournalpostHendelse(record: GenericRecord): InngaaendeJournalpostDTO {
return InngaaendeJournalpostDTO(
fun mapJournalpostHendelse(record: GenericRecord): InngaaendeJournalpostDTO =
InngaaendeJournalpostDTO(
record.get("hendelsesId") as String,
record.get("versjon") as Int,
record.get("hendelsesType") as String,
Expand All @@ -16,4 +16,3 @@ fun mapJournalpostHendelse(record: GenericRecord): InngaaendeJournalpostDTO {
record.get("kanalReferanseId") as String,
record.get("behandlingstema") as String,
)
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package no.nav.syfo.kafkamottak

class InntektsmeldingConsumerException(exception: Exception) : RuntimeException(exception)
class InntektsmeldingConsumerException(
exception: Exception,
) : RuntimeException(exception)
Loading

0 comments on commit f6125b9

Please sign in to comment.