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 7a174f814..3a2142cbf 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 @@ -1725,13 +1725,13 @@ public Stream updateCase(final ProsecutionCase prosecutionCase, final Li } }); // LAA suppression of false proceedings concluded - if (isNotEmpty(defendantListForProceedingsConcludedEventTrigger) && isAllDefendantProceedingConcluded(prosecutionCase, defendantListForProceedingsConcludedEventTrigger)) { + if (isNotEmpty(defendantListForProceedingsConcludedEventTrigger) && isAllDefendantProceedingConcludedLaa(prosecutionCase, defendantListForProceedingsConcludedEventTrigger)) { // filter for defendants having representation final List listOfDefendantsWithLaaRepresentation = getDefendantsWithLaaRepresentation(defendantListForProceedingsConcludedEventTrigger); final UUID resultedHearingId = hearingId != null ? hearingId : latestHearingId; if (!listOfDefendantsWithLaaRepresentation.isEmpty()) { streamBuilder.add(laaDefendantProceedingConcludedChanged() - .withDefendants(listOfDefendantsWithLaaRepresentation) + .withDefendants(defendantListForProceedingsConcludedEventTrigger)//listOfDefendantsWithLaaRepresentation) .withHearingId(resultedHearingId) .withProsecutionCaseId(prosecutionCase.getId()) .build()); 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 54868fb17..140ec37e2 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 @@ -90,20 +90,62 @@ public static boolean hearingCaseDefendantsProceedingsConcluded(final Prosecutio // initial implemented filter code public static boolean isAllDefendantProceedingConcluded(final ProsecutionCase prosecutionCase, final List updatedDefendants) { - return prosecutionCase.getDefendants().stream().map(defendant -> { + + 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, isConcluded(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 boolean isAllDefendantProceedingConcludedLaa(final ProsecutionCase prosecutionCase, final List updatedDefendants) { + + List defs = prosecutionCase.getDefendants(); + + boolean result = defs.stream().map(defendant -> { + final List updatedOffences = new ArrayList<>(); + final List offs = defendant.getOffences(); + + + final List proConcludedList = offs.stream() + .map(offence -> { + return getUpdatedOffence(updatedOffences, offence, isConcludedForLaa(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 == true); + + return result; + } + + public static List getDefendantsWithLaaRepresentation(final List defendants) { return defendants.stream() .filter(defendant -> LegalAidStatusEnum.GRANTED.equals(defendant.getLegalAidStatus())) @@ -280,6 +322,12 @@ private static boolean isAnyChangeInProceedingConcludedFromPreviousState(List judicialResult.getCategory().equals(JudicialResultCategory.FINAL)) + && offence.getProceedingsConcluded() != null ? offence.getProceedingsConcluded(): false; + } + public static boolean isConcluded(final Offence offence) { return isNotEmpty(offence.getJudicialResults()) && offence.getJudicialResults().stream() .anyMatch(judicialResult -> judicialResult.getCategory().equals(JudicialResultCategory.FINAL));