Skip to content

Commit

Permalink
DOCUMENT_DISTRIBUTED
Browse files Browse the repository at this point in the history
  • Loading branch information
flexable777 committed Jan 5, 2024
1 parent c23e10b commit 34d2758
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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,
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
)
)
}
}
}

0 comments on commit 34d2758

Please sign in to comment.