-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CIV-10561 Transfer case online (#3383)
* 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
1 parent
a443fdb
commit f149d08
Showing
7 changed files
with
348 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
...va/uk/gov/hmcts/reform/civil/handler/callback/user/TransferOnlineCaseCallbackHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
...k/gov/hmcts/reform/civil/handler/callback/user/TransferOnlineCaseCallbackHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.