From 7b71e0b7852f3b0efbd7f8133baf67a92a82d827 Mon Sep 17 00:00:00 2001 From: Amardeep Chimber Date: Mon, 21 Oct 2024 10:32:02 +0100 Subject: [PATCH] MAN-28 - update api --- .../hmpps/LicenceConditionIntegrationTest.kt | 31 ++++++++++++++----- .../digital/hmpps/SentenceIntegrationTest.kt | 3 +- .../api/model/sentence/LicenceCondition.kt | 5 +-- .../hmpps/service/LicenceConditionService.kt | 28 +++++++++++++---- .../digital/hmpps/service/SentenceService.kt | 11 ------- 5 files changed, 50 insertions(+), 28 deletions(-) diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/LicenceConditionIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/LicenceConditionIntegrationTest.kt index ddd489c693..7a8a4c8065 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/LicenceConditionIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/LicenceConditionIntegrationTest.kt @@ -16,7 +16,10 @@ import uk.gov.justice.digital.hmpps.service.toSummary import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.contentAsJson import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken import java.time.LocalDate -import org.springframework.test.web.servlet.result.MockMvcResultHandlers.print +import uk.gov.justice.digital.hmpps.api.model.sentence.LicenceCondition +import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LC_WITH_NOTES +import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LIC_COND_MAIN_CAT +import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LIC_COND_SUB_CAT @AutoConfigureMockMvc @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -50,13 +53,22 @@ class LicenceConditionIntegrationTest { fun `note not found`() { val response = mockMvc .perform( - MockMvcRequestBuilders.get("/sentence/${PersonGenerator.OVERVIEW.crn}/licence-condition/${LicenceConditionGenerator.LC_WITH_NOTES.id}/note/7") + MockMvcRequestBuilders.get("/sentence/${PersonGenerator.OVERVIEW.crn}/licence-condition/${LC_WITH_NOTES.id}/note/7") .withToken() ) .andExpect(MockMvcResultMatchers.status().isOk) .andReturn().response.contentAsJson() - val expected = LicenceConditionNoteDetail(PersonGenerator.OVERVIEW.toSummary()) + val expected = LicenceConditionNoteDetail( + PersonGenerator.OVERVIEW.toSummary(), + LicenceCondition( + LC_WITH_NOTES.id, + LIC_COND_MAIN_CAT.description, + LIC_COND_SUB_CAT.description, + LocalDate.now().minusDays(7), + LocalDate.now() + ) + ) assertEquals(expected, response) } @@ -65,22 +77,27 @@ class LicenceConditionIntegrationTest { fun `get note for licence condition`() { val response = mockMvc .perform( - MockMvcRequestBuilders.get("/sentence/${PersonGenerator.OVERVIEW.crn}/licence-condition/${LicenceConditionGenerator.LC_WITH_NOTES.id}/note/0") + MockMvcRequestBuilders.get("/sentence/${PersonGenerator.OVERVIEW.crn}/licence-condition/${LC_WITH_NOTES.id}/note/0") .withToken() ) - .andDo(print()) .andExpect(MockMvcResultMatchers.status().isOk) .andReturn().response.contentAsJson() val expected = LicenceConditionNoteDetail( PersonGenerator.OVERVIEW.toSummary(), - LicenceConditionNote( + LicenceCondition( + LC_WITH_NOTES.id, + LIC_COND_MAIN_CAT.description, + LIC_COND_SUB_CAT.description, + LocalDate.now().minusDays(7), + LocalDate.now(), + note = LicenceConditionNote( 0, "CVL Service", LocalDate.of(2024, 4, 22), """ ${LicenceConditionGenerator.LONG_NOTE} - """.trimIndent() + System.lineSeparator() + """.trimIndent() + System.lineSeparator()) ) ) diff --git a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt index 80b23208ff..94a03fd281 100644 --- a/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt +++ b/projects/manage-supervision-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/SentenceIntegrationTest.kt @@ -24,7 +24,6 @@ import uk.gov.justice.digital.hmpps.test.MockMvcExtensions.withToken import java.time.LocalDate import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LIC_COND_MAIN_CAT import uk.gov.justice.digital.hmpps.data.generator.LicenceConditionGenerator.LIC_COND_SUB_CAT -import org.springframework.test.web.servlet.result.MockMvcResultHandlers.print @AutoConfigureMockMvc @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -50,7 +49,6 @@ class SentenceIntegrationTest { fun `get active sentences`() { val response = mockMvc .perform(MockMvcRequestBuilders.get("/sentence/${PersonGenerator.OVERVIEW.crn}").withToken()) - .andDo(print()) .andExpect(MockMvcResultMatchers.status().isOk) .andReturn().response.contentAsJson() @@ -157,6 +155,7 @@ class SentenceIntegrationTest { LC_WITHOUT_NOTES.id, LIC_COND_MAIN_CAT.description, imposedReleasedDate = LocalDate.now().minusDays(14), + notes = listOf() ), LicenceCondition( LC_WITH_NOTES_WITHOUT_ADDED_BY.id, diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt index 851ffd10ed..d471f6ba2e 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/model/sentence/LicenceCondition.kt @@ -9,7 +9,8 @@ data class LicenceCondition( val subTypeDescription: String? = null, val imposedReleasedDate: LocalDate, val actualStartDate: LocalDate? = null, - val notes: List = listOf() + val notes: List? = null, + val note: LicenceConditionNote? = null ) data class LicenceConditionNote( @@ -22,5 +23,5 @@ data class LicenceConditionNote( data class LicenceConditionNoteDetail( val personSummary: PersonSummary, - val licenceConditionNote: LicenceConditionNote? = null + val licenceCondition: LicenceCondition? = null ) \ No newline at end of file diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/LicenceConditionService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/LicenceConditionService.kt index 66213e9237..f03ed55e1b 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/LicenceConditionService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/LicenceConditionService.kt @@ -1,6 +1,7 @@ package uk.gov.justice.digital.hmpps.service import org.springframework.stereotype.Service +import uk.gov.justice.digital.hmpps.api.model.sentence.LicenceCondition import uk.gov.justice.digital.hmpps.api.model.sentence.LicenceConditionNote import uk.gov.justice.digital.hmpps.api.model.sentence.LicenceConditionNoteDetail import uk.gov.justice.digital.hmpps.datetime.DeliusDateFormatter @@ -23,17 +24,32 @@ class LicenceConditionService( return LicenceConditionNoteDetail( person.toSummary(), - licenceCondition?.toLicenceConditionNote(false)?.let { - when { - it.size > noteId -> it[noteId] - else -> null - } - } + licenceCondition?.toLicenceConditionSingleNote(noteId, false) ) } } +fun EntityLicenceCondition.toLicenceCondition() = + LicenceCondition( + id, + mainCategory.description, + subCategory?.description, + imposedReleasedDate, + actualStartDate, + toLicenceConditionNote(true) + ) + +fun EntityLicenceCondition.toLicenceConditionSingleNote(noteId: Int, truncateNote: Boolean) = + LicenceCondition( + id, + mainCategory.description, + subCategory?.description, + imposedReleasedDate, + actualStartDate, + note = toLicenceConditionNote(truncateNote).elementAtOrNull(noteId) + ) + fun EntityLicenceCondition.toLicenceConditionNote(truncateNote: Boolean): List { return notes?.let { diff --git a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt index 4360803d86..920c7d03d7 100644 --- a/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt +++ b/projects/manage-supervision-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/SentenceService.kt @@ -14,7 +14,6 @@ import java.time.Duration import java.time.LocalDate import kotlin.time.toKotlinDuration import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.AdditionalSentence as ExtraSentence -import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.LicenceCondition as EntityLicenceCondition @Service class SentenceService( @@ -77,16 +76,6 @@ class SentenceService( } ?: emptyList(), ) - fun EntityLicenceCondition.toLicenceCondition() = - LicenceCondition( - id, - mainCategory.description, - subCategory?.description, - imposedReleasedDate, - actualStartDate, - toLicenceConditionNote(true) - ) - fun ExtraSentence.toAdditionalSentence(): AdditionalSentence = AdditionalSentence(length, amount, notes, type.description)