-
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.
Logikk for å sende Avsluttet hendelse i BekreftelseUtgangStream.kt, l…
…aget PeriodeStream for å lagre identitetsnummer i state for åpne perioder, og slette state for avsluttede perioder
- Loading branch information
1 parent
92fca31
commit c19d3ac
Showing
9 changed files
with
127 additions
and
30 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
74 changes: 60 additions & 14 deletions
74
...e-utgang/src/main/kotlin/no/nav/paw/bekreftelseutgang/topology/BekreftelseUtgangStream.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,32 +1,78 @@ | ||
package no.nav.paw.bekreftelseutgang.topology | ||
|
||
import no.nav.paw.arbeidssokerregisteret.intern.v1.Avsluttet | ||
import no.nav.paw.arbeidssokerregisteret.intern.v1.Hendelse | ||
import no.nav.paw.arbeidssokerregisteret.intern.v1.HendelseSerde | ||
import no.nav.paw.arbeidssokerregisteret.intern.v1.vo.Bruker | ||
import no.nav.paw.arbeidssokerregisteret.intern.v1.vo.BrukerType | ||
import no.nav.paw.arbeidssokerregisteret.intern.v1.vo.Metadata | ||
import no.nav.paw.bekreftelse.internehendelser.BekreftelseHendelse | ||
import no.nav.paw.bekreftelse.internehendelser.baOmAaAvsluttePeriodeHendelsesType | ||
import no.nav.paw.bekreftelse.internehendelser.registerGracePeriodeUtloeptHendelseType | ||
import no.nav.paw.bekreftelseutgang.config.ApplicationConfig | ||
import no.nav.paw.config.kafka.streams.Punctuation | ||
import no.nav.paw.config.env.appImageOrDefaultForLocal | ||
import no.nav.paw.config.kafka.streams.genericProcess | ||
import org.apache.kafka.common.serialization.Serdes | ||
import org.apache.kafka.streams.StreamsBuilder | ||
import org.apache.kafka.streams.kstream.Produced | ||
import org.apache.kafka.streams.processor.PunctuationType | ||
import org.slf4j.LoggerFactory | ||
import org.apache.kafka.streams.state.KeyValueStore | ||
import java.time.Instant | ||
import java.util.* | ||
|
||
fun StreamsBuilder.buildBekreftelseUtgangStream(applicationConfig: ApplicationConfig) { | ||
with(applicationConfig.kafkaTopology) { | ||
stream<Long, no.nav.paw.bekreftelse.internehendelser.BekreftelseHendelse>(bekreftelseHendelseloggTopic) | ||
.genericProcess<Long, no.nav.paw.bekreftelse.internehendelser.BekreftelseHendelse, Long, Hendelse>( | ||
stream<Long, BekreftelseHendelse>(bekreftelseHendelseloggTopic) | ||
.genericProcess<Long, BekreftelseHendelse, Long, Hendelse>( | ||
name = "bekreftelseUtgangStream", | ||
internStateStoreName, | ||
punctuation = Punctuation( | ||
punctuationInterval, | ||
PunctuationType.WALL_CLOCK_TIME, | ||
{ _, _ -> true }, // TODO() | ||
), | ||
punctuation = null, | ||
) { record -> | ||
// TODO() | ||
} | ||
.to(hendelseloggTopic, Produced.with(Serdes.Long(), HendelseSerde())) | ||
val stateStore = getStateStore<KeyValueStore<UUID, String>>(internStateStoreName) | ||
// TODO: Må jeg ta høyde for at periodeStream ikke er ajoure og har lagt inn identitetsnummer i state? | ||
val identitetsnummer = stateStore[record.value().periodeId] ?: return@genericProcess | ||
|
||
when(record.value().hendelseType) { | ||
registerGracePeriodeUtloeptHendelseType -> avsluttetHendelse( | ||
identitetsnummer = identitetsnummer, | ||
periodeId = record.value().periodeId, | ||
arbeidssoekerId = record.value().arbeidssoekerId, | ||
utfoertAv = Bruker( | ||
type = BrukerType.SYSTEM, | ||
id = applicationConfig.getAppImage() | ||
), | ||
aarsak = "Graceperiode utløpt" | ||
) | ||
baOmAaAvsluttePeriodeHendelsesType -> avsluttetHendelse( | ||
identitetsnummer = identitetsnummer, | ||
periodeId = record.value().periodeId, | ||
arbeidssoekerId = record.value().arbeidssoekerId, | ||
utfoertAv = Bruker( | ||
type = BrukerType.SLUTTBRUKER, | ||
id = identitetsnummer | ||
), | ||
aarsak = "Svarte NEI på spørsmål 'Vil du fortsatt være registrert som arbeidssøker?'" | ||
) | ||
else -> { | ||
return@genericProcess | ||
} | ||
} | ||
}.to(hendelseloggTopic, Produced.with(Serdes.Long(), HendelseSerde())) | ||
} | ||
} | ||
|
||
private val bekreftelseUtgangLogger = LoggerFactory.getLogger("bekreftelseUtgangLogger") | ||
fun ApplicationConfig.getAppImage() = runtimeEnvironment.appImageOrDefaultForLocal("paw-arbeidssoekerregisteret-bekreftelse-utgang:LOCAL") | ||
|
||
fun avsluttetHendelse(identitetsnummer: String, periodeId: UUID, arbeidssoekerId: Long, utfoertAv: Bruker, aarsak: String) = Avsluttet( | ||
hendelseId = UUID.randomUUID(), | ||
id = arbeidssoekerId, | ||
identitetsnummer = identitetsnummer, | ||
metadata = metadata(utfoertAv, aarsak), | ||
periodeId = periodeId, | ||
) | ||
|
||
fun metadata(utfoertAv: Bruker, aarsak: String) = Metadata( | ||
tidspunkt = Instant.now(), | ||
utfoertAv = utfoertAv, | ||
kilde = "paw.arbeidssoekerregisteret.bekreftelse-utgang", | ||
aarsak = aarsak, | ||
) |
25 changes: 25 additions & 0 deletions
25
...bekreftelse-utgang/src/main/kotlin/no/nav/paw/bekreftelseutgang/topology/PeriodeStream.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,25 @@ | ||
package no.nav.paw.bekreftelseutgang.topology | ||
|
||
import no.nav.paw.bekreftelseutgang.config.ApplicationConfig | ||
import org.apache.kafka.streams.StreamsBuilder | ||
import no.nav.paw.arbeidssokerregisteret.api.v1.Periode | ||
import no.nav.paw.config.kafka.streams.mapNonNull | ||
import org.apache.kafka.streams.state.KeyValueStore | ||
import java.util.* | ||
|
||
fun StreamsBuilder.buildPeriodeStream(applicationConfig: ApplicationConfig){ | ||
with(applicationConfig.kafkaTopology){ | ||
stream<Long, Periode>(periodeTopic) | ||
.mapNonNull( | ||
"lagreEllerSlettPeriode", | ||
internStateStoreName | ||
) { periode -> | ||
val stateStore: KeyValueStore<UUID, String> = getStateStore(internStateStoreName) | ||
if(periode.avsluttet == null) { | ||
stateStore.put(periode.id, periode.identitetsnummer) | ||
} else { | ||
stateStore.delete(periode.id) | ||
} | ||
} | ||
} | ||
} |
17 changes: 7 additions & 10 deletions
17
apps/bekreftelse-utgang/src/main/kotlin/no/nav/paw/bekreftelseutgang/topology/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,28 @@ | ||
package no.nav.paw.bekreftelseutgang.topology | ||
|
||
import kotlinx.coroutines.runBlocking | ||
import no.nav.paw.bekreftelseutgang.config.ApplicationConfig | ||
import no.nav.paw.bekreftelseutgang.context.ApplicationContext | ||
import no.nav.paw.kafkakeygenerator.client.KafkaKeysClient | ||
import no.nav.paw.kafkakeygenerator.client.KafkaKeysResponse | ||
import org.apache.kafka.common.serialization.Serdes | ||
import org.apache.kafka.streams.StreamsBuilder | ||
import org.apache.kafka.streams.Topology | ||
import org.apache.kafka.streams.state.Stores | ||
|
||
fun buildTopology( | ||
applicationContext: ApplicationContext | ||
): Topology = StreamsBuilder().apply { | ||
//buildInternStateStore(applicationContext.applicationConfig) | ||
buildInternStateStore(applicationContext.applicationConfig) | ||
buildPeriodeStream(applicationContext.applicationConfig) | ||
buildBekreftelseUtgangStream(applicationContext.applicationConfig) | ||
}.build() | ||
|
||
/*fun StreamsBuilder.buildInternStateStore(applicationConfig: ApplicationConfig) { | ||
fun StreamsBuilder.buildInternStateStore(applicationConfig: ApplicationConfig) { | ||
with(applicationConfig.kafkaTopology) { | ||
addStateStore( | ||
Stores.keyValueStoreBuilder( | ||
Stores.persistentKeyValueStore(internStateStoreName), | ||
Serdes.UUID(), | ||
InternTilstandSerde() | ||
Serdes.String() | ||
) | ||
) | ||
} | ||
}*/ | ||
|
||
fun KafkaKeysClient.getIdAndKeyBlocking(identitetsnummer: String): KafkaKeysResponse = runBlocking { | ||
getIdAndKey(identitetsnummer) | ||
} |
1 change: 1 addition & 0 deletions
1
apps/bekreftelse-utgang/src/main/resources/local/application_config.toml
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
1 change: 1 addition & 0 deletions
1
apps/bekreftelse-utgang/src/main/resources/nais/application_config.toml
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