Skip to content

Commit

Permalink
try with individual transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-britton-moj committed Jan 21, 2025
1 parent f1b7535 commit 118a462
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package uk.gov.justice.digital.hmpps.messaging

import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import uk.gov.justice.digital.hmpps.integrations.delius.service.DeliusService
import uk.gov.justice.digital.hmpps.integrations.prison.CaseNoteTypesOfInterest.forSearchRequest
import uk.gov.justice.digital.hmpps.integrations.prison.PrisonCaseNoteFilters
Expand All @@ -13,7 +12,6 @@ import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService
import java.net.URI

@Transactional
@Service
class PrisonIdentifierAdded(
private val caseNotesApi: PrisonCaseNotesClient,
Expand All @@ -30,8 +28,17 @@ class PrisonIdentifierAdded(
val caseNotes = caseNotesApi.searchCaseNotes(uri, SearchCaseNotes(forSearchRequest())).content
.filter { cn -> PrisonCaseNoteFilters.filters.none { it.predicate.invoke(cn) } }

caseNotes.forEach { pcn ->
deliusService.mergeCaseNote(pcn.toDeliusCaseNote())
val exceptions = caseNotes.mapNotNull { pcn ->
try {
deliusService.mergeCaseNote(pcn.toDeliusCaseNote())
null
} catch (e: Exception) {
e
}
}

if (exceptions.isNotEmpty()) {
throw exceptions.first()
}

telemetryService.trackEvent(
Expand Down

0 comments on commit 118a462

Please sign in to comment.