-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #260 from navikt/feature/beregn-særtilskudd
Feature/beregn særtilskudd
- Loading branch information
Showing
70 changed files
with
9,784 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>no.nav.bidrag</groupId> | ||
<artifactId>bidrag-beregn-felles</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>bidrag-beregn-saertilskudd</artifactId> | ||
|
||
<properties> | ||
<revision>1.0-SNAPSHOT</revision> | ||
<guava.version>33.2.0-jre</guava.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>no.nav.bidrag</groupId> | ||
<artifactId>bidrag-beregn-core</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.github.oshai</groupId> | ||
<artifactId>kotlin-logging-jvm</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>no.nav.bidrag</groupId> | ||
<artifactId>bidrag-domene-felles</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>no.nav.bidrag</groupId> | ||
<artifactId>bidrag-commons-felles</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>${guava.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-jsr310</artifactId> | ||
</dependency> | ||
<!-- test --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito.kotlin</groupId> | ||
<artifactId>mockito-kotlin</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-test-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.mockk</groupId> | ||
<artifactId>mockk-jvm</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory> | ||
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<configuration> | ||
<compilerPlugins> | ||
<plugin>spring</plugin> | ||
</compilerPlugins> | ||
</configuration> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-allopen</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-antrun-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
32 changes: 32 additions & 0 deletions
32
...g-beregn-særtilskudd/src/main/kotlin/no/nav/bidrag/beregn/særbidrag/BeregnSærbidragApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package no.nav.bidrag.beregn.særbidrag | ||
|
||
import no.nav.bidrag.beregn.særbidrag.service.BeregnSærbidragService | ||
import no.nav.bidrag.commons.service.sjablon.EnableSjablonProvider | ||
import no.nav.bidrag.transport.behandling.beregning.felles.BeregnGrunnlag | ||
import no.nav.bidrag.transport.behandling.beregning.særbidrag.BeregnetSærbidragResultat | ||
import org.springframework.stereotype.Service | ||
|
||
/** | ||
* BeregnSærbidragApi eksponerer api for å beregne særbidrag. | ||
* | ||
* For å ta i bruk beregnings-apiet må følgende gjøres: | ||
* | ||
* Legg til Import-annotering i konfigurasjonen for å initalisere BeregnSærbidragApi-bønnen | ||
* ```kotlin | ||
* @Import(BeregnSærbidragApi::class) | ||
* ``` | ||
* | ||
* Definer BIDRAG_SJABLON_URL miljøvariabler i naiskonfigurasjonen. | ||
* ```yaml | ||
* BIDRAG_SJABLON_URL: https://bidrag-sjablon.<prod-fss|dev-fss>-pub.nais.io/bidrag-sjablon | ||
* ``` | ||
* | ||
* Åpne outbound traffik for `BIDRAG_SJABLON_URL` i naiskonfigurasjonen | ||
*/ | ||
@EnableSjablonProvider | ||
@Service | ||
class BeregnSærbidragApi { | ||
private val service = BeregnSærbidragService() | ||
|
||
fun beregn(beregnSærbidragGrunnlag: BeregnGrunnlag): BeregnetSærbidragResultat = service.beregn(beregnSærbidragGrunnlag) | ||
} |
100 changes: 100 additions & 0 deletions
100
...lskudd/src/main/kotlin/no/nav/bidrag/beregn/særbidrag/core/bidragsevne/BidragsevneCore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package no.nav.bidrag.beregn.særbidrag.core.bidragsevne | ||
|
||
import no.nav.bidrag.beregn.core.bo.Avvik | ||
import no.nav.bidrag.beregn.core.bo.Periode | ||
import no.nav.bidrag.beregn.core.dto.PeriodeCore | ||
import no.nav.bidrag.beregn.særbidrag.core.bidragsevne.bo.BarnIHusstandPeriode | ||
import no.nav.bidrag.beregn.særbidrag.core.bidragsevne.bo.BeregnBidragsevneGrunnlag | ||
import no.nav.bidrag.beregn.særbidrag.core.bidragsevne.bo.BeregnBidragsevneResultat | ||
import no.nav.bidrag.beregn.særbidrag.core.bidragsevne.bo.InntektPeriode | ||
import no.nav.bidrag.beregn.særbidrag.core.bidragsevne.bo.ResultatPeriode | ||
import no.nav.bidrag.beregn.særbidrag.core.bidragsevne.bo.VoksneIHusstandPeriode | ||
import no.nav.bidrag.beregn.særbidrag.core.bidragsevne.dto.BeregnBidragsevneGrunnlagCore | ||
import no.nav.bidrag.beregn.særbidrag.core.bidragsevne.dto.BeregnBidragsevneResultatCore | ||
import no.nav.bidrag.beregn.særbidrag.core.bidragsevne.dto.ResultatBeregningCore | ||
import no.nav.bidrag.beregn.særbidrag.core.bidragsevne.dto.ResultatPeriodeCore | ||
import no.nav.bidrag.beregn.særbidrag.core.bidragsevne.periode.BidragsevnePeriode | ||
import no.nav.bidrag.beregn.særbidrag.core.felles.FellesCore | ||
import no.nav.bidrag.beregn.særbidrag.core.felles.dto.BarnIHusstandenPeriodeCore | ||
import no.nav.bidrag.beregn.særbidrag.core.felles.dto.InntektPeriodeCore | ||
import no.nav.bidrag.beregn.særbidrag.core.felles.dto.VoksneIHusstandenPeriodeCore | ||
|
||
internal class BidragsevneCore(private val bidragsevnePeriode: BidragsevnePeriode = BidragsevnePeriode()) : FellesCore() { | ||
|
||
fun beregnBidragsevne(grunnlag: BeregnBidragsevneGrunnlagCore): BeregnBidragsevneResultatCore { | ||
val beregnBidragsevneGrunnlag = mapTilBusinessObject(grunnlag) | ||
val avvikListe = bidragsevnePeriode.validerInput(beregnBidragsevneGrunnlag) | ||
val beregnBidragsevneResultat = | ||
if (avvikListe.isEmpty()) { | ||
bidragsevnePeriode.beregnPerioder(beregnBidragsevneGrunnlag) | ||
} else { | ||
BeregnBidragsevneResultat(emptyList()) | ||
} | ||
return mapFraBusinessObject(avvikListe = avvikListe, resultat = beregnBidragsevneResultat) | ||
} | ||
|
||
private fun mapTilBusinessObject(grunnlag: BeregnBidragsevneGrunnlagCore) = BeregnBidragsevneGrunnlag( | ||
beregnDatoFra = grunnlag.beregnDatoFra, | ||
beregnDatoTil = grunnlag.beregnDatoTil, | ||
inntektPeriodeListe = mapInntektPeriodeListe(grunnlag.inntektPeriodeListe), | ||
barnIHusstandPeriodeListe = mapBarnIHusstandPeriodeListe(grunnlag.barnIHusstandenPeriodeListe), | ||
voksneIHusstandPeriodeListe = mapVoksneIHusstandPeriodeListe(grunnlag.voksneIHusstandenPeriodeListe), | ||
sjablonPeriodeListe = mapSjablonPeriodeListe(grunnlag.sjablonPeriodeListe), | ||
) | ||
|
||
private fun mapFraBusinessObject(avvikListe: List<Avvik>, resultat: BeregnBidragsevneResultat) = BeregnBidragsevneResultatCore( | ||
resultatPeriodeListe = mapResultatPeriode(resultat.resultatPeriodeListe), | ||
sjablonListe = mapSjablonGrunnlagListe(resultat.resultatPeriodeListe).toMutableList(), | ||
avvikListe = mapAvvik(avvikListe), | ||
) | ||
|
||
private fun mapInntektPeriodeListe(inntektPeriodeListeCore: List<InntektPeriodeCore>) = inntektPeriodeListeCore.map { | ||
InntektPeriode( | ||
referanse = it.referanse, | ||
periode = Periode(datoFom = it.periode.datoFom, datoTil = it.periode.datoTil), | ||
beløp = it.beløp, | ||
) | ||
} | ||
|
||
private fun mapBarnIHusstandPeriodeListe(antallBarnIHusstandenPeriodeListeCore: List<BarnIHusstandenPeriodeCore>) = | ||
antallBarnIHusstandenPeriodeListeCore.map { | ||
BarnIHusstandPeriode( | ||
referanse = it.referanse, | ||
periode = Periode(datoFom = it.periode.datoFom, datoTil = it.periode.datoTil), | ||
antall = it.antall, | ||
) | ||
} | ||
|
||
private fun mapVoksneIHusstandPeriodeListe(bostatusVoksneIHusstandenPeriodeListeCore: List<VoksneIHusstandenPeriodeCore>) = | ||
bostatusVoksneIHusstandenPeriodeListeCore.map { | ||
VoksneIHusstandPeriode( | ||
referanse = it.referanse, | ||
periode = Periode(datoFom = it.periode.datoFom, datoTil = it.periode.datoTil), | ||
borMedAndre = it.borMedAndre, | ||
) | ||
} | ||
|
||
private fun mapResultatPeriode(resultatPeriodeListe: List<ResultatPeriode>) = resultatPeriodeListe.map { | ||
ResultatPeriodeCore( | ||
periode = PeriodeCore(datoFom = it.periode.datoFom, datoTil = it.periode.datoTil), | ||
resultat = ResultatBeregningCore(it.resultat.beløp), | ||
grunnlagsreferanseListe = mapReferanseListe(it).sorted().toMutableList(), | ||
) | ||
} | ||
|
||
private fun mapReferanseListe(resultatPeriode: ResultatPeriode): List<String> { | ||
val (inntekt, antallBarnIHusstand, antallVoksneIHusstand) = resultatPeriode.grunnlag | ||
val sjablonListe = resultatPeriode.resultat.sjablonListe | ||
val referanseListe = mutableListOf<String>() | ||
if (inntekt != null) referanseListe.add(inntekt.referanse) | ||
referanseListe.add(antallBarnIHusstand.referanse) | ||
referanseListe.add(antallVoksneIHusstand.referanse) | ||
referanseListe.addAll(sjablonListe.map { lagSjablonReferanse(it) }.distinct()) | ||
return referanseListe.sorted() | ||
} | ||
|
||
private fun mapSjablonGrunnlagListe(resultatPeriodeListe: List<ResultatPeriode>) = resultatPeriodeListe | ||
.map { it.resultat.sjablonListe } | ||
.flatMap { mapSjablonListe(it) } | ||
.distinct() | ||
} |
Oops, something went wrong.