-
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.
Implementert scheduleUpdateTilstand, rettet navn i package, laget fel…
…les verdier for bekreftelse, lagt til en case i oversikt.txt, lagt in stateStoreNames parameter i Punctuation
- Loading branch information
1 parent
645ecad
commit 1a83c5e
Showing
17 changed files
with
253 additions
and
67 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
2 changes: 1 addition & 1 deletion
2
.../paw/bekretelsetjeneste/AnsvarTopology.kt → ...paw/bekreftelsetjeneste/AnsvarTopology.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
2 changes: 1 addition & 1 deletion
2
...telsetjeneste/ApplicationConfiguration.kt → ...telsetjeneste/ApplicationConfiguration.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,4 +1,4 @@ | ||
package no.nav.paw.bekretelsetjeneste | ||
package no.nav.paw.bekreftelsetjeneste | ||
|
||
import java.time.Duration | ||
|
||
|
4 changes: 2 additions & 2 deletions
4
.../bekretelsetjeneste/ApplicationContext.kt → ...bekreftelsetjeneste/ApplicationContext.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
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
26 changes: 26 additions & 0 deletions
26
apps/bekreftelse-tjeneste/src/main/kotlin/no/nav/paw/bekreftelsetjeneste/KontrolerFrister.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,26 @@ | ||
package no.nav.paw.bekreftelsetjeneste | ||
|
||
import no.nav.paw.bekreftelsetjeneste.tilstand.Bekreftelse | ||
import no.nav.paw.bekreftelsetjeneste.tilstand.BekreftelseConfig | ||
import java.time.Instant | ||
|
||
fun Bekreftelse.erKlarForUtfylling(now: Instant): Boolean = | ||
gjelderTil.minus(BekreftelseConfig.bekreftelseTilgjengeligOffset).isAfter(now) | ||
|
||
fun Bekreftelse.harFristUtloept(now: Instant): Boolean = | ||
gjelderTil.isBefore(now) | ||
|
||
fun Bekreftelse.skalPurres(now: Instant): Boolean = | ||
sistePurring == null && gjelderTil.plus( | ||
BekreftelseConfig.varselFoerGracePeriodeUtloept | ||
).isAfter(now) | ||
|
||
fun Bekreftelse.harGracePeriodeUtloept(now: Instant): Boolean = | ||
gjelderTil.plus(BekreftelseConfig.gracePeriode) | ||
.isAfter(now) | ||
|
||
fun Bekreftelse.skalLageNyBekreftelseTilgjengelig(now: Instant, bekreftelser: List<Bekreftelse>): Boolean = | ||
gjelderTil.plus(BekreftelseConfig.bekreftelseInterval) | ||
.minus(BekreftelseConfig.bekreftelseTilgjengeligOffset).isAfter(now) && bekreftelser.size < 2 | ||
|
||
|
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
149 changes: 149 additions & 0 deletions
149
...eftelse-tjeneste/src/main/kotlin/no/nav/paw/bekreftelsetjeneste/ScheduleUpdateTilstand.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,149 @@ | ||
package no.nav.paw.bekreftelsetjeneste | ||
|
||
import no.nav.paw.bekreftelse.internehendelser.BekreftelseHendelse | ||
import no.nav.paw.bekreftelse.internehendelser.BekreftelseTilgjengelig | ||
import no.nav.paw.bekreftelse.internehendelser.LeveringsfristUtloept | ||
import no.nav.paw.bekreftelse.internehendelser.RegisterGracePeriodeGjendstaaendeTid | ||
import no.nav.paw.bekreftelse.internehendelser.RegisterGracePeriodeUtloept | ||
import no.nav.paw.bekreftelsetjeneste.tilstand.BekreftelseConfig | ||
import no.nav.paw.bekreftelsetjeneste.tilstand.Tilstand | ||
import no.nav.paw.bekreftelsetjeneste.tilstand.fristForNesteBekreftelse | ||
import no.nav.paw.bekreftelsetjeneste.tilstand.gjenstaendeGracePeriode | ||
import org.apache.kafka.streams.KeyValue | ||
import org.apache.kafka.streams.processor.api.ProcessorContext | ||
import org.apache.kafka.streams.processor.api.Record | ||
import java.time.Instant | ||
import java.util.* | ||
|
||
fun scheduleUpdateTilstand(timestamp: Instant, ctx: ProcessorContext<Long, BekreftelseHendelse>, stateStoreNames: Array<out String>) { | ||
val stateStore: StateStore = ctx.getStateStore(stateStoreNames[0]) | ||
|
||
stateStore.all().use { states -> | ||
states.forEach { (key, value) -> | ||
value.bekreftelser.forEach { bekreftelse -> | ||
when { | ||
bekreftelse.tilstand == Tilstand.IkkeKlarForUtfylling | ||
&& bekreftelse.erKlarForUtfylling(timestamp) -> { | ||
val updatedBekreftelse = bekreftelse.copy(tilstand = Tilstand.KlarForUtfylling) | ||
val updatedInternTilstand = | ||
value.copy(bekreftelser = value.bekreftelser - bekreftelse + updatedBekreftelse) | ||
|
||
stateStore.put(key, updatedInternTilstand) | ||
|
||
val record = Record<Long, BekreftelseHendelse>( | ||
value.periode.recordKey, | ||
BekreftelseTilgjengelig( | ||
hendelseId = UUID.randomUUID(), | ||
periodeId = value.periode.periodeId, | ||
arbeidssoekerId = value.periode.arbeidsoekerId, | ||
bekreftelseId = bekreftelse.bekreftelseId, | ||
gjelderFra = bekreftelse.gjelderFra, | ||
gjelderTil = bekreftelse.gjelderTil | ||
), | ||
Instant.now().toEpochMilli() | ||
) | ||
ctx.forward(record) | ||
} | ||
|
||
bekreftelse.tilstand == Tilstand.KlarForUtfylling | ||
&& bekreftelse.harFristUtloept(timestamp) -> { | ||
val updatedBekreftelse = bekreftelse.copy(tilstand = Tilstand.VenterSvar) | ||
val updatedInternTilstand = | ||
value.copy(bekreftelser = value.bekreftelser - bekreftelse + updatedBekreftelse) | ||
|
||
stateStore.put(key, updatedInternTilstand) | ||
|
||
val record = Record<Long, BekreftelseHendelse>( | ||
value.periode.recordKey, | ||
LeveringsfristUtloept( | ||
hendelseId = UUID.randomUUID(), | ||
periodeId = value.periode.periodeId, | ||
arbeidssoekerId = value.periode.arbeidsoekerId, | ||
bekreftelseId = bekreftelse.bekreftelseId, | ||
), | ||
Instant.now().toEpochMilli() | ||
) | ||
ctx.forward(record) | ||
} | ||
|
||
bekreftelse.tilstand == Tilstand.VenterSvar && bekreftelse.skalPurres(timestamp) -> { | ||
val updatedBekreftelse = bekreftelse.copy(sistePurring = timestamp) | ||
val updatedInternTilstand = | ||
value.copy(bekreftelser = value.bekreftelser - bekreftelse + updatedBekreftelse) | ||
|
||
stateStore.put(key, updatedInternTilstand) | ||
|
||
val record = Record<Long, BekreftelseHendelse>( | ||
value.periode.recordKey, | ||
RegisterGracePeriodeGjendstaaendeTid( | ||
hendelseId = UUID.randomUUID(), | ||
periodeId = value.periode.periodeId, | ||
arbeidssoekerId = value.periode.arbeidsoekerId, | ||
bekreftelseId = bekreftelse.bekreftelseId, | ||
gjenstaandeTid = gjenstaendeGracePeriode(timestamp, bekreftelse.gjelderTil) | ||
), | ||
Instant.now().toEpochMilli() | ||
) | ||
ctx.forward(record) | ||
} | ||
|
||
bekreftelse.tilstand == Tilstand.VenterSvar && bekreftelse.harGracePeriodeUtloept(timestamp) -> { | ||
|
||
// TODO: Mangler vi tilstand.utloept eller er det riktig at den skal fjernes her? | ||
val updatedInternTilstand = value.copy( | ||
bekreftelser = value.bekreftelser - bekreftelse | ||
) | ||
|
||
stateStore.put(key, updatedInternTilstand) | ||
|
||
val record = Record<Long, BekreftelseHendelse>( | ||
value.periode.recordKey, | ||
RegisterGracePeriodeUtloept( | ||
hendelseId = UUID.randomUUID(), | ||
periodeId = value.periode.periodeId, | ||
arbeidssoekerId = value.periode.arbeidsoekerId, | ||
bekreftelseId = bekreftelse.bekreftelseId | ||
), | ||
Instant.now().toEpochMilli() | ||
) | ||
|
||
ctx.forward(record) | ||
} | ||
|
||
bekreftelse.skalLageNyBekreftelseTilgjengelig(timestamp, value.bekreftelser) -> { | ||
val newBekreftelse = bekreftelse.copy( | ||
tilstand = Tilstand.KlarForUtfylling, | ||
sistePurring = null, | ||
bekreftelseId = UUID.randomUUID(), | ||
gjelderFra = bekreftelse.gjelderTil, | ||
gjelderTil = fristForNesteBekreftelse(bekreftelse.gjelderTil, BekreftelseConfig.bekreftelseInterval) | ||
|
||
) | ||
val updatedInternTilstand = value.copy( | ||
bekreftelser = value.bekreftelser + newBekreftelse | ||
) | ||
stateStore.put(key, updatedInternTilstand) | ||
|
||
val record = Record<Long, BekreftelseHendelse>( | ||
value.periode.recordKey, | ||
BekreftelseTilgjengelig( | ||
hendelseId = UUID.randomUUID(), | ||
periodeId = value.periode.periodeId, | ||
arbeidssoekerId = value.periode.arbeidsoekerId, | ||
bekreftelseId = newBekreftelse.bekreftelseId, | ||
gjelderFra = newBekreftelse.gjelderFra, | ||
gjelderTil = newBekreftelse.gjelderTil | ||
), | ||
Instant.now().toEpochMilli() | ||
) | ||
|
||
ctx.forward(record) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private operator fun <K, V> KeyValue<K, V>.component1(): K = key | ||
private operator fun <K, V> KeyValue<K, V>.component2(): V = value |
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
4 changes: 2 additions & 2 deletions
4
...no/nav/paw/bekretelsetjeneste/Topology.kt → ...o/nav/paw/bekreftelsetjeneste/Topology.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
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
2 changes: 1 addition & 1 deletion
2
...etjeneste/tilstand/InternTilstandSerde.kt → ...etjeneste/tilstand/InternTilstandSerde.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
Oops, something went wrong.