Skip to content

Commit

Permalink
CIV-10561 Transfer case online (#3383)
Browse files Browse the repository at this point in the history
* CIV-10564 transfer online case handler changes

* CIV-10564 not suitable sdo handler changes

* CIV-10564 not suitable sdo handler changes

* CIV-10564 not suitable sdo handler changes

* CIV-10564 not suitable sdo handler changes

* CIV-10564 fix sonar issues

* CIV-10564 Handler changes

* CIV-10564 Object change to match CCD

* CIV-10564 Fix handler

* CIV-10564 Fix handler

* CIV-10564 Fix sonar issues

* CIV-10564 Add tests

* CIV-10564 Add tests

* CIV-10564 Fix checkstyle issue

* CIV-10564 Fix tests

* CIV-10564 Fix checkstyle issue

* CIV-10564 Fix sonar issue

* CIV-105661 Initial Commit

CIV-105661 Initial Commit

* CIV-10561 - Changes

CIV-10561 - Changes

* CIV-10561 added all callbacks

* CIV-10561 delete SDO changes

* CIV-10561 delete SDO changes

* CIV-10561 delete SDO changes

* CIV-10561 removed complex type and add summary

---------

Co-authored-by: hmcts-version1-ignacio <[email protected]>
Co-authored-by: Manish Garg <[email protected]>
Co-authored-by: hmcts-version1-ignacio <[email protected]>
Co-authored-by: ShwetaTandel-hmcts <[email protected]>
Co-authored-by: krishnanuthalapati <[email protected]>
Co-authored-by: Azam <[email protected]>
  • Loading branch information
7 people authored Oct 26, 2023
1 parent a443fdb commit f149d08
Show file tree
Hide file tree
Showing 7 changed files with 348 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public enum CaseEvent {
RECORD_JUDGMENT(USER),
SET_ASIDE_JUDGMENT(USER),
JUDGMENT_PAID_IN_FULL(USER),
TRANSFER_ONLINE_CASE(USER),
ASSIGN_CASE_TO_APPLICANT_SOLICITOR1(CAMUNDA),
ASSIGN_CASE_TO_APPLICANT1(CAMUNDA),
TRIGGER_APPLICATION_CLOSURE(CAMUNDA),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package uk.gov.hmcts.reform.civil.handler.callback.user;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse;
import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse;
import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse;
import uk.gov.hmcts.reform.civil.callback.Callback;
import uk.gov.hmcts.reform.civil.callback.CallbackHandler;
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.helpers.LocationHelper;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.common.DynamicList;
import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService;
import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData;
import uk.gov.hmcts.reform.civil.utils.CourtLocationUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static java.lang.String.format;
import static java.util.Objects.nonNull;
import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.MID;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRANSFER_ONLINE_CASE;
import static uk.gov.hmcts.reform.civil.model.common.DynamicList.fromList;

@Service
@RequiredArgsConstructor
public class TransferOnlineCaseCallbackHandler extends CallbackHandler {

private static final List<CaseEvent> EVENTS = Collections.singletonList(TRANSFER_ONLINE_CASE);
protected final ObjectMapper objectMapper;
private final LocationRefDataService locationRefDataService;
private final CourtLocationUtils courtLocationUtils;
private static final String ERROR_SELECT_DIFF_LOCATION = "Select a different hearing court location to transfer!";

@Override
protected Map<String, Callback> callbacks() {
return new ImmutableMap.Builder<String, Callback>()
.put(callbackKey(ABOUT_TO_START), this::locationList)
.put(callbackKey(MID, "validate-court-location"), this::validateCourtLocation)
.put(callbackKey(ABOUT_TO_SUBMIT), this::saveTransferOnlineCase)
.put(callbackKey(SUBMITTED), this::buildConfirmation)
.build();
}

private CallbackResponse validateCourtLocation(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder<?, ?> caseDataBuilder = caseData.toBuilder();
List<String> errors = new ArrayList<>();

if (ifSameCourtSelected(callbackParams)) {
errors.add(ERROR_SELECT_DIFF_LOCATION);
}
return AboutToStartOrSubmitCallbackResponse.builder()
.data(caseDataBuilder.build().toMap(objectMapper))
.errors(errors)
.build();
}

private CallbackResponse buildConfirmation(CallbackParams callbackParams) {
return SubmittedCallbackResponse.builder()
.confirmationHeader(getHeader())
.confirmationBody(getBody())
.build();
}

private CallbackResponse locationList(CallbackParams callbackParams) {
var caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder<?, ?> caseDataBuilder = caseData.toBuilder();
List<LocationRefData> locations = fetchLocationData(callbackParams);
caseDataBuilder.transferCourtLocationList(getLocationsFromList(locations));

return AboutToStartOrSubmitCallbackResponse.builder()
.data(caseDataBuilder.build().toMap(objectMapper))
.build();
}

private DynamicList getLocationsFromList(final List<LocationRefData> locations) {
return fromList(locations.stream().map(location -> new StringBuilder().append(location.getSiteName())
.append(" - ").append(location.getCourtAddress())
.append(" - ").append(location.getPostcode()).toString())
.collect(Collectors.toList()));
}

private String getHeader() {
return format("# Case transferred to new location");
}

private String getBody() {
return format("# Case transferred to new location");
}

private CallbackResponse saveTransferOnlineCase(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
CaseData.CaseDataBuilder<?, ?> caseDataBuilder = caseData.toBuilder();
LocationRefData newCourtLocation = courtLocationUtils.findPreferredLocationData(
fetchLocationData(callbackParams),
callbackParams.getCaseData().getTransferCourtLocationList());
if (nonNull(newCourtLocation)) {
caseDataBuilder.caseManagementLocation(LocationHelper.buildCaseLocation(newCourtLocation));
}
DynamicList tempLocationList = caseData.getTransferCourtLocationList();
tempLocationList.setListItems(null);
caseDataBuilder.transferCourtLocationList(tempLocationList);
return AboutToStartOrSubmitCallbackResponse.builder()
.data(caseDataBuilder.build().toMap(objectMapper))
.build();
}

private boolean ifSameCourtSelected(CallbackParams callbackParams) {
LocationRefData newCourtLocation = courtLocationUtils.findPreferredLocationData(
fetchLocationData(callbackParams),
callbackParams.getCaseData().getTransferCourtLocationList());
LocationRefData caseManagementLocation =
getLocationRefData(callbackParams);
if (caseManagementLocation != null && newCourtLocation.getCourtLocationCode().equals(caseManagementLocation.getCourtLocationCode())) {
return true;
}
return false;
}

private LocationRefData getLocationRefData(CallbackParams callbackParams) {
List<LocationRefData> locations = fetchLocationData(callbackParams);
var matchedLocations = locations.stream().filter(loc -> loc.getEpimmsId().equals(callbackParams.getCaseData().getCaseManagementLocation().getBaseLocation())).toList();
return matchedLocations.size() > 0 ? matchedLocations.get(0) : null;
}

private List<LocationRefData> fetchLocationData(CallbackParams callbackParams) {
String authToken = callbackParams.getParams().get(BEARER_TOKEN).toString();
return locationRefDataService.getCourtLocationsForDefaultJudgments(authToken);
}

@Override
public List<CaseEvent> handledEvents() {
return EVENTS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,8 @@ public boolean isApplicantNotRepresented() {
private String pcqId;

// TOC
private String reasonForTransfer;
private DynamicList transferCourtLocationList;
private NotSuitableSdoOptions notSuitableSdoOptions;
private TocTransferCaseReason tocTransferCaseReason;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.SET_ASIDE_JUDGMENT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.JUDGMENT_PAID_IN_FULL;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.RECORD_JUDGMENT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRANSFER_ONLINE_CASE;
import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.AWAITING_RESPONSES_FULL_DEFENCE_RECEIVED;
import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.AWAITING_RESPONSES_NOT_FULL_DEFENCE_RECEIVED;
import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.CLAIM_DETAILS_NOTIFIED;
Expand Down Expand Up @@ -277,7 +278,8 @@ public class FlowStateAllowedEventService {
EVIDENCE_UPLOAD_RESPONDENT,
GENERATE_DIRECTIONS_ORDER,
TRIAL_READINESS,
BUNDLE_CREATION_NOTIFICATION
BUNDLE_CREATION_NOTIFICATION,
TRANSFER_ONLINE_CASE
)
),

Expand Down Expand Up @@ -536,7 +538,8 @@ public class FlowStateAllowedEventService {
ADD_UNAVAILABLE_DATES,
SET_ASIDE_JUDGMENT,
JUDGMENT_PAID_IN_FULL,
RECORD_JUDGMENT
RECORD_JUDGMENT,
TRANSFER_ONLINE_CASE
)
),

Expand Down Expand Up @@ -1082,7 +1085,8 @@ public class FlowStateAllowedEventService {
SET_ASIDE_JUDGMENT,
JUDGMENT_PAID_IN_FULL,
RECORD_JUDGMENT,
LIP_CLAIM_SETTLED
LIP_CLAIM_SETTLED,
TRANSFER_ONLINE_CASE
)
),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package uk.gov.hmcts.reform.civil.handler.callback.user;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse;
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
import uk.gov.hmcts.reform.civil.callback.CaseEvent;
import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.common.DynamicList;
import uk.gov.hmcts.reform.civil.model.common.DynamicListElement;
import uk.gov.hmcts.reform.civil.model.defaultjudgment.CaseLocationCivil;
import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService;
import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData;
import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder;
import uk.gov.hmcts.reform.civil.sampledata.LocationRefSampleDataBuilder;
import uk.gov.hmcts.reform.civil.utils.CourtLocationUtils;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.MID;

@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = {
TransferOnlineCaseCallbackHandler.class,
JacksonAutoConfiguration.class})
class TransferOnlineCaseCallbackHandlerTest extends BaseCallbackHandlerTest {

@Autowired
private TransferOnlineCaseCallbackHandler handler;

@MockBean
protected LocationRefDataService locationRefDataService;
@MockBean
protected CourtLocationUtils courtLocationUtils;

@Nested
class AboutToStartCallback extends LocationRefSampleDataBuilder {

@BeforeEach
void setup() {
given(locationRefDataService.getCourtLocationsForDefaultJudgments(any()))
.willReturn(getSampleCourLocationsRefObject());
}

@Test
void shouldReturnLocationDataWhenAboutToStartCalled() {
CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed().build();
CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_START);
var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);
assertThat(response.getData())
.extracting("transferCourtLocationList")
.extracting("list_items")
.asList().hasSize(3);
}
}

@Nested
class MidCallback extends LocationRefSampleDataBuilder {

@BeforeEach
void setup() {
given(locationRefDataService.getCourtLocationsForDefaultJudgments(any()))
.willReturn(getSampleCourLocationsRefObject());
}

@Test
void shouldGiveErrorIfSameCourtLocationSelected() {

CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed()
.caseManagementLocation(CaseLocationCivil.builder()
.region("2")
.baseLocation("111")
.build())
.transferCourtLocationList(DynamicList.builder().value(DynamicListElement.builder()
.label("Site 1 - Adr 1 - AAA 111").build()).build()).build();
given(courtLocationUtils.findPreferredLocationData(any(), any()))
.willReturn(LocationRefData.builder().siteName("")
.epimmsId("111")
.siteName("Site 1").courtAddress("Adr 1").postcode("AAA 111")
.courtLocationCode("court1").build());

CallbackParams params = callbackParamsOf(caseData, MID, "validate-court-location");
//When: handler is called with MID event
var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);
assertThat(response.getErrors()).contains("Select a different hearing court location to transfer!");
}

@Test
void shouldNotGiveErrorIfDifferentCourtLocationSelected() {

CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed()
.caseManagementLocation(CaseLocationCivil.builder()
.region("2")
.baseLocation("111")
.build())
.transferCourtLocationList(DynamicList.builder().value(DynamicListElement.builder()
.label("Site 1 - Adr 1 - AAA 111").build()).build()).build();

given(courtLocationUtils.findPreferredLocationData(any(), any()))
.willReturn(LocationRefData.builder().siteName("")
.epimmsId("111")
.siteName("Site 1").courtAddress("Adr 1").postcode("AAA 111")
.courtLocationCode("other code").build());
CallbackParams params = callbackParamsOf(caseData, MID, "validate-court-location");
//When: handler is called with MID event
var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);
assertThat(response.getErrors()).isEmpty();
}
}

@Nested
class AboutToSubmitCallback {
@Test
void shouldPopulateCorrectCaseDataWhenSubmitted() {
CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed()
.caseManagementLocation(CaseLocationCivil.builder()
.region("2")
.baseLocation("111")
.build())
.reasonForTransfer("Reason")
.transferCourtLocationList(DynamicList.builder().value(DynamicListElement.builder()
.label("Site 1 - Adr 1 - AAA 111").build()).build()).build();
given(courtLocationUtils.findPreferredLocationData(any(), any()))
.willReturn(LocationRefData.builder().siteName("")
.epimmsId("222")
.siteName("Site 2").courtAddress("Adr 2").postcode("BBB 222")
.courtLocationCode("other code").build());
CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT);
var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);
assertThat(response.getData())
.extracting("reasonForTransfer")
.isEqualTo("Reason");
assertThat(response.getData())
.extracting("transferCourtLocationList")
.extracting("value")
.extracting("label")
.isEqualTo("Site 1 - Adr 1 - AAA 111");
assertThat(response.getData())
.extracting("transferCourtLocationList")
.extracting("list_items")
.isNull();
assertThat(response.getData())
.extracting("caseManagementLocation")
.extracting("baseLocation")
.isEqualTo("222");
}
}

@Nested
class SubmittedCallback {

}

@Test
void handleEventsReturnsTheExpectedCallbackEvent() {
assertThat(handler.handledEvents()).contains(CaseEvent.TRANSFER_ONLINE_CASE);
}
}
Loading

0 comments on commit f149d08

Please sign in to comment.