Skip to content

Commit

Permalink
Merge branch 'master' into DIAC-577
Browse files Browse the repository at this point in the history
  • Loading branch information
alivenichoppa authored Dec 9, 2024
2 parents 598c5da + 788bbf7 commit bd97590
Show file tree
Hide file tree
Showing 21 changed files with 871 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"description": "Upload hearing recording confirmation",
"request": {
"uri": "/bail/ccdSubmitted",
"credentials": "AdminOfficer",
"input": {
"id": 1111,
"eventId": "uploadHearingRecording",
"state": "decisionDecided",
"caseData": {
"template": "minimal-application-submitted.json"
}
}
},
"expectation": {
"status": 200,
"errors": [],
"confirmation": {
"header": "# You’ve uploaded the hearing recording",
"body": "#### What happens next\nThis file is now available in the Documents tab and the Hearing and appointment tab."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,18 @@ public enum BailCaseFieldDefinition {
LIST_CASE_HEARING_DATE(
"listingHearingDate", new TypeReference<String>(){}),

LISTING_HEARING_DURATION(
"listingHearingDuration", new TypeReference<String>(){}),

LISTING_LOCATION(
"listingLocation", new TypeReference<ListingHearingCentre>(){}),

PREVIOUS_LISTING_DETAILS(
"previousListingDetails", new TypeReference<List<IdValue<PreviousListingDetails>>>() {}),
HAS_BEEN_RELISTED(
"hasBeenRelisted", new TypeReference<YesOrNo>() {}),
PREVIOUS_DECISION_DETAILS(
"previousDecisionDetails", new TypeReference<List<IdValue<PreviousDecisionDetails>>>() {}),
HO_HAS_IMA_STATUS(
"hoHasImaStatus", new TypeReference<YesOrNo>(){}),
ADMIN_HAS_IMA_STATUS(
Expand All @@ -654,7 +663,10 @@ public enum BailCaseFieldDefinition {
IS_BAILS_LOCATION_REFERENCE_DATA_ENABLED_FT(
"isBailsLocationReferenceDataEnabledFt", new TypeReference<YesOrNo>() {}),
HAS_CASE_BEEN_FORCED_TO_HEARING(
"hasCaseBeenForcedToHearing", new TypeReference<YesOrNo>() {});
"hasCaseBeenForcedToHearing", new TypeReference<YesOrNo>() {}),

HEARING_RECORDING_DOCUMENTS(
"hearingRecordingDocuments", new TypeReference<List<IdValue<HearingRecordingDocument>>>(){});

private final String value;
private final TypeReference typeReference;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package uk.gov.hmcts.reform.bailcaseapi.domain.entities;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Value;
import lombok.extern.jackson.Jacksonized;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.field.Document;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.field.HasDocument;

@Value
@Builder
@Jacksonized
@AllArgsConstructor
public class HearingRecordingDocument implements HasDocument {
Document document;
String description;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public enum Event {
UPLOAD_SIGNED_DECISION_NOTICE("uploadSignedDecisionNotice"),
VIEW_PREVIOUS_APPLICATIONS("viewPreviousApplications"),
TEST_TIMED_EVENT_SCHEDULE("testTimedEventSchedule"),
UPLOAD_HEARING_RECORDING("uploadHearingRecording"),

@JsonEnumDefaultValue
UNKNOWN("unknown");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.field;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PreviousDecisionDetails {

private String decisionDetailsDate;
private String recordDecisionType;
private Document uploadSignedDecisionNoticeDocument;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.field;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ListingEvent;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ListingHearingCentre;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PreviousListingDetails {

private ListingEvent listingEvent;
private ListingHearingCentre listingLocation;
private String listingHearingDate;
private String listingHearingDuration;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package uk.gov.hmcts.reform.bailcaseapi.domain.handlers.postsubmit;

import static java.util.Objects.requireNonNull;

import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.BailCase;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.Event;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.callback.Callback;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.callback.PostSubmitCallbackResponse;
import uk.gov.hmcts.reform.bailcaseapi.domain.handlers.PostSubmitCallbackHandler;

@Component
public class UploadHearingRecordingConfirmation implements PostSubmitCallbackHandler<BailCase> {

public boolean canHandle(
Callback<BailCase> callback
) {
requireNonNull(callback, "callback must not be null");

return callback.getEvent() == Event.UPLOAD_HEARING_RECORDING;
}

public PostSubmitCallbackResponse handle(
Callback<BailCase> callback
) {
if (!canHandle(callback)) {
throw new IllegalStateException("Cannot handle callback");
}

PostSubmitCallbackResponse postSubmitResponse =
new PostSubmitCallbackResponse();

postSubmitResponse.setConfirmationHeader(
"""
# You’ve uploaded the hearing recording""");
postSubmitResponse.setConfirmationBody("""
#### What happens next
This file is now available in the Documents tab and the Hearing and appointment tab.""");

return postSubmitResponse;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
package uk.gov.hmcts.reform.bailcaseapi.domain.handlers.presubmit;

import static java.time.format.DateTimeFormatter.ISO_DATE_TIME;
import static java.util.Collections.emptyList;
import static java.util.Objects.requireNonNull;
import static uk.gov.hmcts.reform.bailcaseapi.domain.entities.BailCaseFieldDefinition.DATE_OF_COMPLIANCE;
import static uk.gov.hmcts.reform.bailcaseapi.domain.entities.BailCaseFieldDefinition.IS_BAILS_LOCATION_REFERENCE_DATA_ENABLED;
import static uk.gov.hmcts.reform.bailcaseapi.domain.entities.BailCaseFieldDefinition.LISTING_EVENT;
import static uk.gov.hmcts.reform.bailcaseapi.domain.entities.BailCaseFieldDefinition.LISTING_LOCATION;
import static uk.gov.hmcts.reform.bailcaseapi.domain.entities.BailCaseFieldDefinition.LIST_CASE_HEARING_DATE;
import static uk.gov.hmcts.reform.bailcaseapi.domain.entities.BailCaseFieldDefinition.REF_DATA_LISTING_LOCATION;
import static uk.gov.hmcts.reform.bailcaseapi.domain.entities.BailCaseFieldDefinition.REF_DATA_LISTING_LOCATION_DETAIL;
import static uk.gov.hmcts.reform.bailcaseapi.domain.entities.BailCaseFieldDefinition.SEND_DIRECTION_DESCRIPTION;
import static uk.gov.hmcts.reform.bailcaseapi.domain.entities.BailCaseFieldDefinition.SEND_DIRECTION_LIST;
import static uk.gov.hmcts.reform.bailcaseapi.domain.entities.BailCaseFieldDefinition.UPLOAD_BAIL_SUMMARY_ACTION_AVAILABLE;
import static uk.gov.hmcts.reform.bailcaseapi.domain.entities.BailCaseFieldDefinition.*;
import static uk.gov.hmcts.reform.bailcaseapi.domain.entities.ListingEvent.INITIAL_LISTING;
import static uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.field.YesOrNo.NO;
import static uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.field.YesOrNo.YES;
Expand All @@ -20,34 +12,41 @@
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import com.microsoft.applicationinsights.boot.dependencies.apachecommons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.bailcaseapi.domain.RequiredFieldMissingException;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.BailCase;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.DynamicList;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ListingEvent;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ListingHearingCentre;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.Value;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.*;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.CaseDetails;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.Event;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.callback.Callback;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.callback.PreSubmitCallbackResponse;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.field.IdValue;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.field.PreviousListingDetails;
import uk.gov.hmcts.reform.bailcaseapi.domain.entities.ccd.field.YesOrNo;
import uk.gov.hmcts.reform.bailcaseapi.domain.handlers.PreSubmitCallbackHandler;
import uk.gov.hmcts.reform.bailcaseapi.domain.service.Appender;
import uk.gov.hmcts.reform.bailcaseapi.domain.service.DueDateService;
import uk.gov.hmcts.reform.bailcaseapi.domain.service.LocationRefDataService;
import uk.gov.hmcts.reform.bailcaseapi.infrastructure.clients.model.refdata.CourtVenue;

@Component
public class CaseListingHandler implements PreSubmitCallbackHandler<BailCase> {

private final Appender<PreviousListingDetails> previousListingDetailsAppender;
private final DueDateService dueDateService;
private final LocationRefDataService locationRefDataService;

public CaseListingHandler(DueDateService dueDateService, LocationRefDataService locationRefDataService) {
public CaseListingHandler(
Appender<PreviousListingDetails> previousListingDetailsAppender,
DueDateService dueDateService,
LocationRefDataService locationRefDataService
) {
this.dueDateService = dueDateService;
this.previousListingDetailsAppender = previousListingDetailsAppender;
this.locationRefDataService = locationRefDataService;
}

Expand All @@ -62,22 +61,17 @@ public boolean canHandle(
&& callback.getEvent() == Event.CASE_LISTING;
}

@Override
public PreSubmitCallbackResponse<BailCase> handle(
PreSubmitCallbackStage callbackStage,
Callback<BailCase> callback
) {
if (!canHandle(callbackStage, callback)) {
throw new IllegalStateException("Cannot handle callback");
}

final BailCase bailCase =
callback
.getCaseDetails()
.getCaseData();

BailCase bailCase = callback.getCaseDetails().getCaseData();
ListingEvent listingEvent = bailCase.read(LISTING_EVENT, ListingEvent.class)
.orElseThrow(() -> new RequiredFieldMissingException("listingEvent is not present"));

if (listingEvent == INITIAL_LISTING) {
String hearingDate = bailCase.read(LIST_CASE_HEARING_DATE, String.class)
.orElseThrow(() -> new RequiredFieldMissingException("listingHearingDate is not present"));
Expand Down Expand Up @@ -111,7 +105,41 @@ public PreSubmitCallbackResponse<BailCase> handle(

bailCase.write(SEND_DIRECTION_LIST, "Home Office");
bailCase.write(DATE_OF_COMPLIANCE, dueDate);
bailCase.write(UPLOAD_BAIL_SUMMARY_ACTION_AVAILABLE, YesOrNo.YES);
bailCase.write(UPLOAD_BAIL_SUMMARY_ACTION_AVAILABLE, YES);
} else {
CaseDetails<BailCase> caseDetailsBefore = callback.getCaseDetailsBefore().orElse(null);
BailCase bailCaseBefore = caseDetailsBefore == null ? null : caseDetailsBefore.getCaseData();
if (bailCaseBefore != null) {
ListingEvent prevListingEvent = bailCaseBefore.read(LISTING_EVENT, ListingEvent.class)
.orElse(null);
ListingHearingCentre prevListingLocation = bailCaseBefore.read(LISTING_LOCATION,
ListingHearingCentre.class)
.orElse(null);
String prevListingHearingDate = bailCaseBefore.read(LIST_CASE_HEARING_DATE, String.class)
.orElse(null);
String prevListingHearingDuration = bailCaseBefore.read(LISTING_HEARING_DURATION, String.class)
.orElse(null);

if (prevListingEvent == null || prevListingLocation == null || prevListingHearingDate == null || prevListingHearingDuration == null) {
PreSubmitCallbackResponse<BailCase> response = new PreSubmitCallbackResponse<>(bailCase);
response.addError("Relisting is only available after an initial listing.");
return response;
}

Optional<List<IdValue<PreviousListingDetails>>> maybeExistingPreviousListingDetails =
bailCase.read(PREVIOUS_LISTING_DETAILS);
final PreviousListingDetails newPreviousListingDetails =
new PreviousListingDetails(prevListingEvent,
prevListingLocation,
prevListingHearingDate,
prevListingHearingDuration);
List<IdValue<PreviousListingDetails>> allPreviousListingDetails =
previousListingDetailsAppender.append(newPreviousListingDetails,
maybeExistingPreviousListingDetails.orElse(emptyList()));

bailCase.write(PREVIOUS_LISTING_DETAILS, allPreviousListingDetails);
bailCase.write(HAS_BEEN_RELISTED, YES);
}
}

updateListingLocValueByUsingRefDataLocValue(bailCase);
Expand All @@ -125,7 +153,7 @@ private void updateListingLocValueByUsingRefDataLocValue(BailCase bailCase) {

if (isBailsLocationRefDataEnabled == YES) {
Value selectedRefDataLocation = bailCase.read(REF_DATA_LISTING_LOCATION, DynamicList.class)
.map(dynamicList -> dynamicList.getValue()).orElse(null);
.map(DynamicList::getValue).orElse(null);

if (selectedRefDataLocation != null) {
saveRefDataListingLocationDetail(bailCase, selectedRefDataLocation.getCode());
Expand All @@ -147,9 +175,7 @@ private void updateListingLocValueByUsingRefDataLocValue(BailCase bailCase) {
private void saveRefDataListingLocationDetail(BailCase bailCase, String epimmsId) {
if (!StringUtils.isEmpty(epimmsId)) {
Optional<CourtVenue> courtVenue = locationRefDataService.getCourtVenuesByEpimmsId(epimmsId);
if (courtVenue.isPresent()) {
bailCase.write(REF_DATA_LISTING_LOCATION_DETAIL, courtVenue.get());
}
courtVenue.ifPresent(venue -> bailCase.write(REF_DATA_LISTING_LOCATION_DETAIL, venue));
}
}
}
Loading

0 comments on commit bd97590

Please sign in to comment.