Skip to content

Commit

Permalink
Merge branch 'master' into DFPL-2325
Browse files Browse the repository at this point in the history
  • Loading branch information
AlistairEdwinOsborne authored Aug 28, 2024
2 parents 6980255 + dd4d8b2 commit 01c9fbe
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import uk.gov.hmcts.reform.aac.client.CaseAssignmentApi;
import uk.gov.hmcts.reform.aac.model.DecisionRequest;
import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse;
import uk.gov.hmcts.reform.ccd.model.CaseLocation;
import uk.gov.hmcts.reform.ccd.model.ChangeOrganisationRequest;
import uk.gov.hmcts.reform.ccd.model.OrganisationPolicy;
import uk.gov.hmcts.reform.fpl.controllers.AbstractCallbackTest;
Expand Down Expand Up @@ -49,7 +50,6 @@
import static uk.gov.hmcts.reform.ccd.model.ChangeOrganisationApprovalStatus.APPROVED;
import static uk.gov.hmcts.reform.ccd.model.OrganisationPolicy.organisationPolicy;
import static uk.gov.hmcts.reform.fpl.Constants.COURT_1;
import static uk.gov.hmcts.reform.fpl.Constants.COURT_2;
import static uk.gov.hmcts.reform.fpl.Constants.LOCAL_AUTHORITY_1_CODE;
import static uk.gov.hmcts.reform.fpl.Constants.LOCAL_AUTHORITY_1_ID;
import static uk.gov.hmcts.reform.fpl.Constants.LOCAL_AUTHORITY_1_NAME;
Expand Down Expand Up @@ -79,6 +79,10 @@
@OverrideAutoConfiguration(enabled = true)
class ManageLocalAuthoritiesControllerAboutToSubmitTest extends AbstractCallbackTest {

private static final Court WREXHAM = new Court("Wrexham", "", "384", "Wales", "637145", "7", null);
private static final Court WORCESTER = new Court("Worcester", "", "380", "Midlands", "102050", "2", null);
private static final Pair<String, String> WORCESTER_LIST_ENTRY = Pair.of(WORCESTER.getName(), WORCESTER.getCode());
private static final Pair<String, String> WREXHAM_LIST_ENTRY = Pair.of(WREXHAM.getName(), WREXHAM.getCode());
@Autowired
private Time time;

Expand Down Expand Up @@ -281,8 +285,7 @@ void init() {

@Test
void shouldTransferCaseToSecondaryLocalAuthorityAndCourt() {

when(dfjAreaLookUpService.getDfjArea(COURT_2.getCode()))
when(dfjAreaLookUpService.getDfjArea(WREXHAM.getCode()))
.thenReturn(dfjAreaCourtMapping);

final Colleague existingSocialWorker = Colleague.builder()
Expand All @@ -305,8 +308,8 @@ void shouldTransferCaseToSecondaryLocalAuthorityAndCourt() {
final LocalAuthoritiesEventData eventData = LocalAuthoritiesEventData.builder()
.localAuthorityAction(TRANSFER)
.courtsToTransfer(dynamicLists.from(1,
Pair.of(COURT_1.getName(), COURT_1.getCode()),
Pair.of(COURT_2.getName(), COURT_2.getCode())))
WORCESTER_LIST_ENTRY,
WREXHAM_LIST_ENTRY))
.localAuthorityToTransfer(newDesignatedLocalAuthority)
.localAuthorityToTransferSolicitor(newDesignatedLocalAuthoritySolicitor)
.build();
Expand All @@ -329,6 +332,7 @@ void shouldTransferCaseToSecondaryLocalAuthorityAndCourt() {
.localAuthorityPolicy(organisationPolicy(LOCAL_AUTHORITY_1_ID, LOCAL_AUTHORITY_1_NAME, LASOLICITOR))
.localAuthoritiesEventData(eventData)
.localAuthorities(wrapElements(designatedLocalAuthority, secondaryLocalAuthority))
.caseManagementLocation(new CaseLocation("1111", "1"))
.build();

final CaseData updatedCaseData = extractCaseData(postAboutToSubmitEvent(initialCaseData));
Expand All @@ -339,7 +343,8 @@ void shouldTransferCaseToSecondaryLocalAuthorityAndCourt() {
assertThat(updatedCaseData.getSharedLocalAuthorityPolicy()).isNull();
assertThat(updatedCaseData.getCaseLocalAuthority()).isEqualTo(LOCAL_AUTHORITY_2_CODE);
assertThat(updatedCaseData.getCaseLocalAuthorityName()).isEqualTo(newDesignatedLocalAuthority.getName());
assertThat(updatedCaseData.getCourt()).isEqualTo(COURT_2);
assertThat(updatedCaseData.getCourt()).extracting("code", "name")
.containsExactly(WREXHAM.getCode(), "Family Court sitting at Wrexham");
assertThat(updatedCaseData.getLocalAuthorities()).extracting(Element::getValue).containsExactly(
LocalAuthority.builder()
.id(newDesignatedLocalAuthority.getId())
Expand All @@ -359,6 +364,8 @@ void shouldTransferCaseToSecondaryLocalAuthorityAndCourt() {
.reference(existingSolicitor.getReference())
.build()))
.build());
assertThat(updatedCaseData.getCaseManagementLocation())
.isEqualTo(new CaseLocation(WREXHAM.getEpimmsId(), WREXHAM.getRegionId()));
}

@Test
Expand Down Expand Up @@ -415,14 +422,14 @@ class TransferToAnotherCourt {

@Test
void shouldTransferToOrdinaryCourt() {
when(dfjAreaLookUpService.getDfjArea("384"))
when(dfjAreaLookUpService.getDfjArea(WREXHAM.getCode()))
.thenReturn(dfjAreaCourtMapping);

final LocalAuthoritiesEventData eventData = LocalAuthoritiesEventData.builder()
.localAuthorityAction(TRANSFER_COURT)
.courtsToTransferWithoutTransferLA(dynamicLists.from(1,
Pair.of("Worcester", "380"),
Pair.of("Wrexham", "384")))
WORCESTER_LIST_ENTRY,
WREXHAM_LIST_ENTRY))
.build();

final CaseData initialCaseData = CaseData.builder()
Expand All @@ -436,7 +443,7 @@ void shouldTransferToOrdinaryCourt() {
final CaseData updatedCaseData = extractCaseData(resp);

Court currentCourt = updatedCaseData.getCourt();
assertThat(currentCourt.getCode()).isEqualTo("384");
assertThat(currentCourt.getCode()).isEqualTo(WREXHAM.getCode());
assertThat(currentCourt.getName()).isEqualTo("Family Court sitting at Wrexham");
assertThat(currentCourt.getDateTransferred()).isNotNull();
assertThat(updatedCaseData.getPastCourtList()).hasSize(1);
Expand All @@ -450,19 +457,19 @@ void shouldTransferToOrdinaryCourt() {
assertThat(updatedCaseData.getDfjArea()).isEqualTo(dfjAreaCourtMapping.getDfjArea());
assertThat(updatedCaseData.getCourtField()).isNull();
assertThat(resp.getData()).extracting("caseManagementLocation")
.extracting("baseLocation", "region").containsExactly("637145", "7");
.extracting("baseLocation", "region").containsExactly(WREXHAM.getEpimmsId(), WREXHAM.getRegionId());
}

@Test
void shouldTransferToOrdinaryCourtAgain() {
when(dfjAreaLookUpService.getDfjArea("384"))
when(dfjAreaLookUpService.getDfjArea(WREXHAM.getCode()))
.thenReturn(dfjAreaCourtMapping);

final LocalAuthoritiesEventData eventData = LocalAuthoritiesEventData.builder()
.localAuthorityAction(TRANSFER_COURT)
.courtsToTransferWithoutTransferLA(dynamicLists.from(1,
Pair.of("Worcester", "380"),
Pair.of("Wrexham", "384")))
WORCESTER_LIST_ENTRY,
WREXHAM_LIST_ENTRY))
.build();

final CaseData initialCaseData = CaseData.builder()
Expand All @@ -488,7 +495,7 @@ void shouldTransferToOrdinaryCourtAgain() {
final CaseData updatedCaseData = extractCaseData(postAboutToSubmitEvent(initialCaseData));

Court currentCourt = updatedCaseData.getCourt();
assertThat(currentCourt.getCode()).isEqualTo("384");
assertThat(currentCourt.getCode()).isEqualTo(WREXHAM.getCode());
assertThat(currentCourt.getName()).isEqualTo("Family Court sitting at Wrexham");
assertThat(currentCourt.getDateTransferred()).isNotNull();
assertThat(updatedCaseData.getPastCourtList()).hasSize(2);
Expand All @@ -510,7 +517,7 @@ void shouldTransferToRcjHighCourt() {
final LocalAuthoritiesEventData eventData = LocalAuthoritiesEventData.builder()
.localAuthorityAction(TRANSFER_COURT)
.courtsToTransferWithoutTransferLA(dynamicLists.from(1,
Pair.of("Worcester", "380"),
WORCESTER_LIST_ENTRY,
Pair.of(RCJ_HIGH_COURT_NAME, RCJ_HIGH_COURT_CODE)))
.build();

Expand Down Expand Up @@ -543,13 +550,13 @@ void shouldTransferToRcjHighCourt() {

@Test
void shouldTransferOutOfTheHighCourt() {
when(dfjAreaLookUpService.getDfjArea("380"))
when(dfjAreaLookUpService.getDfjArea(WORCESTER.getCode()))
.thenReturn(dfjAreaCourtMapping);

final LocalAuthoritiesEventData eventData = LocalAuthoritiesEventData.builder()
.localAuthorityAction(TRANSFER_COURT)
.courtsToTransferWithoutTransferLA(dynamicLists.from(0,
Pair.of("Worcester", "380"),
WORCESTER_LIST_ENTRY,
Pair.of(RCJ_HIGH_COURT_NAME, RCJ_HIGH_COURT_CODE)))
.build();

Expand All @@ -563,7 +570,7 @@ void shouldTransferOutOfTheHighCourt() {

final CaseData updatedCaseData = extractCaseData(postAboutToSubmitEvent(initialCaseData));

assertThat(updatedCaseData.getCourt().getCode()).isEqualTo("380");
assertThat(updatedCaseData.getCourt().getCode()).isEqualTo(WORCESTER.getCode());
assertThat(updatedCaseData.getCourt().getName()).isEqualTo("Family Court sitting at Worcester");
assertThat(updatedCaseData.getCourt().getDateTransferred()).isNotNull();
assertThat(updatedCaseData.getPastCourtList()).hasSize(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package uk.gov.hmcts.reform.ccd.model;

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

@Data
@Builder(toBuilder = true)
@AllArgsConstructor
public class CaseLocation {

private String baseLocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse;
import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest;
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails;
import uk.gov.hmcts.reform.ccd.model.CaseLocation;
import uk.gov.hmcts.reform.ccd.model.Organisation;
import uk.gov.hmcts.reform.fpl.enums.CaseRole;
import uk.gov.hmcts.reform.fpl.enums.LocalAuthorityAction;
Expand Down Expand Up @@ -183,7 +182,7 @@ public AboutToStartOrSubmitCallbackResponse handleAboutToSubmit(@RequestBody Cal
caseDetails.getData().put("caseLocalAuthorityName", caseData.getCaseLocalAuthorityName());
caseDetails.getData().put("localAuthorities", caseData.getLocalAuthorities());

updateDfjAreaCourtDetails(caseDetails, caseData.getCourt());
updateCourtDetails(caseDetails, caseData.getCourt());

removeTemporaryFields(caseDetails);

Expand All @@ -210,12 +209,6 @@ public AboutToStartOrSubmitCallbackResponse handleAboutToSubmit(@RequestBody Cal
caseDetails.getData().put(PAST_COURT_LIST_KEY, caseData.getPastCourtList());
caseDetails.getData().put(COURT_KEY, courtTransferred);

// Add the caseManagementLocation for global search/challenged access
caseDetails.getData().put("caseManagementLocation", CaseLocation.builder()
.baseLocation(courtTransferred.getEpimmsId())
.region(courtTransferred.getRegionId())
.build());

if (!isEmpty(courtTransferred) && RCJ_HIGH_COURT_CODE.equals(courtTransferred.getCode())) {
// transferred to the high court -> turn off sendToCtsc
caseDetails.getData().put("sendToCtsc", YesNo.NO.getValue());
Expand All @@ -224,7 +217,7 @@ public AboutToStartOrSubmitCallbackResponse handleAboutToSubmit(@RequestBody Cal
// we were in the high court, now we're not -> sendToCtsc again
caseDetails.getData().put("sendToCtsc", YesNo.YES.getValue());
}
updateDfjAreaCourtDetails(caseDetails, courtTransferred);
updateCourtDetails(caseDetails, courtTransferred);
}


Expand Down Expand Up @@ -255,10 +248,13 @@ public AboutToStartOrSubmitCallbackResponse handleTransferCourtWithoutTransferLA
return respond(caseDetails, errors);
}

private void updateDfjAreaCourtDetails(CaseDetails caseDetails, Court court) {
private void updateCourtDetails(CaseDetails caseDetails, Court court) {
DfjAreaCourtMapping dfjArea = dfjAreaLookUpService.getDfjArea(court.getCode());
caseDetails.getData().keySet().removeAll(dfjAreaLookUpService.getAllCourtFields());
caseDetails.getData().put("dfjArea", dfjArea.getDfjArea());
caseDetails.getData().put(dfjArea.getCourtField(), court.getCode());

service.getCaseManagementLocation(court)
.ifPresent(caseLocation -> caseDetails.getData().put("caseManagementLocation", caseLocation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.ccd.model.CaseLocation;
import uk.gov.hmcts.reform.ccd.model.ChangeOrganisationRequest;
import uk.gov.hmcts.reform.ccd.model.Organisation;
import uk.gov.hmcts.reform.ccd.model.OrganisationPolicy;
Expand Down Expand Up @@ -63,6 +64,7 @@
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ManageLocalAuthoritiesService {

public static final String FAMILY_COURT_SITTING_AT = "Family Court sitting at ";
private final Time time;
private final CourtService courtService;
private final ValidateEmailService emailService;
Expand Down Expand Up @@ -352,10 +354,8 @@ public Court transferCourtWithoutTransferLA(CaseData caseData) {
.map(DynamicList::getValueCode)
.flatMap(courtLookUpService::getCourtByCode);
if (chosenCourt.isPresent()) {
boolean isHighCourt = chosenCourt.get().getCode().equals(RCJ_HIGH_COURT_CODE);
Court newCourt = chosenCourt.get().toBuilder()
Court newCourt = adjustCourtName(chosenCourt.get()).toBuilder()
.dateTransferred(time.now())
.name((isHighCourt ? "" : "Family Court sitting at ") + chosenCourt.get().getName())
.build();
caseData.setPastCourtList(buildPastCourtsList(caseData));
caseData.setCourt(newCourt);
Expand Down Expand Up @@ -421,7 +421,8 @@ public Organisation transfer(CaseData caseData) {

ofNullable(eventData.getCourtsToTransfer())
.map(DynamicList::getValueCode)
.flatMap(courtLookup::getCourtByCode)
.flatMap(courtLookUpService::getCourtByCode)
.map(this::adjustCourtName)
.ifPresent(caseData::setCourt);

caseData.setCaseLocalAuthority(localAuthorityIds.getLocalAuthorityCode(newDesignatedLocalAuthority.getId())
Expand Down Expand Up @@ -488,4 +489,27 @@ private String getLocalAuthorityToTransferCode(CaseData caseData) {
return eventData.getLocalAuthoritiesToTransfer().getValueCode();
}

public Optional<CaseLocation> getCaseManagementLocation(Court court) {
String courtCode = court.getCode();
Optional<Court> lookedUpCourt = courtLookUpService.getCourtByCode(courtCode);

return lookedUpCourt.map(c -> CaseLocation.builder()
.baseLocation(c.getEpimmsId())
.region(c.getRegionId())
.build());
}

private Court adjustCourtName(Court court) {
boolean isHighCourt = court.getCode().equals(RCJ_HIGH_COURT_CODE);
boolean hasFamilyCourt = court.getName().contains("Family Court sitting at");

if (isHighCourt || hasFamilyCourt) {
return court;
} else {
return court.toBuilder()
.name(FAMILY_COURT_SITTING_AT + court.getName())
.build();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ class Transfer {
void init() {
when(courtLookup.getCourtByCode("C1")).thenReturn(Optional.of(oldCourt));
when(courtLookup.getCourtByCode("C2")).thenReturn(Optional.of(newCourt));
when(courtLookUpService.getCourtByCode("C1")).thenReturn(Optional.of(oldCourt));
when(courtLookUpService.getCourtByCode("C2")).thenReturn(Optional.of(newCourt));
when(localAuthorityIds.getLocalAuthorityCode(newDesignatedLocalAuthorityOrgId))
.thenReturn(Optional.of(newDesignatedLocalAuthorityCode));
}
Expand Down Expand Up @@ -636,7 +638,8 @@ void shouldTransferCaseToSecondaryLocalAuthorityWithCourtChange() {
.containsExactly(expectedLocalAuthority);
assertThat(caseData.getCaseLocalAuthority()).isEqualTo(newDesignatedLocalAuthorityCode);
assertThat(caseData.getCaseLocalAuthorityName()).isEqualTo(newDesignatedLocalAuthorityName);
assertThat(caseData.getCourt()).isEqualTo(newCourt);
assertThat(caseData.getCourt()).extracting("name", "code")
.containsExactly("Family Court sitting at Court 2", "C2");
}

@Test
Expand Down Expand Up @@ -857,7 +860,8 @@ void shouldTransferCaseToNewLocalAuthorityWithCourtChange() {
.containsExactly(expectedLocalAuthority);
assertThat(caseData.getCaseLocalAuthority()).isEqualTo(newDesignatedLocalAuthorityCode);
assertThat(caseData.getCaseLocalAuthorityName()).isEqualTo(newDesignatedLocalAuthorityName);
assertThat(caseData.getCourt()).isEqualTo(newCourt);
assertThat(caseData.getCourt()).extracting("name", "code")
.containsExactly("Family Court sitting at Court 2", "C2");
}

@Test
Expand Down Expand Up @@ -914,7 +918,8 @@ void shouldTransferCaseToNonSecondaryLocalAuthorityWithCourtChange() {
.containsExactly(expectedLocalAuthority, sharedLocalAuthority);
assertThat(caseData.getCaseLocalAuthority()).isEqualTo(newDesignatedLocalAuthorityCode);
assertThat(caseData.getCaseLocalAuthorityName()).isEqualTo(newDesignatedLocalAuthorityName);
assertThat(caseData.getCourt()).isEqualTo(newCourt);
assertThat(caseData.getCourt()).extracting("name", "code")
.containsExactly("Family Court sitting at Court 2", "C2");
}
}

Expand Down

0 comments on commit 01c9fbe

Please sign in to comment.