-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IS-1646: Consume huskelapp-status in personoversiktstatus #316
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2699d5f
IS-1646: Add new field huskelapp_active in personoversiktstatus
eirikdahlen 3e95834
IS-1646: Process records from huskelapp topic
eirikdahlen 7c2dfd3
IS-1646: Add toggle for consumer
eirikdahlen a815ada
IS-1646: Remove unnecessary tombstone check and receive more records …
eirikdahlen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package no.nav.syfo.huskelapp | ||
|
||
import no.nav.syfo.application.database.DatabaseInterface | ||
import no.nav.syfo.huskelapp.domain.Huskelapp | ||
import no.nav.syfo.huskelapp.kafka.COUNT_KAFKA_CONSUMER_HUSKELAPP_READ | ||
import no.nav.syfo.personstatus.db.createPersonOversiktStatus | ||
import no.nav.syfo.personstatus.db.getPersonOversiktStatusList | ||
import no.nav.syfo.personstatus.db.updateHuskelappActive | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
|
||
class HuskelappService( | ||
private val database: DatabaseInterface, | ||
) { | ||
fun processHuskelapp(records: List<Huskelapp>) { | ||
database.connection.use { connection -> | ||
records.forEach { huskelapp -> | ||
val existingPersonOversiktStatus = connection.getPersonOversiktStatusList( | ||
fnr = huskelapp.personIdent.value, | ||
).firstOrNull() | ||
|
||
if (existingPersonOversiktStatus == null) { | ||
val personoversiktStatus = huskelapp.toPersonoversiktStatus() | ||
connection.createPersonOversiktStatus( | ||
commit = false, | ||
personOversiktStatus = personoversiktStatus, | ||
) | ||
} else { | ||
connection.updateHuskelappActive( | ||
isHuskelappActive = huskelapp.isActive, | ||
personIdent = huskelapp.personIdent, | ||
) | ||
} | ||
|
||
log.info("Received huskelapp with uuid=${huskelapp.uuid}") | ||
COUNT_KAFKA_CONSUMER_HUSKELAPP_READ.increment() | ||
} | ||
connection.commit() | ||
} | ||
} | ||
|
||
companion object { | ||
val log: Logger = LoggerFactory.getLogger(this::class.java) | ||
} | ||
} |
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.syfo.huskelapp.domain | ||
|
||
import no.nav.syfo.domain.PersonIdent | ||
import no.nav.syfo.personstatus.domain.PersonOversiktStatus | ||
import java.util.UUID | ||
|
||
data class Huskelapp( | ||
val uuid: UUID, | ||
val personIdent: PersonIdent, | ||
val isActive: Boolean, | ||
) { | ||
fun toPersonoversiktStatus() = PersonOversiktStatus( | ||
fnr = personIdent.value, | ||
).copy( | ||
huskelappActive = isActive, | ||
) | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/no/nav/syfo/huskelapp/kafka/HuskelappConsumer.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,36 @@ | ||
package no.nav.syfo.huskelapp.kafka | ||
|
||
import no.nav.syfo.huskelapp.HuskelappService | ||
import no.nav.syfo.kafka.KafkaConsumerService | ||
import org.apache.kafka.clients.consumer.ConsumerRecords | ||
import org.apache.kafka.clients.consumer.KafkaConsumer | ||
import org.slf4j.LoggerFactory | ||
import java.time.Duration | ||
|
||
class HuskelappConsumer( | ||
private val huskelappService: HuskelappService | ||
) : KafkaConsumerService<KafkaHuskelapp> { | ||
|
||
override val pollDurationInMillis: Long = 1000 | ||
|
||
override fun pollAndProcessRecords(kafkaConsumer: KafkaConsumer<String, KafkaHuskelapp>) { | ||
val records = kafkaConsumer.poll(Duration.ofMillis(pollDurationInMillis)) | ||
if (records.count() > 0) { | ||
processRecords(records) | ||
kafkaConsumer.commitSync() | ||
} | ||
} | ||
|
||
private fun processRecords( | ||
consumerRecords: ConsumerRecords<String, KafkaHuskelapp>, | ||
) { | ||
val validRecords = consumerRecords.requireNoNulls() | ||
huskelappService.processHuskelapp( | ||
records = validRecords.map { it.value().toHuskelapp() } | ||
) | ||
} | ||
|
||
companion object { | ||
private val log = LoggerFactory.getLogger(HuskelappConsumer::class.java) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/no/nav/syfo/huskelapp/kafka/HuskelappConsumerMetrics.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,12 @@ | ||
package no.nav.syfo.huskelapp.kafka | ||
|
||
import io.micrometer.core.instrument.Counter | ||
import no.nav.syfo.metric.METRICS_NS | ||
import no.nav.syfo.metric.METRICS_REGISTRY | ||
|
||
const val KAFKA_CONSUMER_HUSKELAPP_BASE = "${METRICS_NS}_kafka_consumer_huskelapp" | ||
const val KAFKA_CONSUMER_HUSKELAPP_READ = "${KAFKA_CONSUMER_HUSKELAPP_BASE}_read" | ||
|
||
val COUNT_KAFKA_CONSUMER_HUSKELAPP_READ: Counter = Counter.builder(KAFKA_CONSUMER_HUSKELAPP_READ) | ||
.description("Counts the number of reads from topic - huskelapp") | ||
.register(METRICS_REGISTRY) |
44 changes: 44 additions & 0 deletions
44
src/main/kotlin/no/nav/syfo/huskelapp/kafka/HuskelappTask.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,44 @@ | ||
package no.nav.syfo.huskelapp.kafka | ||
|
||
import no.nav.syfo.application.ApplicationState | ||
import no.nav.syfo.application.database.database | ||
import no.nav.syfo.application.kafka.KafkaEnvironment | ||
import no.nav.syfo.application.kafka.kafkaAivenConsumerConfig | ||
import no.nav.syfo.huskelapp.HuskelappService | ||
import no.nav.syfo.kafka.launchKafkaTask | ||
import no.nav.syfo.util.configuredJacksonMapper | ||
import org.apache.kafka.clients.consumer.ConsumerConfig | ||
import org.apache.kafka.common.serialization.Deserializer | ||
import java.util.* | ||
|
||
const val HUSKELAPP_TOPIC = | ||
"teamsykefravr.huskelapp" | ||
|
||
fun launchHuskelappConsumer( | ||
applicationState: ApplicationState, | ||
kafkaEnvironment: KafkaEnvironment, | ||
) { | ||
val huskelappService = HuskelappService( | ||
database = database | ||
) | ||
val huskelappConsumer = HuskelappConsumer( | ||
huskelappService = huskelappService, | ||
) | ||
val consumerProperties = Properties().apply { | ||
putAll(kafkaAivenConsumerConfig(kafkaEnvironment = kafkaEnvironment)) | ||
this[ConsumerConfig.MAX_POLL_RECORDS_CONFIG] = "10" | ||
this[ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG] = KafkaHuskelappDeserializer::class.java.canonicalName | ||
} | ||
launchKafkaTask( | ||
applicationState = applicationState, | ||
topic = HUSKELAPP_TOPIC, | ||
consumerProperties = consumerProperties, | ||
kafkaConsumerService = huskelappConsumer | ||
) | ||
} | ||
|
||
class KafkaHuskelappDeserializer : Deserializer<KafkaHuskelapp> { | ||
private val mapper = configuredJacksonMapper() | ||
override fun deserialize(topic: String, data: ByteArray): KafkaHuskelapp = | ||
mapper.readValue(data, KafkaHuskelapp::class.java) | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/no/nav/syfo/huskelapp/kafka/KafkaHuskelapp.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,22 @@ | ||
package no.nav.syfo.huskelapp.kafka | ||
|
||
import no.nav.syfo.domain.PersonIdent | ||
import no.nav.syfo.huskelapp.domain.Huskelapp | ||
import java.time.OffsetDateTime | ||
import java.util.UUID | ||
|
||
data class KafkaHuskelapp( | ||
val uuid: UUID, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Så at det var There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tror det skal gå bra, men vi får teste i dev 💥 |
||
val personIdent: String, | ||
val veilederIdent: String, | ||
val tekst: String, | ||
val isActive: Boolean, | ||
val createdAt: OffsetDateTime, | ||
val updatedAt: OffsetDateTime, | ||
) { | ||
fun toHuskelapp() = Huskelapp( | ||
uuid = uuid, | ||
personIdent = PersonIdent(personIdent), | ||
isActive = isActive, | ||
) | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gjorde sånn i stedet for å "fylle ut" det store objektet, nå som vi har default-values.
Hadde det vært penere med en
.create()
-metode? I så fall burde man kanskje lage flere, for aktivitetskrav, huskelapp, dialogmøtestatusendring etc etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Hadde nok vært fint og ryddet litt opp i det ja, men får ta det i en egen PR.