Skip to content
Merged
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 @@ -71,7 +71,6 @@ public class ListingCommandApi {
private static final String LISTING_COMMAND_LIST_UNSCHEDULED_NEXT_HEARINGS_ENRICHED = "listing.command.list-unscheduled-next-hearings-enriched";
private static final String LISTING_COMMAND_EXTEND_HEARING_FOR_HEARING_ENRICHED = "listing.command.extend-hearing-for-hearing-enriched";
private static final String LISTING_COMMAND_VACATE_TRIAL = "listing.command.vacate-trial-enriched";
private static final String LISTING_COMMAND_CORRECT_HEARING_DAYS_WO_CC = "listing.command.correct-hearing-days-without-court-centre";
private static final String LISTING_COMMAND_DUPLICATE_UNALLOCATED_HEARING = "listing.command.mark-unallocated-hearing-as-duplicate";
private static final String LISTING_COMMAND_UPDATE_EXISTING_HEARING = "listing.command.update-existing-hearing";
private static final String LISTING_COMMAND_DELETE_NEXT_HEARINGS = "listing.command.delete-next-hearings";
Expand Down Expand Up @@ -410,12 +409,6 @@ public void handleDeleteNote(final JsonEnvelope jsonEnvelope) {
jsonEnvelope.payloadAsJsonObject()));
}

@Handles("listing.correct-hearing-days-without-court-centre")
public void handleCorrectHearingDaysWithoutCourtCentre(final JsonEnvelope envelope) {
sender.send(envelopeFrom(metadataFrom(envelope.metadata()).withName(LISTING_COMMAND_CORRECT_HEARING_DAYS_WO_CC),
envelope.payload()));
}

@Handles("listing.update-hearing-day-court-schedule")
public void handleUpdateHearingDayCourtSchedule(JsonEnvelope envelope) {
sender.send(envelopeFrom(metadataFrom(envelope.metadata()).withName(LISTING_COMMAND_UPDATE_HEARING_DAY_COURT_SCHEDULE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,24 +279,6 @@ protocols: [ HTTP, HTTPS ]
description: Request accepted


/correct-hearing-days-without-court-centre:
post:
description: |
Update HearingDays without CourtCentre
...
(mapping):
requestType: application/vnd.listing.correct-hearing-days-without-court-centre+json
name: listing.correct-hearing-days-without-court-centre
...
body:
application/vnd.listing.correct-hearing-days-without-court-centre+json:
schema: !include json/schema/listing.correct-hearing-days-without-court-centre.json
example: !include json/listing.correct-hearing-days-without-court-centre.json

responses:
202:
description: Request accepted

/update-hearing-day-court-schedule:
post:
description: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,17 +897,6 @@ public void shouldEditNote() {

}

@Test
public void shouldHandleCorrectHearingDaysWithoutCourtCentre() {
final Metadata mockMetadata = MetadataBuilderFactory.metadataWithRandomUUIDAndName().build();
when(envelope.metadata()).thenReturn(mockMetadata);

listingCommandApi.handleCorrectHearingDaysWithoutCourtCentre(envelope);

verify(sender).send(envelopeArgumentCaptor.capture());
assertThat(envelopeArgumentCaptor.getValue().metadata().name(), is("listing.command.correct-hearing-days-without-court-centre"));
}

@Test
public void shouldHandleMarkUnallocatedHearingAsDuplicate() {
final Metadata mockMetadata = MetadataBuilderFactory.metadataWithRandomUUIDAndName().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1406,19 +1406,6 @@ public void cancelHearingDays(final Envelope<CancelHearingDays> envelope) throws
appendEventsToStream(envelope, eventStream, events);
}

@Handles("listing.command.correct-hearing-days-without-court-centre")
public void correctHearingDaysWithoutCourtCentre(final JsonEnvelope commandEnvelope) throws EventStreamException {
final JsonObject payload = commandEnvelope.payloadAsJsonObject();
final UUID hearingId = fromString(payload.getString("id"));

final List<uk.gov.justice.listing.events.HearingDay> hearingDays = new ArrayList<>();

payload.getJsonArray("hearingDays").getValuesAs(JsonObject.class).stream()
.forEach(hearingDay -> hearingDays.add(jsonObjectConverter.convert(hearingDay, uk.gov.justice.listing.events.HearingDay.class)));

updateHearingEventStream(commandEnvelope, hearingId, (Hearing hearing) -> hearing.raiseHearingDaysWithoutCourtCentreCorrected(hearingId, hearingDays));
}

@Handles("listing.command.update-hearing-day-court-schedule")
public void updateHearingDayCourtSchedule(final JsonEnvelope commandEnvelope) throws EventStreamException {
final JsonObject payload = commandEnvelope.payloadAsJsonObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,6 @@ baseUri: message://command/handler/message/listing
schema: !include json/schema/listing.command.handler.modify-hearing-counsel.json
example: !include json/listing.command.handler.modify-hearing-counsel.json

application/vnd.listing.command.correct-hearing-days-without-court-centre+json:
schema: !include json/schema/listing.command.correct-hearing-days-without-court-centre.json
example: !include json/listing.command.correct-hearing-days-without-court-centre.json

application/vnd.listing.command.update-hearing-day-court-schedule+json:
schema: !include json/schema/listing.command.update-hearing-day-court-schedule.json
example: !include json/listing.command.update-hearing-day-court-schedule.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3990,24 +3990,6 @@ public void shouldRequestPublicationOfACourtListForAllCrownCourtsWhenItsSaturday
MONDAY_3rd_DECEMBER_2018);
}

@Test
public void shouldHandleCorrectHearingDaysWithoutCourtCentreCommand() throws EventStreamException, IOException {
final String hearingId = randomUUID().toString();
final String hearingDaysUpdatedJson = "[{\"durationMinutes\":15,\"endTime\":\"2020-09-24T13:15:00.000Z\",\"hearingDate\":\"2020-09-24\",\"sequence\":0,\"startTime\":\"2020-09-24T13:00:00.000Z\",\"courtRoomId\":\"b4562684-9209-3ec4-a544-7f80dabd94d8\",\"courtCentreId\":\"f8254db1-1683-483e-afb3-b87fde5a0a26\"}]";

final JsonObject payloadToBeCorrected = createObjectBuilder()
.add("id", hearingId)
.add("hearingDays", objectMapper.readValue(hearingDaysUpdatedJson, JsonArray.class)).build();

final JsonEnvelope commandEnvelope = envelopeFrom(metadataWithRandomUUID("listing.command.correct-hearing-days-without-court-centre"), payloadToBeCorrected);
when(eventSource.getStreamById(any(UUID.class))).thenReturn(eventStream);

listingCommandHandler.correctHearingDaysWithoutCourtCentre(commandEnvelope);

verify(hearing).raiseHearingDaysWithoutCourtCentreCorrected(any(), any());

}

@Test
public void shouldHandleUpdateHearingDaysWithoutCourtSchedule() throws EventStreamException, IOException {
final String hearingId = randomUUID().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@ public CourtRoomMapping getCourtRoomMappingBy(final UUID courtCentreId, final UU
.orElse(new CourtRoomMapping(UNMAPPED_COURT_ROOM_NAME));
}

public Optional<String> getCourtRoomDisplayName(final UUID courtCentreId, final UUID courtRoomUUID) {
try {
return Optional.ofNullable(getCpCourtRoom(courtCentreId, courtRoomUUID).getString("courtroomName", null));
} catch (final Exception e) {
LOGGER.warn("Cannot find court room display name for courtCentreId={}, courtRoomUUID={}", courtCentreId, courtRoomUUID);
return Optional.empty();
}
}

public Optional<String> getWelshCourtRoomDisplayName(final UUID courtCentreId, final UUID courtRoomUUID) {
try {
return Optional.ofNullable(getCpCourtRoom(courtCentreId, courtRoomUUID).getString("welshCourtroomName", null));
} catch (final Exception e) {
LOGGER.warn("Cannot find Welsh court room display name for courtCentreId={}, courtRoomUUID={}", courtCentreId, courtRoomUUID);
return Optional.empty();
}
}

private UUID getOrganisationUnitIdByOuCode(final String ouCode) {
final OrganisationUnit organisationUnit = referenceDataCache.getOrganisationUnitMapCache(ouCode)
.orElseThrow(() -> new InvalidReferenceDataException(format("Cannot find organisation unit with code %s", ouCode)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,37 @@ public void shouldGetCourtRoom() {

}

@Test
void shouldGetCourtRoomDisplayName() {
final UUID courtCentreId = randomUUID();
final UUID courtRoomId = randomUUID();

final JsonObject cpCourtRoom = JsonObjects.createObjectBuilder()
.add("id", courtRoomId.toString())
.add("courtroomId", 1)
.add("courtroomName", "Court Room 1")
.add("welshCourtroomName", "Ystafell Llys 1")
.build();

when(referenceDataCache.getCpCourtRoomCache(courtCentreId)).thenReturn(asList(cpCourtRoom));

assertThat(commonXhibitReferenceDataService.getCourtRoomDisplayName(courtCentreId, courtRoomId), is(of("Court Room 1")));
assertThat(commonXhibitReferenceDataService.getWelshCourtRoomDisplayName(courtCentreId, courtRoomId), is(of("Ystafell Llys 1")));
}

@Test
void shouldReturnEmptyWhenCourtRoomDisplayNameNotFound() {
final UUID courtCentreId = randomUUID();
final UUID unknownRoomId = randomUUID();

when(referenceDataCache.getCpCourtRoomCache(courtCentreId)).thenReturn(asList(
JsonObjects.createObjectBuilder().add("id", randomUUID().toString()).add("courtroomId", 1).build()
));

assertThat(commonXhibitReferenceDataService.getCourtRoomDisplayName(courtCentreId, unknownRoomId), is(empty()));
assertThat(commonXhibitReferenceDataService.getWelshCourtRoomDisplayName(courtCentreId, unknownRoomId), is(empty()));
}


private CourtLocation createCourtLocation(final CourtMapping courtMapping) {

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static java.util.Objects.nonNull;
import static java.util.Optional.ofNullable;
import static java.util.UUID.randomUUID;
import static uk.gov.justice.services.messaging.JsonObjects.createArrayBuilder;
import static uk.gov.justice.services.messaging.JsonObjects.createObjectBuilder;
import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
import static uk.gov.justice.listing.events.PublicListingNewDefendantAddedForCourtProceedings.publicListingNewDefendantAddedForCourtProceedings;
Expand Down Expand Up @@ -100,7 +99,6 @@

import javax.inject.Inject;
import javax.json.JsonArray;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonValue;
Expand All @@ -115,7 +113,6 @@ public class ListingEventProcessor {
static final String PUBLIC_EVENT_HEARING_UPDATED = "public.listing.hearing-updated";
static final String PUBLIC_EVENT_VACATED_TRIAL_UPDATED = "public.listing.vacated-trial-updated";
static final String PUBLIC_EVENT_HEARING_CHANGES_SAVED = "public.listing.hearing-changes-saved";
static final String PUBLIC_EVENT_LISTING_EVENTS_HEARING_DAYS_WITHOUT_COURT_CENTRE_CORRECTED = "public.events.listing.hearing-days-without-court-centre-corrected";
static final String COMMAND_UPDATE_CASE_DEFENDANT_DETAILS = "listing.command.update-case-defendant-details"; //command back of public event
static final String COMMAND_UPDATE_CASE_DEFENDANT_OFFENCES = "listing.command.update-case-defendant-offences";
static final String COMMAND_ADD_DEFENDANTS_TO_COURT_PROCEEDINGS = "listing.command.add-defendants-to-court-proceedings";
Expand All @@ -126,7 +123,6 @@ public class ListingEventProcessor {
static final String COMMAND_APPLICATION_EJECTED = "listing.command.eject-application";
static final String COMMAND_UPDATE_HEARING_TO_CASE = "listing.command.update-hearing-to-case";
static final String PRIVATE_COMMAND_HEARING_VACATE_TRIAL = "listing.command.hearing-vacate-trial";
static final String COMMAND_UPDATE_HEARING_DAY_COURT_SCHEDULE = "listing.command.update-hearing-day-court-schedule";

private static final String COMMAND_PAYLOAD_DEBUG_STRING = "Sending '{}' command with payload {}";
private static final String EVENT_PAYLOAD_DEBUG_STRING = "Received '{}' event with payload {}";
Expand Down Expand Up @@ -171,7 +167,6 @@ public class ListingEventProcessor {
private static final String PRIVATE_EVENT_HEARING_RESCHEDULED = "listing.events.hearing-rescheduled";
private static final String PRIVATE_EVENT_HEARING_UNALLOCATED_FOR_LISTING = "listing.events.hearing-unallocated-for-listing";
private static final String LISTING_EVENTS_CASE_RESULTED_DEFENDANT_PROCEEDINGS_UPDATED = "listing.events.case-resulted-defendant-proceedings-updated";
private static final String LISTING_EVENTS_HEARING_DAYS_WITHOUT_COURT_CENTRE_CORRECTED = "listing.events.hearing-days-without-court-centre-corrected";
private static final String COMMAND_ADD_HEARING_TO_CASE = "listing.command.add-hearing-to-case";
private static final String COMMAND_ADD_COURT_APPLICATION_TO_HEARING = "listing.command.add-court-application-to-hearing";
private static final String COMMAND_UPDATE_DEFENDANTS_FOR_HEARING = "listing.command.update-defendants-for-hearing"; // command back of private event
Expand Down Expand Up @@ -218,9 +213,7 @@ public class ListingEventProcessor {
private static final String PRIVATE_EVENT_HEARING_MARKED_AS_DELETED = "listing.events.hearing-marked-as-deleted";
private static final String PRIVATE_EVENT_HEARING_MARKED_FOR_PARTIAL_UPDATE = "listing.events.hearing-marked-for-partial-update";
private static final String PRIVATE_EVENTS_HEARING_ADDED_TO_CASE = "listing.events.hearing-added-to-case";
static final String COMMAND_CHANGE_JUDICIARY_FOR_HEARINGS = "listing.command.change-judiciary-for-hearings";
public static final String PUBLIC_HEARING_OFFENCES_REMOVED_FROM_EXISTING_HEARING = "public.hearing.selected-offences-removed-from-existing-hearing";
private static final String COURT_CENTRE_ID_FIELD = "courtCentreId";
private static final String PRIVATE_LISTING_HEARING_DAYS_CHANGED_FOR_HEARING = "listing.events.hearing-days-changed-for-hearing";
private static final String PUBLIC_LISTING_HEARING_DAYS_CHANGED_FOR_HEARING = "public.listing.hearing-days-changed-for-hearing";

Expand Down Expand Up @@ -830,38 +823,13 @@ public void handleHearingUnallocatedForListing(final JsonEnvelope envelope) {
}
}

@Handles(LISTING_EVENTS_HEARING_DAYS_WITHOUT_COURT_CENTRE_CORRECTED)
public void hearingDaysWithoutCourtCentreCorrected(final JsonEnvelope envelope) {
final JsonObject publicEvent = Optional.of(envelope.payloadAsJsonObject())
.map(payload -> createObjectBuilder()
.add("id", payload.get("id"))
.add("hearingDays", getHearingDays(payload.getJsonArray("hearingDays")))
.build()).orElse(createObjectBuilder().build());
sender.send(envelopeFrom(metadataFrom(envelope.metadata()).withName(PUBLIC_EVENT_LISTING_EVENTS_HEARING_DAYS_WITHOUT_COURT_CENTRE_CORRECTED), publicEvent));
}

@Handles(PUBLIC_HEARING_OFFENCES_REMOVED_FROM_EXISTING_HEARING)
public void offencesRemovedFromExistingHearing(final JsonEnvelope envelope) {
sender.send(envelopeFrom(metadataFrom(envelope.metadata()).withName("listing.command.remove-selected-offences-from-existing-hearing"),
envelope.payloadAsJsonObject()));
}


private JsonArray getHearingDays(JsonArray hearingDays) {
final JsonArrayBuilder builder = createArrayBuilder();
hearingDays.stream()
.map(hearingDay -> (JsonObject) hearingDay)
.map(hearingDay -> createObjectBuilder().add(COURT_CENTRE_ID_FIELD, hearingDay.getString(COURT_CENTRE_ID_FIELD, null))
.add("courtRoomId", hearingDay.getString("courtRoomId", null))
.add("listedDurationMinutes", hearingDay.getInt("durationMinutes"))
.add("listingSequence", hearingDay.getInt("sequence"))
.add("sittingDay", hearingDay.getString("startTime"))
.build())
.forEach(builder::add);

return builder.build();
}

@Handles(PRIVATE_EVENT_HEARING_MARKED_AS_DELETED)
public void handleHearingMarkedAsDeleted(final JsonEnvelope envelope) {

Expand Down
Loading
Loading