Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package uk.gov.hmcts.reform.prl.services;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails;
import uk.gov.hmcts.reform.prl.models.complextypes.PartyDetails;
import uk.gov.hmcts.reform.prl.models.dto.ccd.CaseData;
import uk.gov.hmcts.reform.prl.utils.CaseUtils;

import static org.apache.commons.lang3.ObjectUtils.isNotEmpty;
import static uk.gov.hmcts.reform.prl.constants.PrlAppsConstants.C100_CASE_TYPE;
import static uk.gov.hmcts.reform.prl.constants.PrlAppsConstants.FL401_CASE_TYPE;
import static uk.gov.hmcts.reform.prl.utils.ElementUtils.nullSafeList;

@Service
@RequiredArgsConstructor
public class PartyRepresentationService {

private final ObjectMapper objectMapper;

public boolean areNoPartiesRepresented(CaseDetails caseDetail) {
CaseData caseData = CaseUtils.getCaseData(caseDetail, objectMapper);
return areNoPartiesRepresented(caseData);
}

public boolean areNoPartiesRepresented(CaseData caseData) {
if (C100_CASE_TYPE.equalsIgnoreCase(caseData.getCaseTypeOfApplication())) {
return nullSafeList(caseData.getApplicants()).stream().noneMatch(
el -> hasLegalRepresentation(el.getValue()))
&& nullSafeList(caseData.getRespondents()).stream().noneMatch(
el -> hasLegalRepresentation(el.getValue()));
} else if (FL401_CASE_TYPE.equalsIgnoreCase(caseData.getCaseTypeOfApplication())) {
return !hasLegalRepresentation(caseData.getApplicantsFL401())
&& !hasLegalRepresentation(caseData.getRespondentsFL401());
} else {
throw new IllegalArgumentException("Case has no case type");
}
}

public boolean areAnyPartiesRepresented(CaseData caseData) {
return !areNoPartiesRepresented(caseData);
}

private boolean hasLegalRepresentation(PartyDetails partyDetails) {
if (isNotEmpty(partyDetails)) {
return (isNotEmpty(partyDetails.getSolicitorOrg())
&& isNotEmpty(partyDetails.getSolicitorOrg().getOrganisationID()))
|| isNotEmpty(partyDetails.getRepresentativeFirstName())
|| isNotEmpty(partyDetails.getRepresentativeLastName())
|| isNotEmpty(partyDetails.getSolicitorEmail())
|| isNotEmpty(partyDetails.getSolicitorTelephone());
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import uk.gov.hmcts.reform.prl.clients.ccd.records.StartAllTabsUpdateDataContent;
import uk.gov.hmcts.reform.prl.enums.CaseEvent;
import uk.gov.hmcts.reform.prl.enums.State;
import uk.gov.hmcts.reform.prl.models.complextypes.PartyDetails;
import uk.gov.hmcts.reform.prl.models.dto.ccd.CaseData;
import uk.gov.hmcts.reform.prl.models.dto.ccd.request.Bool;
import uk.gov.hmcts.reform.prl.models.dto.ccd.request.Filter;
import uk.gov.hmcts.reform.prl.models.dto.ccd.request.LastModified;
Expand All @@ -27,7 +25,6 @@
import uk.gov.hmcts.reform.prl.models.dto.ccd.request.StateFilter;
import uk.gov.hmcts.reform.prl.services.hearings.HearingService;
import uk.gov.hmcts.reform.prl.services.tab.alltabs.AllTabServiceImpl;
import uk.gov.hmcts.reform.prl.utils.CaseUtils;

import java.time.LocalDate;
import java.util.ArrayList;
Expand All @@ -36,10 +33,7 @@
import java.util.List;

import static org.apache.commons.lang3.ObjectUtils.isNotEmpty;
import static uk.gov.hmcts.reform.prl.constants.PrlAppsConstants.C100_CASE_TYPE;
import static uk.gov.hmcts.reform.prl.constants.PrlAppsConstants.CASE_TYPE;
import static uk.gov.hmcts.reform.prl.constants.PrlAppsConstants.FL401_CASE_TYPE;
import static uk.gov.hmcts.reform.prl.utils.ElementUtils.nullSafeList;

@Slf4j
@Service
Expand All @@ -52,7 +46,7 @@ public class PrepareHearingBundleService {
private final AllTabServiceImpl allTabService;
private final EsQueryService esQueryService;
private final HearingService hearingService;
private final ObjectMapper objectMapper;
private final PartyRepresentationService partyRepresentationService;

@Value("${prepare-hearing-bundle.calendar-days-before-hearing:7}")
private int calendarDaysBeforeHearing;
Expand Down Expand Up @@ -85,7 +79,7 @@ public void searchForHearingsIn5DaysAndCreateTasks() {
private List<CaseDetails> filterCasesWithNoRepresentation(List<CaseDetails> caseDetails) {
List<CaseDetails> filteredCases = new ArrayList<>();
caseDetails.stream().forEach(caseDetail -> {
if (areNoPartiesRepresented(caseDetail)) {
if (partyRepresentationService.areNoPartiesRepresented(caseDetail)) {
filteredCases.add(caseDetail);
} else {
log.info("Case {} has representation, skipping creation of 'Prepare Hearing Bundle' task",
Expand All @@ -95,32 +89,6 @@ private List<CaseDetails> filterCasesWithNoRepresentation(List<CaseDetails> case
return filteredCases;
}

private boolean areNoPartiesRepresented(CaseDetails caseDetail) {
CaseData caseData = CaseUtils.getCaseData(caseDetail, objectMapper);
if (C100_CASE_TYPE.equalsIgnoreCase(caseData.getCaseTypeOfApplication())) {
return nullSafeList(caseData.getApplicants()).stream().noneMatch(
el -> hasLegalRepresentation(el.getValue()))
&& nullSafeList(caseData.getRespondents()).stream().noneMatch(
el -> hasLegalRepresentation(el.getValue()));
} else if (FL401_CASE_TYPE.equalsIgnoreCase(caseData.getCaseTypeOfApplication())) {
return !hasLegalRepresentation(caseData.getApplicantsFL401()) && !hasLegalRepresentation(caseData.getRespondentsFL401());
} else {
throw new IllegalArgumentException("Case " + caseDetail.getId() + " has no case type");
}
}

private boolean hasLegalRepresentation(PartyDetails partyDetails) {
if (isNotEmpty(partyDetails)) {
return (isNotEmpty(partyDetails.getSolicitorOrg())
&& isNotEmpty(partyDetails.getSolicitorOrg().getOrganisationID()))
|| isNotEmpty(partyDetails.getRepresentativeFirstName())
|| isNotEmpty(partyDetails.getRepresentativeLastName())
|| isNotEmpty(partyDetails.getSolicitorEmail())
|| isNotEmpty(partyDetails.getSolicitorTelephone());
}
return false;
}

private void createPrepareBundleWaTask(List<CaseDetails> cases) {
cases.forEach(caseDetails ->
triggerSystemEventForWorkAllocationTask(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class UpdateHearingActualsService {
private final AllTabServiceImpl allTabService;

private final ObjectMapper objectMapper;
private final PartyRepresentationService partyRepresentationService;

@Value("${ccd.elastic-search-api.result-size}")
private String ccdElasticSearchApiResultSize;
Expand Down Expand Up @@ -95,8 +96,9 @@ private void createUpdateHearingActualWaTask(List<CaseDetails> caseDetailsList,
CaseData caseData = CaseUtils.getCaseData(caseDetails, objectMapper);
log.info("Hearing id {}", hearingId);
triggerSystemEventForWorkAllocationTask(caseId, CaseEvent.ENABLE_UPDATE_HEARING_ACTUAL_TASK.getValue(), new HashMap<>());
if (!checkIfHearingIdIsMappedInOrders(caseData, hearingId)) {
log.info("Hearing id is not mapped in orders");
if (!checkIfHearingIdIsMappedInOrders(caseData, hearingId)
&& partyRepresentationService.areAnyPartiesRepresented(caseData)) {
log.info("Hearing id is not mapped in orders and case has represented parties");
triggerSystemEventForWorkAllocationTask(caseId, CaseEvent.ENABLE_REQUEST_SOLICITOR_ORDER_TASK.getValue(), new HashMap<>());
}
}
Expand Down Expand Up @@ -207,8 +209,13 @@ private QueryParam buildCcdQueryParam() {
private List<String> fetchFieldsRequiredForHearingActualTask() {
return List.of(
"data.nextHearingDate",
"data.caseTypeOfApplication",
"data.draftOrderCollection",
"data.orderCollection"
"data.orderCollection",
"data.applicants",
"data.respondents",
"data.applicantsFL401",
"data.respondentsFL401"
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
package uk.gov.hmcts.reform.prl.services;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails;
import uk.gov.hmcts.reform.prl.models.Element;
import uk.gov.hmcts.reform.prl.models.Organisation;
import uk.gov.hmcts.reform.prl.models.complextypes.PartyDetails;
import uk.gov.hmcts.reform.prl.models.dto.ccd.CaseData;

import java.util.List;
import java.util.UUID;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import static uk.gov.hmcts.reform.prl.constants.PrlAppsConstants.C100_CASE_TYPE;
import static uk.gov.hmcts.reform.prl.constants.PrlAppsConstants.FL401_CASE_TYPE;

@RunWith(MockitoJUnitRunner.class)
public class PartyRepresentationServiceTest {

@Mock
private ObjectMapper objectMapper;

@InjectMocks
private PartyRepresentationService partyRepresentationService;

@Test
public void areAnyPartiesRepresentedShouldReturnTrueForC100WhenApplicantHasSolicitorOrg() {
CaseData caseData = CaseData.builder()
.caseTypeOfApplication(C100_CASE_TYPE)
.applicants(List.of(element(PartyDetails.builder()
.solicitorOrg(Organisation.builder().organisationID("ORG123").build())
.build())))
.respondents(List.of(element(PartyDetails.builder().build())))
.build();

assertTrue(partyRepresentationService.areAnyPartiesRepresented(caseData));
}

@Test
public void areAnyPartiesRepresentedShouldReturnTrueForC100WhenApplicantHasRepresentativeFirstName() {
CaseData caseData = CaseData.builder()
.caseTypeOfApplication(C100_CASE_TYPE)
.applicants(List.of(element(PartyDetails.builder()
.representativeFirstName("John")
.build())))
.respondents(List.of(element(PartyDetails.builder().build())))
.build();

assertTrue(partyRepresentationService.areAnyPartiesRepresented(caseData));
}

@Test
public void areAnyPartiesRepresentedShouldReturnTrueForC100WhenApplicantHasRepresentativeLastName() {
CaseData caseData = CaseData.builder()
.caseTypeOfApplication(C100_CASE_TYPE)
.applicants(List.of(element(PartyDetails.builder()
.representativeLastName("Smith")
.build())))
.respondents(List.of(element(PartyDetails.builder().build())))
.build();

assertTrue(partyRepresentationService.areAnyPartiesRepresented(caseData));
}

@Test
public void areAnyPartiesRepresentedShouldReturnTrueForC100WhenApplicantHasSolicitorEmail() {
CaseData caseData = CaseData.builder()
.caseTypeOfApplication(C100_CASE_TYPE)
.applicants(List.of(element(PartyDetails.builder()
.solicitorEmail("solicitor@example.com")
.build())))
.respondents(List.of(element(PartyDetails.builder().build())))
.build();

assertTrue(partyRepresentationService.areAnyPartiesRepresented(caseData));
}

@Test
public void areAnyPartiesRepresentedShouldReturnTrueForC100WhenApplicantHasSolicitorTelephone() {
CaseData caseData = CaseData.builder()
.caseTypeOfApplication(C100_CASE_TYPE)
.applicants(List.of(element(PartyDetails.builder()
.solicitorTelephone("01234567890")
.build())))
.respondents(List.of(element(PartyDetails.builder().build())))
.build();

assertTrue(partyRepresentationService.areAnyPartiesRepresented(caseData));
}

@Test
public void areAnyPartiesRepresentedShouldReturnFalseForC100WhenNoPartiesRepresented() {
CaseData caseData = CaseData.builder()
.caseTypeOfApplication(C100_CASE_TYPE)
.applicants(List.of(element(PartyDetails.builder().build())))
.respondents(List.of(element(PartyDetails.builder().build())))
.build();

assertFalse(partyRepresentationService.areAnyPartiesRepresented(caseData));
}

@Test
public void areAnyPartiesRepresentedShouldReturnFalseForC100WhenSolicitorOrgHasNoId() {
CaseData caseData = CaseData.builder()
.caseTypeOfApplication(C100_CASE_TYPE)
.applicants(List.of(element(PartyDetails.builder()
.solicitorOrg(Organisation.builder().build())
.build())))
.respondents(List.of(element(PartyDetails.builder().build())))
.build();

assertFalse(partyRepresentationService.areAnyPartiesRepresented(caseData));
}

@Test
public void areAnyPartiesRepresentedShouldReturnTrueForC100WhenRespondentRepresented() {
CaseData caseData = CaseData.builder()
.caseTypeOfApplication(C100_CASE_TYPE)
.applicants(List.of(element(PartyDetails.builder().build())))
.respondents(List.of(element(PartyDetails.builder()
.representativeFirstName("Jane")
.build())))
.build();

assertTrue(partyRepresentationService.areAnyPartiesRepresented(caseData));
}

@Test
public void areAnyPartiesRepresentedShouldReturnFalseForC100WithNullLists() {
CaseData caseData = CaseData.builder()
.caseTypeOfApplication(C100_CASE_TYPE)
.build();

assertFalse(partyRepresentationService.areAnyPartiesRepresented(caseData));
}

@Test
public void areAnyPartiesRepresentedShouldReturnTrueForFL401WhenApplicantRepresented() {
CaseData caseData = CaseData.builder()
.caseTypeOfApplication(FL401_CASE_TYPE)
.applicantsFL401(PartyDetails.builder()
.solicitorOrg(Organisation.builder().organisationID("ORG1").build())
.build())
.respondentsFL401(PartyDetails.builder().build())
.build();

assertTrue(partyRepresentationService.areAnyPartiesRepresented(caseData));
}

@Test
public void areAnyPartiesRepresentedShouldReturnTrueForFL401WhenRespondentRepresented() {
CaseData caseData = CaseData.builder()
.caseTypeOfApplication(FL401_CASE_TYPE)
.applicantsFL401(PartyDetails.builder().build())
.respondentsFL401(PartyDetails.builder()
.solicitorEmail("resp-solicitor@example.com")
.build())
.build();

assertTrue(partyRepresentationService.areAnyPartiesRepresented(caseData));
}

@Test
public void areAnyPartiesRepresentedShouldReturnFalseForFL401WhenNoPartiesRepresented() {
CaseData caseData = CaseData.builder()
.caseTypeOfApplication(FL401_CASE_TYPE)
.applicantsFL401(PartyDetails.builder().build())
.respondentsFL401(PartyDetails.builder().build())
.build();

assertFalse(partyRepresentationService.areAnyPartiesRepresented(caseData));
}

@Test(expected = IllegalArgumentException.class)
public void areAnyPartiesRepresentedShouldThrowWhenNoCaseType() {
CaseData caseData = CaseData.builder().build();

partyRepresentationService.areAnyPartiesRepresented(caseData);
}

@Test
public void areNoPartiesRepresentedWithCaseDetailsShouldReturnTrue() {
CaseDetails caseDetails = CaseDetails.builder().id(1234567890L).build();
CaseData caseData = CaseData.builder()
.caseTypeOfApplication(C100_CASE_TYPE)
.applicants(List.of(element(PartyDetails.builder().build())))
.respondents(List.of(element(PartyDetails.builder().build())))
.build();

when(objectMapper.convertValue(caseDetails.getData(), CaseData.class))
.thenReturn(caseData);

assertTrue(partyRepresentationService.areNoPartiesRepresented(caseDetails));
}

@Test
public void areNoPartiesRepresentedWithCaseDetailsShouldReturnFalse() {
CaseDetails caseDetails = CaseDetails.builder().id(1234567890L).build();
CaseData caseData = CaseData.builder()
.caseTypeOfApplication(C100_CASE_TYPE)
.applicants(List.of(element(PartyDetails.builder()
.solicitorEmail("solicitor@example.com")
.build())))
.respondents(List.of(element(PartyDetails.builder().build())))
.build();

when(objectMapper.convertValue(caseDetails.getData(), CaseData.class))
.thenReturn(caseData);

assertFalse(partyRepresentationService.areNoPartiesRepresented(caseDetails));
}

private static Element<PartyDetails> element(PartyDetails partyDetails) {
return Element.<PartyDetails>builder()
.id(UUID.randomUUID())
.value(partyDetails)
.build();
}
}
Loading