Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
<material.version>17.0.72</material.version>
<json-transformer.version>1.0.6</json-transformer.version>
<access.control.version>6.4.1</access.control.version>
<referencedata.version>17.0.120</referencedata.version>
<referencedata.version>17.103.124</referencedata.version>
<listing.version>17.0.125</listing.version>
<hearing.version>17.0.134</hearing.version>
<hearing.version>17.0.142</hearing.version>
<usersgroups.version>17.0.37</usersgroups.version>
<defence.version>17.0.85</defence.version>
<referencedata.offence.version>17.0.38</referencedata.offence.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,17 +617,19 @@ private void handleProsecutionCaseOffencesUpdated(final ProsecutionCaseOffencesU
offenceSet.addAll(prosecutionCaseOffencesUpdated.getDefendantCaseOffences().getOffences());
offenceSet.addAll(defendant.getOffences());
Defendant.Builder builder = Defendant.defendant().withValuesFrom(defendant);
uk.gov.moj.cpp.progression.events.CustodialEstablishment custodialEstablishment = defendantCustodialEstablishmentMap.get(defendant.getId());
if (custodialEstablishment != null) {
final uk.gov.justice.core.courts.CustodialEstablishment.Builder custodialEstablishmentBuilder = uk.gov.justice.core.courts.CustodialEstablishment.custodialEstablishment();
custodialEstablishmentBuilder.withCustody(custodialEstablishment.getCustody())
.withId(custodialEstablishment.getId())
.withName(custodialEstablishment.getName());
Defendant latestDefendant = this.defendantsMap.get(defendant.getId());
PersonDefendant personDefendant = PersonDefendant.personDefendant().withValuesFrom(defendant.getPersonDefendant())
.withBailStatus(latestDefendant.getPersonDefendant().getBailStatus())
.withCustodialEstablishment(custodialEstablishmentBuilder.build()).build();
builder.withPersonDefendant(personDefendant);
Defendant latestDefendant = this.defendantsMap.get(defendant.getId());
if(defendant.getPersonDefendant() != null){
PersonDefendant.Builder personDefendant = PersonDefendant.personDefendant().withValuesFrom(defendant.getPersonDefendant())
.withBailStatus(latestDefendant.getPersonDefendant().getBailStatus());
uk.gov.moj.cpp.progression.events.CustodialEstablishment custodialEstablishment = defendantCustodialEstablishmentMap.get(defendant.getId());
if (custodialEstablishment != null) {
final uk.gov.justice.core.courts.CustodialEstablishment.Builder custodialEstablishmentBuilder = uk.gov.justice.core.courts.CustodialEstablishment.custodialEstablishment();
custodialEstablishmentBuilder.withCustody(custodialEstablishment.getCustody())
.withId(custodialEstablishment.getId())
.withName(custodialEstablishment.getName());
personDefendant.withCustodialEstablishment(custodialEstablishmentBuilder.build());
}
builder.withPersonDefendant(personDefendant.build());
}
defendantList.add(builder.withOffences(offenceSet.stream().collect(toList()))
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.json.Json;
Expand Down Expand Up @@ -325,6 +326,7 @@ class CaseAggregateTest {
.withLastName("lastName")
.withDateOfBirth(LocalDate.now().minusYears(20))
.build())
.withBailStatus(BailStatus.bailStatus().withCode("C").withDescription("Custody").build())
.build())
.withCourtProceedingsInitiated(ZonedDateTime.now())
.withOffences(asList(offence().withId(randomUUID())
Expand Down Expand Up @@ -7881,6 +7883,61 @@ void shouldNotRaiseHearingResultedCaseUpdatedEvenIfCaseIsEjected(){
assertThat(eventStream.toList().size(), is(0));
}

@Test
public void shouldRetainCorrectBailStatusAfterLAAReferenceAndRepresentationOrder() {
final UUID caseId = fromString(CASE_ID);
final UUID defendantId = fromString(DEFENDANT_ID);
final UUID offenceId = fromString(OFFENCE_ID);
final UUID defendantId2 = randomUUID();
final UUID associatedOrganisationId = randomUUID();
final UUID currentOrganisationId = randomUUID();
final DefendantsAddedToCourtProceedings defendantsAddedToCourtProceedings = buildDefendantsAddedToCourtProceedings(
caseId, defendantId, defendantId2, offenceId);
Defendant currentDefendant1 = prosecutionCase.getDefendants().get(0);
Defendant.Builder defendant1 = defendant().withValuesFrom(currentDefendant1);
PersonDefendant personDefendant = currentDefendant1.getPersonDefendant();
final PersonDefendant newPersonDefendant = personDefendant().withValuesFrom(personDefendant).withBailStatus(BailStatus.bailStatus()
.withCode("B")
.withDescription("Conditional Bail")
.build()).build();
defendant1.withPersonDefendant(newPersonDefendant);
ProsecutionCase hearingResultedProsecutionCase = ProsecutionCase.prosecutionCase()
.withValuesFrom(prosecutionCase)
.withDefendants(Lists.newArrayList(defendant1.build()))
.build();
final HearingResultedCaseUpdated hearingResultedCaseUpdated = HearingResultedCaseUpdated.hearingResultedCaseUpdated()
.withProsecutionCase(hearingResultedProsecutionCase)
.build();
final CaseAggregate caseAggregate = new CaseAggregate();
caseAggregate.apply(new ProsecutionCaseCreated(prosecutionCase, null));
caseAggregate.apply(hearingResultedCaseUpdated);
caseAggregate.defendantsAddedToCourtProceedings(defendantsAddedToCourtProceedings.getDefendants(),
defendantsAddedToCourtProceedings.getListHearingRequests(), Optional.of(createJsonList())).collect(toList());
final LaaReference laaReference = generateRecordLAAReferenceForOffence("G2", GRANTED.getDescription());

final ReceiveRepresentationOrderForDefendant receiveRepresentationOrderForDefendant = ReceiveRepresentationOrderForDefendant
.receiveRepresentationOrderForDefendant()
.withDefendantId(currentDefendant1.getId())
.withProsecutionCaseId(caseId)
.withOffenceId(currentDefendant1.getOffences().get(0).getId())
.withDefenceOrganisation(DefenceOrganisation.defenceOrganisation()
.withOrganisation(Organisation.organisation()
.withName("XYZ Organisation")
.withId(associatedOrganisationId)
.build())
.withLaaContractNumber("LAA Contract Number")
.build())
.build();
final OrganisationDetails organisationDetails = OrganisationDetails.newBuilder().withId(currentOrganisationId).build();
caseAggregate.recordLAAReferenceForOffence(caseId, currentDefendant1.getId(), currentDefendant1.getOffences().get(0).getId(), laaReference).collect(toList());
final LaaReference laaReference1 = laaReference().withValuesFrom(laaReference).withLaaContractNumber("ABCD").build();
final List<Object> eventStream = caseAggregate.receiveRepresentationOrderForDefendant(receiveRepresentationOrderForDefendant, laaReference1, organisationDetails, associatedOrganisationId.toString())
.collect(Collectors.toUnmodifiableList());
assertThat(eventStream.size(), is(8));
Optional<Object> pcdUpdated = eventStream.stream().filter(event -> event instanceof ProsecutionCaseDefendantUpdated).findFirst();
assertThat(((ProsecutionCaseDefendantUpdated)pcdUpdated.get()).getDefendant().getPersonDefendant().getBailStatus().getDescription(), is("Conditional Bail"));
}

private Defendant getDefendant(final UUID defendantId1) {
return Defendant.defendant()
.withOffences(asList(uk.gov.justice.core.courts.Offence.offence().build()))
Expand Down