Skip to content

Commit

Permalink
Publiser meldinger med Kafka-key i servicer (#788)
Browse files Browse the repository at this point in the history
* Publiser meldinger med Kafka-key i servicer

* Presiser at fnr tilhører sykmeldt
  • Loading branch information
bjerga authored Nov 25, 2024
1 parent 5c68103 commit ed918d9
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class AktiveOrgnrService(
steg0: Steg0,
) {
rapid.publish(
key = steg0.sykmeldtFnr,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.ARBEIDSGIVERE.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand All @@ -106,6 +107,7 @@ class AktiveOrgnrService(
)

rapid.publish(
key = steg0.sykmeldtFnr,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_ARBEIDSFORHOLD.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand All @@ -116,6 +118,7 @@ class AktiveOrgnrService(
)

rapid.publish(
key = steg0.sykmeldtFnr,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_PERSONER.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand Down Expand Up @@ -144,6 +147,7 @@ class AktiveOrgnrService(
utfoerSteg2(data, steg0, steg1, Steg2(emptyMap()))
} else {
rapid.publish(
key = steg0.sykmeldtFnr,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_VIRKSOMHET_NAVN.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class BerikInntektsmeldingService(
) {
rapid
.publish(
key = steg0.skjema.forespoerselId,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_TRENGER_IM.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand All @@ -120,6 +121,7 @@ class BerikInntektsmeldingService(
) {
rapid
.publish(
key = steg0.skjema.forespoerselId,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_VIRKSOMHET_NAVN.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand All @@ -138,6 +140,7 @@ class BerikInntektsmeldingService(
) {
rapid
.publish(
key = steg0.skjema.forespoerselId,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_PERSONER.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand Down Expand Up @@ -187,6 +190,7 @@ class BerikInntektsmeldingService(

rapid
.publish(
key = steg0.skjema.forespoerselId,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.LAGRE_IM.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand Down Expand Up @@ -214,6 +218,7 @@ class BerikInntektsmeldingService(
if (!steg4.erDuplikat) {
val publisert =
rapid.publish(
key = steg0.skjema.forespoerselId,
Key.EVENT_NAME to EventName.INNTEKTSMELDING_MOTTATT.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Key.DATA to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import no.nav.helsearbeidsgiver.utils.json.toJson
import no.nav.helsearbeidsgiver.utils.wrapper.Fnr
import java.util.UUID

fun MessageContext.publish(vararg messageFields: Pair<Key, JsonElement>): JsonElement = publish(null, messageFields.toMap())

fun MessageContext.publish(
key: Fnr,
vararg messageFields: Pair<Key, JsonElement>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,6 @@ class RiverUtilsKtTest :

context("publish") {

test("vararg pairs (uten key)") {
val melding =
arrayOf(
Key.FORESPOERSEL_ID to UUID.randomUUID().toJson(),
Key.INNTEKTSMELDING to mockInntektsmeldingV1().toJson(Inntektsmelding.serializer()),
Key.FNR_LISTE to setOf("111", "333", "555").toJson(String.serializer()),
)

testRapid.publish(*melding)

verifySequence {
testRapid.publish(
withArg<String> {
it.parseJson().toMap() shouldContainExactly melding.toMap()
},
)
}
}

test("vararg pairs (fnr-key)") {
val key = Fnr.genererGyldig()
val melding =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class InnsendingService(
) {
rapid
.publish(
key = steg0.skjema.forespoerselId,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.LAGRE_IM_SKJEMA.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand All @@ -84,15 +85,15 @@ class InnsendingService(

if (!steg1.erDuplikat) {
val publisert =
rapid
.publish(
Key.EVENT_NAME to EventName.INNTEKTSMELDING_SKJEMA_LAGRET.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Key.DATA to
data
.plus(Key.INNSENDING_ID to steg1.innsendingId.toJson(Long.serializer()))
.toJson(),
)
rapid.publish(
key = steg0.skjema.forespoerselId,
Key.EVENT_NAME to EventName.INNTEKTSMELDING_SKJEMA_LAGRET.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Key.DATA to
data
.plus(Key.INNSENDING_ID to steg1.innsendingId.toJson(Long.serializer()))
.toJson(),
)

MdcUtils.withLogFields(
Log.event(EventName.INNTEKTSMELDING_SKJEMA_LAGRET),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class KvitteringService(
) {
val publisert =
rapid.publish(
key = steg0.forespoerselId,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_LAGRET_IM.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import java.util.UUID
data class Steg0(
val transaksjonId: UUID,
val orgnr: Orgnr,
val fnr: Fnr,
val sykmeldtFnr: Fnr,
val inntektsdato: LocalDate,
)

Expand All @@ -50,8 +50,8 @@ class InntektSelvbestemtService(
override fun lesSteg0(melding: Map<Key, JsonElement>): Steg0 =
Steg0(
transaksjonId = Key.KONTEKST_ID.les(UuidSerializer, melding),
fnr = Key.FNR.les(Fnr.serializer(), melding),
orgnr = Key.ORGNRUNDERENHET.les(Orgnr.serializer(), melding),
sykmeldtFnr = Key.FNR.les(Fnr.serializer(), melding),
inntektsdato = Key.INNTEKTSDATO.les(LocalDateSerializer, melding),
)

Expand All @@ -66,6 +66,7 @@ class InntektSelvbestemtService(
) {
val publisert =
rapid.publish(
key = steg0.sykmeldtFnr,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_INNTEKT.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand All @@ -74,7 +75,7 @@ class InntektSelvbestemtService(
.plus(
mapOf(
Key.ORGNRUNDERENHET to steg0.orgnr.toJson(),
Key.FNR to steg0.fnr.toJson(),
Key.FNR to steg0.sykmeldtFnr.toJson(),
Key.INNTEKTSDATO to steg0.inntektsdato.toJson(),
),
).toJson(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class InntektService(
) {
rapid
.publish(
key = steg0.forespoerselId,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_TRENGER_IM.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand All @@ -96,6 +97,7 @@ class InntektService(
) {
rapid
.publish(
key = steg0.forespoerselId,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_INNTEKT.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class HentDataTilPaaminnelseService(
}

rapid.publish(
key = steg0.forespoerselId,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_TRENGER_IM.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand All @@ -71,17 +72,17 @@ class HentDataTilPaaminnelseService(
steg0: Steg0,
steg1: Steg1,
) {
rapid
.publish(
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_VIRKSOMHET_NAVN.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Key.DATA to
data
.plus(
Key.ORGNR_UNDERENHETER to setOf(steg1.forespoersel.orgnr).toJson(String.serializer()),
).toJson(),
)
rapid.publish(
key = steg0.forespoerselId,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_VIRKSOMHET_NAVN.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Key.DATA to
data
.plus(
Key.ORGNR_UNDERENHETER to setOf(steg1.forespoersel.orgnr).toJson(String.serializer()),
).toJson(),
)
}

override fun utfoerSteg2(
Expand All @@ -98,6 +99,7 @@ class HentDataTilPaaminnelseService(
val orgNavn = steg2.orgnrMedNavn[steg1.forespoersel.orgnr.let(::Orgnr)] ?: ORG_NAVN_DEFAULT

rapid.publish(
key = steg0.forespoerselId,
Key.EVENT_NAME to EventName.OPPGAVE_ENDRE_PAAMINNELSE_REQUESTED.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Key.DATA to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class HentDataTilSakOgOppgaveService(
}

rapid.publish(
key = steg0.forespoerselId,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_VIRKSOMHET_NAVN.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand All @@ -91,17 +92,17 @@ class HentDataTilSakOgOppgaveService(
steg0: Steg0,
steg1: Steg1,
) {
rapid
.publish(
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_PERSONER.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Key.DATA to
data
.plus(
Key.FNR_LISTE to setOf(steg0.forespoersel.fnr).toJson(String.serializer()),
).toJson(),
)
rapid.publish(
key = steg0.forespoerselId,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_PERSONER.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Key.DATA to
data
.plus(
Key.FNR_LISTE to setOf(steg0.forespoersel.fnr).toJson(String.serializer()),
).toJson(),
)
}

override fun utfoerSteg2(
Expand All @@ -119,6 +120,7 @@ class HentDataTilSakOgOppgaveService(
val sykmeldt = steg2.personer[steg0.forespoersel.fnr.let(::Fnr)] ?: personDefault(steg0.forespoersel.fnr.let(::Fnr))

rapid.publish(
key = steg0.forespoerselId,
Key.EVENT_NAME to EventName.SAK_OG_OPPGAVE_OPPRETT_REQUESTED.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Key.DATA to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class HentSelvbestemtImService(
) {
val publisert =
rapid.publish(
key = steg0.selvbestemtId,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_SELVBESTEMT_IM.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class LagreSelvbestemtImService(
kontrollerSkjema(steg0.skjema)

rapid.publish(
key = steg0.skjema.sykmeldtFnr,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_VIRKSOMHET_NAVN.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand All @@ -140,6 +141,7 @@ class LagreSelvbestemtImService(
)

rapid.publish(
key = steg0.skjema.sykmeldtFnr,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_PERSONER.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand All @@ -156,6 +158,7 @@ class LagreSelvbestemtImService(
)

rapid.publish(
key = steg0.skjema.sykmeldtFnr,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_ARBEIDSFORHOLD.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand Down Expand Up @@ -198,6 +201,7 @@ class LagreSelvbestemtImService(
if (erAktivtArbeidsforhold) {
rapid
.publish(
key = inntektsmelding.type.id,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.LAGRE_SELVBESTEMT_IM.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand Down Expand Up @@ -234,6 +238,7 @@ class LagreSelvbestemtImService(
AarsakInnsending.Ny -> {
rapid
.publish(
key = steg2.inntektsmelding.type.id,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.OPPRETT_SELVBESTEMT_SAK.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand Down Expand Up @@ -270,6 +275,7 @@ class LagreSelvbestemtImService(
if (!steg2.erDuplikat) {
val publisert =
rapid.publish(
key = steg2.inntektsmelding.type.id,
Key.EVENT_NAME to EventName.SELVBESTEMT_IM_LAGRET.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Key.DATA to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class TilgangForespoerselService(
) {
rapid
.publish(
key = steg0.forespoerselId,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.HENT_TRENGER_IM.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand All @@ -99,6 +100,7 @@ class TilgangForespoerselService(
) {
rapid
.publish(
key = steg0.forespoerselId,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.TILGANGSKONTROLL.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class TilgangOrgService(
) {
rapid
.publish(
key = steg0.fnr,
Key.EVENT_NAME to eventName.toJson(),
Key.BEHOV to BehovType.TILGANGSKONTROLL.toJson(),
Key.KONTEKST_ID to steg0.transaksjonId.toJson(),
Expand Down
Loading

0 comments on commit ed918d9

Please sign in to comment.