From 34d27585ce74a75a19f291e7deba8628df30ec11 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Fri, 5 Jan 2024 12:27:44 +0100 Subject: [PATCH] DOCUMENT_DISTRIBUTED --- .../service/FerdigstillDokumentService.kt | 32 +++++++++++++++++-- ...endBehandlingEndretToKafkaEventListener.kt | 18 ----------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/main/kotlin/no/nav/klage/dokument/service/FerdigstillDokumentService.kt b/src/main/kotlin/no/nav/klage/dokument/service/FerdigstillDokumentService.kt index 8548c7f56..043941386 100644 --- a/src/main/kotlin/no/nav/klage/dokument/service/FerdigstillDokumentService.kt +++ b/src/main/kotlin/no/nav/klage/dokument/service/FerdigstillDokumentService.kt @@ -3,8 +3,10 @@ package no.nav.klage.dokument.service import net.javacrumbs.shedlock.spring.annotation.SchedulerLock import no.nav.klage.dokument.domain.dokumenterunderarbeid.DokumentUnderArbeidAsHoveddokument import no.nav.klage.oppgave.domain.events.DokumentFerdigstiltAvSaksbehandler -import no.nav.klage.oppgave.domain.kafka.Event +import no.nav.klage.oppgave.domain.kafka.* +import no.nav.klage.oppgave.service.BehandlingService import no.nav.klage.oppgave.service.KafkaInternalEventService +import no.nav.klage.oppgave.service.SaksbehandlerService import no.nav.klage.oppgave.util.getLogger import no.nav.klage.oppgave.util.getSecureLogger import org.hibernate.Hibernate @@ -13,12 +15,14 @@ import org.springframework.scheduling.annotation.Scheduled import org.springframework.stereotype.Service import org.springframework.transaction.event.TransactionPhase import org.springframework.transaction.event.TransactionalEventListener +import java.util.* @Service class FerdigstillDokumentService( private val dokumentUnderArbeidService: DokumentUnderArbeidService, private val dokumentUnderArbeidCommonService: DokumentUnderArbeidCommonService, private val kafkaInternalEventService: KafkaInternalEventService, + private val saksbehandlerService: SaksbehandlerService, ) { companion object { @Suppress("JAVA_CLASS_ON_COMPANION") @@ -55,7 +59,6 @@ class FerdigstillDokumentService( logger.debug("dokumentUnderArbeidService.ferdigstillDokumentEnhet(updatedDokument.id) for document with id {} done", updatedDokument.id) - logger.debug("about to publish 'finished' to Kafka for document with id {}", updatedDokument.id) //Send to all subscribers. If this fails, it's not the end of the world. kafkaInternalEventService.publishEvent( @@ -67,6 +70,21 @@ class FerdigstillDokumentService( ) ) + publishInternalEvent( + data = BehandlingService.objectMapper.writeValueAsString( + DocumentDistributedEvent( + actor = BaseEvent.Actor( + navIdent = updatedDokument.markertFerdigBy!!, + name = saksbehandlerService.getNameForIdent(updatedDokument.markertFerdigBy!!), + ), + timestamp = updatedDokument.ferdigstilt!!, + id = updatedDokument.id.toString(), + ) + ), + behandlingId = updatedDokument.behandlingId, + type = InternalEventType.DOCUMENT_DISTRIBUTED, + ) + } catch (e: Exception) { logger.error("Could not 'ferdigstillHovedDokumenter' with dokumentEnhetId: ${updatedDokument.dokumentEnhetId}. See secure logs.") secureLogger.error( @@ -76,4 +94,14 @@ class FerdigstillDokumentService( } logger.debug("ferdigstill for document with id {} successful", updatedDokument.id) } + + private fun publishInternalEvent(data: String, behandlingId: UUID, type: InternalEventType) { + kafkaInternalEventService.publishEventV2( + InternalBehandlingEvent( + behandlingId = behandlingId.toString(), + type = type, + data = data, + ) + ) + } } \ No newline at end of file diff --git a/src/main/kotlin/no/nav/klage/oppgave/eventlisteners/SendBehandlingEndretToKafkaEventListener.kt b/src/main/kotlin/no/nav/klage/oppgave/eventlisteners/SendBehandlingEndretToKafkaEventListener.kt index 61d534c47..ae67c0e72 100644 --- a/src/main/kotlin/no/nav/klage/oppgave/eventlisteners/SendBehandlingEndretToKafkaEventListener.kt +++ b/src/main/kotlin/no/nav/klage/oppgave/eventlisteners/SendBehandlingEndretToKafkaEventListener.kt @@ -5,7 +5,6 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import no.nav.klage.kodeverk.Type import no.nav.klage.oppgave.domain.events.BehandlingEndretEvent -import no.nav.klage.oppgave.domain.kafka.Event import no.nav.klage.oppgave.domain.klage.AnkeITrygderettenbehandling import no.nav.klage.oppgave.domain.klage.Ankebehandling import no.nav.klage.oppgave.domain.klage.Behandling @@ -50,21 +49,4 @@ class SendBehandlingEndretToKafkaEventListener( logger.error("could not index behandling with id ${behandlingEndretEvent.behandling.id}", e) } } - - //POC for updating FE - @EventListener - @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) - fun publishInternalEvent(behandlingEndretEvent: BehandlingEndretEvent) { - logger.debug("Publishing internal event based on BehandlingEndretEvent for behandlingId {}", behandlingEndretEvent.behandling.id) - behandlingEndretEvent.endringslogginnslag.forEach { - kafkaInternalEventService.publishEvent( - Event( - behandlingId = behandlingEndretEvent.behandling.id.toString(), - name = it.felt.toString(), - id = "", - data = objectMapper.writeValueAsString(it.tilVerdi), - ) - ) - } - } } \ No newline at end of file