-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Oppdaterte kafka streams tilstands klassen til bekreftelse-tjeneste
- Loading branch information
Showing
21 changed files
with
413 additions
and
316 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
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
51 changes: 51 additions & 0 deletions
51
...kreftelse-tjeneste/src/main/kotlin/no/nav/paw/bekreftelsetjeneste/tilstand/Bekreftelse.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,51 @@ | ||
package no.nav.paw.bekreftelsetjeneste.tilstand | ||
|
||
import arrow.core.NonEmptyList | ||
import java.time.Duration | ||
import java.time.Instant | ||
import java.util.* | ||
|
||
@JvmRecord | ||
data class Bekreftelse( | ||
val tilstandsLogg: BekreftelseTilstandsLogg, | ||
val bekreftelseId: UUID, | ||
val gjelderFra: Instant, | ||
val gjelderTil: Instant | ||
) | ||
|
||
inline fun <reified T: BekreftelseTilstand> Bekreftelse.tilstand(): T? = tilstandsLogg.get() | ||
|
||
inline fun <reified T: BekreftelseTilstand> Bekreftelse.has(): Boolean = tilstand<T>() != null | ||
|
||
fun Bekreftelse.sisteTilstand(): BekreftelseTilstand = tilstandsLogg.siste | ||
|
||
operator fun Bekreftelse.plus(bekreftelseTilstand: BekreftelseTilstand): Bekreftelse = | ||
copy(tilstandsLogg = tilstandsLogg + bekreftelseTilstand) | ||
|
||
fun opprettFoersteBekreftelse( | ||
periode: PeriodeInfo, | ||
interval: Duration, | ||
): Bekreftelse = | ||
Bekreftelse( | ||
BekreftelseTilstandsLogg(IkkeKlarForUtfylling(periode.startet), emptyList()), | ||
bekreftelseId = UUID.randomUUID(), | ||
gjelderFra = periode.startet, | ||
gjelderTil = fristForNesteBekreftelse(periode.startet, interval) | ||
) | ||
|
||
|
||
fun NonEmptyList<Bekreftelse>.opprettNesteTilgjengeligeBekreftelse( | ||
tilgjengeliggjort: Instant, | ||
interval: Duration | ||
): Bekreftelse { | ||
val sisteBekreftelse = maxBy { it.gjelderTil } | ||
return Bekreftelse( | ||
bekreftelseId = UUID.randomUUID(), | ||
gjelderFra = sisteBekreftelse.gjelderTil, | ||
gjelderTil = fristForNesteBekreftelse(sisteBekreftelse.gjelderTil, interval), | ||
tilstandsLogg = BekreftelseTilstandsLogg( | ||
siste = KlarForUtfylling(tilgjengeliggjort), | ||
tidligere = emptyList() | ||
) | ||
) | ||
} |
28 changes: 28 additions & 0 deletions
28
...e-tjeneste/src/main/kotlin/no/nav/paw/bekreftelsetjeneste/tilstand/BekreftelseTilstand.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,28 @@ | ||
package no.nav.paw.bekreftelsetjeneste.tilstand | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo | ||
import java.time.Instant | ||
|
||
@JsonTypeInfo( | ||
use = JsonTypeInfo.Id.NAME, | ||
include = JsonTypeInfo.As.PROPERTY, | ||
property = "type" | ||
) | ||
@JsonSubTypes( | ||
JsonSubTypes.Type(value = IkkeKlarForUtfylling::class, name = "IkkeKlarForUtfylling"), | ||
JsonSubTypes.Type(value = KlarForUtfylling::class, name = "KlarForUtfylling"), | ||
JsonSubTypes.Type(value = VenterSvar::class, name = "VenterSvar"), | ||
JsonSubTypes.Type(value = GracePeriodeUtloept::class, name = "GracePeriodeUtloept"), | ||
JsonSubTypes.Type(value = Levert::class, name = "Levert") | ||
) | ||
sealed interface BekreftelseTilstand { | ||
val timestamp: Instant | ||
} | ||
|
||
data class GracePeriodeUtloept(override val timestamp: Instant) : BekreftelseTilstand | ||
data class GracePeriodeVarselet(override val timestamp: Instant) : BekreftelseTilstand | ||
data class IkkeKlarForUtfylling(override val timestamp: Instant) : BekreftelseTilstand | ||
data class KlarForUtfylling(override val timestamp: Instant) : BekreftelseTilstand | ||
data class Levert(override val timestamp: Instant) : BekreftelseTilstand | ||
data class VenterSvar(override val timestamp: Instant) : BekreftelseTilstand |
34 changes: 34 additions & 0 deletions
34
...neste/src/main/kotlin/no/nav/paw/bekreftelsetjeneste/tilstand/BekreftelseTilstandsLogg.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,34 @@ | ||
package no.nav.paw.bekreftelsetjeneste.tilstand | ||
|
||
import arrow.core.NonEmptyList | ||
import arrow.core.nonEmptyListOf | ||
import org.slf4j.LoggerFactory | ||
|
||
@JvmRecord | ||
data class BekreftelseTilstandsLogg( | ||
val siste: BekreftelseTilstand, | ||
val tidligere: List<BekreftelseTilstand> | ||
) | ||
|
||
private val bekreftelseTilstandsLoggProblemerLogger = LoggerFactory.getLogger(BekreftelseTilstandsLogg::class.java) | ||
operator fun BekreftelseTilstandsLogg.plus(bekreftelseTilstand: BekreftelseTilstand): BekreftelseTilstandsLogg = | ||
(tidligere + siste + bekreftelseTilstand) | ||
.groupBy { it::class } | ||
.values | ||
.map { gruppe -> | ||
if (gruppe.size == 1) gruppe.first() | ||
else { | ||
bekreftelseTilstandsLoggProblemerLogger.warn("Flere tilstander av samme type i tilstandslogg: $gruppe, beholder den nyeste") | ||
gruppe.maxBy { it.timestamp } | ||
} | ||
} | ||
.let { alle -> | ||
val siste = alle.maxBy { it.timestamp } | ||
val tidligere = alle.filterNot { it == siste }.sortedBy { it.timestamp } | ||
BekreftelseTilstandsLogg(siste, tidligere) | ||
} | ||
|
||
inline fun <reified T : BekreftelseTilstand> BekreftelseTilstandsLogg.get(): T? = | ||
tidligere.filterIsInstance<T>().firstOrNull() ?: siste as? T | ||
|
||
fun BekreftelseTilstandsLogg.asList(): NonEmptyList<BekreftelseTilstand> = nonEmptyListOf(siste) + tidligere |
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
17 changes: 17 additions & 0 deletions
17
...kreftelse-tjeneste/src/main/kotlin/no/nav/paw/bekreftelsetjeneste/tilstand/PeriodeInfo.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,17 @@ | ||
package no.nav.paw.bekreftelsetjeneste.tilstand | ||
|
||
import java.time.Instant | ||
import java.util.* | ||
|
||
@JvmRecord | ||
data class PeriodeInfo( | ||
val periodeId: UUID, | ||
val identitetsnummer: String, | ||
val arbeidsoekerId: Long, | ||
val recordKey: Long, | ||
val startet: Instant, | ||
val avsluttet: Instant? | ||
) { | ||
val erAvsluttet: Boolean | ||
get() = avsluttet != 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
Oops, something went wrong.