From 5df0967a26724d7c101d02a1a3b994cdd76a04b7 Mon Sep 17 00:00:00 2001 From: Anusree Gopinath Date: Thu, 2 Apr 2026 15:01:20 +0100 Subject: [PATCH] CAD-492 civil tranche 1 toggle off --- .../aggregate/hearing/PleaDelegate.java | 54 +++++++++++----- .../aggregate/hearing/PleaDelegateTest.java | 62 +++++++++++++++++++ pom.xml | 6 +- 3 files changed, 102 insertions(+), 20 deletions(-) diff --git a/hearing-domain/hearing-domain-aggregate/src/main/java/uk/gov/moj/cpp/hearing/domain/aggregate/hearing/PleaDelegate.java b/hearing-domain/hearing-domain-aggregate/src/main/java/uk/gov/moj/cpp/hearing/domain/aggregate/hearing/PleaDelegate.java index 859e6c5b32..83206d3f8d 100644 --- a/hearing-domain/hearing-domain-aggregate/src/main/java/uk/gov/moj/cpp/hearing/domain/aggregate/hearing/PleaDelegate.java +++ b/hearing-domain/hearing-domain-aggregate/src/main/java/uk/gov/moj/cpp/hearing/domain/aggregate/hearing/PleaDelegate.java @@ -1,7 +1,9 @@ package uk.gov.moj.cpp.hearing.domain.aggregate.hearing; +import static java.util.Objects.isNull; import static java.util.Objects.nonNull; import static java.util.Optional.ofNullable; +import static org.apache.commons.collections.CollectionUtils.isNotEmpty; import static uk.gov.justice.core.courts.IndicatedPleaValue.INDICATED_GUILTY; import static uk.gov.moj.cpp.hearing.domain.aggregate.util.PleaVerdictUtil.isGuiltyVerdict; import static uk.gov.moj.cpp.hearing.domain.event.ConvictionDateAdded.convictionDateAdded; @@ -9,6 +11,7 @@ import uk.gov.justice.core.courts.CourtApplication; import uk.gov.justice.core.courts.CourtOrderOffence; +import uk.gov.justice.core.courts.Hearing; import uk.gov.justice.core.courts.IndicatedPlea; import uk.gov.justice.core.courts.Offence; import uk.gov.justice.core.courts.Plea; @@ -132,28 +135,33 @@ public Stream updatePlea(final UUID hearingId, final PleaModel pleaModel } setOriginatingHearingId(hearingId, pleaModel); + final boolean isCivil = isCivilCase(); + final PleaModel pleaToUpdate = isCivil ? pleaModel.setAllocationDecision(null) : pleaModel; + + final Plea plea = pleaToUpdate.getPlea(); final List events = new ArrayList<>(); - final Plea plea = pleaModel.getPlea(); events.add(PleaUpsert.pleaUpsert() .setHearingId(hearingId) - .setPleaModel(pleaModel)); - - if (nonNull(plea)) { - addConvictionDateEventForPlea(hearingId, guiltyPleaTypes, offenceId, prosecutionCaseId, courtApplicationId, events, plea); - } else if (nonNull(pleaModel.getIndicatedPlea()) ) { - // indicated plea logic for updating conviction dates is not changing as it is out of scope for DD-2825 - // and will be covered under a separate CR - addConvictionDateEventForIndicatedPlea(hearingId, pleaModel, offenceId, prosecutionCaseId, courtApplicationId, events); - } else if (canRemoveConvictionDate(offenceId, courtApplicationId)){ - events.add( - convictionDateRemoved() - .setCaseId(prosecutionCaseId) - .setHearingId(hearingId) - .setOffenceId(offenceId) - .setCourtApplicationId(courtApplicationId)); + .setPleaModel(pleaToUpdate)); + + if (!isCivil) { + if (nonNull(plea)) { + addConvictionDateEventForPlea(hearingId, guiltyPleaTypes, offenceId, prosecutionCaseId, courtApplicationId, events, plea); + } else if (nonNull(pleaToUpdate.getIndicatedPlea()) ) { + // indicated plea logic for updating conviction dates is not changing as it is out of scope for DD-2825 + // and will be covered under a separate CR + addConvictionDateEventForIndicatedPlea(hearingId, pleaToUpdate, offenceId, prosecutionCaseId, courtApplicationId, events); + } else if (canRemoveConvictionDate(offenceId, courtApplicationId)) { + events.add( + convictionDateRemoved() + .setCaseId(prosecutionCaseId) + .setHearingId(hearingId) + .setOffenceId(offenceId) + .setCourtApplicationId(courtApplicationId)); + } } - return events.stream(); + return events.stream(); } private void addConvictionDateEventForIndicatedPlea(final UUID hearingId, final PleaModel pleaModel, final UUID offenceId, final UUID prosecutionCaseId, final UUID courtApplicationId, final List events) { @@ -244,4 +252,16 @@ private void setOffence(final Offence offence) { private void setApplicationPlea(final CourtApplication courtApplication) { courtApplication.setPlea(this.momento.getPleas().get(courtApplication.getId())); } + + private boolean isCivilCase() { + final Hearing hearing = momento.getHearing(); + if (isNull(hearing)) { + return false; + } + + return isNotEmpty(hearing.getProsecutionCases()) + && hearing.getProsecutionCases().stream() + .filter(Objects::nonNull) + .anyMatch(prosecutionCase -> Boolean.TRUE.equals(prosecutionCase.getIsCivil())); + } } diff --git a/hearing-domain/hearing-domain-aggregate/src/test/java/uk/gov/moj/cpp/hearing/domain/aggregate/hearing/PleaDelegateTest.java b/hearing-domain/hearing-domain-aggregate/src/test/java/uk/gov/moj/cpp/hearing/domain/aggregate/hearing/PleaDelegateTest.java index 401ae0dac6..5817349886 100644 --- a/hearing-domain/hearing-domain-aggregate/src/test/java/uk/gov/moj/cpp/hearing/domain/aggregate/hearing/PleaDelegateTest.java +++ b/hearing-domain/hearing-domain-aggregate/src/test/java/uk/gov/moj/cpp/hearing/domain/aggregate/hearing/PleaDelegateTest.java @@ -475,6 +475,9 @@ public void shouldAddConvictionDateAddedEventWhenIndicatedPleaIsGuilty() { .withProsecutionCaseId(CASE_ID) .withDefendantId(DEFENDANT_ID) .withOffenceId(OFFENCE_ID) + .withAllocationDecision(AllocationDecision.allocationDecision() + .withOffenceId(OFFENCE_ID) + .build()) .withIndicatedPlea(IndicatedPlea.indicatedPlea() .withOffenceId(OFFENCE_ID) .withIndicatedPleaDate(indicatedPleaDate) @@ -487,6 +490,7 @@ public void shouldAddConvictionDateAddedEventWhenIndicatedPleaIsGuilty() { final PleaUpsert pleaUpsert = (PleaUpsert) events.get(0); assertThat(pleaUpsert, is(notNullValue())); assertThat(pleaUpsert.getHearingId(), is(HEARING_ID)); + assertThat(pleaUpsert.getPleaModel().getAllocationDecision(), is(notNullValue())); final ConvictionDateAdded convictionDateAdded = (ConvictionDateAdded) events.get(1); assertThat(convictionDateAdded, is(notNullValue())); @@ -590,6 +594,64 @@ public void shouldNotAddConvictionDateRemovedEventWhenIndicatedPleaIsNotGuilty() assertThat(pleaUpsert.getHearingId(), is(HEARING_ID)); } + @Test + public void shouldNotAddConvictionDateIfCaseIsCivil() { + final Hearing hearing = getHearing(OFFENCE_ID, DEFENDANT_ID, CASE_ID, HEARING_ID); + hearing.getProsecutionCases().get(0).setIsCivil(true); + + this.hearingAggregateMomento.setHearing(hearing); + + final PleaModel pleaModel = PleaModel.pleaModel() + .withProsecutionCaseId(CASE_ID) + .withDefendantId(DEFENDANT_ID) + .withOffenceId(OFFENCE_ID) + .withPlea(Plea.plea() + .withOffenceId(OFFENCE_ID) + .withPleaDate(PAST_LOCAL_DATE.next()) + .withPleaValue(GUILTY) + .build()) + .build(); + + final List events = pleaDelegate.updatePlea(HEARING_ID, pleaModel, guiltyPleaTypes()).toList(); + + assertThat(events.size(), is(1)); + final PleaUpsert pleaUpsert = (PleaUpsert) events.get(0); + assertThat(pleaUpsert, is(notNullValue())); + assertThat(pleaUpsert.getHearingId(), is(HEARING_ID)); + + assertThat(events.stream().filter(ConvictionDateAdded.class::isInstance).count(), is(0L)); + } + + @Test + public void shouldRemoveAllocationDecisionValuesWhenCaseIsCivil() { + final Hearing hearing = getHearing(OFFENCE_ID, DEFENDANT_ID, CASE_ID, HEARING_ID); + hearing.getProsecutionCases().get(0).setIsCivil(true); + + this.hearingAggregateMomento.setHearing(hearing); + + final PleaModel pleaModel = PleaModel.pleaModel() + .withProsecutionCaseId(CASE_ID) + .withDefendantId(DEFENDANT_ID) + .withOffenceId(OFFENCE_ID) + .withAllocationDecision(AllocationDecision.allocationDecision() + .withOffenceId(OFFENCE_ID) + .build()) + .withPlea(Plea.plea() + .withOffenceId(OFFENCE_ID) + .withPleaDate(PAST_LOCAL_DATE.next()) + .withPleaValue(GUILTY) + .build()) + .build(); + + final List events = pleaDelegate.updatePlea(HEARING_ID, pleaModel, guiltyPleaTypes()).toList(); + + assertThat(events.size(), is(1)); + final PleaUpsert pleaUpsert = (PleaUpsert) events.get(0); + assertThat(pleaUpsert, is(notNullValue())); + assertThat(pleaUpsert.getHearingId(), is(HEARING_ID)); + assertThat(pleaUpsert.getPleaModel().getAllocationDecision(), is(nullValue())); + } + @Test public void shouldAddConvictionDateWhenPleaIsGuiltyType() { GUILTY_PLEA_LIST.forEach(this::shouldAddConvictionDateAddedWhenPleaIsGuiltyType); diff --git a/pom.xml b/pom.xml index b95cb65789..6b8f147e95 100644 --- a/pom.xml +++ b/pom.xml @@ -25,13 +25,13 @@ 0.8 1.3.3 0.1.96 - 17.103.11 - 17.103.128 + 17.103.12 + 17.103.129 17.0.57 17.0.58 17.0.1 17.103.73 - 17.0.215 + 17.0.240 2.2.11 2.6.3 5.7