Skip to content

Commit

Permalink
Henter person fødselsdato når vi ikke har den i systemet
Browse files Browse the repository at this point in the history
  • Loading branch information
unorsk committed Oct 10, 2023
1 parent 534b7f6 commit bf0d902
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .nais/feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: bidrag-behandling-feature
ingresses:
- https://bidrag-behandling-feature.intern.dev.nav.no
env:
BIDRAG_PERSON_URL: https://bidrag-person
BIDRAG_PERSON_SCOPE: dev-fss.bidrag.bidrag-person-feature
BIDRAG_BEREGN_FORSKUDD_URL: http://bidrag-beregn-forskudd-rest-feature
BIDRAG_BEREGN_FORSKUDD_SCOPE: dev-gcp.bidrag.bidrag-beregn-forskudd-rest-feature
BIDRAG_GRUNNLAG_URL: http://bidrag-grunnlag-feature
Expand Down Expand Up @@ -31,6 +33,7 @@ database:
autoResize: false
tier: db-f1-micro
outbound-access-apps:
- bidrag-person
- bidrag-beregn-forskudd-rest-feature
- bidrag-grunnlag-feature
- bidrag-dokument-forsendelse-feature
Expand Down
3 changes: 3 additions & 0 deletions .nais/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: bidrag-behandling
ingresses:
- https://bidrag-behandling.intern.dev.nav.no
env:
BIDRAG_PERSON_URL: https://bidrag-person
BIDRAG_PERSON_SCOPE: dev-fss.bidrag.bidrag-person
BIDRAG_BEREGN_FORSKUDD_URL: http://bidrag-beregn-forskudd-rest
BIDRAG_BEREGN_FORSKUDD_SCOPE: dev-gcp.bidrag.bidrag-beregn-forskudd-rest
BIDRAG_GRUNNLAG_URL: http://bidrag-grunnlag
Expand Down Expand Up @@ -31,6 +33,7 @@ database:
autoResize: false
tier: db-f1-micro
outbound-access-apps:
- bidrag-person
- bidrag-beregn-forskudd-rest
- bidrag-grunnlag
- bidrag-dokument-forsendelse
Expand Down
3 changes: 3 additions & 0 deletions .nais/prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: bidrag-behandling
ingresses:
- https://bidrag-behandling.intern.nav.no
env:
BIDRAG_PERSON_URL: https://bidrag-person
BIDRAG_PERSON_SCOPE: prod-fss.bidrag.bidrag-person
BIDRAG_BEREGN_FORSKUDD_URL: http://bidrag-beregn-forskudd-rest
BIDRAG_BEREGN_FORSKUDD_SCOPE: prod-gcp.bidrag.bidrag-beregn-forskudd-rest
BIDRAG_GRUNNLAG_URL: http://bidrag-grunnlag
Expand Down Expand Up @@ -31,6 +33,7 @@ database:
autoResize: false
tier: db-custom-1-3840
outbound-access-apps:
- bidrag-person
- bidrag-beregn-forskudd-rest
- bidrag-grunnlag
- bidrag-dokument-forsendelse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import no.nav.bidrag.behandling.database.datamodell.Rolle
import no.nav.bidrag.behandling.database.datamodell.SivilstandType
import no.nav.bidrag.behandling.transformers.INFINITY
import no.nav.bidrag.behandling.transformers.toCompactString
import no.nav.bidrag.behandling.transformers.toLocalDate
import no.nav.bidrag.behandling.transformers.toNoString
import no.nav.bidrag.beregn.felles.enums.BostatusKode
import no.nav.bidrag.beregn.felles.enums.SivilstandKode
Expand All @@ -28,16 +27,15 @@ import java.time.LocalDate

@Service
class ForskuddBeregning {

private fun prepareSoknadsBarn(soknadBarn: Rolle): List<Grunnlag> =
private fun prepareSoknadsBarn(soknadBarn: Rolle, fDato: String): List<Grunnlag> =
listOf(
Grunnlag(
referanse = "Mottatt_SoknadsbarnInfo_SB" + soknadBarn.id,
type = GrunnlagType.SOKNADSBARN_INFO,
innhold = POJONode(
SoknadsBarnNode(
soknadsbarnId = soknadBarn.id!!.toInt(),
fodselsdato = soknadBarn.fodtDato?.toLocalDate()?.toNoString(),
fodselsdato = fDato,
),
),
),
Expand All @@ -52,7 +50,11 @@ class ForskuddBeregning {
BostatusKode.BOR_IKKE_MED_FORELDRE
}

private fun prepareBostatus(husstandsBarnPerioder: List<HusstandsBarnPeriodeModel>, soknadsBarnIdent: String, soknadBarn: Rolle): List<Grunnlag> =
private fun prepareBostatus(
husstandsBarnPerioder: List<HusstandsBarnPeriodeModel>,
soknadsBarnIdent: String,
soknadBarn: Rolle
): List<Grunnlag> =
husstandsBarnPerioder
.filter { soknadsBarnIdent == it.ident }
.map {
Expand Down Expand Up @@ -211,20 +213,19 @@ class ForskuddBeregning {
roller = behandling.roller,
)

fun toPayload(b: BehandlingBeregningModel, soknadsBarn: Rolle): BeregnGrunnlag =
fun toPayload(b: BehandlingBeregningModel, soknadsBarn: Rolle, fDato: String): BeregnGrunnlag =
BeregnGrunnlag(
beregnDatoFra = b.virkningsDato,
beregnDatoTil = b.datoTom,
grunnlagListe = prepareSoknadsBarn(soknadsBarn) +
prepareBarnIHusstand(b) +
prepareBostatus(b.husstandsBarnPerioder, soknadsBarn.ident, soknadsBarn) +
prepareInntekterForBeregning(
b.inntekter,
b.barnetillegg,
b.utvidetbarnetrygd,
) +
prepareSivilstand(b.sivilstand),

grunnlagListe = prepareSoknadsBarn(soknadsBarn, fDato) +
prepareBarnIHusstand(b) +
prepareBostatus(b.husstandsBarnPerioder, soknadsBarn.ident, soknadsBarn) +
prepareInntekterForBeregning(
b.inntekter,
b.barnetillegg,
b.utvidetbarnetrygd,
) +
prepareSivilstand(b.sivilstand),
)
}

Expand Down Expand Up @@ -254,7 +255,7 @@ data class BostatusNode(

data class SoknadsBarnNode(
val soknadsbarnId: Int,
val fodselsdato: String?,
val fodselsdato: String,
)

data class InntektNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import java.util.concurrent.TimeUnit
@EnableUserCache
class CacheConfig {
companion object {
const val PERSON_CACHE = "PERSON_CACHE"
const val SAK_CACHE = "SAK_CACHE"
const val TILGANG_TEMA_CACHE = "TILGANG_TEMA_CACHE"
const val TILGANG_PERSON_CACHE = "TILGANG_PERSON_CACHE"
Expand All @@ -26,6 +27,7 @@ class CacheConfig {
@Bean
fun cacheManager(): CacheManager {
val caffeineCacheManager = CaffeineCacheManager()
caffeineCacheManager.registerCustomCache(PERSON_CACHE, Caffeine.newBuilder().expireAfter(InvaliderCacheFørStartenAvArbeidsdag()).build())
caffeineCacheManager.registerCustomCache(TILGANG_TEMA_CACHE, Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build())
caffeineCacheManager.registerCustomCache(TILGANG_PERSON_CACHE, Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build())
caffeineCacheManager.registerCustomCache(TILGANG_SAK_CACHE, Caffeine.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).build())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package no.nav.bidrag.behandling.consumer

import no.nav.bidrag.behandling.config.CacheConfig.Companion.PERSON_CACHE
import no.nav.bidrag.behandling.dto.HentPersonRequest
import no.nav.bidrag.behandling.dto.HentPersonResponse
import no.nav.bidrag.commons.cache.BrukerCacheable
import no.nav.bidrag.commons.web.client.AbstractRestClient
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import org.springframework.web.client.RestTemplate
import org.springframework.web.util.UriComponentsBuilder
import java.net.URI

@Service
class BidragPersonConsumer(
@Value("\${BIDRAG_PERSON_URL}") bidragPersonUrl: URI,
@Qualifier("azure") restTemplate: RestTemplate,
) : AbstractRestClient(restTemplate, "bidrag-person") {

private val hentPersonUri =
UriComponentsBuilder.fromUri(bidragPersonUrl).pathSegment("informasjon").build().toUri()

@BrukerCacheable(PERSON_CACHE)
fun hentPerson(ident: String): HentPersonResponse {
return postForNonNullEntity(hentPersonUri, HentPersonRequest(ident))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement
import mu.KotlinLogging
import no.nav.bidrag.behandling.beregning.ForskuddBeregning
import no.nav.bidrag.behandling.consumer.BidragBeregnForskuddConsumer
import no.nav.bidrag.behandling.consumer.BidragPersonConsumer
import no.nav.bidrag.behandling.dto.beregning.ForskuddBeregningPerBarn
import no.nav.bidrag.behandling.dto.beregning.ForskuddBeregningRespons
import no.nav.bidrag.behandling.service.BehandlingService
import no.nav.bidrag.domain.enums.Rolletype
import no.nav.bidrag.behandling.transformers.toLocalDate
import no.nav.bidrag.behandling.transformers.toNoString
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.client.HttpClientErrorException
Expand All @@ -23,6 +25,7 @@ class BehandlingBeregnForskuddController(
private val behandlingService: BehandlingService,
private val bidragBeregnForskuddConsumer: BidragBeregnForskuddConsumer,
private val forskuddBeregning: ForskuddBeregning,
private val bidragPersonConsumer: BidragPersonConsumer
) {
private fun isPeriodOneWithinPeriodTwo(
datoFom1: LocalDate?,
Expand All @@ -49,10 +52,13 @@ class BehandlingBeregnForskuddController(
val behandlingModel = forskuddBeregning.toBehandlingBeregningModel(behandling).bind()
val results =
behandling
.roller
.filter { Rolletype.BARN == it.rolleType }
.getSøknadsBarn()
.mapOrAccumulate {
val payload = forskuddBeregning.toPayload(behandlingModel, it)
val fDato = if (it.fodtDato == null) {
bidragPersonConsumer.hentPerson(it.ident).fødselsdato
} else it.fodtDato.toLocalDate().toNoString()

val payload = forskuddBeregning.toPayload(behandlingModel, it, fDato)

try {
val respons =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.OneToMany
import no.nav.bidrag.domain.enums.EngangsbelopType
import no.nav.bidrag.domain.enums.Rolletype
import no.nav.bidrag.domain.enums.StonadType
import org.hibernate.annotations.SQLDelete
import org.hibernate.annotations.Where
Expand Down Expand Up @@ -70,4 +71,6 @@ class Behandling(
@OneToMany(fetch = FetchType.EAGER, mappedBy = "behandling", cascade = [CascadeType.ALL], orphanRemoval = true)
var utvidetbarnetrygd: MutableSet<Utvidetbarnetrygd> = mutableSetOf(),
var deleted: Boolean = false,
)
) {
fun getSøknadsBarn() = roller.filter { it.rolleType == Rolletype.BARN }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package no.nav.bidrag.behandling.dto

data class HentPersonRequest(val ident: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package no.nav.bidrag.behandling.dto

data class HentPersonResponse(
val ident: String,
valdselsdato: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class BehandlingServiceTest : TestContainerRunner() {
),
)

assertEquals(2, behandlingService.hentBehandlingById(b.id!!).roller.filter { r -> r.rolleType == Rolletype.BARN }.size)
assertEquals(2, behandlingService.hentBehandlingById(b.id!!).getSøknadsBarn().size)
}

@Test
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/application-test.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
BIDRAG_PERSON_URL: http://localhost:${wiremock.server.port}/bidrag-person
BIDRAG_BEREGN_FORSKUDD_URL: http://localhost:${wiremock.server.port}/beregn-forskudd
BIDRAG_FORSENDELSE_URL: http://localhost:${wiremock.server.port}/forsendelse
BIDRAG_TILGANGSKONTROLL_URL: http://localhost:${wiremock.server.port}/tilgangskontroll
Expand Down

0 comments on commit bf0d902

Please sign in to comment.