Skip to content

Commit

Permalink
Revert "Delete maxdate api (#602)" (#603)
Browse files Browse the repository at this point in the history
This reverts commit 38e399a.
  • Loading branch information
Vitenok authored Nov 18, 2024
1 parent 38e399a commit ed26f06
Show file tree
Hide file tree
Showing 35 changed files with 1,876 additions and 31 deletions.
21 changes: 21 additions & 0 deletions nais/alerts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,24 @@ spec:
labels:
namespace: team-esyfo
severity: warning
- alert: KAFKA INFOTRYGD CONSUMER LAG
expr: kafka_consumergroup_group_topic_sum_lag{topic="aap.sykepengedager.infotrygd.v1", group="esyfovarsel-group-infotrygd-01"} > 0
for: 15m
annotations:
summary: "esyfovarsel har ukonsumerte Kafkameldinger på topic aap.sykepengedager.infotrygd.v1"
action: "Finn ut hvorfor esyfovarsel har stoppet å konsumere fra topic"
labels:
namespace: team-esyfo
severity: warning
- alert: KAFKA UTBETALING CONSUMER LAG
expr: kafka_consumergroup_group_topic_sum_lag{topic="flex.ditt-sykefravaer-melding", group="esyfovarsel-group-utbetaling-spleis-01"} > 0
for: 15m
annotations:
summary: "esyfovarsel har ukonsumerte Kafkameldinger på topic tbd.utbetaling"
action: "Finn ut hvorfor esyfovarsel har stoppet å konsumere fra topic"
labels:
namespace: team-esyfo
severity: warning



41 changes: 41 additions & 0 deletions src/main/kotlin/no/nav/syfo/BootstrapApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ import no.nav.syfo.consumer.distribuerjournalpost.JournalpostdistribusjonConsume
import no.nav.syfo.consumer.dkif.DkifConsumer
import no.nav.syfo.consumer.narmesteLeder.NarmesteLederConsumer
import no.nav.syfo.consumer.narmesteLeder.NarmesteLederService
import no.nav.syfo.consumer.pdl.PdlConsumer
import no.nav.syfo.consumer.syfosmregister.SykmeldingerConsumer
import no.nav.syfo.consumer.veiledertilgang.VeilederTilgangskontrollConsumer
import no.nav.syfo.db.Database
import no.nav.syfo.db.DatabaseInterface
import no.nav.syfo.db.grantAccessToIAMUsers
import no.nav.syfo.job.closeExpiredMicrofrontendsJob
import no.nav.syfo.kafka.common.launchKafkaListener
import no.nav.syfo.kafka.consumers.infotrygd.InfotrygdKafkaConsumer
import no.nav.syfo.kafka.consumers.testdata.reset.TestdataResetConsumer
import no.nav.syfo.kafka.consumers.utbetaling.UtbetalingKafkaConsumer
import no.nav.syfo.kafka.consumers.varselbus.VarselBusKafkaConsumer
import no.nav.syfo.kafka.producers.brukernotifikasjoner.BrukernotifikasjonKafkaProducer
import no.nav.syfo.kafka.producers.dinesykmeldte.DineSykmeldteHendelseKafkaProducer
Expand All @@ -57,6 +61,7 @@ import no.nav.syfo.service.MerVeiledningVarselService
import no.nav.syfo.service.MotebehovVarselService
import no.nav.syfo.service.OppfolgingsplanVarselService
import no.nav.syfo.service.SenderFacade
import no.nav.syfo.service.SykepengerMaxDateService
import no.nav.syfo.service.SykmeldingService
import no.nav.syfo.service.TestdataResetService
import no.nav.syfo.service.VarselBusService
Expand Down Expand Up @@ -103,6 +108,7 @@ fun createEngineEnvironment(): ApplicationEngineEnvironment = applicationEngineE
database.grantAccessToIAMUsers()

val azureAdTokenConsumer = AzureAdTokenConsumer(env.authEnv)
val pdlConsumer = getPdlConsumer(env.urlEnv, azureAdTokenConsumer)
val dkifConsumer = getDkifConsumer(env.urlEnv, azureAdTokenConsumer)
val sykmeldingerConsumer = SykmeldingerConsumer(env.urlEnv, azureAdTokenConsumer)
val narmesteLederConsumer = NarmesteLederConsumer(env.urlEnv, azureAdTokenConsumer)
Expand Down Expand Up @@ -157,6 +163,7 @@ fun createEngineEnvironment(): ApplicationEngineEnvironment = applicationEngineE
val manglendeMedvirkningVarselService = ManglendeMedvirkningVarselService(senderFacade)
val oppfolgingsplanVarselService =
OppfolgingsplanVarselService(senderFacade, accessControlService, env.urlEnv.oppfolgingsplanerUrl)
val sykepengerMaxDateService = SykepengerMaxDateService(database, pdlConsumer)
val merVeiledningVarselService = MerVeiledningVarselService(
senderFacade = senderFacade,
env = env,
Expand Down Expand Up @@ -188,6 +195,9 @@ fun createEngineEnvironment(): ApplicationEngineEnvironment = applicationEngineE
merVeiledningVarselService
)

val veilederTilgangskontrollConsumer =
VeilederTilgangskontrollConsumer(env.urlEnv, azureAdTokenConsumer)

val testdataResetService = TestdataResetService(database, mikrofrontendService, senderFacade)

connector {
Expand All @@ -199,17 +209,27 @@ fun createEngineEnvironment(): ApplicationEngineEnvironment = applicationEngineE

serverModule(
env,
sykepengerMaxDateService,
mikrofrontendService,
veilederTilgangskontrollConsumer,
)

kafkaModule(
env,
varselBusService,
sykepengerMaxDateService,
testdataResetService,
)
}
}

private fun getPdlConsumer(urlEnv: UrlEnv, azureADConsumer: AzureAdTokenConsumer): PdlConsumer {
return when {
isLocal() -> PdlConsumer.LocalPdlConsumer(urlEnv, azureADConsumer)
else -> PdlConsumer(urlEnv, azureADConsumer)
}
}

private fun getDkifConsumer(urlEnv: UrlEnv, azureADConsumer: AzureAdTokenConsumer): DkifConsumer {
return when {
isLocal() -> DkifConsumer(urlEnv, azureADConsumer)
Expand All @@ -219,7 +239,9 @@ private fun getDkifConsumer(urlEnv: UrlEnv, azureADConsumer: AzureAdTokenConsume

fun Application.serverModule(
env: Environment,
sykepengerMaxDateService: SykepengerMaxDateService,
mikrofrontendService: MikrofrontendService,
veilederTilgangskontrollConsumer: VeilederTilgangskontrollConsumer,
) {
install(ContentNegotiation) {
jackson {
Expand All @@ -243,13 +265,17 @@ fun Application.serverModule(
runningRemotely {
setupRoutesWithAuthentication(
mikrofrontendService,
sykepengerMaxDateService,
veilederTilgangskontrollConsumer,
env.authEnv,
)
}

runningLocally {
setupLocalRoutesWithAuthentication(
mikrofrontendService,
sykepengerMaxDateService,
veilederTilgangskontrollConsumer,
env.authEnv,
)
}
Expand All @@ -265,9 +291,24 @@ fun Application.serverModule(
fun Application.kafkaModule(
env: Environment,
varselbusService: VarselBusService,
sykepengerMaxDateService: SykepengerMaxDateService,
testdataResetService: TestdataResetService,
) {
runningRemotely {
launch(backgroundTasksContext) {
launchKafkaListener(
state,
InfotrygdKafkaConsumer(env, sykepengerMaxDateService),
)
}

launch(backgroundTasksContext) {
launchKafkaListener(
state,
UtbetalingKafkaConsumer(env, sykepengerMaxDateService),
)
}

launch(backgroundTasksContext) {
launchKafkaListener(
state,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package no.nav.syfo.api.maxdate

import io.ktor.http.HttpStatusCode
import io.ktor.server.application.ApplicationCall
import io.ktor.server.application.call
import io.ktor.server.response.respond
import io.ktor.server.routing.Route
import io.ktor.server.routing.get
import net.logstash.logback.argument.StructuredArguments
import no.nav.syfo.consumer.veiledertilgang.VeilederTilgangskontrollConsumer
import no.nav.syfo.domain.PersonIdent
import no.nav.syfo.service.SykepengerMaxDateService
import no.nav.syfo.utils.*
import org.slf4j.LoggerFactory
import java.io.Serializable
import java.time.LocalDate

fun Route.registerSykepengerMaxDateAzureApi(
sykepengerMaxDateService: SykepengerMaxDateService,
veilederTilgangskontrollConsumer: VeilederTilgangskontrollConsumer,
) {
val log = LoggerFactory.getLogger("no.nav.syfo.api.maxdate.SykepengerMaxDateAzureApi")
get("/api/azure/v1/sykepenger/maxdate") {
val personIdent = call.personIdent()
val token = call.bearerToken()
val callId = call.getCallId()

if (veilederTilgangskontrollConsumer.hasAccess(personIdent, token, callId)) {
try {
val sykepengerMaxDate = sykepengerMaxDateService.getSykepengerMaxDate(personIdent.value)
log.info("Fetched sykepengerMaxDate from database: ${sykepengerMaxDate?.forelopig_beregnet_slutt}")
call.respond(SykepengerMaxDateAzureResponse(sykepengerMaxDate?.forelopig_beregnet_slutt))
} catch (e: Exception) {
log.error("Encountered exception during fetching sykepengerMaxDate from database: ${e.message}")
call.respond(
HttpStatusCode.InternalServerError,
"Encountered exception during fetching max date from database: ${e.message}",
)
}
} else {
val message = "Cannot fetch max date: Veileder has no access to person"
log.warn("$message, {}", callIdArgument(callId))
call.respond(HttpStatusCode.Forbidden, message)
}
}
}

data class SykepengerMaxDateAzureResponse(
val maxDate: LocalDate?,
) : Serializable

private fun ApplicationCall.personIdent(): PersonIdent = this.getPersonIdent()
?: throw IllegalArgumentException("Failed to get maxDate: No $NAV_PERSONIDENT_HEADER supplied in request header")

private fun ApplicationCall.bearerToken(): String = this.getBearerToken()
?: throw IllegalArgumentException("Failed to get maxDate: No Authorization header supplied")

private fun callIdArgument(callId: String) = StructuredArguments.keyValue("callId", callId)!!
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package no.nav.syfo.api.maxdate

import io.ktor.http.HttpStatusCode
import io.ktor.server.application.ApplicationCall
import io.ktor.server.application.call
import io.ktor.server.response.respond
import io.ktor.server.routing.Route
import io.ktor.server.routing.get
import net.logstash.logback.argument.StructuredArguments
import no.nav.syfo.consumer.veiledertilgang.VeilederTilgangskontrollConsumer
import no.nav.syfo.db.domain.PMaksDato
import no.nav.syfo.domain.PersonIdent
import no.nav.syfo.service.SykepengerMaxDateService
import no.nav.syfo.utils.NAV_PERSONIDENT_HEADER
import no.nav.syfo.utils.getBearerToken
import no.nav.syfo.utils.getCallId
import no.nav.syfo.utils.getPersonIdent
import org.slf4j.LoggerFactory
import java.io.Serializable

fun Route.registerSykepengerMaxDateAzureApiV2(
sykepengerMaxDateService: SykepengerMaxDateService,
veilederTilgangskontrollConsumer: VeilederTilgangskontrollConsumer,
) {
val log = LoggerFactory.getLogger("no.nav.syfo.api.maxdate.SykepengerMaxDateAzureApiV2")
get("/api/azure/v2/sykepenger/maxdate") {
val personIdent = call.personIdent()
val token = call.bearerToken()
val callId = call.getCallId()

if (veilederTilgangskontrollConsumer.hasAccess(personIdent, token, callId)) {
try {
val sykepengerMaxDate = sykepengerMaxDateService.getSykepengerMaxDate(personIdent.value)
log.info("Fetched sykepengerMaxDate from database: ${sykepengerMaxDate?.forelopig_beregnet_slutt}")
call.respond(SykepengerMaxDateAzureV2Response(sykepengerMaxDate))
} catch (e: Exception) {
log.error("Encountered exception during fetching sykepengerMaxDate from database: ${e.message}")
call.respond(
HttpStatusCode.InternalServerError,
"Encountered exception during fetching max date from database: ${e.message}",
)
}
} else {
val message = "Cannot fetch max date: Veileder has no access to person"
log.warn("$message, {}", callIdArgument(callId))
call.respond(HttpStatusCode.Forbidden, message)
}
}
}

data class SykepengerMaxDateAzureV2Response(
val maxDate: PMaksDato?,
) : Serializable

private fun ApplicationCall.personIdent(): PersonIdent = this.getPersonIdent()
?: throw IllegalArgumentException("Failed to get maxDate: No $NAV_PERSONIDENT_HEADER supplied in request header")

private fun ApplicationCall.bearerToken(): String = this.getBearerToken()
?: throw IllegalArgumentException("Failed to get maxDate: No Authorization header supplied")

private fun callIdArgument(callId: String) = StructuredArguments.keyValue("callId", callId)!!
62 changes: 62 additions & 0 deletions src/main/kotlin/no/nav/syfo/api/maxdate/SykepengerMaxDateRest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package no.nav.syfo.api.maxdate

import io.ktor.http.HttpStatusCode
import io.ktor.server.application.call
import io.ktor.server.auth.authentication
import io.ktor.server.response.respond
import io.ktor.server.routing.Route
import io.ktor.server.routing.get
import no.nav.syfo.auth.BrukerPrincipal
import no.nav.syfo.service.SykepengerMaxDateService
import no.nav.syfo.utils.formatDateForLetter
import org.slf4j.LoggerFactory
import java.io.Serializable

fun Route.registerSykepengerMaxDateRestApi(
sykepengerMaxDateService: SykepengerMaxDateService,
) {
val log = LoggerFactory.getLogger("no.nav.syfo.api.maxdate.SykepengerMaxDateRest")
get("/api/v1/sykepenger/maxdate") {
val principal: BrukerPrincipal = call.authentication.principal()!!
val sykmeldtFnr = principal.fnr
val isoFormat = call.request.queryParameters["isoformat"]?.toBoolean() ?: false

try {
val sykepengerMaxDate = sykepengerMaxDateService.getSykepengerMaxDate(sykmeldtFnr)
val maxDate = sykepengerMaxDate?.let {
if (isoFormat) {
it.forelopig_beregnet_slutt.toString()
} else {
formatDateForLetter(it.forelopig_beregnet_slutt)
}
}
val utbetaltTom = sykepengerMaxDate?.let {
if (isoFormat) {
it.utbetalt_tom.toString()
} else {
formatDateForLetter(it.utbetalt_tom)
}
}
log.info("Fetched sykepengerMaxDate from database: ${sykepengerMaxDate?.forelopig_beregnet_slutt}")
call.respond(
SykepengerMaxDateResponse(
maxDate = maxDate,
utbetaltTom = utbetaltTom,
gjenstaendeSykedager = sykepengerMaxDate?.gjenstaende_sykedager
)
)
} catch (e: Exception) {
log.error("Encountered exception during fetching sykepengerMaxDate from database: ${e.message}")
call.respond(
HttpStatusCode.InternalServerError,
"Encountered exception during fetching max date from database: ${e.message}",
)
}
}
}

data class SykepengerMaxDateResponse(
val maxDate: String?,
val utbetaltTom: String?,
val gjenstaendeSykedager: String?
) : Serializable
Loading

0 comments on commit ed26f06

Please sign in to comment.