Skip to content

Commit

Permalink
Use correct Transactional annotation from Spring.
Browse files Browse the repository at this point in the history
No need to cleanup if previous transaction failed.
  • Loading branch information
flexable777 committed Nov 21, 2024
1 parent 13ebe72 commit 2ed21c9
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package no.nav.klage.dokument.service

import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import jakarta.transaction.Transactional
import no.nav.klage.dokument.api.mapper.DokumentMapper
import no.nav.klage.dokument.api.view.*
import no.nav.klage.dokument.clients.kabalsmarteditorapi.model.request.CommentInput
Expand Down Expand Up @@ -31,6 +30,7 @@ import no.nav.klage.oppgave.util.getSecureLogger
import no.nav.klage.oppgave.util.ourJacksonObjectMapper
import org.springframework.context.ApplicationEventPublisher
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDateTime
import java.util.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import no.nav.klage.oppgave.util.getSecureLogger
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Propagation
import org.springframework.transaction.annotation.Transactional
import org.springframework.transaction.event.TransactionPhase
import org.springframework.transaction.event.TransactionalEventListener
import java.time.LocalDateTime
import java.util.*

Expand Down Expand Up @@ -50,6 +53,8 @@ class CleanupAfterBehandlingEventListener(
}

@EventListener
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
@Transactional(propagation = Propagation.REQUIRES_NEW)
fun cleanupAfterBehandling(behandlingEndretEvent: BehandlingEndretEvent) {
val behandling = behandlingEndretEvent.behandling

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class SendBehandlingEndretToKafkaEventListener(
val objectMapper: ObjectMapper = ourJacksonObjectMapper()
}

/* This code needs a transaction b/c of lazy loading */
@EventListener
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
@Transactional(propagation = Propagation.REQUIRES_NEW)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nav.klage.oppgave.eventlisteners

import no.nav.klage.oppgave.domain.events.BehandlingEndretEvent
import no.nav.klage.oppgave.service.StatistikkTilDVHService
import no.nav.klage.oppgave.util.getLogger
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package no.nav.klage.oppgave.eventlisteners
import com.fasterxml.jackson.databind.ObjectMapper
import no.nav.klage.oppgave.domain.events.BehandlingEndretEvent
import no.nav.klage.oppgave.domain.klage.Felt
import no.nav.klage.oppgave.repositories.BehandlingRepository
import no.nav.klage.oppgave.service.GosysOppgaveService
import no.nav.klage.oppgave.util.getLogger
import no.nav.klage.oppgave.util.ourJacksonObjectMapper
Expand All @@ -17,7 +16,6 @@ import org.springframework.transaction.event.TransactionalEventListener

@Service
class UpdateGosysOppgaveEventListener(
private val behandlingRepository: BehandlingRepository,
private val gosysOppgaveService: GosysOppgaveService,
@Value("\${SYSTEMBRUKER_IDENT}") private val systembrukerIdent: String,
) {
Expand All @@ -28,7 +26,6 @@ class UpdateGosysOppgaveEventListener(
val objectMapper: ObjectMapper = ourJacksonObjectMapper()
}

/* This code needs a transaction b/c of lazy loading */
@EventListener
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
@Transactional(propagation = Propagation.REQUIRES_NEW)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import no.nav.klage.oppgave.domain.kafka.EventType
import no.nav.klage.oppgave.domain.kafka.StatistikkTilDVH
import no.nav.klage.oppgave.domain.kafka.UtsendingStatus
import no.nav.klage.oppgave.domain.klage.*
import no.nav.klage.oppgave.eventlisteners.StatistikkTilDVHService.Companion.TR_ENHET
import no.nav.klage.oppgave.repositories.*
import no.nav.klage.oppgave.service.StatistikkTilDVHService.Companion.TR_ENHET
import no.nav.klage.oppgave.util.*
import org.slf4j.Logger
import org.springframework.beans.factory.annotation.Value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package no.nav.klage.oppgave.service
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import jakarta.transaction.Transactional
import no.nav.klage.dokument.api.view.JournalfoertDokumentReference
import no.nav.klage.kodeverk.hjemmel.Hjemmel
import no.nav.klage.kodeverk.hjemmel.ytelseTilRegistreringshjemlerV2
Expand All @@ -21,6 +20,7 @@ import no.nav.klage.oppgave.util.getLogger
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.ApplicationEventPublisher
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.*

@Service
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package no.nav.klage.oppgave.service

import jakarta.transaction.Transactional
import no.nav.klage.dokument.api.view.JournalfoertDokumentReference
import no.nav.klage.kodeverk.Type
import no.nav.klage.oppgave.clients.kaka.KakaApiGateway
import no.nav.klage.oppgave.domain.events.BehandlingEndretEvent
import no.nav.klage.oppgave.domain.klage.*
import no.nav.klage.oppgave.repositories.AnkebehandlingRepository
import no.nav.klage.oppgave.repositories.BehandlingEtterTrygderettenOpphevetRepository
import no.nav.klage.oppgave.repositories.BehandlingRepository
import no.nav.klage.oppgave.util.getLogger
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.ApplicationEventPublisher
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDate
import java.time.Period
import java.util.*
Expand All @@ -21,14 +20,11 @@ import java.util.*
@Transactional
class AnkebehandlingService(
private val ankebehandlingRepository: AnkebehandlingRepository,
private val behandlingEtterTrygderettenOpphevetRepository: BehandlingEtterTrygderettenOpphevetRepository,
private val behandlingRepository: BehandlingRepository,
private val kakaApiGateway: KakaApiGateway,
private val dokumentService: DokumentService,
private val behandlingService: BehandlingService,
private val applicationEventPublisher: ApplicationEventPublisher,
@Value("#{T(java.time.LocalDate).parse('\${KAKA_VERSION_2_DATE}')}")
private val kakaVersion2Date: LocalDate,
@Value("\${SYSTEMBRUKER_IDENT}") private val systembrukerIdent: String,
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package no.nav.klage.oppgave.service
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import jakarta.transaction.Transactional
import no.nav.klage.dokument.api.view.JournalfoertDokumentReference
import no.nav.klage.kodeverk.Type
import no.nav.klage.oppgave.clients.kaka.KakaApiGateway
Expand All @@ -17,6 +16,7 @@ import no.nav.klage.oppgave.util.getLogger
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.ApplicationEventPublisher
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDate
import java.time.LocalDateTime

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import no.nav.klage.oppgave.domain.kafka.GosysoppgaveEvent
import no.nav.klage.oppgave.domain.kafka.InternalBehandlingEvent
import no.nav.klage.oppgave.domain.kafka.InternalEventType
import no.nav.klage.oppgave.domain.klage.Behandling
import no.nav.klage.oppgave.exceptions.GosysOppgaveClientException
import no.nav.klage.oppgave.exceptions.GosysOppgaveNotEditableException
import no.nav.klage.oppgave.exceptions.IllegalOperation
import no.nav.klage.oppgave.util.getLogger
Expand Down Expand Up @@ -282,7 +283,7 @@ class GosysOppgaveService(
val mappeResponse = gosysOppgaveClient.getMappe(id = id, systemContext = systemContext)

if (mappeResponse.id == null) {
throw OppgaveClientException("Mappe did not contain id")
throw GosysOppgaveClientException("Mappe did not contain id")
}

return GosysOppgaveMappeView(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.nav.klage.oppgave.eventlisteners
package no.nav.klage.oppgave.service

import no.nav.klage.kodeverk.Fagsystem
import no.nav.klage.kodeverk.PartIdType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import no.nav.klage.kodeverk.Ytelse
import no.nav.klage.oppgave.domain.events.BehandlingEndretEvent
import no.nav.klage.oppgave.domain.klage.*
import no.nav.klage.oppgave.repositories.KafkaEventRepository
import no.nav.klage.oppgave.service.StatistikkTilDVHService
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
Expand Down

0 comments on commit 2ed21c9

Please sign in to comment.