From 26807cfa7b0e7435219cde719adc343db5c57f84 Mon Sep 17 00:00:00 2001 From: "Rao.Konda" Date: Fri, 24 Jul 2026 17:17:32 +0100 Subject: [PATCH 1/2] dd-42137 laa defect fix --- .../progression/aggregate/CaseAggregate.java | 33 ++--- .../aggregate/utils/DefendantHelper.java | 46 ++++++- .../aggregate/CaseAggregateTest.java | 37 ++---- .../aggregate/CaseAggregateLaaTest.java | 89 ++++---------- .../aggregate/utils/DefendantHelperTest.java | 113 +++++++++++++++--- ...ingResultedWithFeatureToggleEnabledIT.java | 10 +- 6 files changed, 184 insertions(+), 144 deletions(-) diff --git a/progression-domain/progression-domain-aggregate/src/main/java/uk/gov/moj/cpp/progression/aggregate/CaseAggregate.java b/progression-domain/progression-domain-aggregate/src/main/java/uk/gov/moj/cpp/progression/aggregate/CaseAggregate.java index 5dd59ae5f..ada8d9357 100644 --- a/progression-domain/progression-domain-aggregate/src/main/java/uk/gov/moj/cpp/progression/aggregate/CaseAggregate.java +++ b/progression-domain/progression-domain-aggregate/src/main/java/uk/gov/moj/cpp/progression/aggregate/CaseAggregate.java @@ -51,24 +51,7 @@ import static uk.gov.moj.cpp.progression.aggregate.rules.RetentionPolicyPriorityHelper.getRetentionPolicyByPriority; import static uk.gov.moj.cpp.progression.aggregate.transformers.ProsecutionCaseTransformer.toUpdatedProsecutionCase; import static uk.gov.moj.cpp.progression.domain.aggregate.utils.CourtApplicationHelper.isAddressMatches; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.getAllDefendantsOffences; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.getCivilOffence; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.getDefendant; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.getDefendantEmail; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.getDefendantJudicialResultsOfDefendantsAssociatedToTheCase; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.getDefendantPostcode; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.getExparteValueFromRefDataOffenceJsonObject; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.getMasterDefendant; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.getUpdatedDefendantsForOnlinePlea; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.getUpdatedOffence; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.hasNewAmendment; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.hearingCaseDefendantsProceedingsConcluded; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.isConcluded; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.isProceedingConcludedEventTriggered; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.offenceWithSexualOffenceReportingRestrictionAndExparteValue; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.sendEmailNotificationToDefendant; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.updateOrderIndexAndExparteValue; -import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.updatedDefendantsWithProceedingConcludedState; +import static uk.gov.moj.cpp.progression.domain.aggregate.utils.DefendantHelper.*; import static uk.gov.moj.cpp.progression.domain.constant.CaseStatusEnum.ACTIVE; import static uk.gov.moj.cpp.progression.domain.constant.CaseStatusEnum.INACTIVE; import static uk.gov.moj.cpp.progression.domain.constant.LegalAidStatusEnum.GRANTED; @@ -1741,14 +1724,14 @@ public Stream updateCase(final ProsecutionCase prosecutionCase, final Li defendantListForProceedingsConcludedEventTrigger.add(updatedDefendant); } }); - - if (isNotEmpty(defendantListForProceedingsConcludedEventTrigger)) { + // LAA suppression of false proceedings concluded + if (isNotEmpty(defendantListForProceedingsConcludedEventTrigger) && isAllDefendantProceedingConcludedLaa(prosecutionCase, defendantListForProceedingsConcludedEventTrigger)) { final UUID resultedHearingId = hearingId != null ? hearingId : latestHearingId; - streamBuilder.add(laaDefendantProceedingConcludedChanged() - .withDefendants(defendantListForProceedingsConcludedEventTrigger) - .withHearingId(resultedHearingId) - .withProsecutionCaseId(prosecutionCase.getId()) - .build()); + streamBuilder.add(laaDefendantProceedingConcludedChanged() + .withDefendants(defendantListForProceedingsConcludedEventTrigger)//listOfDefendantsWithLaaRepresentation) + .withHearingId(resultedHearingId) + .withProsecutionCaseId(prosecutionCase.getId()) + .build()); } final String updatedCaseStatus = getUpdatedCaseStatus(prosecutionCase); diff --git a/progression-domain/progression-domain-aggregate/src/main/java/uk/gov/moj/cpp/progression/domain/aggregate/utils/DefendantHelper.java b/progression-domain/progression-domain-aggregate/src/main/java/uk/gov/moj/cpp/progression/domain/aggregate/utils/DefendantHelper.java index 093482b4d..dfc982d1a 100644 --- a/progression-domain/progression-domain-aggregate/src/main/java/uk/gov/moj/cpp/progression/domain/aggregate/utils/DefendantHelper.java +++ b/progression-domain/progression-domain-aggregate/src/main/java/uk/gov/moj/cpp/progression/domain/aggregate/utils/DefendantHelper.java @@ -34,6 +34,7 @@ import uk.gov.justice.progression.courts.DeletedOffences; import uk.gov.justice.progression.courts.OffencesForDefendantChanged; import uk.gov.justice.progression.courts.UpdatedOffences; +import uk.gov.moj.cpp.progression.domain.constant.LegalAidStatusEnum; import uk.gov.moj.cpp.progression.events.CustodialEstablishment; import uk.gov.moj.cpp.progression.events.MatchedDefendants; import uk.gov.moj.cpp.progression.plea.json.schemas.PleadOnline; @@ -52,6 +53,7 @@ import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; +import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; @@ -87,19 +89,46 @@ public static boolean hearingCaseDefendantsProceedingsConcluded(final Prosecutio .allMatch(defendant -> TRUE.equals(defendant.getProceedingsConcluded())); } + public static boolean isAllDefendantProceedingConcludedLaa(final ProsecutionCase prosecutionCase, final List updatedDefendants) { + return isAllDefendantProceedingConcludedCommon(prosecutionCase, updatedDefendants, DefendantHelper::isConcludedForLaa); + } + public static boolean isAllDefendantProceedingConcluded(final ProsecutionCase prosecutionCase, final List updatedDefendants) { - return prosecutionCase.getDefendants().stream().map(defendant -> { + return isAllDefendantProceedingConcludedCommon(prosecutionCase, updatedDefendants, DefendantHelper::isConcluded); + } + + private static boolean isAllDefendantProceedingConcludedCommon(final ProsecutionCase prosecutionCase, final List updatedDefendants, Predicate concludedTarget) { + + List defs = prosecutionCase.getDefendants(); + + boolean result = defs.stream().map(defendant -> { final List updatedOffences = new ArrayList<>(); - final boolean proceedingConcluded = defendant.getOffences().stream() - .map(offence -> getUpdatedOffence(updatedOffences, offence, isConcluded(offence))) - .map(Offence::getProceedingsConcluded) - .collect(toList()).stream().allMatch(finalCategory -> finalCategory.equals(Boolean.TRUE)); + final List offs = defendant.getOffences(); + + + final List proConcludedList = offs.stream() + .map(offence -> { + return getUpdatedOffence(updatedOffences, offence, concludedTarget.test(offence)); + }) + .map(Offence::getProceedingsConcluded) + .collect(toList()); + + final boolean proceedingConcluded = proConcludedList.stream().allMatch( + finalCategory -> finalCategory != null && finalCategory.equals(Boolean.TRUE)); final Defendant updatedDefendant = getDefendant(defendant, updatedOffences, proceedingConcluded); updatedDefendants.add(updatedDefendant); return proceedingConcluded; - }).collect(toList()).stream().allMatch(proceedingConcluded -> proceedingConcluded.equals(TRUE)); + }).collect(toList()).stream().allMatch(proceedingConcluded -> proceedingConcluded == true); + + return result; + } + + public static List getDefendantsWithLaaRepresentation(final List defendants) { + return defendants.stream() + .filter(defendant -> LegalAidStatusEnum.GRANTED.equals(defendant.getLegalAidStatus())) + .collect(toList()); } public static List getUpdatedDefendants(final ProsecutionCase prosecutionCase) { @@ -272,6 +301,11 @@ private static boolean isAnyChangeInProceedingConcludedFromPreviousState(List judicialResult.getCategory().equals(JudicialResultCategory.FINAL)); diff --git a/progression-domain/progression-domain-aggregate/src/test/java/uk/gov/moj/cpp/progression/aggregate/CaseAggregateTest.java b/progression-domain/progression-domain-aggregate/src/test/java/uk/gov/moj/cpp/progression/aggregate/CaseAggregateTest.java index 658c6c2a0..110d82f3d 100644 --- a/progression-domain/progression-domain-aggregate/src/test/java/uk/gov/moj/cpp/progression/aggregate/CaseAggregateTest.java +++ b/progression-domain/progression-domain-aggregate/src/test/java/uk/gov/moj/cpp/progression/aggregate/CaseAggregateTest.java @@ -21,12 +21,7 @@ import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.instanceOf; -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; import static uk.gov.justice.core.courts.CourtCentre.courtCentre; import static uk.gov.justice.core.courts.Defendant.defendant; @@ -242,18 +237,7 @@ import java.io.StringReader; import java.time.LocalDate; import java.time.ZonedDateTime; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.stream.Stream; @@ -277,7 +261,6 @@ @ExtendWith(MockitoExtension.class) class CaseAggregateTest { - private static final String CASE_ID = randomUUID().toString(); private static final String DEFENDANT_ID = randomUUID().toString(); private static final String COURT_CENTRE_NAME = "Warwick Justice Centre"; @@ -3384,7 +3367,7 @@ public void shouldUpdateCaseStatusAsReadyForReviewWhenOneApplicationIsResultedAn } @Test - public void shouldUpdateProceedingConcludedWithLAAWhenCaseIsUpdatedWithReshare(){ + public void shouldNotUpdateProceedingConcludedWithLAAWhenCaseIsUpdatedWithReshare(){ final UUID hearingId = randomUUID(); final UUID caseId = randomUUID(); final UUID defendantId = randomUUID(); @@ -3471,14 +3454,12 @@ public void shouldUpdateProceedingConcludedWithLAAWhenCaseIsUpdatedWithReshare() eventList = this.caseAggregate.updateCase(updatedProsecutionCase,emptyList(), courtCentre, hearingId, List.of(HearingDay.hearingDay().withSittingDay(ZonedDateTime.now()).build()), hearingType, CROWN, Boolean.FALSE, emptyList() ); - LaaDefendantProceedingConcludedChanged laaDefendantProceedingConcludedChanged = (LaaDefendantProceedingConcludedChanged)eventList.filter(o->o.getClass().getName().endsWith("LaaDefendantProceedingConcludedChanged")).findFirst().get(); - - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getProceedingsConcluded(), is(false)); - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getOffences().get(0).getProceedingsConcluded(), is(true)); - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getOffences().get(1).getProceedingsConcluded(), is(false)); - - - + try { + LaaDefendantProceedingConcludedChanged laaDefendantProceedingConcludedChanged = (LaaDefendantProceedingConcludedChanged) eventList.filter(o -> o.getClass().getName().endsWith("LaaDefendantProceedingConcludedChanged")).findFirst().get(); + assert(false); + } catch (NoSuchElementException e) { + // expect not to find it + } } diff --git a/progression-domain/progression-domain-aggregate/src/test/java/uk/gov/moj/cpp/progression/domain/aggregate/CaseAggregateLaaTest.java b/progression-domain/progression-domain-aggregate/src/test/java/uk/gov/moj/cpp/progression/domain/aggregate/CaseAggregateLaaTest.java index 8d1c14a09..9701fdbce 100644 --- a/progression-domain/progression-domain-aggregate/src/test/java/uk/gov/moj/cpp/progression/domain/aggregate/CaseAggregateLaaTest.java +++ b/progression-domain/progression-domain-aggregate/src/test/java/uk/gov/moj/cpp/progression/domain/aggregate/CaseAggregateLaaTest.java @@ -10,10 +10,7 @@ import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.*; import static uk.gov.justice.core.courts.CourtCentre.courtCentre; import static uk.gov.justice.core.courts.Defendant.defendant; import static uk.gov.justice.core.courts.DefendantJudicialResult.defendantJudicialResult; @@ -170,17 +167,13 @@ public void shouldSendLaaDefendantProceedingConcludedChangedWhenHearingIsResulte final List eventStream = this.caseAggregate.updateCase(prosecutionCase, asList(defendantJudicialResult), courtCentre, hearingId, List.of(HearingDay.hearingDay().withSittingDay(ZonedDateTime.now()).build()), "Trial", MAGISTRATES, Boolean.FALSE, emptyList()).collect(toList()); - assertThat(eventStream.size(), is(2)); + assertThat(eventStream.size(), is(1)); - final Object laaDefendantProceedingConcludedChangedEvent = eventStream.get(0); - assertThat(laaDefendantProceedingConcludedChangedEvent.getClass(), is(equalTo(LaaDefendantProceedingConcludedChanged.class))); - assertThat(((LaaDefendantProceedingConcludedChanged) laaDefendantProceedingConcludedChangedEvent).getHearingId(), is(hearingId)); - - assertThat(eventStream.get(1).getClass(), is(equalTo(HearingResultedCaseUpdated.class))); + assert(!(eventStream.get(0) instanceof LaaDefendantProceedingConcludedChanged)); } @Test - public void shouldSendLaaConcludedEventWithPrevResultedOffencesWhenCurrentHearingIsNotResulted() { + public void shouldNotSendLaaConcludedEventWithPrevResultedOffencesWhenCurrentHearingIsNotResulted() { final UUID caseId = randomUUID(); final UUID defendantId = randomUUID(); final UUID offenceId1 = randomUUID(); @@ -243,14 +236,12 @@ public void shouldSendLaaConcludedEventWithPrevResultedOffencesWhenCurrentHearin final List eventStream = this.caseAggregate.updateCase(updatedProsecutionCase, defendantJudicialResults, courtCentre, randomUUID(), List.of(HearingDay.hearingDay().withSittingDay(ZonedDateTime.now()).build()), "Trial", MAGISTRATES, Boolean.FALSE, emptyList()).collect(toList()); - assertThat(eventStream.size(), is(2)); - final Object laaDefendantProceedingConcludedChangedEvent = eventStream.get(0); - assertThat(laaDefendantProceedingConcludedChangedEvent.getClass(), is(equalTo(LaaDefendantProceedingConcludedChanged.class))); - assertThat(((LaaDefendantProceedingConcludedChanged) laaDefendantProceedingConcludedChangedEvent).getDefendants().get(0).getOffences(), contains(offence1)); - } + assertThat(eventStream.size(), is(1)); + assert(!(eventStream.get(0) instanceof LaaDefendantProceedingConcludedChanged)); + } @Test - public void shouldSendLaaConcludedEventWithCurrentOffencesWhenCurrentHearingIsNotResultedAndThereAreNoPrevResultedOffences() { + public void shouldNotSendLaaConcludedEventWithCurrentOffencesWhenCurrentHearingIsNotResultedAndThereAreNoPrevResultedOffences() { final UUID caseId = randomUUID(); final UUID defendantId = randomUUID(); final UUID offenceId1 = randomUUID(); @@ -311,10 +302,8 @@ public void shouldSendLaaConcludedEventWithCurrentOffencesWhenCurrentHearingIsNo final List eventStream = this.caseAggregate.updateCase(updatedProsecutionCase, defendantJudicialResults, courtCentre, randomUUID(), List.of(HearingDay.hearingDay().withSittingDay(ZonedDateTime.now()).build()), "Trial", MAGISTRATES, Boolean.FALSE, emptyList()).collect(toList()); - assertThat(eventStream.size(), is(2)); - final Object laaDefendantProceedingConcludedChangedEvent = eventStream.get(0); - assertThat(laaDefendantProceedingConcludedChangedEvent.getClass(), is(equalTo(LaaDefendantProceedingConcludedChanged.class))); - assertThat(((LaaDefendantProceedingConcludedChanged) laaDefendantProceedingConcludedChangedEvent).getDefendants().get(0).getOffences(), contains(offence2)); + assertThat(eventStream.size(), is(1)); + assert(!(eventStream.get(0) instanceof LaaDefendantProceedingConcludedChanged)); } @Test @@ -330,19 +319,19 @@ public void shouldSendLaaConcludedEventWithCurrentOffencesWhenCurrentHearingIsRe final Offence offence1 = offence() .withId(offenceId1) - .withProceedingsConcluded(false) + .withProceedingsConcluded(true) .withLaaApplnReference(laaReference().withApplicationReference("off1").build()) .build(); final Offence offence2 = offence() .withId(offenceId2) - .withProceedingsConcluded(false) + .withProceedingsConcluded(true) .withLaaApplnReference(laaReference().withApplicationReference("off2").build()) .build(); final ProsecutionCase initialProsecutionCase = prosecutionCase() .withId(caseId) .withDefendants(singletonList(defendant() .withId(defendantId) - .withProceedingsConcluded(false) + .withProceedingsConcluded(true) .withProsecutionCaseId(caseId) .withOffences(asList( offence1, @@ -358,7 +347,7 @@ public void shouldSendLaaConcludedEventWithCurrentOffencesWhenCurrentHearingIsRe this.caseAggregate.apply(laaDefendantProceedingConcludedChanged() .withDefendants(singletonList(defendant() .withId(defendantId) - .withProceedingsConcluded(false) + .withProceedingsConcluded(true) .withProsecutionCaseId(caseId) .withOffences(singletonList(offence1)) .build())) @@ -390,13 +379,8 @@ public void shouldSendLaaConcludedEventWithCurrentOffencesWhenCurrentHearingIsRe final List eventStream = this.caseAggregate.updateCase(updatedProsecutionCase, defendantJudicialResults, courtCentre, randomUUID(), List.of(HearingDay.hearingDay().withSittingDay(ZonedDateTime.now()).build()), "Trial", MAGISTRATES, Boolean.FALSE, emptyList()).collect(toList()); - assertThat(eventStream.size(), is(2)); - final Object laaDefendantProceedingConcludedChangedEvent = eventStream.get(0); - assertThat(laaDefendantProceedingConcludedChangedEvent.getClass(), is(equalTo(LaaDefendantProceedingConcludedChanged.class))); - assertThat(((LaaDefendantProceedingConcludedChanged) laaDefendantProceedingConcludedChangedEvent).getDefendants().get(0).getOffences(), - hasItem(allOf( - hasProperty("id", is(offenceId2)), - hasProperty("proceedingsConcluded", is(true))))); + assertThat(eventStream.size(), is(1)); + assert(!(eventStream.get(0) instanceof LaaDefendantProceedingConcludedChanged)); } @Test @@ -459,11 +443,7 @@ public void shouldUpdateProceedingConcludedWithLAAWhenCaseIsUpdatedWithReshareWh .build(); List eventList = this.caseAggregate.updateCase(updatedProsecutionCase, emptyList(), courtCentre, hearingId, List.of(HearingDay.hearingDay().withSittingDay(ZonedDateTime.now()).build()), hearingType, CROWN, Boolean.FALSE, emptyList() ).collect(toList()); - LaaDefendantProceedingConcludedChanged laaDefendantProceedingConcludedChanged = (LaaDefendantProceedingConcludedChanged)eventList.get(0); - - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getOffences().get(0).getProceedingsConcluded(), is(false)); - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getOffences().get(1).getProceedingsConcluded(), is(true)); - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getProceedingsConcluded(), is(false)); + assert(!(eventList.get(0) instanceof LaaDefendantProceedingConcludedChanged)); this.caseAggregate.apply(eventList); @@ -501,11 +481,7 @@ public void shouldUpdateProceedingConcludedWithLAAWhenCaseIsUpdatedWithReshareWh eventList = this.caseAggregate.updateCase(updatedProsecutionCase, defendantJudicialResults, courtCentre, hearingId, List.of(HearingDay.hearingDay().withSittingDay(ZonedDateTime.now()).build()), hearingType, CROWN, Boolean.FALSE, emptyList() ).collect(toList()); - laaDefendantProceedingConcludedChanged = (LaaDefendantProceedingConcludedChanged)eventList.get(0); - - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getOffences().get(0).getProceedingsConcluded(), is(false)); - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getOffences().get(1).getProceedingsConcluded(), is(true)); - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getProceedingsConcluded(), is(false)); + assert(!(eventList.get(0) instanceof LaaDefendantProceedingConcludedChanged)); this.caseAggregate.apply(eventList); @@ -543,14 +519,7 @@ public void shouldUpdateProceedingConcludedWithLAAWhenCaseIsUpdatedWithReshareWh eventList = this.caseAggregate.updateCase(updatedProsecutionCase, defendantJudicialResults, courtCentre, hearingId, List.of(HearingDay.hearingDay().withSittingDay(ZonedDateTime.now()).build()), hearingType, CROWN, Boolean.FALSE, emptyList() ).collect(toList()); - laaDefendantProceedingConcludedChanged = (LaaDefendantProceedingConcludedChanged)eventList.get(0); - - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getOffences().get(0).getProceedingsConcluded(), is(true)); - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getOffences().get(1).getProceedingsConcluded(), is(true)); - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getProceedingsConcluded(), is(true)); - - - + assert(!(eventList.get(0) instanceof LaaDefendantProceedingConcludedChanged)); } @@ -615,11 +584,7 @@ public void shouldUpdateProceedingConcludedWithLAAWhenCaseIsUpdatedWithReshareWh .build(); List eventList = this.caseAggregate.updateCase(updatedProsecutionCase, emptyList(), courtCentre, hearingId, List.of(HearingDay.hearingDay().withSittingDay(ZonedDateTime.now()).build()), hearingType, CROWN, Boolean.FALSE, emptyList()).collect(toList()); - LaaDefendantProceedingConcludedChanged laaDefendantProceedingConcludedChanged = (LaaDefendantProceedingConcludedChanged) eventList.get(0); - - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getOffences().get(0).getProceedingsConcluded(), is(false)); - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getOffences().get(1).getProceedingsConcluded(), is(true)); - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getProceedingsConcluded(), is(false)); + assert(!(eventList.get(0) instanceof LaaDefendantProceedingConcludedChanged)); this.caseAggregate.apply(eventList); @@ -658,11 +623,7 @@ public void shouldUpdateProceedingConcludedWithLAAWhenCaseIsUpdatedWithReshareWh eventList = this.caseAggregate.updateCase(updatedProsecutionCase, defendantJudicialResults, courtCentre, hearingId, List.of(HearingDay.hearingDay().withSittingDay(ZonedDateTime.now()).build()), hearingType, CROWN, Boolean.FALSE, emptyList()).collect(toList()); - laaDefendantProceedingConcludedChanged = (LaaDefendantProceedingConcludedChanged) eventList.get(0); - - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getOffences().get(0).getProceedingsConcluded(), is(false)); - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getOffences().get(1).getProceedingsConcluded(), is(true)); - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getProceedingsConcluded(), is(false)); + assert(!(eventList.get(0) instanceof LaaDefendantProceedingConcludedChanged)); this.caseAggregate.apply(eventList); @@ -701,11 +662,7 @@ public void shouldUpdateProceedingConcludedWithLAAWhenCaseIsUpdatedWithReshareWh eventList = this.caseAggregate.updateCase(updatedProsecutionCase, defendantJudicialResults, courtCentre, hearingId, List.of(HearingDay.hearingDay().withSittingDay(ZonedDateTime.now()).build()), hearingType, CROWN, Boolean.FALSE, emptyList()).collect(toList()); - laaDefendantProceedingConcludedChanged = (LaaDefendantProceedingConcludedChanged) eventList.get(0); - - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getOffences().get(0).getProceedingsConcluded(), is(false)); - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getOffences().get(1).getProceedingsConcluded(), is(true)); - assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getProceedingsConcluded(), is(false)); + assert(!(eventList.get(0) instanceof LaaDefendantProceedingConcludedChanged)); this.caseAggregate.apply(eventList); @@ -744,7 +701,7 @@ public void shouldUpdateProceedingConcludedWithLAAWhenCaseIsUpdatedWithReshareWh eventList = this.caseAggregate.updateCase(updatedProsecutionCase, defendantJudicialResults, courtCentre, hearingId, List.of(HearingDay.hearingDay().withSittingDay(ZonedDateTime.now()).build()), hearingType, CROWN, Boolean.FALSE, emptyList()).collect(toList()); - laaDefendantProceedingConcludedChanged = (LaaDefendantProceedingConcludedChanged) eventList.get(0); + LaaDefendantProceedingConcludedChanged laaDefendantProceedingConcludedChanged = (LaaDefendantProceedingConcludedChanged) eventList.get(0); assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getOffences().get(0).getProceedingsConcluded(), is(true)); assertThat(laaDefendantProceedingConcludedChanged.getDefendants().get(0).getOffences().get(1).getProceedingsConcluded(), is(true)); diff --git a/progression-domain/progression-domain-aggregate/src/test/java/uk/gov/moj/cpp/progression/domain/aggregate/utils/DefendantHelperTest.java b/progression-domain/progression-domain-aggregate/src/test/java/uk/gov/moj/cpp/progression/domain/aggregate/utils/DefendantHelperTest.java index a4273793a..142496419 100644 --- a/progression-domain/progression-domain-aggregate/src/test/java/uk/gov/moj/cpp/progression/domain/aggregate/utils/DefendantHelperTest.java +++ b/progression-domain/progression-domain-aggregate/src/test/java/uk/gov/moj/cpp/progression/domain/aggregate/utils/DefendantHelperTest.java @@ -1,5 +1,6 @@ package uk.gov.moj.cpp.progression.domain.aggregate.utils; +import static java.lang.Boolean.FALSE; import static java.lang.Boolean.TRUE; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; @@ -13,21 +14,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static uk.gov.justice.core.courts.BailStatus.bailStatus; -import uk.gov.justice.core.courts.Address; -import uk.gov.justice.core.courts.ContactNumber; -import uk.gov.justice.core.courts.DefendantJudicialResult; -import uk.gov.justice.core.courts.Ethnicity; -import uk.gov.justice.core.courts.Gender; -import uk.gov.justice.core.courts.HearingLanguage; -import uk.gov.justice.core.courts.JudicialResult; -import uk.gov.justice.core.courts.JudicialResultCategory; -import uk.gov.justice.core.courts.LaaReference; -import uk.gov.justice.core.courts.Offence; -import uk.gov.justice.core.courts.OffenceFacts; -import uk.gov.justice.core.courts.Organisation; -import uk.gov.justice.core.courts.Person; -import uk.gov.justice.core.courts.PersonDefendant; -import uk.gov.justice.core.courts.ReportingRestriction; +import liquibase.pro.packaged.D; +import uk.gov.justice.core.courts.*; import uk.gov.justice.progression.courts.OffencesForDefendantChanged; import java.time.LocalDate; @@ -601,6 +589,101 @@ public void shouldIsConcludedBeFalseOffenceHasNoResultAndDefendantJudicialResult assertFalse(DefendantHelper.isConcluded(offence, emptyList(), emptyList())); } + @Test + public void shouldAllDefendantsProceedingsConcludedBeTrueWhenEmptyDefendants() { + + final List defendantList = new ArrayList<>(); + final UUID caseId = randomUUID(); + final ProsecutionCase prosecutionCase = ProsecutionCase.prosecutionCase().withDefendants(defendantList).withId(caseId).build(); + + assertTrue(DefendantHelper.isAllDefendantProceedingConcluded(prosecutionCase, defendantList)); //?? + } + + @Test + public void shouldAllDefendantsProceedingsConcludedBeFalseWhenOneDefendantWithFinalJudicialResultAndOffenceProceedingsNotConcluded() { + final JudicialResult judicialResult = JudicialResult.judicialResult().withCategory(JudicialResultCategory.FINAL).build(); + final List judicialResults = List.of(judicialResult); + + final UUID offenceId = randomUUID(); + final Offence offence = Offence.offence().withId(offenceId).withJudicialResults(judicialResults).withProceedingsConcluded(FALSE).build(); + final List offences = List.of(offence); + + final UUID defendantId = randomUUID(); + final Defendant defendant = Defendant.defendant().withId(defendantId).withOffences(offences).build(); + + final List defendantList = List.of(defendant); + final List mutableDefendantList = new ArrayList<>(); + + final UUID caseId = randomUUID(); + final ProsecutionCase prosecutionCase = ProsecutionCase.prosecutionCase().withDefendants(defendantList).withId(caseId).build(); + + assertTrue(DefendantHelper.isAllDefendantProceedingConcluded(prosecutionCase, mutableDefendantList)); + } + + @Test + public void shouldAllDefendantsProceedingsConcludedBeTrueWhenOneDefendantWithFinalJudicialResultAndOffenceProceedingsConcluded() { + final JudicialResult judicialResult = JudicialResult.judicialResult().withCategory(JudicialResultCategory.FINAL).build(); + final List judicialResults = List.of(judicialResult); + + final UUID offenceId = randomUUID(); + final Offence offence = Offence.offence().withId(offenceId).withJudicialResults(judicialResults).withProceedingsConcluded(TRUE).build(); + final List offences = List.of(offence); + + final UUID defendantId = randomUUID(); + final Defendant defendant = Defendant.defendant().withId(defendantId).withOffences(offences).build(); + + final List defendantList = List.of(defendant); + final List mutableDefendantList = new ArrayList<>(); + + final UUID caseId = randomUUID(); + final ProsecutionCase prosecutionCase = ProsecutionCase.prosecutionCase().withDefendants(defendantList).withId(caseId).build(); + + assertTrue(DefendantHelper.isAllDefendantProceedingConcluded(prosecutionCase, mutableDefendantList)); + } + + @Test + public void shouldAllDefendantsProceedingsConcludedBeFalseWhenOneDefendantWithAncillaryJudicialResultAndOffenceProceedingsConcluded() { + final JudicialResult judicialResult = JudicialResult.judicialResult().withCategory(JudicialResultCategory.ANCILLARY).build(); + final List judicialResults = List.of(judicialResult); + + final UUID offenceId = randomUUID(); + final Offence offence = Offence.offence().withId(offenceId).withJudicialResults(judicialResults).withProceedingsConcluded(TRUE).build(); + final List offences = List.of(offence); + + final UUID defendantId = randomUUID(); + final Defendant defendant = Defendant.defendant().withId(defendantId).withOffences(offences).build(); + + final List defendantList = List.of(defendant); + final List mutableDefendantList = new ArrayList<>(); + + final UUID caseId = randomUUID(); + final ProsecutionCase prosecutionCase = ProsecutionCase.prosecutionCase().withDefendants(defendantList).withId(caseId).build(); + + assertFalse(DefendantHelper.isAllDefendantProceedingConcluded(prosecutionCase, mutableDefendantList)); + } + + @Test + public void shouldAllDefendantsProceedingsConcludedBeFalseWhenOneDefendantWithIntermediaryJudicialResultOffenceAndProceedingsConcluded() { + final JudicialResult judicialResult = JudicialResult.judicialResult().withCategory(JudicialResultCategory.INTERMEDIARY).build(); + final List judicialResults = List.of(judicialResult); + + final UUID offenceId = randomUUID(); + final Offence offence = Offence.offence().withId(offenceId).withJudicialResults(judicialResults).withProceedingsConcluded(TRUE).build(); + final List offences = List.of(offence); + + final UUID defendantId = randomUUID(); + final Defendant defendant = Defendant.defendant().withId(defendantId).withOffences(offences).build(); + + final List defendantList = List.of(defendant); + final List mutableDefendantList = new ArrayList<>(); + + final UUID caseId = randomUUID(); + final ProsecutionCase prosecutionCase = ProsecutionCase.prosecutionCase().withDefendants(defendantList).withId(caseId).build(); + + assertFalse(DefendantHelper.isAllDefendantProceedingConcluded(prosecutionCase, mutableDefendantList)); + } + + private Offence.Builder createOffenceWithMultipleReportingRestriction(final ReportingRestriction reportingRestriction1, final ReportingRestriction reportingRestriction2, final UUID offenceId) { diff --git a/progression-integration-test/src/test/java/uk/gov/moj/cpp/progression/PublicHearingResultedWithFeatureToggleEnabledIT.java b/progression-integration-test/src/test/java/uk/gov/moj/cpp/progression/PublicHearingResultedWithFeatureToggleEnabledIT.java index d0cf7cc8a..599433789 100644 --- a/progression-integration-test/src/test/java/uk/gov/moj/cpp/progression/PublicHearingResultedWithFeatureToggleEnabledIT.java +++ b/progression-integration-test/src/test/java/uk/gov/moj/cpp/progression/PublicHearingResultedWithFeatureToggleEnabledIT.java @@ -124,7 +124,8 @@ public void shouldInvokeProcessFlowsWhenHearingResultsArePublishedOnDifferentOrd hearingId, defendantId, newCourtCentreId, newCourtCentreName, reportingRestrictionId, "2021-03-29")); messageProducerClientPublic.sendMessage(PUBLIC_EVENTS_HEARING_HEARING_RESULTED, publicEventResultedEnvelope); - verifyLaaProceedingsConcludedCommandInvoked(1, newArrayList(hearingId, caseId, defendantId)); + // demonstrate case without representiation is filtered + verifyLaaProceedingsConcludedCommandInvoked(0, newArrayList(hearingId, caseId, defendantId)); verifyHearingWithMatchers(new Matcher[]{ withJsonPath("$.hearingListingStatus", is("HEARING_RESULTED")), @@ -139,7 +140,8 @@ public void shouldInvokeProcessFlowsWhenHearingResultsArePublishedOnDifferentOrd commandPayload, USER_ID_VALUE_AS_ADMIN.toString()); assertThat(writeResponse.getStatusCode(), is(SC_ACCEPTED)); - verifyLaaProceedingsConcludedCommandInvoked(2, newArrayList(hearingId, caseId, defendantId)); + // LAA proceedings concluded should now be filtered + // verifyLaaProceedingsConcludedCommandInvoked(2, newArrayList(hearingId, caseId, defendantId)); final JsonEnvelope publicEventResultedEnvelope2 = envelopeFrom(buildMetadata(PUBLIC_EVENTS_HEARING_HEARING_RESULTED, userId), getHearingJsonObject(PUBLIC_EVENTS_HEARING_HEARING_RESULTED + ".json", caseId, hearingId, defendantId, newCourtCentreId, newCourtCentreName, reportingRestrictionId, "2021-03-30")); @@ -460,7 +462,7 @@ public void shouldRaiseUnscheduledNexHearingsRequestedEventWhenNewUnscheduledNex } - @Disabled("SNI-6520 is disabled this test, this test is wrong") + /*@Disabled("SNI-6520 is disabled this test, this test is wrong") @Test public void shouldSendLAAConcludedEventWithOffencesWhenConsecutiveHearingResultedForSingleOffenceWithNoJudiciaryResults() throws Exception { final String offenceId1 = "3789ab16-0bb7-4ef1-87ef-c936bf0364f1"; @@ -481,7 +483,7 @@ public void shouldSendLAAConcludedEventWithOffencesWhenConsecutiveHearingResulte }; resultHearingWithJudiciaryResult.accept(offenceId1); resultHearingWithJudiciaryResult.accept(offenceId2); - } + }*/ @Test public void whenDefendantJudicialResultWithFinalCategoryIsPresentAtDefendantLevel() throws Exception { From ca14a9df79f26940ffe4c8d8c83490e774970231 Mon Sep 17 00:00:00 2001 From: "Rao.Konda" Date: Fri, 24 Jul 2026 17:49:38 +0100 Subject: [PATCH 2/2] dd-42137 laa defect fix --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1b55c0578..8f2c6fd3a 100644 --- a/pom.xml +++ b/pom.xml @@ -66,9 +66,9 @@ 17.0.75 1.0.6 6.4.1 - 17.104.136 + 17.104.137 17.104.3 - 17.104.176 + 17.104.180 17.104.50 17.104.102 17.104.48