Skip to content

Commit 50fd153

Browse files
1 parent 044347a commit 50fd153

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppstier/service/TierCalculationService.kt

+7-14
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ class TierCalculationService(
3434
mapOf("crn" to crn, "reason" to reason),
3535
)
3636
} catch (e: Exception) {
37-
log.error("Unable to remove tier calculations for $crn")
3837
telemetryService.trackEvent(
3938
TIER_CALCULATION_REMOVAL_FAILED,
4039
mapOf("crn" to crn, "reasonToDelete" to reason, "failureReason" to e.message),
4140
)
41+
throw e
4242
}
4343

4444
fun calculateTierForCrn(crn: String, recalculationSource: RecalculationSource, allowUpdates: Boolean) {
@@ -59,18 +59,15 @@ class TierCalculationService(
5959
)
6060
}
6161
} catch (e: Exception) {
62-
if (e is DataIntegrityViolationException) {
63-
log.error("Multiple concurrent attempts to calculate tier for $crn => $recalculationSource")
64-
return
65-
}
6662
val eventType = if (allowUpdates) TIER_CALCULATION_FAILED else TIER_RECALCULATION_DRY_RUN_FAILURE
6763
telemetryService.trackEvent(
6864
eventType,
6965
mapOf(
7066
"crn" to crn,
7167
"exception" to e.message,
7268
"recalculationSource" to recalculationSource::class.simpleName,
73-
"recalculationReason" to if (recalculationSource is RecalculationSource.EventSource) recalculationSource.type else ""
69+
"recalculationReason" to if (recalculationSource is RecalculationSource.EventSource) recalculationSource.type else "",
70+
"duplicateAttempt" to (e is DataIntegrityViolationException).toString()
7471
),
7572
)
7673
if (allowUpdates) {
@@ -80,10 +77,10 @@ class TierCalculationService(
8077
}
8178

8279
private fun checkForCrnNotFound(crn: String, e: Exception) {
83-
if (e is CrnNotFoundException) {
84-
deleteCalculationsForCrn(crn, "Not Found in Delius")
85-
} else {
86-
throw e
80+
when (e) {
81+
is DataIntegrityViolationException -> return
82+
is CrnNotFoundException -> deleteCalculationsForCrn(crn, "Not Found in Delius")
83+
else -> throw e
8784
}
8885
}
8986

@@ -138,8 +135,4 @@ class TierCalculationService(
138135
).toMap()
139136

140137
private fun NeedSection.mapSeverity(): Pair<Need, NeedSeverity>? = severity?.let { section to it }
141-
142-
companion object {
143-
private val log = LoggerFactory.getLogger(this::class.java)
144-
}
145138
}

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppstier/service/TierReader.kt

-8
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,19 @@ class TierReader(
2020

2121
fun getLatestTierByCrn(crn: String): TierDto? =
2222
tierSummaryRepository.findByIdOrNull(crn)?.let {
23-
log.info("Found latest tier calculation for $crn")
2423
TierDto.from(it)
2524
}
2625

2726
fun getLatestTierDetailsByCrn(crn: String): TierDetailsDto? =
2827
getLatestTierCalculation(crn)?.let {
29-
log.info("Found latest tier calculation for $crn")
3028
TierDetailsDto.from(it)
3129
}
3230

3331
fun getTierByCalculationId(crn: String, calculationId: UUID): TierDto? =
3432
tierCalculationRepository.findByCrnAndUuid(crn, calculationId)?.let {
35-
log.info("Found tier for $crn and $calculationId")
3633
TierDto.from(it)
3734
}
3835

3936
private fun getLatestTierCalculation(crn: String): TierCalculationEntity? =
4037
tierCalculationRepository.findFirstByCrnOrderByCreatedDesc(crn)
41-
42-
companion object {
43-
private val log =
44-
LoggerFactory.getLogger(this::class.java)
45-
}
4638
}

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppstier/integration/CannotCalculateTierTest.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class CannotCalculateTierTest : IntegrationTestBase() {
2020
"crn" to "X123456",
2121
"exception" to "404 Not Found from GET http://localhost:8093/tier-details/X123456",
2222
"recalculationSource" to "OffenderEventRecalculation",
23-
"recalculationReason" to "OFFENDER_MANAGEMENT_TIER_CALCULATION_REQUIRED"
23+
"recalculationReason" to "OFFENDER_MANAGEMENT_TIER_CALCULATION_REQUIRED",
24+
"duplicateAttempt" to "false"
2425
),
2526
null,
2627
)

0 commit comments

Comments
 (0)