Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AudunSorheim committed Dec 6, 2024
1 parent 814d1fc commit 85ae140
Show file tree
Hide file tree
Showing 28 changed files with 2,385 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package no.nav.syfo.oppfolgingsplan.controller.external

import no.nav.security.token.support.core.api.ProtectedWithClaims
import no.nav.security.token.support.core.context.TokenValidationContextHolder
import no.nav.syfo.auth.tokenx.TokenXUtil.TokenXIssuer.TOKENX
import no.nav.syfo.metric.Metrikk
import no.nav.syfo.narmesteleder.NarmesteLederClient
import no.nav.syfo.util.NAV_PERSONIDENT_HEADER
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.MediaType.APPLICATION_JSON_VALUE
import org.springframework.web.bind.annotation.*
import javax.inject.Inject

@RestController
@ProtectedWithClaims(issuer = TOKENX, claimMap = ["acr=Level4", "acr=idporten-loa-high"], combineWithOr = true)
@RequestMapping(value = ["/api/v2/arbeidsgiver/oppfolgingsplaner"])
class ArbeidsgiverOppfolgingsplanControllerV1 @Inject constructor(
private val contextHolder: TokenValidationContextHolder,
private val narmesteLederClient: NarmesteLederClient,
private val oppfolgingsplanService: OppfolgingsplanService,
private val arbeidsforholdService: ArbeidsforholdService,
private val pdlConsumer: PdlConsumer,
private val metrikk: Metrikk,
@Value("\${oppfolgingsplan.frontend.client.id}")
private val oppfolgingsplanClientId: String,
) {

@GetMapping(produces = [APPLICATION_JSON_VALUE])
fun hentArbeidsgiversOppfolgingsplanerPaPersonident(@RequestHeader(name = NAV_PERSONIDENT_HEADER) personident: String, @RequestParam("virksomhetsnummer") virksomhetsnummer: String): List<BrukerOppfolgingsplan> {
val innloggetIdent = TokenXUtil.validateTokenXClaims(contextHolder, oppfolgingsplanClientId)
.fnrFromIdportenTokenX()
.value
val arbeidsgiversOppfolgingsplaner = oppfolgingsplanService.arbeidsgiversOppfolgingsplanerPaFnr(innloggetIdent, personident, virksomhetsnummer)
val liste = arbeidsgiversOppfolgingsplaner.map { it.toBrukerOppfolgingsplan(pdlConsumer) }
liste.forEach { plan -> plan.populerPlanerMedAvbruttPlanListe(liste) }
val arbeidsforhold = arbeidsforholdService.arbeidstakersStillingerForOrgnummer(personident, listOf(virksomhetsnummer))
liste.forEach { plan -> plan.populerArbeidstakersStillinger(arbeidsforhold) }
metrikk.tellHendelse("hent_oppfolgingsplan_ag")
return liste
}

@PostMapping(consumes = [APPLICATION_JSON_VALUE], produces = [APPLICATION_JSON_VALUE])
fun opprettOppfolgingsplanSomArbeidsgiver(@RequestBody opprettOppfolgingsplan: OpprettOppfolgingsplanRequest): Long {
val innloggetFnr = TokenXUtil.validateTokenXClaims(contextHolder, oppfolgingsplanClientId)
.fnrFromIdportenTokenX()
.value
val sykmeldtFnr = opprettOppfolgingsplan.sykmeldtFnr
return if (narmesteLederConsumer.erNaermesteLederForAnsatt(innloggetFnr, sykmeldtFnr)) {
val id = oppfolgingsplanService.opprettOppfolgingsplan(innloggetFnr, opprettOppfolgingsplan.virksomhetsnummer, sykmeldtFnr)
metrikk.tellHendelse("opprett_oppfolgingsplan_ag")
id
} else {
throw ForbiddenException()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package no.nav.syfo.oppfolgingsplan.controller.external

import no.nav.security.token.support.core.api.ProtectedWithClaims
import no.nav.security.token.support.core.context.TokenValidationContextHolder
import no.nav.syfo.metric.Metrikk
import no.nav.syfo.service.ArbeidsoppgaveService
import no.nav.syfo.tokenx.TokenXUtil
import no.nav.syfo.tokenx.TokenXUtil.TokenXIssuer.TOKENX
import no.nav.syfo.tokenx.TokenXUtil.fnrFromIdportenTokenX
import org.springframework.beans.factory.annotation.Value
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import javax.inject.Inject

@RestController
@ProtectedWithClaims(issuer = TOKENX, claimMap = ["acr=Level4", "acr=idporten-loa-high"], combineWithOr = true)
@RequestMapping(value = ["/api/v2/arbeidsoppgave/actions/{arbeidsoppgaveId}"])
class ArbeidsoppgaveControllerV1 @Inject constructor(
private val contextHolder: TokenValidationContextHolder,
private val arbeidsoppgaveService: ArbeidsoppgaveService,
private val metrikk: Metrikk,
@Value("\${oppfolgingsplan.frontend.client.id}")
private val oppfolgingsplanClientId: String,
) {
@PostMapping(path = ["/slett"])
fun slettArbeidsoppgave(@PathVariable("arbeidsoppgaveId") arbeidsoppgaveId: Long) {
val innloggetIdent = TokenXUtil.validateTokenXClaims(contextHolder, oppfolgingsplanClientId)
.fnrFromIdportenTokenX()
.value
arbeidsoppgaveService.slettArbeidsoppgave(arbeidsoppgaveId, innloggetIdent)
metrikk.tellHendelse("slett_arbeidsoppgave")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package no.nav.syfo.oppfolgingsplan.controller.external

import no.nav.security.token.support.core.api.ProtectedWithClaims
import no.nav.security.token.support.core.context.TokenValidationContextHolder
import no.nav.syfo.api.v2.domain.oppfolgingsplan.BrukerOppfolgingsplan
import no.nav.syfo.api.v2.domain.oppfolgingsplan.OpprettOppfolgingsplanRequest
import no.nav.syfo.api.v2.mapper.populerArbeidstakersStillinger
import no.nav.syfo.api.v2.mapper.populerPlanerMedAvbruttPlanListe
import no.nav.syfo.api.v2.mapper.toBrukerOppfolgingsplan
import no.nav.syfo.api.v2.mapper.toVirksomhetsnummer
import no.nav.syfo.domain.Oppfolgingsplan
import no.nav.syfo.metric.Metrikk
import no.nav.syfo.pdl.PdlConsumer
import no.nav.syfo.service.ArbeidsforholdService
import no.nav.syfo.service.OppfolgingsplanService
import no.nav.syfo.tokenx.TokenXUtil
import no.nav.syfo.tokenx.TokenXUtil.TokenXIssuer.TOKENX
import no.nav.syfo.tokenx.TokenXUtil.fnrFromIdportenTokenX
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.*
import javax.inject.Inject

@RestController
@ProtectedWithClaims(issuer = TOKENX, claimMap = ["acr=Level4", "acr=idporten-loa-high"], combineWithOr = true)
@RequestMapping(value = ["/api/v2/arbeidstaker/oppfolgingsplaner"])
class ArbeidstakerOppfolgingsplanControllerV1 @Inject constructor(
private val contextHolder: TokenValidationContextHolder,
private val oppfolgingsplanService: OppfolgingsplanService,
private val arbeidsforholdService: ArbeidsforholdService,
private val pdlConsumer: PdlConsumer,
private val metrikk: Metrikk,
@Value("\${oppfolgingsplan.frontend.client.id}")
private val oppfolgingsplanClientId: String,
@Value("\${ditt.sykefravaer.frontend.client.id}")
private val dittSykefravaerClientId: String,
) {
@GetMapping(produces = [MediaType.APPLICATION_JSON_VALUE])
fun hentArbeidstakersOppfolgingsplaner(): List<BrukerOppfolgingsplan> {
val innloggetIdent =
TokenXUtil.validateTokenXClaims(contextHolder, oppfolgingsplanClientId, dittSykefravaerClientId)
.fnrFromIdportenTokenX()
.value
val arbeidstakersOppfolgingsplaner: List<Oppfolgingsplan> =
oppfolgingsplanService.arbeidstakersOppfolgingsplaner(innloggetIdent)
val liste = arbeidstakersOppfolgingsplaner.map { it.toBrukerOppfolgingsplan(pdlConsumer) }
liste.forEach { plan -> plan.populerPlanerMedAvbruttPlanListe(liste) }
val arbeidstakersStillinger = arbeidsforholdService.arbeidstakersStillingerForOrgnummer(innloggetIdent, liste.toVirksomhetsnummer())
liste.forEach { plan -> plan.populerArbeidstakersStillinger(arbeidstakersStillinger) }
metrikk.tellHendelse("hent_oppfolgingsplan_at")
return liste
}

@PostMapping(consumes = [MediaType.APPLICATION_JSON_VALUE], produces = [MediaType.APPLICATION_JSON_VALUE])
fun opprettOppfolgingsplanSomArbeidstaker(@RequestBody opprettOppfolgingsplan: OpprettOppfolgingsplanRequest): Long {
val innloggetFnr = TokenXUtil.validateTokenXClaims(contextHolder, oppfolgingsplanClientId)
.fnrFromIdportenTokenX()
.value
val id = oppfolgingsplanService.opprettOppfolgingsplan(innloggetFnr, opprettOppfolgingsplan.virksomhetsnummer, innloggetFnr)
metrikk.tellHendelse("opprett_oppfolgingsplan_at")
return id
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package no.nav.syfo.oppfolgingsplan.controller.external

import no.nav.security.token.support.core.api.ProtectedWithClaims
import no.nav.security.token.support.core.context.TokenValidationContextHolder
import no.nav.syfo.api.v2.domain.sykmelding.SykmeldingV2
import no.nav.syfo.api.v2.domain.sykmelding.toSykmeldingV2
import no.nav.syfo.metric.Metrikk
import no.nav.syfo.model.Sykmelding
import no.nav.syfo.oidc.TokenUtil.getIssuerToken
import no.nav.syfo.pdl.PdlConsumer
import no.nav.syfo.sykmeldinger.ArbeidstakerSykmeldingerConsumer
import no.nav.syfo.tokenx.TokenXUtil
import no.nav.syfo.tokenx.TokenXUtil.TokenXIssuer.TOKENX
import no.nav.syfo.tokenx.TokenXUtil.fnrFromIdportenTokenX
import no.nav.syfo.tokenx.tokendings.TokenDingsConsumer
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import javax.inject.Inject

@RestController
@ProtectedWithClaims(issuer = TOKENX, claimMap = ["acr=Level4", "acr=idporten-loa-high"], combineWithOr = true)
@RequestMapping(value = ["/api/v2/arbeidstaker/sykmeldinger"])
class ArbeidstakerSykmeldingerControllerV1 @Inject constructor(
private val contextHolder: TokenValidationContextHolder,
private val metrikk: Metrikk,
private val pdlConsumer: PdlConsumer,
private val arbeidstakerSykmeldingerConsumer: ArbeidstakerSykmeldingerConsumer,
private val tokenDingsConsumer: TokenDingsConsumer,
@Value("\${oppfolgingsplan.frontend.client.id}")
private val oppfolgingsplanClientId: String,
@Value("\${syfosmregister.id}")
private val targetApp: String? = null,
) {
@ResponseBody
@GetMapping
fun getSendteSykmeldinger(@RequestParam(required = false) today: String?): ResponseEntity<List<SykmeldingV2>> {
metrikk.tellHendelse("get_sykmeldinger")
val innloggetIdent = TokenXUtil.validateTokenXClaims(contextHolder, oppfolgingsplanClientId)
.fnrFromIdportenTokenX()
.value
val issuerToken = getIssuerToken(contextHolder, TOKENX)
val exchangedToken = tokenDingsConsumer.exchangeToken(issuerToken, targetApp!!)
val bearerToken = "Bearer $exchangedToken"

val oppslattIdentAktorId = pdlConsumer.aktorid(innloggetIdent)
val isTodayPresent = today.toBoolean()
val sendteSykmeldinger = arbeidstakerSykmeldingerConsumer.getSendteSykmeldinger(oppslattIdentAktorId, bearerToken, isTodayPresent)
.map { sykmeldinger: List<Sykmelding> -> sykmeldinger.map { it.toSykmeldingV2() } }
.orElseGet { emptyList() }

return ResponseEntity
.status(HttpStatus.OK)
.body(sendteSykmeldinger)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package no.nav.syfo.oppfolgingsplan.controller.external

import no.nav.security.token.support.core.api.ProtectedWithClaims
import no.nav.security.token.support.core.context.TokenValidationContextHolder
import no.nav.syfo.metric.Metrikk
import no.nav.syfo.service.PdfService
import no.nav.syfo.tokenx.TokenXUtil
import no.nav.syfo.tokenx.TokenXUtil.TokenXIssuer.TOKENX
import no.nav.syfo.tokenx.TokenXUtil.fnrFromIdportenTokenX
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.MediaType.APPLICATION_PDF
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import javax.inject.Inject

@RestController
@ProtectedWithClaims(issuer = TOKENX, claimMap = ["acr=Level4", "acr=idporten-loa-high"], combineWithOr = true)
@RequestMapping(value = ["/api/v2/dokument/{oppfolgingsplanId}/ekstern"])
class DokumentControllerV1 @Inject constructor(
private val contextHolder: TokenValidationContextHolder,
private val pdfService: PdfService,
private val metrikk: Metrikk,
@Value("\${oppfolgingsplan.frontend.client.id}")
private val oppfolgingsplanClientId: String,
) {
@GetMapping
fun hentPdf(@PathVariable("oppfolgingsplanId") oppfolgingsplanId: Long): ResponseEntity<*> {
val innloggetIdent = TokenXUtil.validateTokenXClaims(contextHolder, oppfolgingsplanClientId)
.fnrFromIdportenTokenX()
.value
val pdf = pdfService.hentPdf(oppfolgingsplanId, innloggetIdent)
metrikk.tellHendelse("hent_pdf")
return ResponseEntity.ok()
.contentType(APPLICATION_PDF)
.body(pdf)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package no.nav.syfo.oppfolgingsplan.controller.external

import no.nav.security.token.support.core.api.ProtectedWithClaims
import no.nav.security.token.support.core.context.TokenValidationContextHolder
import no.nav.syfo.metric.Metrikk
import no.nav.syfo.service.KommentarService
import no.nav.syfo.tokenx.TokenXUtil
import no.nav.syfo.tokenx.TokenXUtil.TokenXIssuer.TOKENX
import no.nav.syfo.tokenx.TokenXUtil.fnrFromIdportenTokenX
import org.springframework.beans.factory.annotation.Value
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import javax.inject.Inject

@RestController
@ProtectedWithClaims(issuer = TOKENX, claimMap = ["acr=Level4", "acr=idporten-loa-high"], combineWithOr = true)
@RequestMapping(value = ["/api/v2/kommentar/actions/{id}"])
class KommentarControllerV1 @Inject constructor(
private val contextHolder: TokenValidationContextHolder,
private val kommentarService: KommentarService,
private val metrikk: Metrikk,
@Value("\${oppfolgingsplan.frontend.client.id}")
private val oppfolgingsplanClientId: String,
) {
@PostMapping(path = ["/slett"])
fun slettKommentar(@PathVariable("id") id: Long) {
val innloggetIdent = TokenXUtil.validateTokenXClaims(contextHolder, oppfolgingsplanClientId)
.fnrFromIdportenTokenX()
.value
kommentarService.slettKommentar(id, innloggetIdent)
metrikk.tellHendelse("slett_kommentar")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package no.nav.syfo.oppfolgingsplan.controller.external

import no.nav.security.token.support.core.api.Unprotected
import no.nav.syfo.pdl.PdlConsumer
import no.nav.syfo.repository.dao.OppfolgingsplanDAO
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import java.util.function.Consumer
import javax.inject.Inject

@RestController
@Unprotected
@RequestMapping(value = ["/internal/v2/oppfolgingsplan"])
class NullstillOppfolgingsplanControllerV1 @Inject constructor(
private val oppfolgingsplanDAO: OppfolgingsplanDAO,
private val pdlConsumer: PdlConsumer
) {
@DeleteMapping(path = ["/slett/{id}"])
fun deleteOppfolgingsplanById(
@PathVariable("id") id: Long,
@Value("\${nais.cluster.name}") env: String
): ResponseEntity<*> {
return if (isDev(env)) {
logger.info("Sletter oppfolgingsplan for id")
oppfolgingsplanDAO.deleteOppfolgingsplan(id)
ResponseEntity.ok().build<Any>()
} else {
handleEndpointNotAvailableForProdError()
}
}

@DeleteMapping(path = ["/slett/person/{fnr}"])
fun deleteOppfolgingsplanByFnr(
@PathVariable("fnr") fnr: String,
@Value("\${nais.cluster.name}") env: String
): ResponseEntity<*> {
return if (isDev(env)) {
val aktorId = pdlConsumer.aktorid(fnr)
val dialogIder = oppfolgingsplanDAO.hentDialogIDerByAktoerId(aktorId)
logger.info("Sletter oppfolgingsplaner for aktorId")
dialogIder.forEach(Consumer { oppfolgingsdialogId: Long ->
oppfolgingsplanDAO.deleteOppfolgingsplan(
oppfolgingsdialogId
)
})
ResponseEntity.ok().build<Any>()
} else {
handleEndpointNotAvailableForProdError()
}
}

private fun handleEndpointNotAvailableForProdError(): ResponseEntity<*> {
logger.error("Det ble gjort kall mot 'slett oppfolgingsplan', men dette endepunktet er togglet av og skal aldri brukes i prod.")
return ResponseEntity.notFound().build<Any>()
}

private fun isDev(env: String): Boolean {
return env == "dev-fss" || env == "local"
}

companion object {
private val logger = LoggerFactory.getLogger(NullstillOppfolgingsplanControllerV1::class.java)
}
}
Loading

0 comments on commit 85ae140

Please sign in to comment.