Skip to content

Commit

Permalink
Mer inntektsjustering aar (#6256)
Browse files Browse the repository at this point in the history
* vedtak sjekker om årlig inntektsjustering med rev årsak

* Omregning lagrer feilmelding og corrid ved feil

* Omregning lagrer feilende steg

* behold stacktrace i feilmelding melding

* Fjerner non null

* Fikse tester
  • Loading branch information
Bjodn authored Nov 7, 2024
1 parent 85277e6 commit d2d88c5
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -223,6 +222,7 @@ class AarligInntektsjusteringJobbService(
private fun publiserKlarForOmregning(
sakId: SakId,
loependeFom: YearMonth,
kjoering: String,
) {
val correlationId = getCorrelationId()
rapid
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -368,6 +371,9 @@ class BehandlingServiceImpl(
sakId: SakId,
status: KjoeringStatus,
kjoering: String,
begrunnelse: String?,
corrId: String?,
feilendeSteg: String?,
) {
runBlocking {
behandlingKlient.put("$url/omregning/kjoering") {
Expand All @@ -377,6 +383,9 @@ class BehandlingServiceImpl(
kjoering = kjoering,
status = status,
sakId = sakId,
begrunnelse = begrunnelse,
corrId = corrId,
feilendeSteg = feilendeSteg,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) }
}
}

Expand All @@ -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,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -27,6 +32,10 @@ internal class OmregningFeiletRiverTest {
val status = slot<KjoeringStatus>()
val sakIdSlot = slot<SakId>()
val sakId = randomSakId()
val begrunnelse = slot<String>()
val corrId = UUID.randomUUID().toString()
val corrIdSlot = slot<String>()
val feilendeSteg = slot<String>()

val melding =
JsonMessage.newMessage(
Expand All @@ -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<BehandlingService>(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())
Expand All @@ -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
Expand All @@ -70,6 +94,8 @@ internal class OmregningFeiletRiverTest {
sakId = sakId,
revurderingaarsak = Revurderingaarsak.REGULERING,
).toPacket(),
FEILMELDING_KEY to "",
FEILENDE_STEG to "",
),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
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(
val kjoering: String,
val loependeFom: YearMonth,
val saker: List<SakId>,
)

object AarligInntektsjusteringKjoering {
fun getKjoering(): String = "Årlig inntektsjustering ${Year.now().plusYears(1)}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit d2d88c5

Please sign in to comment.