Skip to content

Commit

Permalink
Endre transaksjonshåndtering og oppdatere tester
Browse files Browse the repository at this point in the history
  • Loading branch information
s148719 committed Oct 17, 2023
1 parent 1ed625e commit 4019997
Show file tree
Hide file tree
Showing 13 changed files with 644 additions and 412 deletions.
6 changes: 6 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ services:
POSTGRES_DB: bidrag-behandling
volumes:
- db:/var/lib/postgresql/data
zookeeper:
container_name: zookeeper
image: confluentinc/cp-zookeeper:7.1.2
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
kafka:
image: confluentinc/cp-kafka:6.2.1
depends_on:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy
import org.springframework.context.annotation.Import

@EnableAspectJAutoProxy
@OpenAPIDefinition(info = Info(title = "bidrag-behandling", version = "v1"), security = [SecurityRequirement(name = "bearer-key")])
@OpenAPIDefinition(
info = Info(title = "bidrag-behandling", version = "v1"),
security = [SecurityRequirement(name = "bearer-key")],
)
@SecurityScheme(bearerFormat = "JWT", name = "bearer-key", scheme = "bearer", type = SecuritySchemeType.HTTP)
@Configuration
@EnableJwtTokenValidation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,4 @@ class BehandlingBeregnForskuddController(

return ForskuddBeregningRespons(result.getOrNull(), result.leftOrNull())
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ExceptionHandler {
data class Error(
val status: Int,
val message: String,
val fieldErrors: MutableList<CustomFieldError> = mutableListOf()
val fieldErrors: MutableList<CustomFieldError> = mutableListOf(),
) {
fun addFieldError(
objectName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class InntekterController(private val behandlingService: BehandlingService) {
@PathVariable behandlingId: Long,
@RequestBody request: UpdateInntekterRequest,
): InntekterResponse {
val behandling = behandlingService.hentBehandlingById(behandlingId)
var behandling = behandlingService.hentBehandlingById(behandlingId)

behandlingService.oppdaterInntekter(
behandlingId,
request.inntekter.toInntektDomain(behandling),
request.inntekter.toInntektDomain(behandling!!),
request.barnetillegg.toBarnetilleggDomain(behandling),
request.utvidetbarnetrygd.toUtvidetbarnetrygdDomain(behandling),
request.inntektBegrunnelseMedIVedtakNotat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ import java.util.Date

@Entity(name = "inntekt")
class Inntekt(
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "behandling_id", nullable = false)
val behandling: Behandling,
val taMed: Boolean,
val inntektType: String?,
val belop: BigDecimal,
val datoFom: Date?,
val datoTom: Date?,
val ident: String,
val fraGrunnlag: Boolean,
val taMed: Boolean,
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "behandling_id", nullable = false)
val behandling: Behandling? = null,
@OneToMany(fetch = FetchType.EAGER, mappedBy = "inntekt", cascade = [CascadeType.ALL], orphanRemoval = true)
var inntektPostListe: MutableSet<InntektPostDomain> = mutableSetOf(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import java.math.BigDecimal

@Entity(name = "inntekt_post")
class InntektPostDomain(
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "inntekt_id", nullable = false)
val inntekt: Inntekt,
@Column(name = "belop")
val beløp: BigDecimal,
val kode: String,
val visningsnavn: String,
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "inntekt_id", nullable = false)
val inntekt: Inntekt? = null,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.bidrag.behandling.service

import mu.KotlinLogging
import no.nav.bidrag.behandling.behandlingNotFoundException
import no.nav.bidrag.behandling.database.datamodell.Barnetillegg
import no.nav.bidrag.behandling.database.datamodell.Behandling
Expand All @@ -19,7 +20,9 @@ import no.nav.bidrag.behandling.transformers.toRolle
import no.nav.bidrag.domain.enums.Rolletype
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.Date
import java.util.*

private val log = KotlinLogging.logger {}

@Service
class BehandlingService(
Expand Down Expand Up @@ -88,32 +91,39 @@ class BehandlingService(

fun hentBehandlinger(): List<Behandling> = behandlingRepository.hentBehandlinger()

@Transactional
fun oppdaterInntekter(
behandlingId: Long,
inntekter: MutableSet<Inntekt>,
barnetillegg: MutableSet<Barnetillegg>,
utvidetbarnetrygd: MutableSet<Utvidetbarnetrygd>,
inntektBegrunnelseMedIVedtakNotat: String?,
inntektBegrunnelseKunINotat: String?,
) = behandlingRepository.save(
behandlingRepository.findBehandlingById(behandlingId)
) {
var behandling = behandlingRepository.findBehandlingById(behandlingId)
.orElseThrow { behandlingNotFoundException(behandlingId) }
.let {
it.inntektBegrunnelseMedIVedtakNotat = inntektBegrunnelseMedIVedtakNotat
it.inntektBegrunnelseKunINotat = inntektBegrunnelseKunINotat

it.inntekter.clear()
it.inntekter.addAll(inntekter)
behandling.inntektBegrunnelseMedIVedtakNotat = inntektBegrunnelseMedIVedtakNotat
behandling.inntektBegrunnelseKunINotat = inntektBegrunnelseKunINotat

it.barnetillegg.clear()
it.barnetillegg.addAll(barnetillegg)
if (behandling.inntekter != inntekter) {
log.info("Oppdaterer inntekter for behandlingsid $behandlingId")
behandling.inntekter.clear()
behandling.inntekter.addAll(inntekter)
}

it.utvidetbarnetrygd.clear()
it.utvidetbarnetrygd.addAll(utvidetbarnetrygd)
if (behandling.barnetillegg != barnetillegg) {
log.info("Oppdaterer barnetillegg for behandlingsid $behandlingId")
behandling.barnetillegg.clear()
behandling.barnetillegg.addAll(barnetillegg)
}

it
},
)
if (behandling.utvidetbarnetrygd != utvidetbarnetrygd) {
log.info("Oppdaterer utvidet barnetrygd for behandlingsid $behandlingId")
behandling.utvidetbarnetrygd.clear()
behandling.utvidetbarnetrygd.addAll(utvidetbarnetrygd)
}
}

fun updateVirkningsTidspunkt(
behandlingId: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ fun Set<HusstandsBarnPeriodeDto>.toDomain(husstandsBarn: HusstandsBarn) =

fun Set<HusstandsBarn>.toHusstandsBarnDto() =
this.map {
HusstandsBarnDto(it.id!!, it.medISaken, it.perioder.toHusstandsBarnPeriodeDto(), it.ident, it.navn, it.foedselsDato?.toLocalDate())
HusstandsBarnDto(
it.id!!,
it.medISaken,
it.perioder.toHusstandsBarnPeriodeDto(),
it.ident,
it.navn,
it.foedselsDato?.toLocalDate(),
)
}.toSet()

fun Set<HusstandsBarnDto>.toDomain(behandling: Behandling) =
Expand All @@ -91,16 +98,23 @@ fun Set<InntektDto>.toInntektDomain(behandling: Behandling) =
this.map {
val inntekt =
Inntekt(
behandling, it.taMed, it.inntektType, it.belop,
it.datoFom?.toDate(), it.datoTom?.toDate(), it.ident, it.fraGrunnlag, it.id,
it.inntektType,
it.belop,
it.datoFom?.toDate(),
it.datoTom?.toDate(),
it.ident,
it.fraGrunnlag,
it.taMed,
it.id,
behandling,
)
inntekt.inntektPostListe = it.inntektPostListe.toInntektPostDomain(inntekt).toMutableSet()
inntekt
}.toMutableSet()

fun Set<InntektPost>.toInntektPostDomain(inntekt: Inntekt) =
this.map {
InntektPostDomain(inntekt, it.beløp, it.kode, it.visningsnavn)
InntektPostDomain(it.beløp, it.kode, it.visningsnavn, inntekt = inntekt)
}.toSet()

fun Set<InntektPostDomain>.toInntektPost() =
Expand All @@ -110,11 +124,27 @@ fun Set<InntektPostDomain>.toInntektPost() =

fun Set<Inntekt>.toInntektDto() =
this.map {
InntektDto(it.id, it.taMed, it.inntektType, it.belop, it.datoFom?.toLocalDate(), it.datoTom?.toLocalDate(), it.ident, it.fraGrunnlag, it.inntektPostListe.toInntektPost())
InntektDto(
it.id,
it.taMed,
it.inntektType,
it.belop,
it.datoFom?.toLocalDate(),
it.datoTom?.toLocalDate(),
it.ident,
it.fraGrunnlag,
it.inntektPostListe.toInntektPost(),
)
}.toSet()

fun Opplysninger.toDto(): OpplysningerDto {
return OpplysningerDto(this.id!!, this.behandling.id!!, this.opplysningerType, this.data, this.hentetDato.toLocalDate())
return OpplysningerDto(
this.id!!,
this.behandling.id!!,
this.opplysningerType,
this.data,
this.hentetDato.toLocalDate(),
)
}

fun Behandling.tilForsendelseRolleDto() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class ForskuddBeregningTest {
),
)


splitPeriods.size shouldBe 1
}

Expand All @@ -74,9 +73,8 @@ class ForskuddBeregningTest {
),
)


splitPeriods.size shouldBe 1
splitPeriods[0].antall shouldBe 3.0
splitPeriods[0].antall shouldBe 3.0
}

@Test
Expand All @@ -103,7 +101,6 @@ class ForskuddBeregningTest {
cal2.add(Calendar.MONTH, 1)
val tilDato3 = cal2.time


val splitPeriods =
forskuddBeregning.splitPeriods(
listOf(
Expand All @@ -130,13 +127,13 @@ class ForskuddBeregningTest {
val fraDato = cal1.time
cal1.add(Calendar.MONTH, 1)
val tilDato = cal1.time

cal1.add(Calendar.MONTH, 1)
val fraDato1 = cal1.time

cal1.add(Calendar.MONTH, 1)
val tilDato1 = cal1.time

val splitPeriods =
forskuddBeregning.splitPeriods(
listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class BehandlingBeregnForskuddControllerTest : KontrollerTestRunner() {
)
b.inntekter =
mutableSetOf(
Inntekt(b, true, "beskrivelse", BigDecimal.TEN, datoFom, datoTom, "ident", true),
Inntekt("lønn", BigDecimal.TEN, datoFom, datoTom, "ident", true, true),
)
b.barnetillegg =
mutableSetOf(
Expand Down
Loading

0 comments on commit 4019997

Please sign in to comment.