Skip to content

Commit

Permalink
Merge branch 'main' into dev/erstatt-trenger
Browse files Browse the repository at this point in the history
  • Loading branch information
bjerga committed Jun 25, 2024
2 parents 4e064e2 + c771851 commit ca8d3bd
Show file tree
Hide file tree
Showing 62 changed files with 583 additions and 480 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import no.nav.helsearbeidsgiver.felles.rapidsrivers.publish
import no.nav.helsearbeidsgiver.felles.rapidsrivers.redis.RedisKey
import no.nav.helsearbeidsgiver.felles.rapidsrivers.redis.RedisStore
import no.nav.helsearbeidsgiver.felles.utils.Log
import no.nav.helsearbeidsgiver.felles.utils.filterOrgnr
import no.nav.helsearbeidsgiver.felles.utils.orgnrMedHistoriskArbeidsforhold
import no.nav.helsearbeidsgiver.utils.json.fromJson
import no.nav.helsearbeidsgiver.utils.json.serializer.UuidSerializer
import no.nav.helsearbeidsgiver.utils.json.serializer.list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import no.nav.helsearbeidsgiver.felles.Ansettelsesperiode
import no.nav.helsearbeidsgiver.felles.Arbeidsforhold
import no.nav.helsearbeidsgiver.felles.Arbeidsgiver
import no.nav.helsearbeidsgiver.felles.PeriodeNullable
import no.nav.helsearbeidsgiver.felles.utils.orgnrMedHistoriskArbeidsforhold
import java.time.LocalDate
import java.time.LocalDateTime

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import no.nav.helsearbeidsgiver.felles.Key
import no.nav.helsearbeidsgiver.felles.json.toJson
import no.nav.helsearbeidsgiver.felles.rapidsrivers.publish
import no.nav.helsearbeidsgiver.felles.utils.Log
import no.nav.helsearbeidsgiver.felles.utils.randomUuid
import no.nav.helsearbeidsgiver.inntektsmelding.api.logger
import no.nav.helsearbeidsgiver.inntektsmelding.api.sikkerLogger
import no.nav.helsearbeidsgiver.utils.json.toJson
Expand All @@ -20,8 +19,7 @@ class AktiveOrgnrProducer(
init {
logger.info("Starter ${AktiveOrgnrProducer::class.simpleName}...")
}
fun publish(arbeidsgiverFnr: String, arbeidstagerFnr: String): UUID {
val clientId = randomUuid()
fun publish(clientId: UUID, arbeidsgiverFnr: String, arbeidstagerFnr: String) {
MdcUtils.withLogFields(
Log.klasse(this),
Log.event(EventName.AKTIVE_ORGNR_REQUESTED),
Expand All @@ -40,6 +38,5 @@ class AktiveOrgnrProducer(
}
}
}
return clientId
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ import no.nav.helsearbeidsgiver.inntektsmelding.api.sikkerLogger
import no.nav.helsearbeidsgiver.inntektsmelding.api.utils.respondInternalServerError
import no.nav.helsearbeidsgiver.utils.json.fromJson
import no.nav.helsearbeidsgiver.utils.json.toJson
import java.util.UUID

fun Route.aktiveOrgnrRoute(
connection: RapidsConnection,
redis: RedisPoller
) {
val aktiveOrgnrProducer = AktiveOrgnrProducer(connection)
post(Routes.AKTIVEORGNR) {
val clientId = UUID.randomUUID()

try {
val request = call.receive<AktiveOrgnrRequest>()
val arbeidsgiverFnr = call.request.lesFnrFraAuthToken()

val clientId = aktiveOrgnrProducer.publish(arbeidsgiverFnr = arbeidsgiverFnr, arbeidstagerFnr = request.identitetsnummer)
aktiveOrgnrProducer.publish(clientId, arbeidsgiverFnr = arbeidsgiverFnr, arbeidstagerFnr = request.identitetsnummer)

val resultatJson = redis.hent(clientId).fromJson(ResultJson.serializer())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,33 @@ class Tilgangskontroll(
request: ApplicationRequest,
forespoerselId: UUID
) {
validerTilgang(request, forespoerselId.toString()) { fnr ->
tilgangProducer.publishForespoerselId(forespoerselId, fnr)
validerTilgang(request, forespoerselId.toString()) { clientId, fnr ->
tilgangProducer.publishForespoerselId(clientId, fnr, forespoerselId)
}
}

fun validerTilgangTilOrg(
request: ApplicationRequest,
orgnr: String
) {
validerTilgang(request, orgnr) { fnr ->
tilgangProducer.publishOrgnr(orgnr, fnr)
validerTilgang(request, orgnr) { clientId, fnr ->
tilgangProducer.publishOrgnr(clientId, fnr, orgnr)
}
}

private fun validerTilgang(
request: ApplicationRequest,
cacheKeyPostfix: String,
publish: (String) -> UUID
publish: (UUID, String) -> Unit
) {
val clientId = UUID.randomUUID()
val innloggerFnr = request.lesFnrFraAuthToken()

val tilgang = runBlocking {
cache.get("$innloggerFnr:$cacheKeyPostfix") {
logger.info("Fant ikke tilgang i cache, ber om tilgangskontroll.")

val clientId = publish(innloggerFnr)
publish(clientId, innloggerFnr)

val resultat = redisPoller.hent(clientId)
.fromJson(TilgangResultat.serializer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class HentForespoerselProducer(
logger.info("Starter ${HentForespoerselProducer::class.simpleName}...")
}

fun publish(request: HentForespoerselRequest, arbeidsgiverFnr: String): UUID {
val transaksjonId = UUID.randomUUID()

fun publish(transaksjonId: UUID, request: HentForespoerselRequest, arbeidsgiverFnr: String) {
rapid.publish(
Key.EVENT_NAME to EventName.TRENGER_REQUESTED.toJson(EventName.serializer()),
Key.UUID to transaksjonId.toString().toJson(),
Expand All @@ -31,7 +29,5 @@ class HentForespoerselProducer(
logger.info("Publiserte trenger behov med transaksjonId=$transaksjonId")
sikkerLogger.info("Publiserte trenger behov med transaksjonId=$transaksjonId json=${it.toPretty()}")
}

return transaksjonId
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import no.nav.helsearbeidsgiver.inntektsmelding.api.validation.ValidationError
import no.nav.helsearbeidsgiver.inntektsmelding.api.validation.ValidationResponse
import no.nav.helsearbeidsgiver.utils.json.fromJson
import no.nav.helsearbeidsgiver.utils.json.toJson
import java.util.UUID

fun Route.hentForespoerselRoute(
rapid: RapidsConnection,
Expand All @@ -43,6 +44,8 @@ fun Route.hentForespoerselRoute(

setOf(Routes.TRENGER, Routes.HENT_FORESPOERSEL).forEach { routeUrl ->
post(routeUrl) {
val transaksjonId = UUID.randomUUID()

val requestTimer = requestLatency.startTimer()
runCatching {
receive(HentForespoerselRequest.serializer())
Expand All @@ -54,7 +57,7 @@ fun Route.hentForespoerselRoute(

val arbeidsgiverFnr = call.request.lesFnrFraAuthToken()

val transaksjonId = hentForespoerselProducer.publish(request, arbeidsgiverFnr)
hentForespoerselProducer.publish(transaksjonId, request, arbeidsgiverFnr)

val resultatJson = redisPoller.hent(transaksjonId).fromJson(ResultJson.serializer())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class HentSelvbestemtImProducer(
logger.info("Starter ${HentSelvbestemtImProducer::class.simpleName}...")
}

fun publish(selvbestemtId: UUID): UUID {
val transaksjonId = UUID.randomUUID()

fun publish(transaksjonId: UUID, selvbestemtId: UUID) {
MdcUtils.withLogFields(
Log.event(EventName.SELVBESTEMT_IM_REQUESTED),
Log.transaksjonId(transaksjonId),
Expand All @@ -39,7 +37,5 @@ class HentSelvbestemtImProducer(
sikkerLogger.info("Publiserte til kafka:\n${it.toPretty()}")
}
}

return transaksjonId
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ fun Route.hentSelvbestemtImRoute(
val producer = HentSelvbestemtImProducer(rapid)

get(Routes.SELVBESTEMT_INNTEKTSMELDING_MED_ID) {
val transaksjonId = UUID.randomUUID()

val selvbestemtId = call.parameters["selvbestemtId"]
?.runCatching(UUID::fromString)
?.getOrNull()
Expand All @@ -48,9 +50,10 @@ fun Route.hentSelvbestemtImRoute(
} else {
MdcUtils.withLogFields(
Log.apiRoute(Routes.SELVBESTEMT_INNTEKTSMELDING_MED_ID),
Log.selvbestemtId(selvbestemtId)
Log.selvbestemtId(selvbestemtId),
Log.transaksjonId(transaksjonId)
) {
val transaksjonId = producer.publish(selvbestemtId)
producer.publish(transaksjonId, selvbestemtId)

MdcUtils.withLogFields(
Log.transaksjonId(transaksjonId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ class InnsendingProducer(
logger.info("Starter ${InnsendingProducer::class.simpleName}...")
}

fun publish(forespoerselId: UUID, request: Innsending, arbeidsgiverFnr: String): UUID {
val clientId = UUID.randomUUID()

fun publish(clientId: UUID, forespoerselId: UUID, request: Innsending, arbeidsgiverFnr: String) {
rapid.publish(
Key.EVENT_NAME to EventName.INSENDING_STARTED.toJson(),
Key.CLIENT_ID to clientId.toJson(),
Expand All @@ -35,7 +33,5 @@ class InnsendingProducer(
logger.info("Publiserte til kafka forespørselId: $forespoerselId og clientId=$clientId")
sikkerLogger.info("Publiserte til kafka forespørselId: $forespoerselId json=${it.toPretty()}")
}

return clientId
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ fun Route.innsendingRoute(
.register()

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

val forespoerselId = call.parameters["forespoerselId"]
?.runCatching(UUID::fromString)
?.getOrNull()
Expand All @@ -67,7 +69,7 @@ fun Route.innsendingRoute(

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

val resultatJson = redisPoller.hent(clientId).fromJson(ResultJson.serializer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import no.nav.helsearbeidsgiver.felles.Key
import no.nav.helsearbeidsgiver.felles.json.toJson
import no.nav.helsearbeidsgiver.felles.rapidsrivers.publish
import no.nav.helsearbeidsgiver.felles.utils.Log
import no.nav.helsearbeidsgiver.felles.utils.randomUuid
import no.nav.helsearbeidsgiver.inntektsmelding.api.logger
import no.nav.helsearbeidsgiver.inntektsmelding.api.sikkerLogger
import no.nav.helsearbeidsgiver.utils.json.toJson
Expand All @@ -21,9 +20,7 @@ class InntektProducer(
logger.info("Starter ${InntektProducer::class.simpleName}...")
}

fun publish(request: InntektRequest): UUID {
val clientId = randomUuid()

fun publish(clientId: UUID, request: InntektRequest) {
MdcUtils.withLogFields(
Log.klasse(this),
Log.event(EventName.INNTEKT_REQUESTED),
Expand All @@ -43,7 +40,5 @@ class InntektProducer(
}
}
}

return clientId
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import no.nav.helsearbeidsgiver.inntektsmelding.api.utils.respondForbidden
import no.nav.helsearbeidsgiver.inntektsmelding.api.utils.respondInternalServerError
import no.nav.helsearbeidsgiver.utils.json.fromJson
import no.nav.helsearbeidsgiver.utils.json.toJson
import java.util.UUID

// TODO Mangler tester
fun Route.inntektRoute(
Expand All @@ -34,6 +35,8 @@ fun Route.inntektRoute(
val inntektProducer = InntektProducer(rapid)

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

val request = call.receive<InntektRequest>()

tilgangskontroll.validerTilgangTilForespoersel(call.request, request.forespoerselId)
Expand All @@ -44,7 +47,7 @@ fun Route.inntektRoute(
}

try {
val clientId = inntektProducer.publish(request)
inntektProducer.publish(clientId, request)

val resultatJson = redisPoller.hent(clientId).fromJson(ResultJson.serializer())
sikkerLogger.info("Fikk inntektresultat:\n$resultatJson")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ class InntektSelvbestemtProducer(
logger.info("Starter ${InntektSelvbestemtProducer::class.simpleName}...")
}

fun publish(request: InntektSelvbestemtRequest): UUID {
val transaksjonId = UUID.randomUUID()

fun publish(transaksjonId: UUID, request: InntektSelvbestemtRequest) {
MdcUtils.withLogFields(
Log.klasse(this),
Log.event(EventName.INNTEKT_SELVBESTEMT_REQUESTED),
Expand All @@ -45,7 +43,5 @@ class InntektSelvbestemtProducer(
}
}
}

return transaksjonId
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import no.nav.helsearbeidsgiver.inntektsmelding.api.utils.respondForbidden
import no.nav.helsearbeidsgiver.inntektsmelding.api.utils.respondInternalServerError
import no.nav.helsearbeidsgiver.utils.json.fromJson
import no.nav.helsearbeidsgiver.utils.json.toJson
import java.util.UUID

fun Route.inntektSelvbestemtRoute(
rapid: RapidsConnection,
Expand All @@ -33,6 +34,8 @@ fun Route.inntektSelvbestemtRoute(
val inntektSelvbestemtProducer = InntektSelvbestemtProducer(rapid)

post(Routes.INNTEKT_SELVBESTEMT) {
val transaksjonId = UUID.randomUUID()

val request = call.receive<InntektSelvbestemtRequest>()

tilgangskontroll.validerTilgangTilOrg(call.request, request.orgnr.verdi)
Expand All @@ -43,7 +46,7 @@ fun Route.inntektSelvbestemtRoute(
}

try {
val transaksjonId = inntektSelvbestemtProducer.publish(request)
inntektSelvbestemtProducer.publish(transaksjonId, request)

val resultatJson = redisPoller.hent(transaksjonId).fromJson(ResultJson.serializer())
sikkerLogger.info("Fikk inntektsresultat for selvbestemt inntektsmelding:\n$resultatJson")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class KvitteringProducer(
logger.info("Starter ${KvitteringProducer::class.simpleName}...")
}

fun publish(foresporselId: UUID): UUID {
val clientId = UUID.randomUUID()
fun publish(clientId: UUID, foresporselId: UUID) {
val packet: JsonMessage = JsonMessage.newMessage(
mapOf(
Key.EVENT_NAME.str to EventName.KVITTERING_REQUESTED.name,
Expand All @@ -25,6 +24,5 @@ class KvitteringProducer(
)
rapid.publish(packet.toJson())
logger.info("Publiserte kvittering requested, forespørselid=$foresporselId")
return clientId
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ fun Route.kvitteringRoute(
.register()

get(Routes.KVITTERING) {
val clientId = UUID.randomUUID()

val forespoerselId = call.parameters["uuid"]
?.let(::fjernLedendeSlash)
?.runCatching(UUID::fromString)
Expand All @@ -71,7 +73,7 @@ fun Route.kvitteringRoute(
logger.info("Authorize took $it")
}

val clientId = kvitteringProducer.publish(forespoerselId)
kvitteringProducer.publish(clientId, forespoerselId)
val resultatJson = redisPoller.hent(clientId).fromJson(ResultJson.serializer())

sikkerLogger.info("Resultat for henting av kvittering for $forespoerselId: $resultatJson")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ class LagreSelvbestemtImProducer(
logger.info("Starter ${LagreSelvbestemtImProducer::class.simpleName}...")
}

fun publish(skjema: SkjemaInntektsmeldingSelvbestemt, avsenderFnr: String): UUID {
val clientId = UUID.randomUUID()

fun publish(clientId: UUID, skjema: SkjemaInntektsmeldingSelvbestemt, avsenderFnr: String) {
MdcUtils.withLogFields(
Log.event(EventName.SELVBESTEMT_IM_MOTTATT),
Log.clientId(clientId)
Expand All @@ -39,7 +37,5 @@ class LagreSelvbestemtImProducer(
sikkerLogger.info("Publiserte til kafka:\n${it.toPretty()}")
}
}

return clientId
}
}
Loading

0 comments on commit ca8d3bd

Please sign in to comment.