-
Notifications
You must be signed in to change notification settings - Fork 2
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 #1373 from navikt/dry-run-regulering
Dry run regulering
- Loading branch information
Showing
8 changed files
with
274 additions
and
86 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
80 changes: 80 additions & 0 deletions
80
domain/src/main/kotlin/no/nav/su/se/bakover/domain/regulering/ReguleringRunType.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,80 @@ | ||
package no.nav.su.se.bakover.domain.regulering | ||
|
||
import arrow.core.Either | ||
import arrow.core.getOrElse | ||
import no.nav.su.se.bakover.common.persistence.SessionFactory | ||
import no.nav.su.se.bakover.common.persistence.TransactionContext | ||
import no.nav.su.se.bakover.domain.oppdrag.Utbetaling | ||
import no.nav.su.se.bakover.domain.oppdrag.UtbetalingFeilet | ||
import no.nav.su.se.bakover.domain.oppdrag.UtbetalingKlargjortForOversendelse | ||
import no.nav.su.se.bakover.domain.revurdering.iverksett.IverksettTransactionException | ||
import no.nav.su.se.bakover.domain.revurdering.iverksett.KunneIkkeFerdigstilleIverksettelsestransaksjon | ||
import no.nav.su.se.bakover.domain.vedtak.Vedtak | ||
import no.nav.su.se.bakover.domain.vedtak.VedtakInnvilgetRegulering | ||
import no.nav.su.se.bakover.domain.vedtak.VedtakSomKanRevurderes | ||
import java.time.Clock | ||
|
||
interface ReguleringRunType { | ||
val sessionFactory: SessionFactory | ||
val lagreRegulering: (Regulering, TransactionContext) -> Unit | ||
val lagreVedtak: (Vedtak, TransactionContext) -> Unit | ||
val klargjørUtbetaling: (utbetaling: Utbetaling.SimulertUtbetaling, tx: TransactionContext) -> Either<UtbetalingFeilet, UtbetalingKlargjortForOversendelse<UtbetalingFeilet.Protokollfeil>> | ||
val notifyObservers: (VedtakInnvilgetRegulering) -> Unit | ||
} | ||
|
||
sealed class LiveRun : ReguleringRunType { | ||
|
||
data class Opprettet( | ||
override val sessionFactory: SessionFactory, | ||
override val lagreRegulering: (Regulering, TransactionContext) -> Unit, | ||
override val lagreVedtak: (Vedtak, TransactionContext) -> Unit, | ||
override val klargjørUtbetaling: (utbetaling: Utbetaling.SimulertUtbetaling, tx: TransactionContext) -> Either<UtbetalingFeilet, UtbetalingKlargjortForOversendelse<UtbetalingFeilet.Protokollfeil>>, | ||
override val notifyObservers: (VedtakInnvilgetRegulering) -> Unit, | ||
) : LiveRun() { | ||
fun kjørSideffekter(regulering: OpprettetRegulering) { | ||
sessionFactory.withTransactionContext { tx -> | ||
lagreRegulering(regulering, tx) | ||
} | ||
} | ||
} | ||
|
||
data class Iverksatt( | ||
override val sessionFactory: SessionFactory, | ||
override val lagreRegulering: (Regulering, TransactionContext) -> Unit, | ||
override val lagreVedtak: (Vedtak, TransactionContext) -> Unit, | ||
override val klargjørUtbetaling: (utbetaling: Utbetaling.SimulertUtbetaling, tx: TransactionContext) -> Either<UtbetalingFeilet, UtbetalingKlargjortForOversendelse<UtbetalingFeilet.Protokollfeil>>, | ||
override val notifyObservers: (VedtakInnvilgetRegulering) -> Unit, | ||
) : LiveRun() { | ||
fun kjørSideffekter( | ||
regulering: IverksattRegulering, | ||
utbetaling: Utbetaling.SimulertUtbetaling, | ||
clock: Clock, | ||
) { | ||
sessionFactory.withTransactionContext { tx -> | ||
val nyUtbetaling = klargjørUtbetaling( | ||
utbetaling, | ||
tx, | ||
).getOrElse { | ||
throw IverksettTransactionException( | ||
"Kunne ikke opprette utbetaling. Underliggende feil:$it.", | ||
KunneIkkeFerdigstilleIverksettelsestransaksjon.KunneIkkeUtbetale(it), | ||
) | ||
} | ||
|
||
val vedtak = VedtakSomKanRevurderes.from( | ||
regulering = regulering, | ||
utbetalingId = nyUtbetaling.utbetaling.id, | ||
clock = clock, | ||
) | ||
|
||
lagreRegulering(regulering, tx) | ||
lagreVedtak(vedtak, tx) | ||
|
||
nyUtbetaling.sendUtbetaling() | ||
.getOrElse { throw RuntimeException(it.toString()) } | ||
|
||
notifyObservers(vedtak) | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.