Skip to content

Commit db6e2e3

Browse files
authored
Fix kun en iverksatt tilbakekrevingsbehandling bug (#1844)
1 parent 426a5fe commit db6e2e3

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

tilbakekreving/domain/src/main/kotlin/tilbakekreving/domain/TilbakekrevingsbehandlingHendelser.kt

+15-5
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,19 @@ data class TilbakekrevingsbehandlingHendelser private constructor(
7777
Tilbakekrevingsbehandlinger.empty(sakId)
7878
} else {
7979
toCurrentState().also {
80-
it.behandlinger.filterIsInstance<IverksattTilbakekrevingsbehandling>().let {
81-
if (it.size > 1) {
82-
throw IllegalStateException("Kun én iverksatt tilbakekrevingsbehandling kan referere til ett kravgrunnlag, men fant disse IDene: ${it.map { it.id }}")
80+
it.behandlinger.filterIsInstance<IverksattTilbakekrevingsbehandling>()
81+
.also { iverksattTilbakekrevingsbehandlinger ->
82+
iverksattTilbakekrevingsbehandlinger.map { it.kravgrunnlag.eksternKravgrunnlagId }.also {
83+
if (it.distinct().size != it.size) {
84+
throw IllegalStateException("Kun én iverksatt tilbakekrevingsbehandling kan referere til ett kravgrunnlag, men fant disse eksternKravgrunnlagIdene: $it")
85+
}
86+
}
87+
iverksattTilbakekrevingsbehandlinger.map { it.kravgrunnlag.eksternVedtakId }.also {
88+
if (it.distinct().size != it.size) {
89+
throw IllegalStateException("Kun én iverksatt tilbakekrevingsbehandling kan referere til ett kravgrunnlag, men fant disse eksternVedtakId: $it")
90+
}
91+
}
8392
}
84-
}
8593
}
8694
}
8795
}
@@ -98,7 +106,9 @@ data class TilbakekrevingsbehandlingHendelser private constructor(
98106
hendelseId to hendelse.toDomain(
99107
fnr = fnr,
100108
kravgrunnlagPåSakHendelse = kravgrunnlagsDetaljer,
101-
erKravgrunnlagUtdatert = this.kravgrunnlagPåSak.hentSisteKravgrunnagforEksternVedtakId(kravgrunnlagsDetaljer.kravgrunnlag.eksternVedtakId) != kravgrunnlagsDetaljer.kravgrunnlag,
109+
erKravgrunnlagUtdatert = this.kravgrunnlagPåSak.hentSisteKravgrunnagforEksternVedtakId(
110+
kravgrunnlagsDetaljer.kravgrunnlag.eksternVedtakId,
111+
) != kravgrunnlagsDetaljer.kravgrunnlag,
102112
),
103113
)
104114
}

0 commit comments

Comments
 (0)