Skip to content

Commit

Permalink
Legg inn mulighet for å ikke distribuere ved journalføring (#389)
Browse files Browse the repository at this point in the history
* Legg inn mulighet for å ikke distribuere ved journalføring

* Legg inn (tidligere) mulighet for å ikke distribuere ved journalføring

* Fiks serialisering
  • Loading branch information
bjerga authored Dec 22, 2023
1 parent 4c1cfd6 commit 9676d57
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import no.nav.helsearbeidsgiver.utils.json.toPretty
import no.nav.helsearbeidsgiver.utils.log.MdcUtils
import no.nav.helsearbeidsgiver.utils.log.logger
import no.nav.helsearbeidsgiver.utils.log.sikkerLogger
import no.nav.helsearbeidsgiver.utils.pipe.orDefault
import java.util.UUID

class LagreJournalpostIdLoeser(
Expand All @@ -38,6 +39,7 @@ class LagreJournalpostIdLoeser(
it.demandValue(Key.BEHOV.str, BehovType.LAGRE_JOURNALPOST_ID.name)
it.requireKey(Key.UUID.str)
it.requireKey(Key.JOURNALPOST_ID.str)
it.interestedIn(Key.SKAL_DISTRIBUERE.str)
}
}

Expand All @@ -55,6 +57,7 @@ class LagreJournalpostIdLoeser(

val event = Key.EVENT_NAME.les(EventName.serializer(), melding)
val transaksjonId = Key.UUID.les(UuidSerializer, melding)
val skalDistribuere = Key.SKAL_DISTRIBUERE.lesOrNull(Boolean.serializer(), melding).orDefault(true)

val forespoerselId = behov.forespoerselId!!.let(UUID::fromString)

Expand All @@ -64,12 +67,12 @@ class LagreJournalpostIdLoeser(
Log.forespoerselId(forespoerselId)
) {
val journalpostId = Key.JOURNALPOST_ID.lesOrNull(String.serializer(), melding)
lagreJournalpostId(behov, journalpostId, forespoerselId, transaksjonId)
lagreJournalpostId(behov, journalpostId, forespoerselId, transaksjonId, skalDistribuere)
}
}
}

private fun lagreJournalpostId(behov: Behov, journalpostId: String?, forespoerselId: UUID, transaksjonId: UUID) {
private fun lagreJournalpostId(behov: Behov, journalpostId: String?, forespoerselId: UUID, transaksjonId: UUID, skalDistribuere: Boolean) {
if (journalpostId.isNullOrBlank()) {
logger.error("Fant ingen journalpost-ID.")
sikkerLogger.error("Fant ingen journalpost-ID.")
Expand All @@ -88,7 +91,8 @@ class LagreJournalpostIdLoeser(
EventName.INNTEKTSMELDING_JOURNALFOERT,
mapOfNotNull(
Key.JOURNALPOST_ID to journalpostId,
Key.INNTEKTSMELDING_DOKUMENT to inntektsmelding?.toJson(Inntektsmelding.serializer())?.toJsonNode()
Key.INNTEKTSMELDING_DOKUMENT to inntektsmelding?.toJson(Inntektsmelding.serializer())?.toJsonNode(),
Key.SKAL_DISTRIBUERE to skalDistribuere
)
)
.also { publishEvent(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,29 @@ class JournalfoertListener(rapidsConnection: RapidsConnection) : EventListener(r
return River.PacketValidation {
it.requireKey(Key.INNTEKTSMELDING_DOKUMENT.str)
it.requireKey(Key.JOURNALPOST_ID.str)
it.interestedIn(Key.SKAL_DISTRIBUERE.str)
}
}

override fun onEvent(packet: JsonMessage) {
logger.info("Fikk event: ${EventName.INNTEKTSMELDING_JOURNALFOERT}")
sikkerLogger.info("Fikk event: ${EventName.INNTEKTSMELDING_JOURNALFOERT} med pakke\n${packet.toPretty()}")
val jsonMessage = JsonMessage.newMessage(
mapOf(
Key.EVENT_NAME.str to EventName.INNTEKTSMELDING_JOURNALFOERT,
Key.BEHOV.str to BehovType.DISTRIBUER_IM.name,
Key.JOURNALPOST_ID.str to packet[Key.JOURNALPOST_ID.str].asText(),
Key.INNTEKTSMELDING_DOKUMENT.str to packet[Key.INNTEKTSMELDING_DOKUMENT.str]

val skalDistribuere = packet[Key.SKAL_DISTRIBUERE.str].asBoolean(true)
if (skalDistribuere) {
val jsonMessage = JsonMessage.newMessage(
mapOf(
Key.EVENT_NAME.str to EventName.INNTEKTSMELDING_JOURNALFOERT,
Key.BEHOV.str to BehovType.DISTRIBUER_IM.name,
Key.JOURNALPOST_ID.str to packet[Key.JOURNALPOST_ID.str].asText(),
Key.INNTEKTSMELDING_DOKUMENT.str to packet[Key.INNTEKTSMELDING_DOKUMENT.str]
)
)
)
publishBehov(jsonMessage)
logger.info("Publiserte behov om å distribuere inntektsmelding")
publishBehov(jsonMessage)
logger.info("Publiserte behov om å distribuere inntektsmelding")
} else {
logger.info("Publiserte _ikke_ behov om å distribuere inntektsmelding pga. ${Key.SKAL_DISTRIBUERE.str}=false")
sikkerLogger.info("Publiserte _ikke_ behov om å distribuere inntektsmelding pga. ${Key.SKAL_DISTRIBUERE.str}=false")
}
}
}
3 changes: 3 additions & 0 deletions felles/src/main/kotlin/no/nav/helsearbeidsgiver/felles/Key.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ enum class Key(override val str: String) : IKey {
FAIL("fail"),
FAILED_BEHOV("failed-behov"),

// Midlertidig nøkkel
SKAL_DISTRIBUERE("skal_distribuere"),

// Tidligere DataFelt
VIRKSOMHET("virksomhet"),
VIRKSOMHETER("virksomheter"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package no.nav.helsearbeidsgiver.inntektsmelding.joark
import com.fasterxml.jackson.databind.JsonNode
import io.prometheus.client.Summary
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.builtins.serializer
import no.nav.helse.rapids_rivers.RapidsConnection
import no.nav.helse.rapids_rivers.River
import no.nav.helsearbeidsgiver.dokarkiv.DokArkivClient
Expand All @@ -12,11 +13,14 @@ import no.nav.helsearbeidsgiver.domene.inntektsmelding.Inntektsmelding
import no.nav.helsearbeidsgiver.felles.BehovType
import no.nav.helsearbeidsgiver.felles.EventName
import no.nav.helsearbeidsgiver.felles.Key
import no.nav.helsearbeidsgiver.felles.json.toMap
import no.nav.helsearbeidsgiver.felles.rapidsrivers.Loeser
import no.nav.helsearbeidsgiver.felles.rapidsrivers.model.Behov
import no.nav.helsearbeidsgiver.utils.json.fromJson
import no.nav.helsearbeidsgiver.utils.json.parseJson
import no.nav.helsearbeidsgiver.utils.log.logger
import no.nav.helsearbeidsgiver.utils.log.sikkerLogger
import no.nav.helsearbeidsgiver.utils.pipe.orDefault
import java.time.LocalDate
import java.time.LocalDateTime

Expand Down Expand Up @@ -46,10 +50,14 @@ class JournalfoerInntektsmeldingLoeser(
it.demandValue(Key.EVENT_NAME.str, EventName.INNTEKTSMELDING_MOTTATT.name)
it.demandValue(Key.BEHOV.str, JOURNALFOER_BEHOV.name)
it.requireKey(Key.INNTEKTSMELDING_DOKUMENT.str)
it.interestedIn(Key.SKAL_DISTRIBUERE.str)
}
}

override fun onBehov(behov: Behov) {
val json = behov.jsonMessage.toJson().parseJson().toMap()
val skalDistribuere = json[Key.SKAL_DISTRIBUERE]?.fromJson(Boolean.serializer()).orDefault(true)

logger.info("Løser behov " + BehovType.JOURNALFOER + " med uuid ${behov.uuid()}")
var inntektsmelding: Inntektsmelding? = null
try {
Expand All @@ -62,7 +70,8 @@ class JournalfoerInntektsmeldingLoeser(
BehovType.LAGRE_JOURNALPOST_ID,
mapOf(
Key.OPPRETTET to LocalDateTime.now(),
Key.JOURNALPOST_ID to journalpostId
Key.JOURNALPOST_ID to journalpostId,
Key.SKAL_DISTRIBUERE to skalDistribuere
)
)
.also { publishBehov(it) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.helsearbeidsgiver.inntektsmelding.joark

import io.kotest.matchers.shouldBe
import io.mockk.coEvery
import io.mockk.mockk
import io.prometheus.client.CollectorRegistry
Expand All @@ -18,6 +19,7 @@ import no.nav.helsearbeidsgiver.felles.test.mock.mockInntektsmelding
import no.nav.helsearbeidsgiver.felles.test.rapidsrivers.firstMessage
import no.nav.helsearbeidsgiver.felles.test.rapidsrivers.sendJson
import no.nav.helsearbeidsgiver.utils.json.fromJson
import no.nav.helsearbeidsgiver.utils.json.serializer.UuidSerializer
import no.nav.helsearbeidsgiver.utils.json.toJson
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
Expand Down Expand Up @@ -80,13 +82,11 @@ class JournalfoerInntektsmeldingLoeserTest {
Key.UUID to expectedUuid.toJson()
)

val publisert = testRapid.firstMessage()
.toMap()
.mapValues { (_, value) -> value.fromJson(String.serializer()) }
val publisert = testRapid.firstMessage().toMap()

assertEquals(BehovType.LAGRE_JOURNALPOST_ID.name, publisert[Key.BEHOV])
assertEquals("jid-ulende-koala", publisert[Key.JOURNALPOST_ID])
assertEquals(expectedUuid.toString(), publisert[Key.UUID])
publisert[Key.BEHOV]?.fromJson(BehovType.serializer()) shouldBe BehovType.LAGRE_JOURNALPOST_ID
publisert[Key.JOURNALPOST_ID]?.fromJson(String.serializer()) shouldBe "jid-ulende-koala"
publisert[Key.UUID]?.fromJson(UuidSerializer) shouldBe expectedUuid
}

@Test
Expand Down

0 comments on commit 9676d57

Please sign in to comment.