Skip to content

Commit

Permalink
Merge branch 'main' into dev/altinn-maskinporten
Browse files Browse the repository at this point in the history
  • Loading branch information
mettok committed Jul 18, 2024
2 parents dad814d + e67290d commit 8869770
Show file tree
Hide file tree
Showing 21 changed files with 558 additions and 470 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ class InnsendingProducer(
}

fun publish(
clientId: UUID,
transaksjonId: UUID,
forespoerselId: UUID,
request: Innsending,
arbeidsgiverFnr: Fnr,
) {
rapid
.publish(
Key.EVENT_NAME to EventName.INSENDING_STARTED.toJson(),
Key.CLIENT_ID to clientId.toJson(),
Key.UUID to transaksjonId.toJson(),
Key.DATA to "".toJson(),
Key.FORESPOERSEL_ID to forespoerselId.toJson(),
Key.ORGNRUNDERENHET to request.orgnrUnderenhet.toJson(),
Key.IDENTITETSNUMMER to request.identitetsnummer.toJson(),
Key.ARBEIDSGIVER_ID to arbeidsgiverFnr.toJson(),
Key.SKJEMA_INNTEKTSMELDING to request.toJson(Innsending.serializer()),
).also {
logger.info("Publiserte til kafka forespørselId: $forespoerselId og clientId=$clientId")
logger.info("Publiserte til kafka forespørselId: $forespoerselId og transaksjonId=$transaksjonId")
sikkerLogger.info("Publiserte til kafka forespørselId: $forespoerselId json=${it.toPretty()}")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fun Route.innsendingRoute(
.register()

post(Routes.INNSENDING + "/{forespoerselId}") {
val clientId = UUID.randomUUID()
val transaksjonId = UUID.randomUUID()

val forespoerselId =
call.parameters["forespoerselId"]
Expand All @@ -73,10 +73,9 @@ fun Route.innsendingRoute(

request.validate()
val innloggerFnr = call.request.lesFnrFraAuthToken()
producer.publish(clientId, forespoerselId, request, innloggerFnr)
logger.info("Publiserte til rapid med forespørselId: $forespoerselId og clientId=$clientId")
producer.publish(transaksjonId, forespoerselId, request, innloggerFnr)

val resultatJson = redisPoller.hent(clientId).fromJson(ResultJson.serializer())
val resultatJson = redisPoller.hent(transaksjonId).fromJson(ResultJson.serializer())
sikkerLogger.info("Fikk resultat for innsending:\n$resultatJson")

if (resultatJson.success != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@ class InntektProducer(
}

fun publish(
clientId: UUID,
transaksjonId: UUID,
request: InntektRequest,
) {
MdcUtils.withLogFields(
Log.klasse(this),
Log.event(EventName.INNTEKT_REQUESTED),
Log.clientId(clientId),
Log.clientId(transaksjonId),
Log.forespoerselId(request.forespoerselId),
) {
rapid
.publish(
Key.EVENT_NAME to EventName.INNTEKT_REQUESTED.toJson(),
Key.CLIENT_ID to clientId.toJson(),
Key.UUID to transaksjonId.toJson(),
Key.DATA to "".toJson(),
Key.FORESPOERSEL_ID to request.forespoerselId.toJson(),
Key.SKJAERINGSTIDSPUNKT to request.skjaeringstidspunkt.toJson(),
).also { json ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fun Route.inntektRoute(
val inntektProducer = InntektProducer(rapid)

post(Routes.INNTEKT) {
val clientId = UUID.randomUUID()
val transaksjonId = UUID.randomUUID()

val request = call.receive<InntektRequest>()

Expand All @@ -47,9 +47,9 @@ fun Route.inntektRoute(
}

try {
inntektProducer.publish(clientId, request)
inntektProducer.publish(transaksjonId, request)

val resultatJson = redisPoller.hent(clientId).fromJson(ResultJson.serializer())
val resultatJson = redisPoller.hent(transaksjonId).fromJson(ResultJson.serializer())
sikkerLogger.info("Fikk inntektresultat:\n$resultatJson")

val resultat = resultatJson.success?.fromJson(Inntekt.serializer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ class InnsendingProducerTest :
val producer = InnsendingProducer(testRapid)

test("publiserer melding på forventet format") {
val clientId = UUID.randomUUID()
val transaksjonId = UUID.randomUUID()
val forespoerselId = UUID.randomUUID()
val avsenderFnr = Fnr.genererGyldig()

producer.publish(clientId, forespoerselId, gyldigInnsendingRequest, avsenderFnr)
producer.publish(transaksjonId, forespoerselId, gyldigInnsendingRequest, avsenderFnr)

testRapid.inspektør.size shouldBeExactly 1
testRapid.firstMessage().toMap() shouldContainExactly
mapOf(
Key.EVENT_NAME to EventName.INSENDING_STARTED.toJson(),
Key.CLIENT_ID to clientId.toJson(),
Key.UUID to transaksjonId.toJson(),
Key.DATA to "".toJson(),
Key.FORESPOERSEL_ID to forespoerselId.toJson(),
Key.ORGNRUNDERENHET to gyldigInnsendingRequest.orgnrUnderenhet.toJson(),
Key.IDENTITETSNUMMER to gyldigInnsendingRequest.identitetsnummer.toJson(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.nav.helsearbeidsgiver.inntektsmelding.api.inntekt

import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.maps.shouldContainAll
import io.kotest.matchers.maps.shouldContainExactly
import no.nav.helse.rapids_rivers.testsupport.TestRapid
import no.nav.helsearbeidsgiver.felles.EventName
import no.nav.helsearbeidsgiver.felles.Key
Expand All @@ -18,17 +18,18 @@ class InntektProducerTest :
val inntektProducer = InntektProducer(testRapid)

test("Publiserer melding på forventet format") {
val clientId = UUID.randomUUID()
val transaksjonId = UUID.randomUUID()
val request = InntektRequest(UUID.randomUUID(), 18.januar)

inntektProducer.publish(clientId, request)
inntektProducer.publish(transaksjonId, request)

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

publisert shouldContainAll
publisert shouldContainExactly
mapOf(
Key.EVENT_NAME to EventName.INNTEKT_REQUESTED.toJson(),
Key.CLIENT_ID to clientId.toJson(),
Key.UUID to transaksjonId.toJson(),
Key.DATA to "".toJson(),
Key.FORESPOERSEL_ID to request.forespoerselId.toJson(),
Key.SKJAERINGSTIDSPUNKT to request.skjaeringstidspunkt.toJson(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ enum class RedisPrefix {
InntektService,
KvitteringService,
LagreSelvbestemtImService,
ManuellOpprettSakService,
OpprettOppgaveService,
OpprettSakService,
SpinnService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,47 @@ abstract class ServiceMed3Steg<S0, S1, S2, S3> : ServiceMed2Steg<S0, S1, S2>() {
}
}

abstract class ServiceMed4Steg<S0, S1, S2, S3, S4> : ServiceMed3Steg<S0, S1, S2, S3>() {
protected abstract fun lesSteg4(melding: Map<Key, JsonElement>): S4

protected abstract fun utfoerSteg4(
steg0: S0,
steg1: S1,
steg2: S2,
steg3: S3,
steg4: S4,
)

override fun onData(melding: Map<Key, JsonElement>) {
runCatching {
Quintuple(
first = lesSteg0(melding),
second = lesSteg1(melding),
third = lesSteg2(melding),
fourth = lesSteg3(melding),
fifth = lesSteg4(melding),
)
}.onSuccess {
medLoggfelt(it.first) {
utfoerSteg4(it.first, it.second, it.third, it.fourth, it.fifth)
}
}.onFailure {
super.onData(melding)
}
}
}

private class Quadruple<S0, S1, S2, S3>(
val first: S0,
val second: S1,
val third: S2,
val fourth: S3,
)

private class Quintuple<S0, S1, S2, S3, S4>(
val first: S0,
val second: S1,
val third: S2,
val fourth: S3,
val fifth: S4,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import no.nav.helse.rapids_rivers.RapidApplication
import no.nav.helse.rapids_rivers.RapidsConnection
import no.nav.helsearbeidsgiver.felles.rapidsrivers.redis.RedisConnection
import no.nav.helsearbeidsgiver.felles.rapidsrivers.redis.RedisPrefix
import no.nav.helsearbeidsgiver.felles.rapidsrivers.redis.RedisStore
import no.nav.helsearbeidsgiver.felles.rapidsrivers.redis.RedisStoreClassSpecific
import no.nav.helsearbeidsgiver.felles.rapidsrivers.registerShutdownLifecycle
import no.nav.helsearbeidsgiver.felles.rapidsrivers.service.ServiceRiver
Expand All @@ -13,25 +12,25 @@ import no.nav.helsearbeidsgiver.utils.log.logger
private val logger = "helsearbeidsgiver-im-innsending".logger()

fun main() {
val redisStore = RedisStore(Env.redisUrl)
val redisConnection = RedisConnection(Env.redisUrl)

RapidApplication
.create(System.getenv())
.createInnsending(redisStore, redisConnection)
.createInnsending(redisConnection)
.registerShutdownLifecycle {
redisStore.shutdown()
redisConnection.close()
}.start()
}

fun RapidsConnection.createInnsending(
redisStore: RedisStore,
redisConnection: RedisConnection,
): RapidsConnection =
fun RapidsConnection.createInnsending(redisConnection: RedisConnection): RapidsConnection =
also {
logger.info("Starter ${InnsendingService::class.simpleName}...")
InnsendingService(this, redisStore)
ServiceRiver(
InnsendingService(
rapid = this,
redisStore = RedisStoreClassSpecific(redisConnection, RedisPrefix.InnsendingService),
),
).connect(this)

logger.info("Starter ${KvitteringService::class.simpleName}...")
ServiceRiver(
Expand Down
Loading

0 comments on commit 8869770

Please sign in to comment.