-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IS-2121: Behandle oppgave vurder avslag ved konsumering av arbeidsufo…
…rhet-vurdering (#195) * IS-2141: Behandle vurder avslag on consume vurdering * Log error on multiple ubehandlede oppgaver and behandle all
- Loading branch information
1 parent
049e1bc
commit d81bbd1
Showing
7 changed files
with
443 additions
and
4 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
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/no/nav/syfo/arbeidsuforhet/kafka/ArbeidsuforhetVurdering.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.syfo.arbeidsuforhet.kafka | ||
|
||
import no.nav.syfo.personoppgave.domain.PersonOppgave | ||
import no.nav.syfo.util.toLocalDateTimeOslo | ||
import java.time.OffsetDateTime | ||
import java.util.* | ||
|
||
data class ArbeidsuforhetVurdering( | ||
val uuid: UUID, | ||
val personident: String, | ||
val createdAt: OffsetDateTime, | ||
val veilederident: String, | ||
val type: VurderingType, | ||
val begrunnelse: String, | ||
) | ||
|
||
enum class VurderingType { | ||
FORHANDSVARSEL, OPPFYLT, AVSLAG | ||
} | ||
|
||
infix fun ArbeidsuforhetVurdering.behandler(personOppgave: PersonOppgave): Boolean = | ||
this.isFinal() && this.createdAt.toLocalDateTimeOslo().isAfter(personOppgave.opprettet) | ||
|
||
private fun ArbeidsuforhetVurdering.isFinal(): Boolean = when (type) { | ||
VurderingType.FORHANDSVARSEL -> false | ||
VurderingType.OPPFYLT -> true | ||
VurderingType.AVSLAG -> true | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/kotlin/no/nav/syfo/arbeidsuforhet/kafka/ArbeidsuforhetVurderingConsumer.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,56 @@ | ||
package no.nav.syfo.arbeidsuforhet.kafka | ||
|
||
import no.nav.syfo.ApplicationState | ||
import no.nav.syfo.EnvironmentKafka | ||
import no.nav.syfo.arbeidsuforhet.VurderAvslagService | ||
import no.nav.syfo.kafka.KafkaConsumerService | ||
import no.nav.syfo.kafka.kafkaAivenConsumerConfig | ||
import no.nav.syfo.kafka.launchKafkaTask | ||
import org.apache.kafka.clients.consumer.ConsumerRecords | ||
import org.apache.kafka.clients.consumer.KafkaConsumer | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
import java.time.Duration | ||
|
||
class ArbeidsuforhetVurderingConsumer( | ||
private val kafkaEnvironment: EnvironmentKafka, | ||
private val applicationState: ApplicationState, | ||
private val vurderAvslagService: VurderAvslagService, | ||
) : KafkaConsumerService<ArbeidsuforhetVurdering> { | ||
override val pollDurationInMillis: Long = 1000 | ||
|
||
override fun pollAndProcessRecords(kafkaConsumer: KafkaConsumer<String, ArbeidsuforhetVurdering>) { | ||
val records = kafkaConsumer.poll(Duration.ofMillis(pollDurationInMillis)) | ||
if (records.count() > 0) { | ||
log.info("ArbeidsuforhetVurderingConsumer trace: Received ${records.count()} records") | ||
processRecords(records) | ||
kafkaConsumer.commitSync() | ||
} | ||
} | ||
|
||
private fun processRecords(records: ConsumerRecords<String, ArbeidsuforhetVurdering>) { | ||
val (tombstoneRecords, validRecords) = records.partition { it.value() == null } | ||
|
||
if (tombstoneRecords.isNotEmpty()) { | ||
val numberOfTombstones = tombstoneRecords.size | ||
log.warn("Value of $numberOfTombstones ConsumerRecord are null, most probably due to a tombstone. Contact the owner of the topic if an error is suspected") | ||
} | ||
|
||
vurderAvslagService.processArbeidsuforhetVurdering(vurderingList = validRecords.map { it.value() }) | ||
} | ||
|
||
fun launch() { | ||
val consumerProperties = kafkaAivenConsumerConfig<ArbeidsuforhetVurderingDeserializer>(environmentKafka = kafkaEnvironment) | ||
launchKafkaTask( | ||
applicationState = applicationState, | ||
kafkaConsumerService = this, | ||
consumerProperties = consumerProperties, | ||
topics = listOf(ARBEIDSUFORHET_VURDERING_TOPIC), | ||
) | ||
} | ||
|
||
companion object { | ||
const val ARBEIDSUFORHET_VURDERING_TOPIC = "teamsykefravr.arbeidsuforhet-vurdering" | ||
val log: Logger = LoggerFactory.getLogger(this::class.java) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/no/nav/syfo/arbeidsuforhet/kafka/ArbeidsuforhetVurderingDeserializer.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,10 @@ | ||
package no.nav.syfo.arbeidsuforhet.kafka | ||
|
||
import no.nav.syfo.util.configuredJacksonMapper | ||
import org.apache.kafka.common.serialization.Deserializer | ||
|
||
class ArbeidsuforhetVurderingDeserializer : Deserializer<ArbeidsuforhetVurdering> { | ||
private val mapper = configuredJacksonMapper() | ||
override fun deserialize(topic: String, data: ByteArray): ArbeidsuforhetVurdering = | ||
mapper.readValue(data, ArbeidsuforhetVurdering::class.java) | ||
} |
Oops, something went wrong.