Skip to content

Commit

Permalink
Legg til endepunkter for å sende og motta klage
Browse files Browse the repository at this point in the history
  • Loading branch information
almyy committed Oct 13, 2023
1 parent bb92279 commit dd570ac
Show file tree
Hide file tree
Showing 26 changed files with 573 additions and 174 deletions.
10 changes: 10 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ object Versions {
const val gson = "2.10"
const val log4j = "2.19.0"
const val snakeyaml = "2.0"
const val fiksIO = "3.2.2"
const val googleCloudLibraries = "26.14.0"
const val googleCloudSecretmanager = "2.10.0"

const val javaJwt = "4.3.0"
const val jwksRsa = "0.22.0"
Expand Down Expand Up @@ -126,6 +129,13 @@ dependencies {
// Filformat
implementation("no.nav.sbl.dialogarena:soknadsosialhjelp-filformat:${Versions.filformat}")

// Fiks IO
implementation("no.ks.fiks:fiks-io-klient-java:${Versions.fiksIO}")

// Google secret manager
implementation(platform("com.google.cloud:libraries-bom:${Versions.googleCloudLibraries}"))
implementation("com.google.cloud:google-cloud-secretmanager:${Versions.googleCloudSecretmanager}")

// Jackson
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:${Versions.jackson}")

Expand Down
11 changes: 10 additions & 1 deletion nais/dev/mock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ spec:
external:
- host: unleash.nais.io
- host: digisos.ekstern.dev.nav.no
- host: test.maskinporten.no
rules:
- application: sosialhjelp-mock-alt-api-mock
- application: sosialhjelp-soknad-api-mock
Expand All @@ -45,8 +46,16 @@ spec:
requests:
cpu: 10m
memory: 512Mi
maskinporten:
enabled: true
scopes:
consumes:
- name: "ks:fiks"
envFrom:
- configmap: loginservice-idporten
- secret: innsyn-api-fiks-io-integrasjonspassord
filesFrom:
- secret: innyn-api-fiks-io-private-key
env:
- name: SPRING_PROFILES_ACTIVE
value: "mock-alt,log-console,mock-redis"
Expand All @@ -72,7 +81,7 @@ spec:
value: "http://sosialhjelp-mock-alt-api-mock/sosialhjelp/mock-alt-api/well-known/tokenx"
- name: TOKEN_X_CLIENT_ID
value: "dev-gcp:teamdigisos:sosialhjelp-innsyn-api-mock"
- name: MASKINPORTEN_WELL_KNOWN_URL
- name: MOCK_ALT_MASKINPORTEN_WELL_KNOWN_URL
value: "http://sosialhjelp-mock-alt-api-mock/sosialhjelp/mock-alt-api/well-known/maskinporten"
- name: VILKAR_DOKKRAV_FAGSYSTEM_VERSJONER
value: "Socio;10.1.16,mock-alt;1.0-MOCKVERSJON,Testsystemet;1.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,27 @@ import no.nav.sosialhjelp.innsyn.utils.objectMapper
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.http.codec.json.Jackson2JsonDecoder
import org.springframework.http.codec.json.Jackson2JsonEncoder
import org.springframework.web.reactive.function.client.WebClient
import org.springframework.web.reactive.function.client.bodyToMono
import reactor.netty.http.client.HttpClient

@Configuration
class MaskinportenClientConfig(
@Value("\${maskinporten_clientid}") private val clientId: String,
@Value("\${maskinporten_scopes}") private val scopes: String,
@Value("\${maskinporten_well_known_url}") private val wellKnownUrl: String,
@Value("\${maskinporten_client_jwk}") private val clientJwk: String,
sealed class MaskinportenClientConfig(
clientId: String,
scopes: String,
private val wellKnownUrl: String,
clientJwk: String,
webClientBuilder: WebClient.Builder,
proxiedHttpClient: HttpClient,
) {

@Bean
fun maskinportenClient(): MaskinportenClient {
return MaskinportenClient(maskinportenWebClient, maskinportenProperties, wellknown)
}
protected val log by logger()
abstract fun maskinportenClient(): MaskinportenClient

private val maskinportenWebClient: WebClient =
protected val maskinportenWebClient: WebClient =
webClientBuilder
.clientConnector(ReactorClientHttpConnector(proxiedHttpClient))
.codecs {
Expand All @@ -37,24 +35,71 @@ class MaskinportenClientConfig(
}
.build()

private val maskinportenProperties = MaskinportenProperties(
protected val maskinportenProperties = MaskinportenProperties(
clientId = clientId,
clientJwk = clientJwk,
scope = scopes,
wellKnownUrl = wellKnownUrl
)

private val wellknown: WellKnown
protected val wellknown: WellKnown
get() = maskinportenWebClient.get()
.uri(wellKnownUrl)
.retrieve()
.bodyToMono<WellKnown>()
.doOnSuccess { log.info("Hentet WellKnown for Maskinporten.") }
.doOnError { log.warn("Feil ved henting av WellKnown for Maskinporten", it) }
.block() ?: throw RuntimeException("Feil ved henting av WellKnown for Maskinporten")
}

companion object {
private val log by logger()
@Configuration
class MaskinportenClientConfigImpl(
@Value("\${maskinporten_clientid}") private val clientId: String,
@Value("\${maskinporten_scopes}") private val scopes: String,
@Value("\${maskinporten_well_known_url}") private val wellKnownUrl: String,
@Value("\${maskinporten_client_jwk}") private val clientJwk: String,
webClientBuilder: WebClient.Builder,
proxiedHttpClient: HttpClient,
) : MaskinportenClientConfig(clientId, scopes, wellKnownUrl, clientJwk, webClientBuilder, proxiedHttpClient) {
@Bean("maskinportenClient")
override fun maskinportenClient(): MaskinportenClient {
log.info(
"""Setter opp "vanlig" maskinportenklient med
| {
| maskinporten_clientid: $clientId,
| maskinporten_scopes: $scopes,
| maskinporten_well_known_url: $wellKnownUrl,
| maskinporten_client_jwk: $clientJwk
| }
""".trimMargin()
)
return MaskinportenClient(maskinportenWebClient, maskinportenProperties, wellknown)
}
}

@Configuration
@Profile("!local")
class SpecialMaskinportenClientConfig(
@Value("\${special_maskinporten_clientid}") private val clientId: String,
@Value("\${special_maskinporten_scopes}") private val scopes: String,
@Value("\${special_maskinporten_well_known_url}") private val wellKnownUrl: String,
@Value("\${special_maskinporten_client_jwk}") private val clientJwk: String,
webClientBuilder: WebClient.Builder,
proxiedHttpClient: HttpClient,
) : MaskinportenClientConfig(clientId, scopes, wellKnownUrl, clientJwk, webClientBuilder, proxiedHttpClient) {
@Bean("specialMaskinportenClient")
override fun maskinportenClient(): MaskinportenClient {
log.info(
"""Setter opp "special" maskinportenklient med
| {
| maskinporten_clientid: $clientId,
| maskinporten_scopes: $scopes,
| maskinporten_well_known_url: $wellKnownUrl,
| maskinporten_client_jwk: $clientJwk
| }
""".trimMargin()
)
return MaskinportenClient(maskinportenWebClient, maskinportenProperties, wellknown)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import no.nav.sosialhjelp.innsyn.app.exceptions.BadStateException
import no.nav.sosialhjelp.innsyn.app.maskinporten.MaskinportenClient
import no.nav.sosialhjelp.innsyn.utils.IntegrationUtils.BEARER
import no.nav.sosialhjelp.innsyn.utils.logger
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.http.HttpHeaders.AUTHORIZATION
import org.springframework.http.MediaType.APPLICATION_JSON
import org.springframework.stereotype.Component
Expand All @@ -24,6 +25,7 @@ interface DokumentlagerClient {
@Component
class DokumentlagerClientImpl(
private val fiksWebClient: WebClient,
@Qualifier("maskinportenClient")
private val maskinportenClient: MaskinportenClient
) : DokumentlagerClient {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import no.nav.sosialhjelp.innsyn.utils.IntegrationUtils.BEARER
import no.nav.sosialhjelp.innsyn.utils.logger
import no.nav.sosialhjelp.innsyn.utils.objectMapper
import no.nav.sosialhjelp.innsyn.vedlegg.FilForOpplasting
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.context.annotation.Profile
import org.springframework.http.HttpHeaders.AUTHORIZATION
import org.springframework.http.MediaType
Expand All @@ -31,6 +32,7 @@ import org.springframework.web.reactive.function.client.bodyToMono
class DigisosApiTestClientImpl(
private val fiksWebClient: WebClient,
private val digisosApiTestWebClient: WebClient,
@Qualifier("maskinportenClient")
private val maskinportenClient: MaskinportenClient,
private val fiksClientImpl: FiksClientImpl,
) : DigisosApiTestClient {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ data class SaksStatusResponse(
val tittel: String,
val status: SaksStatus?,
val skalViseVedtakInfoPanel: Boolean,
val vedtaksfilUrlList: List<VedtaksfilUrl>?
val vedtaksfilUrlList: List<FilUrl>?,
)

data class VedtaksfilUrl(
data class FilUrl(
@JsonFormat(pattern = "yyyy-MM-dd")
val dato: LocalDate?,
val vedtaksfilUrl: String
val url: String,
val id: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import no.nav.sosialhjelp.innsyn.event.EventService
import no.nav.sosialhjelp.innsyn.utils.logger
import org.springframework.stereotype.Component

const val DEFAULT_SAK_TITTEL = "default_sak_tittel"

@Component
class SaksStatusService(
private val eventService: EventService,
private val fiksClient: FiksClient
private val fiksClient: FiksClient,
) {
private val log by logger()

fun hentSaksStatuser(fiksDigisosId: String, token: String): List<SaksStatusResponse> {
val digisosSak = fiksClient.hentDigisosSak(fiksDigisosId, token, true)
Expand All @@ -29,39 +32,16 @@ class SaksStatusService(
}

private fun mapToResponse(sak: Sak): SaksStatusResponse {
val saksStatus = hentStatusNavn(sak)
val vedtakfilUrlList = when {
sak.vedtak.isEmpty() -> null
else -> sak.vedtak.map {
log.info("Hentet url til vedtaksfil: ${it.vedtaksFilUrl}")
VedtaksfilUrl(it.dato, it.vedtaksFilUrl)
}
val saksStatus = if (sak.vedtak.isEmpty()) {
sak.saksStatus ?: SaksStatus.UNDER_BEHANDLING
} else {
SaksStatus.FERDIGBEHANDLET
}
val skalViseVedtakInfoPanel = getSkalViseVedtakInfoPanel(sak)
val vedtakfilUrlList = sak.vedtak.map {
log.info("Hentet url til vedtaksfil: ${it.vedtaksFilUrl}")
FilUrl(it.dato, it.vedtaksFilUrl, it.id)
}.ifEmpty { null }
val skalViseVedtakInfoPanel = sak.vedtak.all { it.utfall in listOf(UtfallVedtak.DELVIS_INNVILGET, UtfallVedtak.INNVILGET) }
return SaksStatusResponse(sak.tittel ?: DEFAULT_SAK_TITTEL, saksStatus, skalViseVedtakInfoPanel, vedtakfilUrlList)
}

private fun hentStatusNavn(sak: Sak): SaksStatus {
return when {
sak.vedtak.isEmpty() -> sak.saksStatus ?: SaksStatus.UNDER_BEHANDLING
else -> SaksStatus.FERDIGBEHANDLET
}
}

fun getSkalViseVedtakInfoPanel(sak: Sak): Boolean {
var sakHarVedtakslisteMedGjeldendeVedtakInnvilgetEllerDelvisInnvilget = false
for (vedtak in sak.vedtak) {
when {
vedtak.utfall == UtfallVedtak.DELVIS_INNVILGET || vedtak.utfall == UtfallVedtak.INNVILGET -> sakHarVedtakslisteMedGjeldendeVedtakInnvilgetEllerDelvisInnvilget = true
vedtak.utfall == UtfallVedtak.AVSLATT || vedtak.utfall == UtfallVedtak.AVVIST -> sakHarVedtakslisteMedGjeldendeVedtakInnvilgetEllerDelvisInnvilget = false
}
}
return sakHarVedtakslisteMedGjeldendeVedtakInnvilgetEllerDelvisInnvilget
}

companion object {
private val log by logger()

const val DEFAULT_SAK_TITTEL: String = "default_sak_tittel"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.time.YearMonth
@Component
class UtbetalingerService(
private val eventService: EventService,
private val fiksClient: FiksClient
private val fiksClient: FiksClient,
) {

fun hentUtbetalingerForSak(fiksDigisosId: String, token: String): List<UtbetalingerResponse> {
Expand Down Expand Up @@ -189,9 +189,11 @@ class UtbetalingerService(
status == UtbetalingsStatus.UTBETALT && utbetalingsDato == null -> {
log.info("Utbetaling ($referanse) med status=${UtbetalingsStatus.UTBETALT} har ikke utbetalingsDato. Kommune=$kommunenummer")
}

status == UtbetalingsStatus.PLANLAGT_UTBETALING && forfallsDato == null -> {
log.info("Utbetaling ($referanse) med status=${UtbetalingsStatus.PLANLAGT_UTBETALING} har ikke forfallsDato. Kommune=$kommunenummer")
}

status == UtbetalingsStatus.STOPPET && (forfallsDato == null || utbetalingsDato == null) -> {
log.info("Utbetaling ($referanse) med status=${UtbetalingsStatus.STOPPET} mangler forfallsDato eller utbetalingsDato. Kommune=$kommunenummer")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ data class Sak(
)

data class Vedtak(
val id: String,
var utfall: UtfallVedtak?,
var vedtaksFilUrl: String,
var dato: LocalDate?,
Expand Down
22 changes: 19 additions & 3 deletions src/main/kotlin/no/nav/sosialhjelp/innsyn/event/VedtakFattet.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package no.nav.sosialhjelp.innsyn.event

import no.nav.sbl.soknadsosialhjelp.digisos.soker.filreferanse.JsonDokumentlagerFilreferanse
import no.nav.sbl.soknadsosialhjelp.digisos.soker.filreferanse.JsonSvarUtFilreferanse
import no.nav.sbl.soknadsosialhjelp.digisos.soker.hendelse.JsonVedtakFattet
import no.nav.sosialhjelp.innsyn.app.ClientProperties
import no.nav.sosialhjelp.innsyn.digisossak.saksstatus.SaksStatusService.Companion.DEFAULT_SAK_TITTEL
import no.nav.sosialhjelp.innsyn.digisossak.saksstatus.DEFAULT_SAK_TITTEL
import no.nav.sosialhjelp.innsyn.domain.Hendelse
import no.nav.sosialhjelp.innsyn.domain.HendelseTekstType
import no.nav.sosialhjelp.innsyn.domain.InternalDigisosSoker
Expand All @@ -23,7 +25,14 @@ fun InternalDigisosSoker.apply(hendelse: JsonVedtakFattet, clientProperties: Cli
val utfall = utfallString?.let { UtfallVedtak.valueOf(it) }
val vedtaksfilUrl = hentUrlFraFilreferanse(clientProperties, hendelse.vedtaksfil.referanse)

val vedtakFattet = Vedtak(utfall, vedtaksfilUrl, hendelse.hendelsestidspunkt.toLocalDateTime().toLocalDate())
val id = when (val referanse = hendelse.vedtaksfil.referanse) {
is JsonDokumentlagerFilreferanse -> referanse.id
is JsonSvarUtFilreferanse -> referanse.id
else -> error("Ikke støttet referansetype ${referanse.type}")
}
val vedtakFattet = Vedtak(
id, utfall, vedtaksfilUrl, hendelse.hendelsestidspunkt.toLocalDateTime().toLocalDate()
)

var sakForReferanse = saker.firstOrNull { it.referanse == hendelse.saksreferanse || it.referanse == "default" }

Expand All @@ -42,7 +51,14 @@ fun InternalDigisosSoker.apply(hendelse: JsonVedtakFattet, clientProperties: Cli

log.info("Hendelse: Tidspunkt: ${hendelse.hendelsestidspunkt} Vedtak fattet. <skjult tittel> er ferdigbehandlet")
if (sakForReferanse.tittel != null) {
historikk.add(Hendelse(HendelseTekstType.SAK_FERDIGBEHANDLET_MED_TITTEL, hendelse.hendelsestidspunkt.toLocalDateTime(), UrlResponse(HendelseTekstType.VIS_BREVET_LENKETEKST, vedtaksfilUrl), tekstArgument = sakForReferanse.tittel))
historikk.add(
Hendelse(
HendelseTekstType.SAK_FERDIGBEHANDLET_MED_TITTEL,
hendelse.hendelsestidspunkt.toLocalDateTime(),
UrlResponse(HendelseTekstType.VIS_BREVET_LENKETEKST, vedtaksfilUrl),
tekstArgument = sakForReferanse.tittel
)
)
} else {
historikk.add(Hendelse(HendelseTekstType.SAK_FERDIGBEHANDLET_UTEN_TITTEL, hendelse.hendelsestidspunkt.toLocalDateTime(), UrlResponse(HendelseTekstType.VIS_BREVET_LENKETEKST, vedtaksfilUrl)))
}
Expand Down
Loading

0 comments on commit dd570ac

Please sign in to comment.