Skip to content

Commit

Permalink
CIV-11205 Add new fields in GA to store court address and postcode (#…
Browse files Browse the repository at this point in the history
…3557)

* CIV-11205 populated full address for after sdo scenarios

* CIV-11205 update TriggerGenApp to  update address

* CIV-11205 Updated address during TriggerLocationUpdate Event

* CIV-11205 Unit tests covered for location update

* CIV-11205 updated templates with court full address

* CIV-11205 Code smell corrected
  • Loading branch information
deepthidoppalapudihmcts authored Nov 14, 2023
1 parent 31f1542 commit c3af666
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 10 deletions.
Binary file modified docker/docmosis/templates/CV-UNS-GAP-ENG-01067.docx
Binary file not shown.
Binary file modified docker/docmosis/templates/CV-UNS-GAP-ENG-01068.docx
Binary file not shown.
Binary file modified docker/docmosis/templates/CV-UNS-GAP-ENG-01069.docx
Binary file not shown.
Binary file modified docker/docmosis/templates/CV-UNS-GAP-ENG-01073.docx
Binary file not shown.
Binary file modified docker/docmosis/templates/CV-UNS-GAP-ENG-01075.docx
Binary file not shown.
Binary file modified docker/docmosis/templates/CV-UNS-GAP-ENG-01076.docx
Binary file not shown.
Binary file modified docker/docmosis/templates/CV-UNS-GAP-ENG-01078.docx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.List;
import java.util.Map;

import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRIGGER_LOCATION_UPDATE;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRIGGER_UPDATE_GA_LOCATION;
Expand Down Expand Up @@ -44,9 +45,10 @@ public List<CaseEvent> handledEvents() {

private CallbackResponse triggerGaEvent(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
String authToken = callbackParams.getParams().get(BEARER_TOKEN).toString();
try {
if (caseData.getGeneralApplications() != null && !caseData.getGeneralApplications().isEmpty()) {
caseData = helperService.updateApplicationLocationDetailsInClaim(caseData);
caseData = helperService.updateApplicationLocationDetailsInClaim(caseData, authToken);
helperService.triggerEvent(caseData, TRIGGER_LOCATION_UPDATE);
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public class CaseLocationCivil {
private String region;
private String siteName;
private String baseLocation;
private String address;
private String postcode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import uk.gov.hmcts.reform.civil.model.genapplication.GADetailsRespondentSol;
import uk.gov.hmcts.reform.civil.model.genapplication.GeneralApplication;
import uk.gov.hmcts.reform.civil.model.genapplication.GeneralApplicationsDetails;
import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -31,6 +32,7 @@ public class GenAppStateHelperService {

private final CoreCaseDataService coreCaseDataService;
private final CaseDetailsConverter caseDetailsConverter;
private final InitiateGeneralApplicationService genAppService;

private final ObjectMapper objectMapper;

Expand Down Expand Up @@ -69,16 +71,19 @@ public boolean triggerEvent(CaseData caseData, CaseEvent event) {
return true;
}

public CaseData updateApplicationLocationDetailsInClaim(CaseData caseData) {
public CaseData updateApplicationLocationDetailsInClaim(CaseData caseData, String authToken) {

if (!Collections.isEmpty(caseData.getGeneralApplications())) {
List<GeneralApplication> genApps = new ArrayList<>();
CaseData finalCaseData = caseData;
LocationRefData locationDetails = genAppService.getWorkAllocationLocationDetails(finalCaseData.getCaseManagementLocation().getBaseLocation(), authToken);
caseData.getGeneralApplications().forEach(generalApplicationElement -> {
GeneralApplication generalApplication = generalApplicationElement.getValue();
generalApplication.getCaseManagementLocation().setBaseLocation(finalCaseData.getCaseManagementLocation().getBaseLocation());
generalApplication.getCaseManagementLocation().setRegion(finalCaseData.getCaseManagementLocation().getRegion());
generalApplication.getCaseManagementLocation().setSiteName(finalCaseData.getLocationName());
generalApplication.getCaseManagementLocation().setSiteName(locationDetails.getSiteName());
generalApplication.getCaseManagementLocation().setAddress(locationDetails.getCourtAddress());
generalApplication.getCaseManagementLocation().setPostcode(locationDetails.getPostcode());
Map<String, Object> genAppMap = generalApplication.toMap(objectMapper);
genAppMap.put("isCcmccLocation", YesOrNo.NO);
generalApplication = objectMapper.convertValue(genAppMap, GeneralApplication.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ private GeneralApplication buildApplication(CaseData.CaseDataBuilder dataBuilder

Pair<CaseLocationCivil, Boolean> caseLocation = getWorkAllocationLocation(caseData, authToken);
//Setting Work Allocation location and location name
if (Objects.isNull(caseLocation.getLeft().getSiteName())
&& Objects.nonNull(caseLocation.getLeft().getBaseLocation())) {
LocationRefData locationDetails = getWorkAllocationLocationDetails(caseLocation.getLeft().getBaseLocation(), authToken);
caseLocation.getLeft().setSiteName(locationDetails.getSiteName());
caseLocation.getLeft().setAddress(locationDetails.getCourtAddress());
caseLocation.getLeft().setPostcode(locationDetails.getPostcode());
}
applicationBuilder.caseManagementLocation(caseLocation.getLeft());
applicationBuilder.isCcmccLocation(caseLocation.getRight() ? YES : NO);
applicationBuilder.locationName(hasSDOBeenMade(caseData.getCcdState())
Expand Down Expand Up @@ -343,6 +350,8 @@ public Pair<CaseLocationCivil, Boolean> getWorkAllocationLocation(CaseData caseD
.region(ccmccLocation.getRegionId())
.baseLocation(ccmccLocation.getEpimmsId())
.siteName(ccmccLocation.getSiteName())
.address(ccmccLocation.getCourtAddress())
.postcode(ccmccLocation.getPostcode())
.build();
return Pair.of(courtLocation, true);
}
Expand All @@ -369,6 +378,15 @@ private CaseLocationCivil getClaimant1PreferredLocation(CaseData caseData) {
.build();
}

public LocationRefData getWorkAllocationLocationDetails(String baseLocation, String authToken) {
List<LocationRefData> locationDetails = locationRefDataService.getCourtLocationsByEpimmsId(authToken, baseLocation);
if (locationDetails != null && !locationDetails.isEmpty()) {
return locationDetails.get(0);
} else {
return LocationRefData.builder().build();
}
}

private boolean isDefendant1RespondedFirst(CaseData caseData) {
return caseData.getRespondent2ResponseDate() == null
|| (caseData.getRespondent1ResponseDate() != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class TriggerGenAppLocationUpdateCallbackHandlerTest extends BaseCallbackHandler
@MockBean
private GenAppStateHelperService helperService;

private static final String authToken = "Bearer TestAuthToken";

@Test
void handleEventsReturnsTheExpectedCallbackEvent() {
assertThat(handler.handledEvents()).contains(TRIGGER_UPDATE_GA_LOCATION);
Expand All @@ -60,12 +62,12 @@ void shouldTriggerGeneralApplicationEvent_whenCaseHasGeneralApplication() {
true, true,
getOriginalStatusOfGeneralApplication()
);
when(helperService.updateApplicationLocationDetailsInClaim(caseData)).thenReturn(caseData);
when(helperService.updateApplicationLocationDetailsInClaim(any(), any())).thenReturn(caseData);
CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT);
var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);

assertThat(response.getErrors()).isNull();
verify(helperService, times(1)).updateApplicationLocationDetailsInClaim(caseData);
verify(helperService, times(1)).updateApplicationLocationDetailsInClaim(any(), any());
verify(helperService, times(1)).triggerEvent(caseData, TRIGGER_LOCATION_UPDATE);
verify(helperService, times(1)).triggerEvent(caseData, TRIGGER_LOCATION_UPDATE);
verifyNoMoreInteractions(helperService);
Expand Down Expand Up @@ -93,7 +95,7 @@ void triggerGeneralApplicationEventThrowsException_HandleFailure() {
);
String expectedErrorMessage = "Could not trigger event to update location on application under case: "
+ caseData.getCcdCaseReference();
when(helperService.updateApplicationLocationDetailsInClaim(caseData)).thenReturn(caseData);
when(helperService.updateApplicationLocationDetailsInClaim(any(), any())).thenReturn(caseData);
when(helperService.triggerEvent(any(CaseData.class), eq(TRIGGER_LOCATION_UPDATE)))
.thenThrow(new RuntimeException());
CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@
import uk.gov.hmcts.reform.civil.model.genapplication.CaseLocationCivil;
import uk.gov.hmcts.reform.civil.model.genapplication.GADetailsRespondentSol;
import uk.gov.hmcts.reform.civil.model.genapplication.GeneralApplicationsDetails;
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.GeneralApplicationDetailsBuilder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
Expand All @@ -50,13 +55,19 @@ class GenAppStateHelperServiceTest {

@MockBean
private CoreCaseDataService coreCaseDataService;
@MockBean
private InitiateGeneralApplicationService genAppService;

@Autowired
private CaseDetailsConverter caseDetailsConverter;

@MockBean
private LocationRefDataService locationRefDataService;

private static final String APPLICATION_CLOSED_TEXT = "Application Closed";
private static final String APPLICATION_OFFLINE_TEXT = "Proceeds In Heritage";
private static final String SET_DATE = "2022-08-31T22:50:11.2509019";
private static final String authToken = "Bearer TestAuthToken";

@Nested
class StatusChangeInApplicationDetailsInClaim {
Expand Down Expand Up @@ -393,6 +404,10 @@ private CaseDetails getCaseDetails(

@Test
void updateApplicationLocationDetailsLists() {
when(locationRefDataService.getCourtLocationsByEpimmsId(any(), any()))
.thenReturn(getSampleCourLocationsRefObject());
when(genAppService.getWorkAllocationLocationDetails(any(), any()))
.thenReturn(getSampleCourLocationsRefObject1());
CaseData caseData = GeneralApplicationDetailsBuilder.builder()
.getTestCaseDataWithDetails(CaseData.builder().build(),
true,
Expand All @@ -404,8 +419,10 @@ void updateApplicationLocationDetailsLists() {
Pair<CaseLocationCivil, Boolean> caseLocation = Pair.of(CaseLocationCivil.builder()
.region("2")
.baseLocation("00000").siteName("locationOfRegion2")
.address("Prince William House, Peel Cross Road, Salford")
.postcode("M5 4RR")
.build(), false);
CaseData updatedData = service.updateApplicationLocationDetailsInClaim(caseData);
CaseData updatedData = service.updateApplicationLocationDetailsInClaim(caseData, authToken);

assertThat(getGADetailsFromUpdatedCaseData(updatedData, "1234")).isNotNull();
assertThat(updatedData.getGeneralApplications().get(0).getValue().getCaseManagementLocation()).isEqualTo(caseLocation.getLeft());
Expand All @@ -416,6 +433,23 @@ void updateApplicationLocationDetailsLists() {
assertThat(updatedData.getGeneralApplications().get(2).getValue().getIsCcmccLocation()).isEqualTo(YesOrNo.NO);
}

protected List<LocationRefData> getSampleCourLocationsRefObject() {
return new ArrayList<>(List.of(
LocationRefData.builder()
.epimmsId("00000").siteName("locationOfRegion2").courtAddress("Prince William House, Peel Cross Road, Salford")
.postcode("M5 4RR")
.courtLocationCode("court1").build()
));
}

protected LocationRefData getSampleCourLocationsRefObject1() {
return
LocationRefData.builder()
.epimmsId("00000").siteName("locationOfRegion2").courtAddress("Prince William House, Peel Cross Road, Salford")
.postcode("M5 4RR")
.courtLocationCode("court1").build();
}

@Test
void noLocationUpdatesToCaseDataIfThereAreNoGeneralApplications() {
setupForApplicationOffline();
Expand All @@ -427,8 +461,7 @@ void noLocationUpdatesToCaseDataIfThereAreNoGeneralApplications() {
Map.of()
);

CaseData response = service.updateApplicationLocationDetailsInClaim(
caseData);
CaseData response = service.updateApplicationLocationDetailsInClaim(caseData, authToken);

CaseData updatedData = mapper.convertValue(response, CaseData.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,8 @@ void shouldPopulateApplicantDetails() {
CaseData caseData = GeneralApplicationDetailsBuilder.builder()
.getTestCaseDataForConsentUnconsentCheck(GARespondentOrderAgreement.builder().hasAgreed(NO).build());
when(locationRefDataService.getCcmccLocation(any()))
.thenReturn(LocationRefData.builder().regionId("9").epimmsId("574546").siteName("CCMCC").build());
.thenReturn(LocationRefData.builder().regionId("9").epimmsId("574546").siteName("CCMCC")
.courtAddress("Prince William House, Peel Cross Road, Salford").postcode("M5 4RR").build());
CaseData result = service.buildCaseData(caseData.toBuilder(), caseData, UserDetails.builder()
.email(APPLICANT_EMAIL_ID_CONSTANT).id(STRING_NUM_CONSTANT).build(), CallbackParams.builder().toString());

Expand All @@ -914,11 +915,98 @@ void shouldPopulateApplicantDetails() {

assertThat(result.getGeneralApplications().get(0).getValue().getLocationName())
.isEqualTo("CCMCC");
assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getAddress())
.isEqualTo("Prince William House, Peel Cross Road, Salford");
assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getPostcode())
.isEqualTo("M5 4RR");

assertThat(result.getGeneralApplications().get(0).getValue().getGeneralAppRespondentSolicitors()
.stream().filter(e -> STRING_NUM_CONSTANT.equals(e.getValue().getId())).count()).isEqualTo(0);
}

@Test
void shouldPopulateLocationDetailsForBaseLocation() {
when(locationRefDataService.getCourtLocationsByEpimmsId(any(), any())).thenReturn(getSampleCourLocationsRefObject());
CaseData caseData = GeneralApplicationDetailsBuilder.builder()
.getCaseDataForWorkAllocation(null, null, INDIVIDUAL, applicant1DQ, respondent1DQ,
respondent2DQ);
CaseData result = service.buildCaseData(caseData.toBuilder(), caseData, UserDetails.builder()
.email(APPLICANT_EMAIL_ID_CONSTANT).build(), CallbackParams.builder().toString());
assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getBaseLocation())
.isEqualTo("11111");
assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getSiteName())
.isEqualTo("locationOfRegion2");
assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getAddress())
.isEqualTo("Prince William House, Peel Cross Road, Salford");
assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getPostcode())
.isEqualTo("M5 4RR");
}

protected List<LocationRefData> getSampleCourLocationsRefObject() {
return new ArrayList<>(List.of(
LocationRefData.builder()
.epimmsId("11111").siteName("locationOfRegion2").courtAddress("Prince William House, Peel Cross Road, Salford")
.postcode("M5 4RR")
.courtLocationCode("court1").build()
));
}

protected List<LocationRefData> getEmptyCourLocationsRefObject() {
return new ArrayList<>(List.of(
LocationRefData.builder().build()
));
}

protected List<LocationRefData> getSampleCourtLocationsRefObjectMultipleValues() {
return new ArrayList<>(List.of(
LocationRefData.builder()
.epimmsId("11111").siteName("locationOfRegion2").courtAddress("Prince William House, Peel Cross Road, Salford")
.postcode("M5 4RR")
.courtLocationCode("court1").build(),

LocationRefData.builder()
.epimmsId("11111").siteName("locationOfRegion2").courtAddress("Prince William House, Peel Cross Road, Salford")
.postcode("M5 4RR")
.courtLocationCode("court1").build()
));
}

@Test
void shouldPopulateLocationDetailsForBaseLocationWhereListIsEmpty() {
when(locationRefDataService.getCourtLocationsByEpimmsId(any(), any())).thenReturn(getEmptyCourLocationsRefObject());
CaseData caseData = GeneralApplicationDetailsBuilder.builder()
.getCaseDataForWorkAllocation(null, null, INDIVIDUAL, applicant1DQ, respondent1DQ,
respondent2DQ);
CaseData result = service.buildCaseData(caseData.toBuilder(), caseData, UserDetails.builder()
.email(APPLICANT_EMAIL_ID_CONSTANT).build(), CallbackParams.builder().toString());
assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getBaseLocation())
.isEqualTo("11111");
assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getSiteName())
.isNull();
assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getAddress())
.isNull();
assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getPostcode())
.isNull();
}

@Test
void shouldPopulateLocationDetailsForBaseLocationWithMultipleListValues() {
when(locationRefDataService.getCourtLocationsByEpimmsId(any(), any())).thenReturn(getSampleCourtLocationsRefObjectMultipleValues());
CaseData caseData = GeneralApplicationDetailsBuilder.builder()
.getCaseDataForWorkAllocation(null, null, INDIVIDUAL, applicant1DQ, respondent1DQ,
respondent2DQ);
CaseData result = service.buildCaseData(caseData.toBuilder(), caseData, UserDetails.builder()
.email(APPLICANT_EMAIL_ID_CONSTANT).build(), CallbackParams.builder().toString());
assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getBaseLocation())
.isEqualTo("11111");
assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getSiteName())
.isEqualTo("locationOfRegion2");
assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getAddress())
.isEqualTo("Prince William House, Peel Cross Road, Salford");
assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getPostcode())
.isEqualTo("M5 4RR");
}

@Test
void shouldPopulateWorkAllocationLocationOnAboutToSubmit_beforeSDOHasBeenMade() {
when(locationRefDataService.getCcmccLocation(any()))
Expand Down

0 comments on commit c3af666

Please sign in to comment.