-
Notifications
You must be signed in to change notification settings - Fork 8
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 #693 from navikt/perioder-flere-fnr
Håndter at personer kan ha flere identer når vi starter, avslutter og henter periode
- Loading branch information
Showing
13 changed files
with
132 additions
and
52 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
44 changes: 27 additions & 17 deletions
44
src/main/kotlin/no/nav/fo/veilarbregistrering/arbeidssoker/ArbeidssokerperiodeService.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 |
---|---|---|
@@ -1,45 +1,55 @@ | ||
package no.nav.fo.veilarbregistrering.arbeidssoker | ||
|
||
import no.nav.fo.veilarbregistrering.arbeidssoker.formidlingsgruppe.FormidlingsgruppeEndretEvent | ||
import no.nav.fo.veilarbregistrering.bruker.Foedselsnummer | ||
import no.nav.fo.veilarbregistrering.bruker.Bruker | ||
import no.nav.fo.veilarbregistrering.bruker.Periode | ||
import no.nav.fo.veilarbregistrering.bruker.UserService | ||
import no.nav.fo.veilarbregistrering.log.logger | ||
import java.time.LocalDateTime | ||
|
||
class ArbeidssokerperiodeService(val repository: ArbeidssokerperiodeRepository) { | ||
class ArbeidssokerperiodeService( | ||
private val repository: ArbeidssokerperiodeRepository, | ||
private val userService: UserService | ||
) { | ||
|
||
fun startPeriode(foedselsnummer: Foedselsnummer) { | ||
if (harAktivPeriode(foedselsnummer)) { | ||
fun startPeriode(bruker: Bruker) { | ||
if (harAktivPeriode(bruker)) { | ||
throw IllegalStateException("Bruker har allerede en aktiv periode") | ||
} | ||
|
||
repository.startPeriode(foedselsnummer, LocalDateTime.now()) | ||
repository.startPeriode(bruker.gjeldendeFoedselsnummer, LocalDateTime.now()) | ||
} | ||
|
||
fun behandleFormidlingsgruppeEvent(formidlingsgruppeEndretEvent: FormidlingsgruppeEndretEvent) { | ||
if (formidlingsgruppeEndretEvent.erArbeidssoker()) { | ||
return | ||
} | ||
|
||
if (!harAktivPeriode(formidlingsgruppeEndretEvent.foedselsnummer)) { | ||
return | ||
val bruker = userService.finnBrukerGjennomPdlForSystemkontekst(formidlingsgruppeEndretEvent.foedselsnummer) | ||
val aktivPeriode = hentAktivPeriode(bruker) ?: return | ||
|
||
if (aktivPeriode.foedselsnummer != bruker.gjeldendeFoedselsnummer) { | ||
// TODO skal vi i dette tilfellet oppdatere fødselsnummeret på perioden? | ||
logger.warn("Avslutter periode for person som har et annet gjeldende fødselsnummer enn den aktive perioden") | ||
} | ||
|
||
repository.avsluttPeriode(foedselsnummer = formidlingsgruppeEndretEvent.foedselsnummer, LocalDateTime.now()) | ||
repository.avsluttPeriode(id = aktivPeriode.id, LocalDateTime.now()) | ||
} | ||
|
||
fun hentPerioder(foedselsnummer: Foedselsnummer): List<Periode> { | ||
return repository.hentPerioder(foedselsnummer).map { Periode(it.fra.toLocalDate(), it.til?.toLocalDate()) } | ||
fun hentPerioder(bruker: Bruker): List<Periode> { | ||
return repository.hentPerioder(bruker.gjeldendeFoedselsnummer, bruker.historiskeFoedselsnummer) | ||
.map { Periode(it.fra.toLocalDate(), it.til?.toLocalDate()) } | ||
} | ||
|
||
private fun harAktivPeriode(foedselsnummer: Foedselsnummer): Boolean { | ||
return harAktivPeriode(repository.hentPerioder(foedselsnummer)) | ||
private fun harAktivPeriode(bruker: Bruker): Boolean { | ||
return hentAktivPeriode(bruker) != null | ||
} | ||
|
||
private fun harAktivPeriode(perioder: List<ArbeidssokerperiodeDto>): Boolean { | ||
if (perioder.isEmpty()) { | ||
return false | ||
} | ||
private fun hentAktivPeriode(bruker: Bruker): ArbeidssokerperiodeDto? { | ||
val perioder = repository.hentPerioder(bruker.gjeldendeFoedselsnummer, bruker.historiskeFoedselsnummer) | ||
|
||
if (perioder.isEmpty()) return null | ||
|
||
return perioder.first().til == null | ||
return perioder.find { it.til == null } | ||
} | ||
} |
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
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