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
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,129 @@ public void shouldSaveAndFindAvailableHearingByLinkedCase() {
assertThat(actualHearings.get(0).getProperties().toString(), hasJsonPath("$.listedCases[0].linkedCases[0].caseUrn", equalTo(LINKED_CASE_URN)));
}

@Test
public void shouldFindAllAvailableHearingsByCaseUrnRegardlessOfAllocation() {
//given - one allocated, one unallocated hearing, both with the same case reference
givenAvailableHearingsWithMixedAllocation();

final Set<String> caseUrnSet = new HashSet<>();
caseUrnSet.add(CASE_REFERENCE);
final Set<String> masterDefendantIdSet = new HashSet<>();
masterDefendantIdSet.add(EMPTY_STRING);
final Set<String> jurisdictionTypeSet = new HashSet<>();
jurisdictionTypeSet.add(JurisdictionType.CROWN.name());
final Set<String> linkedCaseUrn = new HashSet<>();
linkedCaseUrn.add(EMPTY_STRING);

//when
final List<Hearing> actualHearings = hearingRepository.findHearings(
jurisdictionTypeSet,
null,
caseUrnSet,
masterDefendantIdSet,
linkedCaseUrn,
null,
now());

//then - both allocated and unallocated hearings are returned
assertThat(actualHearings.size(), is(2));
assertThat(extractFields(actualHearings, "$.id"), containsInAnyOrder(HEARING_ID.toString(), OTHER_HEARING_ID.toString()));
assertThat(extractFields(actualHearings, "$.allocated"), containsInAnyOrder(TRUE.toString(), FALSE.toString()));
assertThat(actualHearings.get(0).getProperties().toString(), hasJsonPath("$.listedCases[0].caseIdentifier.caseReference", equalTo(CASE_REFERENCE)));
}

@Test
public void shouldFindAllAvailableHearingsByMasterDefendantIdRegardlessOfAllocation() {
//given - one allocated, one unallocated hearing, both with the same master defendant
givenAvailableHearingsWithMixedAllocation();

final Set<String> caseUrnSet = new HashSet<>();
caseUrnSet.add(EMPTY_STRING);
final Set<String> masterDefendantIdSet = new HashSet<>();
masterDefendantIdSet.add(MASTER_DEFENDANT_ID);
final Set<String> jurisdictionTypeSet = new HashSet<>();
jurisdictionTypeSet.add(JurisdictionType.CROWN.name());
final Set<String> linkedCaseUrn = new HashSet<>();
linkedCaseUrn.add(EMPTY_STRING);

//when
final List<Hearing> actualHearings = hearingRepository.findHearings(
jurisdictionTypeSet,
null,
caseUrnSet,
masterDefendantIdSet,
linkedCaseUrn,
null,
now());

//then - both allocated and unallocated hearings are returned
assertThat(actualHearings.size(), is(2));
assertThat(extractFields(actualHearings, "$.id"), containsInAnyOrder(HEARING_ID.toString(), OTHER_HEARING_ID.toString()));
assertThat(extractFields(actualHearings, "$.allocated"), containsInAnyOrder(TRUE.toString(), FALSE.toString()));
assertThat(actualHearings.get(0).getProperties().toString(), hasJsonPath("$.listedCases[0].defendants[0].masterDefendantId", equalTo(MASTER_DEFENDANT_ID)));
}

@Test
public void shouldFindAllAvailableHearingsByCaseUrnForLinkedCasesRegardlessOfAllocation() {
//given - one allocated, one unallocated hearing, both with a linked case pointing back to the same case reference
givenAvailableHearingsWithMixedAllocation();

final Set<String> caseUrnSet = new HashSet<>();
caseUrnSet.add(EMPTY_STRING);
final Set<String> masterDefendantIdSet = new HashSet<>();
masterDefendantIdSet.add(EMPTY_STRING);
final Set<String> jurisdictionTypeSet = new HashSet<>();
jurisdictionTypeSet.add(CROWN.name());
final Set<String> linkedCaseUrn = new HashSet<>();
linkedCaseUrn.add(EMPTY_STRING);
final String caseUrnForLinkedCases = CASE_REFERENCE;

//when
final List<Hearing> actualHearings = hearingRepository.findHearings(
jurisdictionTypeSet,
null,
caseUrnSet,
masterDefendantIdSet,
linkedCaseUrn,
caseUrnForLinkedCases,
now());

//then - both allocated and unallocated hearings are returned
assertThat(actualHearings.size(), is(2));
assertThat(extractFields(actualHearings, "$.id"), containsInAnyOrder(HEARING_ID.toString(), OTHER_HEARING_ID.toString()));
assertThat(extractFields(actualHearings, "$.allocated"), containsInAnyOrder(TRUE.toString(), FALSE.toString()));
}

@Test
public void shouldFindAllAvailableHearingsByLinkedCaseUrnRegardlessOfAllocation() {
//given - one allocated, one unallocated hearing, both with the same linked case URN
givenAvailableHearingsWithMixedAllocation();

final Set<String> caseUrnSet = new HashSet<>();
caseUrnSet.add(EMPTY_STRING);
final Set<String> masterDefendantIdSet = new HashSet<>();
masterDefendantIdSet.add(EMPTY_STRING);
final Set<String> jurisdictionTypeSet = new HashSet<>();
jurisdictionTypeSet.add(JurisdictionType.CROWN.name());
final Set<String> linkedCaseUrn = new HashSet<>();
linkedCaseUrn.add(LINKED_CASE_URN);

//when
final List<Hearing> actualHearings = hearingRepository.findHearings(
jurisdictionTypeSet,
null,
caseUrnSet,
masterDefendantIdSet,
linkedCaseUrn,
null,
now());

//then - both allocated and unallocated hearings are returned
assertThat(actualHearings.size(), is(2));
assertThat(extractFields(actualHearings, "$.id"), containsInAnyOrder(HEARING_ID.toString(), OTHER_HEARING_ID.toString()));
assertThat(extractFields(actualHearings, "$.allocated"), containsInAnyOrder(TRUE.toString(), FALSE.toString()));
assertThat(actualHearings.get(0).getProperties().toString(), hasJsonPath("$.listedCases[0].linkedCases[0].caseUrn", equalTo(LINKED_CASE_URN)));
}

@Test
public void shouldFindUnscheduledHearingsWithoutParameters() {
Expand Down Expand Up @@ -1804,6 +1927,70 @@ private List<Hearing> givenAvailableHearings() {
return hearingsToBeCreated;
}

private void givenAvailableHearingsWithMixedAllocation() {
hearingRepository.save(getHearingJson(hearingRepositoryContext()
.withHearingId(HEARING_ID)
.withCourtCentreId(COURT_CENTRE_ID)
.withCourtRoomId(COURT_ROOM_ID)
.withAllocated(TRUE)
.withVacated(NOT_VACATED)
.withAuthorityId(AUTHORITY_ID)
.withHearingType(HEARING_TYPE)
.withJurisdictionType(JURISDICTION_TYPE)
.withJudicialId(JUDICIAL_ID)
.withStartDate(START_DATE)
.withEndDate(END_DATE)
.withStartTime(START_TIME)
.withEndTime(END_TIME)
.withHearingDate(HEARING_DATE)
.withHearingDateDay1(DAY_1_HEARING_DATE)
.withStartTimeDay1(DAY_1_START_TIME)
.withEndTimeDay1(DAY_1_END_TIME)
.withCancelledDay1(false)
.withHearingDateDay2(DAY_2_HEARING_DATE)
.withStartTimeDay2(DAY_2_START_TIME)
.withEndTimeDay2(DAY_2_END_TIME)
.withCancelledDay2(false)
.withHearingDateDay3(DAY_3_HEARING_DATE)
.withStartTimeDay3(DAY_3_START_TIME)
.withEndTimeDay3(DAY_3_END_TIME)
.withCancelledDay3(false)
.withFileLocation(TEST_DATA_SAMPLE_MULTIDAY_HEARING_JSON)
.withMultidayHearing(true)
.build()));

hearingRepository.save(getHearingJson(hearingRepositoryContext()
.withHearingId(OTHER_HEARING_ID)
.withCourtCentreId(COURT_CENTRE_ID)
.withCourtRoomId(COURT_ROOM_ID)
.withAllocated(FALSE)
.withVacated(NOT_VACATED)
.withAuthorityId(AUTHORITY_ID)
.withHearingType(HEARING_TYPE)
.withJurisdictionType(JURISDICTION_TYPE)
.withJudicialId(JUDICIAL_ID)
.withStartDate(START_DATE)
.withEndDate(END_DATE)
.withStartTime(START_TIME)
.withEndTime(END_TIME)
.withHearingDate(HEARING_DATE)
.withHearingDateDay1(DAY_1_HEARING_DATE)
.withStartTimeDay1(DAY_1_START_TIME)
.withEndTimeDay1(DAY_1_END_TIME)
.withCancelledDay1(false)
.withHearingDateDay2(DAY_2_HEARING_DATE)
.withStartTimeDay2(DAY_2_START_TIME)
.withEndTimeDay2(DAY_2_END_TIME)
.withCancelledDay2(false)
.withHearingDateDay3(DAY_3_HEARING_DATE)
.withStartTimeDay3(DAY_3_START_TIME)
.withEndTimeDay3(DAY_3_END_TIME)
.withCancelledDay3(false)
.withFileLocation(TEST_DATA_SAMPLE_MULTIDAY_HEARING_JSON)
.withMultidayHearing(true)
.build()));
}

private List<Hearing> givenAvailableHearingsForCrownAndMags() {
final List<Hearing> hearingsToBeCreated = new ArrayList<>();
hearingsToBeCreated.add(getHearingJson(hearingRepositoryContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,9 @@ public abstract List<Hearing> findHearings(@QueryParam("allocated") final boolea
"and (h.end_date is null OR h.end_date >= :currentDate) " +
"and (:hearingId is null or h.id != cast(cast(:hearingId as varchar) as uuid)) " +
"AND " +
"(h.id in (select distinct h.id from hearing h " +
" inner join listed_cases lc on lc.hearing_id = h.id where UPPER(lc.case_reference) in (:caseUrnSet) " +
" and (:hearingId is null or h.id != cast(cast(:hearingId as varchar) as uuid))) " +
"(h.id in (select lc.hearing_id from listed_cases lc " +
" where UPPER(lc.case_reference) in (:caseUrnSet) " +
" and (:hearingId is null or lc.hearing_id != cast(cast(:hearingId as varchar) as uuid))) " +
"OR " +
"(h.id in (SELECT distinct(hrng.id) FROM hearing hrng inner join listed_cases lc3 on lc3.hearing_id = hrng.id " +
" WHERE lc3.case_reference IN (select lnkCase.case_urn as linkedCaseUrn from hearing h2 " +
Expand Down