From c5843afb7b02742d56034a4bf22e3304ba6c533e Mon Sep 17 00:00:00 2001 From: pmcphee77 <150798161+pmcphee77@users.noreply.github.com> Date: Wed, 11 Sep 2024 09:32:45 +0100 Subject: [PATCH] PI-2515: CVL Text has a 4000 byte limit - truncate bytes (#4223) --- .../delius/sentence/entity/LicenceCondition.kt | 2 +- .../digital/hmpps/service/LicenceConditionService.kt | 2 +- .../digital/hmpps/service/LicenceConditionServiceTest.kt | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/LicenceCondition.kt b/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/LicenceCondition.kt index 835e86705e..00de40cc2f 100644 --- a/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/LicenceCondition.kt +++ b/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/sentence/entity/LicenceCondition.kt @@ -38,7 +38,7 @@ class LicenceCondition( @Column(name = "lic_condition_notes") val notes: String?, - @Column + @Column(columnDefinition = "varchar2(4000)") val cvlText: String?, @Column(columnDefinition = "number") diff --git a/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/LicenceConditionService.kt b/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/LicenceConditionService.kt index 5d87264c7e..9f944b4985 100644 --- a/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/LicenceConditionService.kt +++ b/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/LicenceConditionService.kt @@ -32,7 +32,7 @@ class LicenceConditionService( category, subCategory, notes, - cvlText.let { it?.take(4000) } + cvlText?.let { String(it.toByteArray().take(4000).toByteArray()) } ) ) licenceConditionManagerRepository.save( diff --git a/projects/create-and-vary-a-licence-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/LicenceConditionServiceTest.kt b/projects/create-and-vary-a-licence-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/LicenceConditionServiceTest.kt index 08d79e9503..b165d0f801 100644 --- a/projects/create-and-vary-a-licence-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/LicenceConditionServiceTest.kt +++ b/projects/create-and-vary-a-licence-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/LicenceConditionServiceTest.kt @@ -85,7 +85,8 @@ internal class LicenceConditionServiceTest { @Test fun `cvlText is truncated to 4000 chars when greater than 4000`() { - val cvlText = 'A'.repeat(4212) + val cvlText = 'A'.repeat(2000) + '|'.repeat(1000) + '£'.repeat(1120) + val expected = String(cvlText.toByteArray().take(4000).toByteArray()) licenceConditionService.createLicenceCondition( disposal, LocalDate.now(), @@ -97,7 +98,9 @@ internal class LicenceConditionServiceTest { ) val lcCaptor = ArgumentCaptor.forClass(LicenceCondition::class.java) Mockito.verify(licenceConditionRepository, Mockito.times(1)).save(lcCaptor.capture()) - assertThat(lcCaptor.value.cvlText?.length, equalTo(4000)) + val lc = lcCaptor.value.cvlText!! + assertThat(lc.toByteArray().size, equalTo(4000)) + assertThat(lc, equalTo(expected)) } @Test