Skip to content

Commit

Permalink
MAN-28 - update api so that single note call is not truncated
Browse files Browse the repository at this point in the history
  • Loading branch information
achimber-moj committed Oct 18, 2024
1 parent 1f65a94 commit 14cf66e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import java.time.LocalDate

object LicenceConditionGenerator {

val LONG_NOTE = """
Licence Condition created automatically from the Create and Vary a licence system of\nAllow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer. Licence Condition created automatically from the Create and Vary a licence system of\nAllow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer.Licence Condition created automatically from the Create and Vary a licence system of\nAllow person(s) as desi123456
""".trimIndent()

val LIC_COND_MAIN_CAT = LicenceConditionMainCategory(
IdGenerator.getAndIncrement(),
"LicMain",
Expand Down Expand Up @@ -39,7 +43,7 @@ object LicenceConditionGenerator {
LocalDate.now(),
"""
Comment added by CVL Service on 22/04/2024 at 10:00
Licence Condition created automatically from the Create and Vary a licence system of\nAllow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer. Licence Condition created automatically from the Create and Vary a licence system of\nAllow person(s) as designated by your supervising officer to install an electronic monitoring tag on you and access to install any associated equipment in your property, and for the purpose of ensuring that equipment is functioning correctly. You must not damage or tamper with these devices and ensure that the tag is charged, and report to your supervising officer and the EM provider immediately if the tag or the associated equipment are not working correctly. This will be for the purpose of monitoring your alcohol abstinence licence condition(s) unless otherwise authorised by your supervising officer.Licence Condition created automatically from the Create and Vary a licence system of\nAllow person(s) as desi123456
$LONG_NOTE
---------------------------------------------------------
Comment added by Joe Root on 23/04/2024 at 13:45
You must not drink any alcohol until Wednesday 7th August 2024 unless your
Expand All @@ -59,4 +63,6 @@ object LicenceConditionGenerator {
He shall not contact or associate with Peter Jones without the prior approval of the supervising officer;
""".trimIndent()
)


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
import org.springframework.test.web.servlet.result.MockMvcResultHandlers.print
import org.springframework.test.web.servlet.result.MockMvcResultMatchers
import uk.gov.justice.digital.hmpps.api.model.sentence.LicenceConditionNote
import uk.gov.justice.digital.hmpps.api.model.sentence.LicenceConditionNoteDetail
Expand Down Expand Up @@ -38,7 +37,6 @@ class LicenceConditionIntegrationTest {
MockMvcRequestBuilders.get("/sentence/${PersonGenerator.OVERVIEW.crn}/licence-condition/1/note/6")
.withToken()
)
.andDo(print())
.andExpect(MockMvcResultMatchers.status().isOk)
.andReturn().response.contentAsJson<LicenceConditionNoteDetail>()

Expand All @@ -54,7 +52,6 @@ class LicenceConditionIntegrationTest {
MockMvcRequestBuilders.get("/sentence/${PersonGenerator.OVERVIEW.crn}/licence-condition/${LicenceConditionGenerator.LC_WITH_NOTES.id}/note/7")
.withToken()
)
.andDo(print())
.andExpect(MockMvcResultMatchers.status().isOk)
.andReturn().response.contentAsJson<LicenceConditionNoteDetail>()

Expand All @@ -67,25 +64,21 @@ 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/1")
MockMvcRequestBuilders.get("/sentence/${PersonGenerator.OVERVIEW.crn}/licence-condition/${LicenceConditionGenerator.LC_WITH_NOTES.id}/note/0")
.withToken()
)
.andDo(print())
.andExpect(MockMvcResultMatchers.status().isOk)
.andReturn().response.contentAsJson<LicenceConditionNoteDetail>()

val expected = LicenceConditionNoteDetail(
PersonGenerator.OVERVIEW.toSummary(),
LicenceConditionNote(
1,
"Joe Root",
LocalDate.of(2024, 4, 23),
0,
"CVL Service",
LocalDate.of(2024, 4, 22),
"""
You must not drink any alcohol until Wednesday 7th August 2024 unless your
probation officer says you can. You will need to wear an electronic tag all the time so
we can check this.
""".trimIndent(),
false
${LicenceConditionGenerator.LONG_NOTE}
""".trimIndent() + System.lineSeparator()
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LicenceConditionService(

return LicenceConditionNoteDetail(
person.toSummary(),
licenceCondition?.toLicenceConditionNote()?.let {
licenceCondition?.toLicenceConditionNote(false)?.let {
when {
it.size > noteId -> it[noteId]
else -> null
Expand All @@ -34,7 +34,7 @@ class LicenceConditionService(
}
}

fun EntityLicenceCondition.toLicenceConditionNote(): List<LicenceConditionNote>? {
fun EntityLicenceCondition.toLicenceConditionNote(truncateNote: Boolean): List<LicenceConditionNote>? {

return notes?.let {
val splitParam = "---------------------------------------------------------" + System.lineSeparator()
Expand All @@ -55,8 +55,14 @@ fun EntityLicenceCondition.toLicenceConditionNote(): List<LicenceConditionNote>?
index,
userCreatedBy,
dateCreatedBy,
commentText.removeSuffix(System.lineSeparator()).chunked(1500)[0],
note.length > 1500
when (truncateNote) {
true -> commentText.removeSuffix(System.lineSeparator()).chunked(1500)[0]
else -> commentText
},
when (truncateNote) {
true -> note.length > 1500
else -> null
}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class SentenceService(
subCategory?.description,
imposedReleasedDate,
actualStartDate,
toLicenceConditionNote()
toLicenceConditionNote(true)
)


Expand Down

0 comments on commit 14cf66e

Please sign in to comment.