Skip to content

Commit

Permalink
MAN-28 - process note without 'Comment added by...'
Browse files Browse the repository at this point in the history
  • Loading branch information
achimber-moj committed Oct 16, 2024
1 parent 05089f1 commit 65cfc52
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class DataLoader(
LicenceConditionGenerator.LIC_COND_SUB_CAT,
LicenceConditionGenerator.LC_WITH_NOTES,
LicenceConditionGenerator.LC_WITHOUT_NOTES,
LicenceConditionGenerator.LC_WITH_NOTES_WITHOUT_ADDED_BY,
PersonGenerator.TERMINATION_REASON,
PersonGenerator.REF_DATA_YEARS,
PersonGenerator.INACTIVE_ORDER_1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,16 @@ object LicenceConditionGenerator {
we can check this.
""".trimIndent()
)

val LC_WITH_NOTES_WITHOUT_ADDED_BY = LicenceCondition(
IdGenerator.getAndIncrement(),
LIC_COND_MAIN_CAT,
LIC_COND_SUB_CAT,
ACTIVE_ORDER.id,
LocalDate.now().minusDays(7),
LocalDate.now(),
"""
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 @@ -124,7 +124,7 @@ class SentenceIntegrationTest {
LocalDate.now(),
listOf(
LicenceConditionNote(
"Comment added by CVL Service on 22/04/2024 at 10:00",
"Comment added by CVL Service on 22/04/2024 at 10:00" + System.lineSeparator(),
"""
Licence Condition created automatically from the Create and Vary a licence system of
Allow 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.
Expand All @@ -133,26 +133,38 @@ class SentenceIntegrationTest {
false
),
LicenceConditionNote(
"Comment added by Joe Root on 23/04/2024 at 13:45",
"Comment added by Joe Root on 23/04/2024 at 13:45" + System.lineSeparator(),
"""
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
)
),
)
),
LicenceCondition(
"lic cond main",
imposedReleasedDate = LocalDate.now().minusDays(14),
),
LicenceCondition(
"lic cond main",
"Lic Sub cat",
LocalDate.now().minusDays(7),
LocalDate.now(),
listOf(
LicenceConditionNote(
note = "He shall not contact or associate with Peter Jones without the prior approval of the supervising officer;",
hasNotesBeenTruncated = false)
)
)
)
)
),
ProbationHistory(2, LocalDate.now().minusDays(7), 2, 2)
)


assertEquals(expected, response)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data class LicenceCondition(
)

data class LicenceConditionNote(
val createdBy: String,
val createdBy: String? = null,
val note: String,
val hasNotesBeenTruncated: Boolean? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ class SentenceService(
notes?.let {
val splitParam = "---------------------------------------------------------" + System.lineSeparator()
return notes.split(splitParam).map {
val noteSplitList = it.split(System.lineSeparator())
val note = noteSplitList.drop(1).joinToString(System.lineSeparator())
note ->
val addedBy = Regex("^Comment added by .+? on \\d{2}\\/\\d{2}\\/\\d{4} at \\d{2}:\\d{2}"
+ System.lineSeparator()).find(note)?.value
val noteText = addedBy?.let { note.removePrefix(addedBy) } ?: note

LicenceConditionNote(
noteSplitList.first(),
note.chunked(noteLength)[0],
addedBy,
noteText,
note.let { n ->
when {
n.length > noteLength -> true
Expand Down

0 comments on commit 65cfc52

Please sign in to comment.