diff --git a/apps/etterlatte-behandling/src/main/kotlin/behandling/omregning/OmregningDao.kt b/apps/etterlatte-behandling/src/main/kotlin/behandling/omregning/OmregningDao.kt index cb363d628ed..220d94b4ff6 100644 --- a/apps/etterlatte-behandling/src/main/kotlin/behandling/omregning/OmregningDao.kt +++ b/apps/etterlatte-behandling/src/main/kotlin/behandling/omregning/OmregningDao.kt @@ -59,14 +59,16 @@ class OmregningDao( val statement = prepareStatement( """ - INSERT INTO omregningskjoering (kjoering, status, sak_id, begrunnelse) - VALUES (?, ?, ?, ?) + INSERT INTO omregningskjoering (kjoering, status, sak_id, begrunnelse, corr_id, feilende_steg) + VALUES (?, ?, ?, ?, ?, ?) """.trimIndent(), ) statement.setString(1, request.kjoering) statement.setString(2, request.status.name) statement.setSakId(3, request.sakId) - statement.setString(4, request.begrunnelse ?: "") + statement.setString(4, request.begrunnelse) + statement.setString(5, request.corrId) + statement.setString(6, request.feilendeSteg) statement.executeUpdate().also { require(it == 1) } } } diff --git a/apps/etterlatte-behandling/src/main/kotlin/inntektsjustering/AarligInntektsjusteringJobbService.kt b/apps/etterlatte-behandling/src/main/kotlin/inntektsjustering/AarligInntektsjusteringJobbService.kt index 8c8b59af8c2..4423f172d8f 100644 --- a/apps/etterlatte-behandling/src/main/kotlin/inntektsjustering/AarligInntektsjusteringJobbService.kt +++ b/apps/etterlatte-behandling/src/main/kotlin/inntektsjustering/AarligInntektsjusteringJobbService.kt @@ -26,7 +26,6 @@ import no.nav.etterlatte.libs.common.behandling.SakType import no.nav.etterlatte.libs.common.behandling.tilVirkningstidspunkt import no.nav.etterlatte.libs.common.beregning.AarligInntektsjusteringAvkortingSjekkResponse import no.nav.etterlatte.libs.common.feilhaandtering.InternfeilException -import no.nav.etterlatte.libs.common.inntektsjustering.AarligInntektsjusteringKjoering import no.nav.etterlatte.libs.common.inntektsjustering.AarligInntektsjusteringRequest import no.nav.etterlatte.libs.common.logging.getCorrelationId import no.nav.etterlatte.libs.common.person.PdlIdentifikator @@ -155,7 +154,7 @@ class AarligInntektsjusteringJobbService( } oppdaterKjoering(kjoering, KjoeringStatus.KLAR_FOR_OMREGNING, sakId) - publiserKlarForOmregning(sakId, loependeFom) + publiserKlarForOmregning(sakId, loependeFom, kjoering) } catch (e: Exception) { logger.warn("Automatisk jobb feilet! kjøring:$kjoering sak:$sakId", e) oppdaterKjoering( @@ -223,6 +222,7 @@ class AarligInntektsjusteringJobbService( private fun publiserKlarForOmregning( sakId: SakId, loependeFom: YearMonth, + kjoering: String, ) { val correlationId = getCorrelationId() rapid @@ -236,7 +236,7 @@ class AarligInntektsjusteringJobbService( TEKNISK_TID_KEY to Tidspunkt.now(), OmregningDataPacket.KEY to OmregningData( - kjoering = AarligInntektsjusteringKjoering.getKjoering(), + kjoering = kjoering, sakId = sakId, revurderingaarsak = Revurderingaarsak.AARLIG_INNTEKTSJUSTERING, fradato = loependeFom.atDay(1), diff --git a/apps/etterlatte-behandling/src/main/resources/db/migration/V183__omregning_kjoering_corrid_feilendesteg.sql b/apps/etterlatte-behandling/src/main/resources/db/migration/V183__omregning_kjoering_corrid_feilendesteg.sql new file mode 100644 index 00000000000..b366928d4dc --- /dev/null +++ b/apps/etterlatte-behandling/src/main/resources/db/migration/V183__omregning_kjoering_corrid_feilendesteg.sql @@ -0,0 +1,8 @@ +ALTER TABLE omregningskjoering + ADD COLUMN corr_id VARCHAR; + +ALTER TABLE omregningskjoering + ADD COLUMN feilende_steg VARCHAR; + +ALTER TABLE omregningskjoering + ALTER begrunnelse DROP NOT NULL; \ No newline at end of file diff --git a/apps/etterlatte-oppdater-behandling/src/main/kotlin/BehandlingService.kt b/apps/etterlatte-oppdater-behandling/src/main/kotlin/BehandlingService.kt index 05e6b83211c..c7a91884b5f 100644 --- a/apps/etterlatte-oppdater-behandling/src/main/kotlin/BehandlingService.kt +++ b/apps/etterlatte-oppdater-behandling/src/main/kotlin/BehandlingService.kt @@ -122,6 +122,9 @@ interface BehandlingService { sakId: SakId, status: KjoeringStatus, kjoering: String, + begrunnelse: String? = null, + corrId: String? = null, + feilendeSteg: String? = null, ) fun lagreFullfoertKjoering(request: LagreKjoeringRequest) @@ -368,6 +371,9 @@ class BehandlingServiceImpl( sakId: SakId, status: KjoeringStatus, kjoering: String, + begrunnelse: String?, + corrId: String?, + feilendeSteg: String?, ) { runBlocking { behandlingKlient.put("$url/omregning/kjoering") { @@ -377,6 +383,9 @@ class BehandlingServiceImpl( kjoering = kjoering, status = status, sakId = sakId, + begrunnelse = begrunnelse, + corrId = corrId, + feilendeSteg = feilendeSteg, ), ) } diff --git a/apps/etterlatte-oppdater-behandling/src/main/kotlin/regulering/OmregningFeiletRiver.kt b/apps/etterlatte-oppdater-behandling/src/main/kotlin/regulering/OmregningFeiletRiver.kt index 8027523c840..e54d48850df 100644 --- a/apps/etterlatte-oppdater-behandling/src/main/kotlin/regulering/OmregningFeiletRiver.kt +++ b/apps/etterlatte-oppdater-behandling/src/main/kotlin/regulering/OmregningFeiletRiver.kt @@ -1,6 +1,12 @@ package no.nav.etterlatte.regulering import no.nav.etterlatte.BehandlingService +import no.nav.etterlatte.libs.common.rapidsandrivers.CORRELATION_ID_KEY +import no.nav.etterlatte.libs.common.rapidsandrivers.FEILENDE_STEG +import no.nav.etterlatte.libs.common.rapidsandrivers.FEILMELDING_KEY +import no.nav.etterlatte.libs.common.rapidsandrivers.correlationId +import no.nav.etterlatte.libs.common.rapidsandrivers.feilendeSteg +import no.nav.etterlatte.libs.common.rapidsandrivers.feilmelding import no.nav.etterlatte.libs.common.sak.KjoeringStatus import no.nav.etterlatte.rapidsandrivers.EventNames.FEILA import no.nav.etterlatte.rapidsandrivers.KONTEKST_KEY @@ -25,6 +31,9 @@ internal class OmregningFeiletRiver( validate { it.requireKey(OmregningDataPacket.SAK_ID) } validate { it.requireKey(OmregningDataPacket.KJOERING) } validate { it.requireAny(KONTEKST_KEY, listOf(Kontekst.REGULERING.name, Kontekst.OMREGNING.name)) } + validate { it.interestedIn(FEILMELDING_KEY) } + validate { it.interestedIn(FEILENDE_STEG) } + validate { it.interestedIn(CORRELATION_ID_KEY) } } } @@ -39,6 +48,9 @@ internal class OmregningFeiletRiver( kjoering = omregningData.kjoering, sakId = omregningData.sakId, status = KjoeringStatus.FEILA, + begrunnelse = packet.feilmelding, + corrId = packet.correlationId, + feilendeSteg = packet.feilendeSteg, ) } } diff --git a/apps/etterlatte-oppdater-behandling/src/main/kotlin/regulering/VedtakAttestertRiver.kt b/apps/etterlatte-oppdater-behandling/src/main/kotlin/regulering/VedtakAttestertRiver.kt index aceade0c503..cf14ce6bcab 100644 --- a/apps/etterlatte-oppdater-behandling/src/main/kotlin/regulering/VedtakAttestertRiver.kt +++ b/apps/etterlatte-oppdater-behandling/src/main/kotlin/regulering/VedtakAttestertRiver.kt @@ -3,7 +3,7 @@ package no.nav.etterlatte.regulering import no.nav.etterlatte.BehandlingService import no.nav.etterlatte.brev.BrevRequestHendelseType import no.nav.etterlatte.brev.Brevkoder -import no.nav.etterlatte.libs.common.inntektsjustering.AarligInntektsjusteringKjoering +import no.nav.etterlatte.libs.common.behandling.Revurderingaarsak import no.nav.etterlatte.libs.common.rapidsandrivers.setEventNameForHendelseType import no.nav.etterlatte.libs.common.sak.KjoeringStatus import no.nav.etterlatte.libs.common.sak.LagreKjoeringRequest @@ -39,6 +39,7 @@ internal class VedtakAttestertRiver( validate { it.requireKey(OmregningDataPacket.KEY) } validate { it.requireKey(OmregningDataPacket.SAK_ID) } validate { it.requireKey(OmregningDataPacket.KJOERING) } + validate { it.requireKey(OmregningDataPacket.REV_AARSAK) } validate { it.interestedIn(BEREGNING_BELOEP_FOER) } validate { it.interestedIn(BEREGNING_BELOEP_ETTER) } validate { it.interestedIn(BEREGNING_G_FOER) } @@ -75,7 +76,7 @@ internal class VedtakAttestertRiver( ) // Årlig inntektsjustering jobb skal sende ut varsel og vedtak etter at sak er ferdig omregnet - if (kjoering === AarligInntektsjusteringKjoering.getKjoering()) { + if (packet.omregningData.revurderingaarsak == Revurderingaarsak.AARLIG_INNTEKTSJUSTERING) { packet.setEventNameForHendelseType(BrevRequestHendelseType.OPPRETT_JOURNALFOER_OG_DISTRIBUER) packet.brevKode = Brevkoder.OMS_INNTEKTSJUSTERING_VARSEL.name packet.sakId = packet.omregningData.sakId diff --git a/apps/etterlatte-oppdater-behandling/src/test/kotlin/regulering/OmregningFeiletRiverTest.kt b/apps/etterlatte-oppdater-behandling/src/test/kotlin/regulering/OmregningFeiletRiverTest.kt index ed6fe3fe189..4e950c9312d 100644 --- a/apps/etterlatte-oppdater-behandling/src/test/kotlin/regulering/OmregningFeiletRiverTest.kt +++ b/apps/etterlatte-oppdater-behandling/src/test/kotlin/regulering/OmregningFeiletRiverTest.kt @@ -6,9 +6,13 @@ import io.mockk.slot import no.nav.etterlatte.BehandlingService import no.nav.etterlatte.behandling.randomSakId import no.nav.etterlatte.libs.common.behandling.Revurderingaarsak +import no.nav.etterlatte.libs.common.rapidsandrivers.CORRELATION_ID_KEY +import no.nav.etterlatte.libs.common.rapidsandrivers.FEILENDE_STEG +import no.nav.etterlatte.libs.common.rapidsandrivers.FEILMELDING_KEY import no.nav.etterlatte.libs.common.rapidsandrivers.lagParMedEventNameKey import no.nav.etterlatte.libs.common.sak.KjoeringStatus import no.nav.etterlatte.libs.common.sak.SakId +import no.nav.etterlatte.libs.common.toJson import no.nav.etterlatte.rapidsandrivers.EventNames.FEILA import no.nav.etterlatte.rapidsandrivers.HENDELSE_DATA_KEY import no.nav.etterlatte.rapidsandrivers.KONTEKST_KEY @@ -19,6 +23,7 @@ import no.nav.helse.rapids_rivers.JsonMessage import no.nav.helse.rapids_rivers.testsupport.TestRapid import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test +import java.util.UUID internal class OmregningFeiletRiverTest { @Test @@ -27,6 +32,10 @@ internal class OmregningFeiletRiverTest { val status = slot() val sakIdSlot = slot() val sakId = randomSakId() + val begrunnelse = slot() + val corrId = UUID.randomUUID().toString() + val corrIdSlot = slot() + val feilendeSteg = slot() val melding = JsonMessage.newMessage( @@ -40,11 +49,23 @@ internal class OmregningFeiletRiverTest { sakId = sakId, revurderingaarsak = Revurderingaarsak.OMREGNING, ).toPacket(), + FEILMELDING_KEY to "feilmelding", + CORRELATION_ID_KEY to corrId, + FEILENDE_STEG to "feilende steg", ), ) val behandlingService = mockk(relaxed = true) - every { behandlingService.lagreKjoering(capture(sakIdSlot), capture(status), capture(kjoering)) } returns Unit + every { + behandlingService.lagreKjoering( + capture(sakIdSlot), + capture(status), + capture(kjoering), + capture(begrunnelse), + capture(corrIdSlot), + capture(feilendeSteg), + ) + } returns Unit val inspector = TestRapid().apply { OmregningFeiletRiver(this, behandlingService) } inspector.sendTestMessage(melding.toJson()) @@ -53,6 +74,9 @@ internal class OmregningFeiletRiverTest { Assertions.assertEquals("OmregningKjoering", kjoering.captured) Assertions.assertEquals(sakId, sakIdSlot.captured) Assertions.assertEquals(KjoeringStatus.FEILA, status.captured) + Assertions.assertEquals("feilmelding".toJson(), begrunnelse.captured) + Assertions.assertEquals(corrId, corrIdSlot.captured) + Assertions.assertEquals("feilende steg", feilendeSteg.captured) } @Test @@ -70,6 +94,8 @@ internal class OmregningFeiletRiverTest { sakId = sakId, revurderingaarsak = Revurderingaarsak.REGULERING, ).toPacket(), + FEILMELDING_KEY to "", + FEILENDE_STEG to "", ), ) diff --git a/libs/etterlatte-behandling-model/src/main/kotlin/no/nav/etterlatte/libs/common/inntektsjustering/AarligInntektsjusteringRequest.kt b/libs/etterlatte-behandling-model/src/main/kotlin/no/nav/etterlatte/libs/common/inntektsjustering/AarligInntektsjusteringRequest.kt index 4af5fd8a623..ed56cf325b2 100644 --- a/libs/etterlatte-behandling-model/src/main/kotlin/no/nav/etterlatte/libs/common/inntektsjustering/AarligInntektsjusteringRequest.kt +++ b/libs/etterlatte-behandling-model/src/main/kotlin/no/nav/etterlatte/libs/common/inntektsjustering/AarligInntektsjusteringRequest.kt @@ -1,7 +1,6 @@ package no.nav.etterlatte.libs.common.inntektsjustering import no.nav.etterlatte.libs.common.sak.SakId -import java.time.Year import java.time.YearMonth data class AarligInntektsjusteringRequest( @@ -9,7 +8,3 @@ data class AarligInntektsjusteringRequest( val loependeFom: YearMonth, val saker: List, ) - -object AarligInntektsjusteringKjoering { - fun getKjoering(): String = "Årlig inntektsjustering ${Year.now().plusYears(1)}" -} diff --git a/libs/etterlatte-behandling-model/src/main/kotlin/no/nav/etterlatte/libs/common/sak/KjoeringRequest.kt b/libs/etterlatte-behandling-model/src/main/kotlin/no/nav/etterlatte/libs/common/sak/KjoeringRequest.kt index 0c894ee93b7..c3a247d6194 100644 --- a/libs/etterlatte-behandling-model/src/main/kotlin/no/nav/etterlatte/libs/common/sak/KjoeringRequest.kt +++ b/libs/etterlatte-behandling-model/src/main/kotlin/no/nav/etterlatte/libs/common/sak/KjoeringRequest.kt @@ -7,6 +7,8 @@ data class KjoeringRequest( val status: KjoeringStatus, val sakId: SakId, val begrunnelse: String? = null, + val corrId: String? = null, + val feilendeSteg: String? = null, ) data class LagreKjoeringRequest( diff --git a/libs/rapidsandrivers-extras/src/main/kotlin/rapidsandrivers/OmregningHendelseType.kt b/libs/rapidsandrivers-extras/src/main/kotlin/rapidsandrivers/OmregningHendelseType.kt index 3d7f77da3b7..59fd85224af 100644 --- a/libs/rapidsandrivers-extras/src/main/kotlin/rapidsandrivers/OmregningHendelseType.kt +++ b/libs/rapidsandrivers-extras/src/main/kotlin/rapidsandrivers/OmregningHendelseType.kt @@ -130,6 +130,7 @@ data class OmregningDataPacket( val FRA_DATO = "$HENDELSE_DATA_KEY.${OmregningDataPacket::fradato.name}" val BEHANDLING_ID = "$HENDELSE_DATA_KEY.${OmregningDataPacket::behandlingId.name}" val FORRIGE_BEHANDLING_ID = "$HENDELSE_DATA_KEY.${OmregningDataPacket::forrigeBehandlingId.name}" + val REV_AARSAK = "$HENDELSE_DATA_KEY.${OmregningDataPacket::revurderingaarsak.name}" } } diff --git a/libs/rapidsandrivers-extras/src/main/kotlin/rapidsandrivers/RetryOgFeilhaandtering.kt b/libs/rapidsandrivers-extras/src/main/kotlin/rapidsandrivers/RetryOgFeilhaandtering.kt index f092844efd1..ff05fecbda1 100644 --- a/libs/rapidsandrivers-extras/src/main/kotlin/rapidsandrivers/RetryOgFeilhaandtering.kt +++ b/libs/rapidsandrivers-extras/src/main/kotlin/rapidsandrivers/RetryOgFeilhaandtering.kt @@ -33,7 +33,10 @@ internal fun withRetryOgFeilhaandtering( } } catch (e: Exception) { feilhaandteringLogger.error("Håndtering av melding ${packet.id} feila på steg $feilendeSteg.", e) - sikkerLogg.error("Håndtering av melding ${packet.id} feila på steg $feilendeSteg. med body ${packet.toJson()}", e) + sikkerLogg.error( + "Håndtering av melding ${packet.id} feila på steg $feilendeSteg. med body ${packet.toJson()}", + e, + ) publiserFeilamelding(packet, feilendeSteg, kontekst, e, context) feilhaandteringLogger.warn("Fikk feil, sendte ut på feilkø, returnerer nå failure-result")