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

Fjern mellomledd for ferdigstilling av sak og oppgave #762

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ fun main() {

RapidApplication
.create(System.getenv())
.createForespoerselBesvartRivers()
.createForespoerselBesvartRiver()
.start()

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

fun RapidsConnection.createForespoerselBesvartRivers(): RapidsConnection =
fun RapidsConnection.createForespoerselBesvartRiver(): RapidsConnection =
also {
logger.info("Starter ${ForespoerselBesvartFraSimbaRiver::class.simpleName}...")
ForespoerselBesvartFraSimbaRiver().connect(this)

logger.info("Starter ${ForespoerselBesvartFraSpleisRiver::class.simpleName}...")
ForespoerselBesvartFraSpleisRiver(this).connect(this)
logger.info("Starter ${ForespoerselBesvartRiver::class.simpleName}...")
ForespoerselBesvartRiver(this).connect(this)
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import no.nav.helsearbeidsgiver.felles.rapidsrivers.pritopic.toPretty
import no.nav.helsearbeidsgiver.felles.rapidsrivers.publish
import no.nav.helsearbeidsgiver.felles.rapidsrivers.river.PriObjectRiver
import no.nav.helsearbeidsgiver.felles.utils.Log
import no.nav.helsearbeidsgiver.utils.collection.mapValuesNotNull
import no.nav.helsearbeidsgiver.utils.json.serializer.UuidSerializer
import no.nav.helsearbeidsgiver.utils.json.toJson
import no.nav.helsearbeidsgiver.utils.json.toPretty
Expand All @@ -22,29 +23,29 @@ import no.nav.helsearbeidsgiver.utils.log.logger
import no.nav.helsearbeidsgiver.utils.log.sikkerLogger
import java.util.UUID

data class BesvartSpleisMelding(
data class BesvartMelding(
val notisType: Pri.NotisType,
val transaksjonId: UUID,
val forespoerselId: UUID,
val spinnInntektsmeldingId: UUID?,
)

/** Tar imot notifikasjon om at en forespørsel om arbeidsgiveropplysninger er besvart. */
class ForespoerselBesvartFraSpleisRiver(
class ForespoerselBesvartRiver(
private val rapid: RapidsConnection,
) : PriObjectRiver<BesvartSpleisMelding>() {
) : PriObjectRiver<BesvartMelding>() {
private val logger = logger()
private val sikkerLogger = sikkerLogger()

override fun les(json: Map<Pri.Key, JsonElement>): BesvartSpleisMelding =
BesvartSpleisMelding(
override fun les(json: Map<Pri.Key, JsonElement>): BesvartMelding =
BesvartMelding(
notisType = Pri.Key.NOTIS.krev(Pri.NotisType.FORESPOERSEL_BESVART, Pri.NotisType.serializer(), json),
transaksjonId = UUID.randomUUID(),
forespoerselId = Pri.Key.FORESPOERSEL_ID.les(UuidSerializer, json),
spinnInntektsmeldingId = Pri.Key.SPINN_INNTEKTSMELDING_ID.lesOrNull(UuidSerializer, json),
)

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

Expand All @@ -70,10 +71,21 @@ class ForespoerselBesvartFraSpleisRiver(

Metrics.forespoerslerBesvartFraSpleis.inc()

return forespoerselBesvartMelding(transaksjonId, forespoerselId)
return mapOf(
Key.EVENT_NAME to EventName.FORESPOERSEL_BESVART.toJson(),
Key.UUID to transaksjonId.toJson(),
// TODO slett etter overgangsfase
Key.FORESPOERSEL_ID to forespoerselId.toJson(),
Key.DATA to
mapOf(
Key.FORESPOERSEL_ID to forespoerselId.toJson(),
Key.SPINN_INNTEKTSMELDING_ID to spinnInntektsmeldingId?.toJson(),
).mapValuesNotNull { it }
.toJson(),
Comment on lines +79 to +84
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smyger med denne for å gjøre forenklinger i bro-spinn senere.

)
}

override fun BesvartSpleisMelding.haandterFeil(
override fun BesvartMelding.haandterFeil(
json: Map<Pri.Key, JsonElement>,
error: Throwable,
): Map<Key, JsonElement>? {
Expand All @@ -85,9 +97,9 @@ class ForespoerselBesvartFraSpleisRiver(
return null
}

override fun BesvartSpleisMelding.loggfelt(): Map<String, String> =
override fun BesvartMelding.loggfelt(): Map<String, String> =
mapOf(
Log.klasse(this@ForespoerselBesvartFraSpleisRiver),
Log.klasse(this@ForespoerselBesvartRiver),
Log.priNotis(notisType),
Log.transaksjonId(transaksjonId),
Log.forespoerselId(forespoerselId),
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package no.nav.helsearbeidsgiver.inntektsmelding.forespoerselbesvart

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.message
import no.nav.helsearbeidsgiver.felles.test.rapidsrivers.sendJson
import no.nav.helsearbeidsgiver.utils.json.toJson
import java.util.UUID

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

ForespoerselBesvartRiver(testRapid).connect(testRapid)

beforeEach {
testRapid.reset()
clearAllMocks()
}

test("Ved notis om besvart forespørsel publiseres behov om å hente notifikasjon-ID-er uten IM-ID fra Spinn") {
val forespoerselId = UUID.randomUUID()
val forventetPublisert =
mapOf(
Key.EVENT_NAME to EventName.FORESPOERSEL_BESVART.toJson(),
Key.UUID to UUID.randomUUID().toJson(),
Key.FORESPOERSEL_ID to forespoerselId.toJson(),
Key.DATA to
mapOf(
Key.FORESPOERSEL_ID to forespoerselId.toJson(),
).toJson(),
)

testRapid.sendJson(
Pri.Key.NOTIS to Pri.NotisType.FORESPOERSEL_BESVART.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)
}

test("Ved notis om besvart forespørsel publiseres behov om å hente notifikasjon-ID-er med IM-ID fra Spinn") {
val forespoerselId = UUID.randomUUID()
val spinnInntektsmeldingId = UUID.randomUUID()
val forventetPublisert =
mapOf(
Key.EVENT_NAME to EventName.FORESPOERSEL_BESVART.toJson(),
Key.UUID to UUID.randomUUID().toJson(),
Key.FORESPOERSEL_ID to forespoerselId.toJson(),
Key.DATA to
mapOf(
Key.FORESPOERSEL_ID to forespoerselId.toJson(),
Key.SPINN_INNTEKTSMELDING_ID to spinnInntektsmeldingId.toJson(),
).toJson(),
)

testRapid.sendJson(
Pri.Key.NOTIS to Pri.NotisType.FORESPOERSEL_BESVART.toJson(Pri.NotisType.serializer()),
Pri.Key.FORESPOERSEL_ID to forespoerselId.toJson(),
Pri.Key.SPINN_INNTEKTSMELDING_ID to spinnInntektsmeldingId.toJson(),
)

testRapid.inspektør.size shouldBeExactly 2

val publisert = testRapid.message(1).toMap()

publisert shouldContainKey Key.UUID

publisert.minus(Key.UUID) shouldContainExactly forventetPublisert.minus(Key.UUID)
}
})
Loading