Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legg til ny app for å lytte på Infotrygd-eventer #720

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/forespoersel-infotrygd/dev-gcp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kafkaPool: nav-dev
env:
- name: KAFKA_EXTRA_TOPIC
value: helsearbeidsgiver.pri
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ enum class EventName {
FORESPOERSEL_BESVART,
FORESPØRSEL_LAGRET,
FORESPOERSEL_FORKASTET,
FORESPOERSEL_KASTET_TIL_INFOTRYGD,

SAK_OPPRETT_REQUESTED,
SAK_OPPRETTET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ object Pri {
FORESPOERSEL_BESVART,
FORESPOERSEL_BESVART_SIMBA,
FORESPOERSEL_FORKASTET,
FORESPOERSEL_KASTET_TIL_INFOTRYGD,
}

internal object KeySerializer : AsStringSerializer<Key>(
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package no.nav.helsearbeidsgiver.inntektsmelding.forespoerselinfotrygd

import com.github.navikt.tbd_libs.rapids_and_rivers_api.RapidsConnection
import no.nav.helse.rapids_rivers.RapidApplication
import no.nav.helsearbeidsgiver.utils.log.logger

private val logger = "im-forespoersel-infotrygd".logger()

fun main() {
logger.info("Jeg er oppe og kjører!")

RapidApplication
.create(System.getenv())
.createForespoerselKastetTilInfotrygdRiver()
.start()

logger.info("Bye bye, baby, bye bye!")
}

fun RapidsConnection.createForespoerselKastetTilInfotrygdRiver(): RapidsConnection =
also {
logger.info("Starter ${ForespoerselKastetTilInfotrygdRiver::class.simpleName}...")
ForespoerselKastetTilInfotrygdRiver().connect(this)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package no.nav.helsearbeidsgiver.inntektsmelding.forespoerselinfotrygd

import kotlinx.serialization.json.JsonElement
import no.nav.helsearbeidsgiver.felles.EventName
import no.nav.helsearbeidsgiver.felles.Key
import no.nav.helsearbeidsgiver.felles.json.krev
import no.nav.helsearbeidsgiver.felles.json.les
import no.nav.helsearbeidsgiver.felles.json.toJson
import no.nav.helsearbeidsgiver.felles.rapidsrivers.pritopic.Pri
import no.nav.helsearbeidsgiver.felles.rapidsrivers.pritopic.toPretty
import no.nav.helsearbeidsgiver.felles.rapidsrivers.river.PriObjectRiver
import no.nav.helsearbeidsgiver.felles.utils.Log
import no.nav.helsearbeidsgiver.utils.json.serializer.UuidSerializer
import no.nav.helsearbeidsgiver.utils.json.toJson
import no.nav.helsearbeidsgiver.utils.log.logger
import no.nav.helsearbeidsgiver.utils.log.sikkerLogger
import java.util.UUID

data class KastetTilInfotrygdMelding(
val notisType: Pri.NotisType,
val transaksjonId: UUID,
val forespoerselId: UUID,
)

/** Tar imot notis om at en forespørsel om arbeidsgiveropplysninger er kastet til Infotrygd. */
class ForespoerselKastetTilInfotrygdRiver : PriObjectRiver<KastetTilInfotrygdMelding>() {
private val logger = logger()
private val sikkerLogger = sikkerLogger()

override fun les(json: Map<Pri.Key, JsonElement>): KastetTilInfotrygdMelding =
KastetTilInfotrygdMelding(
notisType = Pri.Key.NOTIS.krev(Pri.NotisType.FORESPOERSEL_KASTET_TIL_INFOTRYGD, Pri.NotisType.serializer(), json),
transaksjonId = UUID.randomUUID(),
forespoerselId = Pri.Key.FORESPOERSEL_ID.les(UuidSerializer, json),
)

override fun KastetTilInfotrygdMelding.haandter(json: Map<Pri.Key, JsonElement>): Map<Key, JsonElement> {
logger.info("Mottok melding på pri-topic om ${Pri.NotisType.FORESPOERSEL_KASTET_TIL_INFOTRYGD}.")
sikkerLogger.info("Mottok melding på pri-topic:\n${json.toPretty()}")

return mapOf(
Key.EVENT_NAME to EventName.FORESPOERSEL_KASTET_TIL_INFOTRYGD.toJson(),
Key.UUID to transaksjonId.toJson(),
Key.FORESPOERSEL_ID to forespoerselId.toJson(),
)
}

override fun KastetTilInfotrygdMelding.haandterFeil(
json: Map<Pri.Key, JsonElement>,
error: Throwable,
): Map<Key, JsonElement>? {
"Klarte ikke videresendre beskjed om forespørsel kastet til Infotrygd. Arbeidsgiver kan motta purring selv om de har sendt inn IM gjennom Altinn."
.also {
logger.error("$it Se sikker logg for mer info.")
sikkerLogger.error(it, error)
}

return null
}

override fun KastetTilInfotrygdMelding.loggfelt(): Map<String, String> =
mapOf(
Log.klasse(this@ForespoerselKastetTilInfotrygdRiver),
Log.priNotis(notisType),
Log.transaksjonId(transaksjonId),
Log.forespoerselId(forespoerselId),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package no.nav.helsearbeidsgiver.inntektsmelding.forespoerselinfotrygd

import com.github.navikt.tbd_libs.rapids_and_rivers.test_support.TestRapid
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.ints.shouldBeExactly
import io.kotest.matchers.maps.shouldContainExactly
import io.kotest.matchers.maps.shouldContainKey
import io.mockk.clearAllMocks
import no.nav.helsearbeidsgiver.felles.EventName
import no.nav.helsearbeidsgiver.felles.Key
import no.nav.helsearbeidsgiver.felles.json.toJson
import no.nav.helsearbeidsgiver.felles.json.toMap
import no.nav.helsearbeidsgiver.felles.rapidsrivers.pritopic.Pri
import no.nav.helsearbeidsgiver.felles.test.rapidsrivers.firstMessage
import no.nav.helsearbeidsgiver.felles.test.rapidsrivers.sendJson
import no.nav.helsearbeidsgiver.utils.json.toJson
import java.util.UUID

class ForespoerselKastetTilInfotrygdRiverTest :
FunSpec({
val testRapid = TestRapid()

ForespoerselKastetTilInfotrygdRiver().connect(testRapid)

beforeEach {
testRapid.reset()
clearAllMocks()
}

test("Ved notis om forespørsel kastet til Infotrygd publiseres event om forespørsel kastet til Infotrygd") {
val forespoerselId = UUID.randomUUID()
val forventetPublisert =
mapOf(
Key.EVENT_NAME to EventName.FORESPOERSEL_KASTET_TIL_INFOTRYGD.toJson(),
Key.UUID to UUID.randomUUID().toJson(),
Key.FORESPOERSEL_ID to forespoerselId.toJson(),
)

testRapid.sendJson(
Pri.Key.NOTIS to Pri.NotisType.FORESPOERSEL_KASTET_TIL_INFOTRYGD.toJson(Pri.NotisType.serializer()),
Pri.Key.FORESPOERSEL_ID to forespoerselId.toJson(),
)

testRapid.inspektør.size shouldBeExactly 1

val publisert = testRapid.firstMessage().toMap()

publisert shouldContainKey Key.UUID

publisert.minus(Key.UUID) shouldContainExactly forventetPublisert.minus(Key.UUID)
}
})
1 change: 1 addition & 0 deletions integrasjonstest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {
testImplementation(project(":distribusjon"))
testImplementation(project(":forespoersel-besvart"))
testImplementation(project(":forespoersel-forkastet"))
testImplementation(project(":forespoersel-infotrygd"))
testImplementation(project(":forespoersel-marker-besvart"))
testImplementation(project(":forespoersel-mottatt"))
testImplementation(project(":helsebro"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import no.nav.helsearbeidsgiver.inntektsmelding.distribusjon.createDistribusjonR
import no.nav.helsearbeidsgiver.inntektsmelding.feilbehandler.createFeilLytter
import no.nav.helsearbeidsgiver.inntektsmelding.forespoerselbesvart.createForespoerselBesvartRivers
import no.nav.helsearbeidsgiver.inntektsmelding.forespoerselforkastet.createForespoerselForkastetRiver
import no.nav.helsearbeidsgiver.inntektsmelding.forespoerselinfotrygd.createForespoerselKastetTilInfotrygdRiver
import no.nav.helsearbeidsgiver.inntektsmelding.forespoerselmarkerbesvart.createMarkerForespoerselBesvart
import no.nav.helsearbeidsgiver.inntektsmelding.forespoerselmottatt.createForespoerselMottattRiver
import no.nav.helsearbeidsgiver.inntektsmelding.helsebro.createHelsebroRivers
Expand Down Expand Up @@ -253,6 +254,7 @@ abstract class EndToEndTest : ContainerTest() {
createForespoerselBesvartRivers()
createForespoerselMottattRiver()
createForespoerselForkastetRiver()
createForespoerselKastetTilInfotrygdRiver()
createHelsebroRivers(mockPriProducer)
createHentEksternImRiver(spinnKlient)
createHentInntektRiver(inntektClient)
Expand Down