Skip to content

Frikobler fagsak og behandling fra eksternIder då EmbeddedCollection … #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import no.nav.tilleggsstonader.sak.behandling.domain.BehandlingType
import no.nav.tilleggsstonader.sak.behandling.domain.Behandlingsjournalpost
import no.nav.tilleggsstonader.sak.behandling.domain.BehandlingsjournalpostRepository
import no.nav.tilleggsstonader.sak.behandling.domain.BehandlingÅrsak
import no.nav.tilleggsstonader.sak.behandling.domain.EksternBehandlingId
import no.nav.tilleggsstonader.sak.behandling.domain.EksternBehandlingIdRepository
import no.nav.tilleggsstonader.sak.behandling.domain.Journalposttype
import no.nav.tilleggsstonader.sak.behandling.domain.Saksbehandling
import no.nav.tilleggsstonader.sak.behandling.dto.HenlagtDto
Expand Down Expand Up @@ -42,6 +44,7 @@ import java.util.UUID
class BehandlingService(
private val behandlingsjournalpostRepository: BehandlingsjournalpostRepository,
private val behandlingRepository: BehandlingRepository,
private val eksternBehandlingIdRepository: EksternBehandlingIdRepository,
private val behandlingshistorikkService: BehandlingshistorikkService,
// private val taskService: TaskService,
) {
Expand Down Expand Up @@ -132,6 +135,7 @@ class BehandlingService(
kategori = BehandlingKategori.NASJONAL,
),
)
eksternBehandlingIdRepository.insert(EksternBehandlingId(behandlingId = behandling.id))

behandlingshistorikkService.opprettHistorikkInnslag(
behandlingshistorikk = Behandlingshistorikk(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import no.nav.tilleggsstonader.sak.infrastruktur.exception.brukerfeilHvis
import org.springframework.data.annotation.Id
import org.springframework.data.relational.core.mapping.Column
import org.springframework.data.relational.core.mapping.Embedded
import org.springframework.data.relational.core.mapping.MappedCollection
import org.springframework.data.relational.core.mapping.Table
import java.time.LocalDate
import java.time.LocalDateTime
Expand All @@ -20,8 +19,6 @@ data class Behandling(
val id: UUID = UUID.randomUUID(),
val fagsakId: UUID,
val forrigeBehandlingId: UUID? = null,
@MappedCollection(idColumn = "behandling_id")
val eksternId: EksternBehandlingId = EksternBehandlingId(),
// @Version ?
val versjon: Int = 0,

Expand Down Expand Up @@ -111,4 +108,5 @@ enum class BehandlingStatus {
data class EksternBehandlingId(
@Id
val id: Long = 0,
val behandlingId: UUID,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package no.nav.tilleggsstonader.sak.behandling.domain

import no.nav.tilleggsstonader.sak.infrastruktur.database.repository.InsertUpdateRepository
import no.nav.tilleggsstonader.sak.infrastruktur.database.repository.RepositoryInterface
import org.springframework.stereotype.Repository
import java.util.UUID

@Repository
interface EksternBehandlingIdRepository :
RepositoryInterface<EksternBehandlingId, Long>,
InsertUpdateRepository<EksternBehandlingId> {

fun findByBehandlingId(behandlingId: UUID): EksternBehandlingId
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import no.nav.tilleggsstonader.kontrakter.felles.Stønadstype
import no.nav.tilleggsstonader.sak.behandling.BehandlingService
import no.nav.tilleggsstonader.sak.behandling.domain.Behandling
import no.nav.tilleggsstonader.sak.behandling.dto.tilDto
import no.nav.tilleggsstonader.sak.fagsak.domain.EksternFagsakId
import no.nav.tilleggsstonader.sak.fagsak.domain.EksternFagsakIdRepository
import no.nav.tilleggsstonader.sak.fagsak.domain.Fagsak
import no.nav.tilleggsstonader.sak.fagsak.domain.FagsakDomain
import no.nav.tilleggsstonader.sak.fagsak.domain.FagsakPerson
import no.nav.tilleggsstonader.sak.fagsak.domain.FagsakPersonService
import no.nav.tilleggsstonader.sak.fagsak.domain.FagsakRepository
import no.nav.tilleggsstonader.sak.fagsak.domain.Fagsaker
import no.nav.tilleggsstonader.sak.fagsak.domain.PersonIdent
import no.nav.tilleggsstonader.sak.fagsak.domain.tilFagsakMedPerson
import no.nav.tilleggsstonader.sak.fagsak.dto.FagsakDto
import no.nav.tilleggsstonader.sak.fagsak.dto.tilDto
Expand All @@ -27,6 +30,7 @@ import java.util.UUID
class FagsakService(
private val fagsakPersonService: FagsakPersonService,
private val fagsakRepository: FagsakRepository,
private val eksternFagsakIdRepository: EksternFagsakIdRepository,
private val personService: PersonService,
private val behandlingService: BehandlingService,
) {
Expand Down Expand Up @@ -119,7 +123,7 @@ class FagsakService(
?: throw Feil("Finner ikke fagsak til behandlingId=$behandlingId")
}

fun hentEksternId(fagsakId: UUID): Long = fagsakRepository.findByIdOrThrow(fagsakId).eksternId.id
fun hentEksternId(fagsakId: UUID): Long = eksternFagsakIdRepository.findByFagsakId(fagsakId).id

fun hentFagsakPåEksternId(eksternFagsakId: Long): Fagsak =
fagsakRepository.finnMedEksternId(eksternFagsakId)
Expand Down Expand Up @@ -150,16 +154,23 @@ class FagsakService(
}

private fun opprettFagsak(stønadstype: Stønadstype, fagsakPerson: FagsakPerson): FagsakDomain {
return fagsakRepository.insert(
val fagsak = fagsakRepository.insert(
FagsakDomain(
stønadstype = stønadstype,
fagsakPersonId = fagsakPerson.id,
),
)
eksternFagsakIdRepository.insert(EksternFagsakId(fagsakId = fagsak.id))
return fagsak
}

fun FagsakDomain.tilFagsakMedPerson(): Fagsak {
private fun FagsakDomain.tilFagsakMedPerson(): Fagsak {
val personIdenter = fagsakPersonService.hentIdenter(this.fagsakPersonId)
return this.tilFagsakMedPerson(personIdenter)
}

private fun FagsakDomain.tilFagsakMedPerson(personIdenter: Set<PersonIdent>): Fagsak {
val eksternId = eksternFagsakIdRepository.findByFagsakId(this.id)
return this.tilFagsakMedPerson(personIdenter, eksternId)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package no.nav.tilleggsstonader.sak.fagsak.domain

import no.nav.tilleggsstonader.sak.infrastruktur.database.repository.InsertUpdateRepository
import no.nav.tilleggsstonader.sak.infrastruktur.database.repository.RepositoryInterface
import org.springframework.stereotype.Repository
import java.util.UUID

@Repository
interface EksternFagsakIdRepository : RepositoryInterface<EksternFagsakId, Long>, InsertUpdateRepository<EksternFagsakId> {

fun findByFagsakId(fagsakId: UUID): EksternFagsakId
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import no.nav.tilleggsstonader.sak.infrastruktur.database.Sporbar
import org.springframework.data.annotation.Id
import org.springframework.data.relational.core.mapping.Column
import org.springframework.data.relational.core.mapping.Embedded
import org.springframework.data.relational.core.mapping.MappedCollection
import org.springframework.data.relational.core.mapping.Table
import java.util.UUID

Expand Down Expand Up @@ -35,8 +34,6 @@ data class FagsakDomain(
@Id
val id: UUID = UUID.randomUUID(),
val fagsakPersonId: UUID,
@MappedCollection(idColumn = "fagsak_id")
val eksternId: EksternFagsakId = EksternFagsakId(),
@Column("stonadstype")
val stønadstype: Stønadstype,
@Embedded(onEmpty = Embedded.OnEmpty.USE_EMPTY)
Expand All @@ -47,14 +44,15 @@ data class FagsakDomain(
data class EksternFagsakId(
@Id
val id: Long = 0,
val fagsakId: UUID,
)

fun FagsakDomain.tilFagsakMedPerson(personIdenter: Set<PersonIdent>): Fagsak =
fun FagsakDomain.tilFagsakMedPerson(personIdenter: Set<PersonIdent>, eksternFagsakId: EksternFagsakId): Fagsak =
Fagsak(
id = id,
fagsakPersonId = fagsakPersonId,
personIdenter = personIdenter,
eksternId = eksternId,
eksternId = eksternFagsakId,
stønadstype = stønadstype,
sporbar = sporbar,
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal class BehandlingControllerTest : IntegrationTest() {
@Test
internal fun `Skal returnere 403 dersom man ikke har tilgang til brukeren`() {
val fagsak = testoppsettService.lagreFagsak(fagsak(identer = setOf(PersonIdent("ikkeTilgang"))))
val behandling = behandlingRepository.insert(behandling(fagsak))
val behandling = testoppsettService.lagre(behandling(fagsak))
val respons = catchThrowableOfType<HttpClientErrorException.Forbidden> { hentBehandling(behandling.id) }

assertThat(respons.statusCode).isEqualTo(HttpStatus.FORBIDDEN)
Expand All @@ -45,7 +45,7 @@ internal class BehandlingControllerTest : IntegrationTest() {
@Test
internal fun `Skal henlegge behandling`() {
val fagsak = testoppsettService.lagreFagsak(fagsak(identer = setOf(PersonIdent("12345678901"))))
val behandling = behandlingRepository.insert(behandling(fagsak, type = BehandlingType.FØRSTEGANGSBEHANDLING))
val behandling = testoppsettService.lagre(behandling(fagsak, type = BehandlingType.FØRSTEGANGSBEHANDLING))
val respons = henlegg(behandling.id, HenlagtDto(årsak = HenlagtÅrsak.FEILREGISTRERT))

assertThat(respons.statusCode).isEqualTo(HttpStatus.OK)
Expand All @@ -56,7 +56,7 @@ internal class BehandlingControllerTest : IntegrationTest() {
@Test
internal fun `Skal henlegge FØRSTEGANGSBEHANDLING`() {
val fagsak = testoppsettService.lagreFagsak(fagsak(identer = setOf(PersonIdent("12345678901"))))
val behandling = behandlingRepository.insert(behandling(fagsak, type = BehandlingType.FØRSTEGANGSBEHANDLING))
val behandling = testoppsettService.lagre(behandling(fagsak, type = BehandlingType.FØRSTEGANGSBEHANDLING))
val respons = henlegg(behandling.id, HenlagtDto(årsak = HenlagtÅrsak.FEILREGISTRERT))

assertThat(respons.statusCode).isEqualTo(HttpStatus.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class BehandlingServiceIntegrationTest : IntegrationTest() {
@Test
internal fun `opprettBehandling skal ikke være mulig å opprette en revurdering om forrige behandling ikke er ferdigstilt`() {
val fagsak = testoppsettService.lagreFagsak(fagsak())
behandlingRepository.insert(
testoppsettService.lagre(
behandling(
fagsak = fagsak,
status = BehandlingStatus.UTREDES,
Expand Down Expand Up @@ -64,16 +64,16 @@ internal class BehandlingServiceIntegrationTest : IntegrationTest() {
@Test
internal fun `hentBehandlinger - skal returnere behandlinger`() {
val fagsak = testoppsettService.lagreFagsak(fagsak())
val behandling = behandlingRepository.insert(behandling(fagsak, status = BehandlingStatus.FERDIGSTILT))
val behandling2 = behandlingRepository.insert(behandling(fagsak))
val behandling = testoppsettService.lagre(behandling(fagsak, status = BehandlingStatus.FERDIGSTILT))
val behandling2 = testoppsettService.lagre(behandling(fagsak))

assertThat(behandlingService.hentBehandlinger(setOf(behandling.id, behandling2.id))).hasSize(2)
}

@Test
internal fun `skal finne siste behandling med avslåtte hvis kun avslått`() {
val fagsak = testoppsettService.lagreFagsak(fagsak())
val behandling = behandlingRepository.insert(
val behandling = testoppsettService.lagre(
behandling(fagsak, resultat = BehandlingResultat.AVSLÅTT, status = BehandlingStatus.FERDIGSTILT),
)
val sisteBehandling = behandlingService.finnSisteIverksatteBehandlingMedEventuellAvslått(fagsak.id)
Expand All @@ -83,10 +83,10 @@ internal class BehandlingServiceIntegrationTest : IntegrationTest() {
@Test
internal fun `skal finne siste behandling med avslåtte hvis avslått og henlagt`() {
val fagsak = testoppsettService.lagreFagsak(fagsak())
val avslag = behandlingRepository.insert(
val avslag = testoppsettService.lagre(
behandling(fagsak, resultat = BehandlingResultat.AVSLÅTT, status = BehandlingStatus.FERDIGSTILT),
)
behandlingRepository.insert(
testoppsettService.lagre(
behandling(fagsak, resultat = BehandlingResultat.HENLAGT, status = BehandlingStatus.FERDIGSTILT),
)
val sisteBehandling = behandlingService.finnSisteIverksatteBehandlingMedEventuellAvslått(fagsak.id)
Expand All @@ -96,13 +96,13 @@ internal class BehandlingServiceIntegrationTest : IntegrationTest() {
@Test
internal fun `skal plukke ut førstegangsbehandling hvis det finnes førstegangsbehandling, avslått og henlagt`() {
val fagsak = testoppsettService.lagreFagsak(fagsak())
val førstegang = behandlingRepository.insert(
val førstegang = testoppsettService.lagre(
behandling(fagsak, resultat = BehandlingResultat.INNVILGET, status = BehandlingStatus.FERDIGSTILT),
)
behandlingRepository.insert(
testoppsettService.lagre(
behandling(fagsak, resultat = BehandlingResultat.AVSLÅTT, status = BehandlingStatus.FERDIGSTILT),
)
behandlingRepository.insert(
testoppsettService.lagre(
behandling(fagsak, resultat = BehandlingResultat.HENLAGT, status = BehandlingStatus.FERDIGSTILT),
)
val sisteBehandling = behandlingService.finnSisteIverksatteBehandlingMedEventuellAvslått(fagsak.id)
Expand Down Expand Up @@ -132,16 +132,16 @@ internal class BehandlingServiceIntegrationTest : IntegrationTest() {
),
)

behandlingRepository.insert(
testoppsettService.lagre(
behandling(fagsakOs, resultat = BehandlingResultat.HENLAGT, status = BehandlingStatus.FERDIGSTILT),
)
val førstegangBt = behandlingRepository.insert(
val førstegangBt = testoppsettService.lagre(
behandling(fagsakBt, resultat = BehandlingResultat.INNVILGET, status = BehandlingStatus.FERDIGSTILT),
)
val førstegangSp = behandlingRepository.insert(
val førstegangSp = testoppsettService.lagre(
behandling(fagsakSp, resultat = BehandlingResultat.INNVILGET, status = BehandlingStatus.FERDIGSTILT),
)
val revurderingUnderArbeidSP = behandlingRepository.insert(
val revurderingUnderArbeidSP = testoppsettService.lagre(
behandling(fagsakSp, resultat = BehandlingResultat.IKKE_SATT, status = BehandlingStatus.UTREDES),
)

Expand All @@ -156,7 +156,7 @@ internal class BehandlingServiceIntegrationTest : IntegrationTest() {
@Test
internal fun `opprettBehandling av førstegangsbehandling er ikke mulig hvis det finnes en førstegangsbehandling på vent`() {
val fagsak = testoppsettService.lagreFagsak(fagsak())
behandlingRepository.insert(behandling(fagsak, BehandlingStatus.SATT_PÅ_VENT))
testoppsettService.lagre(behandling(fagsak, BehandlingStatus.SATT_PÅ_VENT))
assertThatThrownBy {
behandlingService.opprettBehandling(
BehandlingType.FØRSTEGANGSBEHANDLING,
Expand All @@ -169,7 +169,7 @@ internal class BehandlingServiceIntegrationTest : IntegrationTest() {
@Test
internal fun `opprettBehandling av revurdering er ikke mulig hvis det finnes en førstegangsbehandling på vent`() {
val fagsak = testoppsettService.lagreFagsak(fagsak())
behandlingRepository.insert(behandling(fagsak, BehandlingStatus.SATT_PÅ_VENT))
testoppsettService.lagre(behandling(fagsak, BehandlingStatus.SATT_PÅ_VENT))
assertThatThrownBy {
behandlingService.opprettBehandling(
BehandlingType.REVURDERING,
Expand All @@ -182,8 +182,8 @@ internal class BehandlingServiceIntegrationTest : IntegrationTest() {
@Test
internal fun `opprettBehandling er mulig hvis det finnes en revurdering på vent`() {
val fagsak = testoppsettService.lagreFagsak(fagsak())
behandlingRepository.insert(behandling(fagsak, BehandlingStatus.FERDIGSTILT))
behandlingRepository.insert(
testoppsettService.lagre(behandling(fagsak, BehandlingStatus.FERDIGSTILT))
testoppsettService.lagre(
behandling(fagsak, BehandlingStatus.SATT_PÅ_VENT, type = BehandlingType.REVURDERING),
)
behandlingService.opprettBehandling(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ internal class BehandlingServiceTest {
BehandlingService(
mockk(),
behandlingRepository,
mockk(),
behandlingshistorikkService,
// taskService,
)
Expand Down
Loading