Skip to content
Open
6 changes: 3 additions & 3 deletions src/main/java/uk/gov/hmcts/reform/pcs/ccd/PCSCaseView.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import uk.gov.hmcts.reform.pcs.ccd.repository.PcsCaseRepository;
import uk.gov.hmcts.reform.pcs.ccd.service.CaseTitleService;
import uk.gov.hmcts.reform.pcs.ccd.service.DraftCaseDataService;
import uk.gov.hmcts.reform.pcs.ccd.service.globalsearch.CaseNameHmctsFormatter;
import uk.gov.hmcts.reform.pcs.ccd.util.ListValueUtils;
import uk.gov.hmcts.reform.pcs.ccd.view.AlternativesToPossessionView;
import uk.gov.hmcts.reform.pcs.ccd.view.AsbProhibitedConductView;
Expand All @@ -34,6 +33,7 @@
import uk.gov.hmcts.reform.pcs.ccd.view.RentDetailsView;
import uk.gov.hmcts.reform.pcs.ccd.view.StatementOfTruthView;
import uk.gov.hmcts.reform.pcs.ccd.view.TenancyLicenceView;
import uk.gov.hmcts.reform.pcs.ccd.view.globalsearch.CaseFieldsView;
import uk.gov.hmcts.reform.pcs.exception.CaseNotFoundException;
import uk.gov.hmcts.reform.pcs.security.SecurityContextService;

Expand Down Expand Up @@ -68,7 +68,7 @@ public class PCSCaseView implements CaseView<PCSCase, State> {
private final RentArrearsView rentArrearsView;
private final NoticeOfPossessionView noticeOfPossessionView;
private final StatementOfTruthView statementOfTruthView;
private final CaseNameHmctsFormatter caseNameHmctsFormatter;
private final CaseFieldsView caseFieldsView;


/**
Expand All @@ -83,7 +83,7 @@ public PCSCase getCase(CaseViewRequest<State> request) {

boolean hasUnsubmittedCaseData = caseHasUnsubmittedData(caseReference, state);

caseNameHmctsFormatter.setCaseNameHmctsField(pcsCase);
caseFieldsView.setCaseFields(pcsCase);

setMarkdownFields(pcsCase, hasUnsubmittedCaseData);

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/PCSCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ public class PCSCase {
)
private Integer caseManagementLocation;

@CCD(
label = "Region Id"
)
private Integer regionId;

@CCD(label = "Party")
private List<ListValue<Party>> parties;

Expand Down Expand Up @@ -521,4 +526,10 @@ public class PCSCase {
)
private String caseNamePublic;

@CCD(
label = "CaseManagementLocation",
access = {GlobalSearchAccess.class}
)
private String caseManagementLocationFormatted;

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.gov.hmcts.reform.pcs.ccd.service.globalsearch;
package uk.gov.hmcts.reform.pcs.ccd.view.globalsearch;

import uk.gov.hmcts.ccd.sdk.type.ListValue;
import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase;
Expand All @@ -7,20 +7,28 @@

import java.util.List;

import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Component;

@Service
@AllArgsConstructor
public class CaseNameHmctsFormatter {
@Component
public class CaseFieldsView {


/**
* Sets case fields for the pcsCase.
* @param pcsCase The current case data
*/
public void setCaseFields(final PCSCase pcsCase) {
setCaseNameHmctsField(pcsCase);
setCaseManagementLocationField(pcsCase);
}

/**
* Builds a formatted string for the case name hmcts field based on
* certain rules and set's the internal, restricted and public field accordingly.
* Builds a formatted string for the case name hmcts field based on certain rules and sets the internal, restricted
* and public field accordingly.
*
* @param pcsCase The current case data
*/
public void setCaseNameHmctsField(final PCSCase pcsCase) {
private void setCaseNameHmctsField(final PCSCase pcsCase) {

final List<ListValue<Party>> defendants = pcsCase.getAllDefendants();
final List<ListValue<Party>> claimants = pcsCase.getAllClaimants();
Expand All @@ -33,27 +41,35 @@ public void setCaseNameHmctsField(final PCSCase pcsCase) {
pcsCase.setCaseNamePublic(formattedCaseName);
}

/**
* Builds a formatted string for the case management location field based on epimsId and regionId.
*
* @param pcsCase The current case data
*/
private void setCaseManagementLocationField(final PCSCase pcsCase) {
Integer epimsId = pcsCase.getCaseManagementLocation();
Integer region = pcsCase.getRegionId();

if (epimsId != null && region != null) {
pcsCase.setCaseManagementLocationFormatted(getFormattedValue(region, epimsId));
}
}

private String getFormattedClaimantName(final List<ListValue<Party>> claimants) {
StringBuilder formattedClaimantName = new StringBuilder();
String formattedClaimantName = null;
if (claimants != null && !claimants.isEmpty()) {
formattedClaimantName.append(claimants.stream()
.findFirst()
.map(claimant ->
claimant.getValue().getOrgName() != null
? claimant.getValue().getOrgName() :
claimant.getValue().getLastName())
.orElse(null));
var claimant = claimants.getFirst().getValue();
formattedClaimantName = claimant.getOrgName() != null
? claimant.getOrgName() :
claimant.getLastName();
}
return formattedClaimantName.toString();
return formattedClaimantName;
}

private String getFormattedDefendantName(final List<ListValue<Party>> defendants) {
StringBuilder formattedDefendantName = new StringBuilder();
if (defendants != null && !defendants.isEmpty() && isDefendantNameKnown(defendants)) {
formattedDefendantName.append(defendants.stream()
.findFirst()
.map(defendant -> defendant.getValue().getLastName())
.orElse(null));
formattedDefendantName.append(defendants.getFirst().getValue().getLastName());
if (defendants.size() > 1) {
formattedDefendantName.append(" and Others");
}
Expand All @@ -66,4 +82,8 @@ private String getFormattedDefendantName(final List<ListValue<Party>> defendants
private boolean isDefendantNameKnown(final List<ListValue<Party>> defendants) {
return defendants.getFirst().getValue().getNameKnown() == VerticalYesNo.YES;
}

private String getFormattedValue(int region, int epimsId) {
return "{region:%s,baseLocation:%s}".formatted(region, epimsId);
}
}
12 changes: 6 additions & 6 deletions src/test/java/uk/gov/hmcts/reform/pcs/ccd/PCSCaseViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import uk.gov.hmcts.reform.pcs.ccd.repository.PcsCaseRepository;
import uk.gov.hmcts.reform.pcs.ccd.service.CaseTitleService;
import uk.gov.hmcts.reform.pcs.ccd.service.DraftCaseDataService;
import uk.gov.hmcts.reform.pcs.ccd.service.globalsearch.CaseNameHmctsFormatter;
import uk.gov.hmcts.reform.pcs.ccd.view.AlternativesToPossessionView;
import uk.gov.hmcts.reform.pcs.ccd.view.AsbProhibitedConductView;
import uk.gov.hmcts.reform.pcs.ccd.view.ClaimGroundsView;
Expand All @@ -35,6 +34,7 @@
import uk.gov.hmcts.reform.pcs.ccd.view.RentDetailsView;
import uk.gov.hmcts.reform.pcs.ccd.view.StatementOfTruthView;
import uk.gov.hmcts.reform.pcs.ccd.view.TenancyLicenceView;
import uk.gov.hmcts.reform.pcs.ccd.view.globalsearch.CaseFieldsView;
import uk.gov.hmcts.reform.pcs.exception.CaseNotFoundException;
import uk.gov.hmcts.reform.pcs.postcodecourt.model.LegislativeCountry;
import uk.gov.hmcts.reform.pcs.security.SecurityContextService;
Expand Down Expand Up @@ -95,7 +95,7 @@ class PCSCaseViewTest {
@Mock
private ClaimEntity claimEntity;
@Mock
private CaseNameHmctsFormatter caseNameHmctsFormatter;
private CaseFieldsView caseFieldsView;

private PCSCaseView underTest;

Expand All @@ -108,7 +108,7 @@ void setUp() {
caseTitleService, claimView, tenancyLicenceView, claimGroundsView, rentDetailsView,
alternativesToPossessionView, housingActWalesView, asbProhibitedConductView,
rentArrearsView, noticeOfPossessionView,
statementOfTruthView, caseNameHmctsFormatter
statementOfTruthView, caseFieldsView
);
}

Expand Down Expand Up @@ -335,14 +335,14 @@ void shouldSetCaseFieldsInViewHelpers() {
}

@Test
void shouldSetCaseNameHmctsField() {
void shouldSetCaseFields() {
// When
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Given here

doNothing().when(caseNameHmctsFormatter).setCaseNameHmctsField(any(PCSCase.class));
doNothing().when(caseFieldsView).setCaseFields(any(PCSCase.class));

PCSCase pcsCase = underTest.getCase(request(CASE_REFERENCE, DEFAULT_STATE));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// When here


// Then
verify(caseNameHmctsFormatter).setCaseNameHmctsField(pcsCase);
verify(caseFieldsView).setCaseFields(pcsCase);
}

private AddressUK stubAddressEntityModelMapper(AddressEntity addressEntity) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package uk.gov.hmcts.reform.pcs.ccd.service.globalsearch;
package uk.gov.hmcts.reform.pcs.ccd.view.globalsearch;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo.NO;
Expand All @@ -14,19 +16,21 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class CaseNameHmctsFormatterTest {
class CaseFieldsViewTest {

private static final String CLAIMANT_NAME = "Freeman";
private static final String DEFENDANT_LAST_NAME = "Jackson";
private static final String CLAIMANT_ORGANISATION_NAME = "Treetops Housing";

@Mock
private PCSCase pcsCase;
private CaseNameHmctsFormatter underTest;
private CaseFieldsView underTest;

@Mock
private ListValue<Party> defendantPartyListValue;
Expand All @@ -42,12 +46,13 @@ class CaseNameHmctsFormatterTest {

@BeforeEach
void setUp() {
underTest = new CaseNameHmctsFormatter();
underTest = new CaseFieldsView();
}


@Test
void shouldSetCaseNameWhenClaimantIsOrgAndDefendantIsKnown() {
//Given
when(pcsCase.getAllClaimants()).thenReturn(List.of(claimantListValue));
when(pcsCase.getAllDefendants()).thenReturn(List.of(defendantPartyListValue));
when(defendantPartyListValue.getValue()).thenReturn(defendantParty);
Expand All @@ -56,7 +61,8 @@ void shouldSetCaseNameWhenClaimantIsOrgAndDefendantIsKnown() {
when(defendantParty.getNameKnown()).thenReturn(YES);
when(defendantParty.getLastName()).thenReturn(DEFENDANT_LAST_NAME);

underTest.setCaseNameHmctsField(pcsCase);
//When
underTest.setCaseFields(pcsCase);

// Then
verify(pcsCase).setCaseNameHmctsRestricted("Treetops Housing vs Jackson");
Expand All @@ -66,6 +72,7 @@ void shouldSetCaseNameWhenClaimantIsOrgAndDefendantIsKnown() {

@Test
void shouldSetCaseNameWhenClaimantIsCitizenAndDefendantIsKnown() {
//Given
when(pcsCase.getAllClaimants()).thenReturn(List.of(claimantListValue));
when(pcsCase.getAllDefendants()).thenReturn(List.of(defendantPartyListValue));
when(defendantPartyListValue.getValue()).thenReturn(defendantParty);
Expand All @@ -74,7 +81,8 @@ void shouldSetCaseNameWhenClaimantIsCitizenAndDefendantIsKnown() {
when(defendantParty.getNameKnown()).thenReturn(YES);
when(defendantParty.getLastName()).thenReturn(DEFENDANT_LAST_NAME);

underTest.setCaseNameHmctsField(pcsCase);
//When
underTest.setCaseFields(pcsCase);

// Then
verify(pcsCase).setCaseNameHmctsRestricted("Freeman vs Jackson");
Expand All @@ -84,6 +92,7 @@ void shouldSetCaseNameWhenClaimantIsCitizenAndDefendantIsKnown() {

@Test
void shouldSetCaseNameWhenClaimantIsOrgAndMultipleDefendants() {
//Given
when(pcsCase.getAllClaimants()).thenReturn(List.of(claimantListValue));
when(pcsCase.getAllDefendants()).thenReturn(List.of(defendantPartyListValue, defendantPartyListValue));
when(defendantPartyListValue.getValue()).thenReturn(defendantParty);
Expand All @@ -92,7 +101,8 @@ void shouldSetCaseNameWhenClaimantIsOrgAndMultipleDefendants() {
when(defendantParty.getNameKnown()).thenReturn(YES);
when(defendantParty.getLastName()).thenReturn(DEFENDANT_LAST_NAME);

underTest.setCaseNameHmctsField(pcsCase);
//When
underTest.setCaseFields(pcsCase);

// Then
verify(pcsCase).setCaseNameHmctsRestricted("Treetops Housing vs Jackson and Others");
Expand All @@ -102,18 +112,53 @@ void shouldSetCaseNameWhenClaimantIsOrgAndMultipleDefendants() {

@Test
void shouldSetCaseNameWhenClaimantIsCitizenAndDefendantUnkown() {
//Given
when(pcsCase.getAllClaimants()).thenReturn(List.of(claimantListValue));
when(pcsCase.getAllDefendants()).thenReturn(List.of(defendantPartyListValue));
when(claimantListValue.getValue()).thenReturn(claimantParty);
when(defendantPartyListValue.getValue()).thenReturn(defendantParty);
when(claimantParty.getLastName()).thenReturn(CLAIMANT_NAME);
when(defendantParty.getNameKnown()).thenReturn(NO);

underTest.setCaseNameHmctsField(pcsCase);
//When
underTest.setCaseFields(pcsCase);

// Then
verify(pcsCase).setCaseNameHmctsRestricted("Freeman vs persons unknown");
verify(pcsCase).setCaseNameHmctsInternal("Freeman vs persons unknown");
verify(pcsCase).setCaseNamePublic("Freeman vs persons unknown");
}

@Test
void shouldSetCaseManagementLocationFormatted() {

//Given
when(pcsCase.getCaseManagementLocation()).thenReturn(29096);
when(pcsCase.getRegionId()).thenReturn(1);

//When
underTest.setCaseFields(pcsCase);

// Then
verify(pcsCase).setCaseManagementLocationFormatted("{region:1,baseLocation:29096}");
}

@ParameterizedTest
@CsvSource(value = {
"2096,null",
"null,1",
"null,null"
}, nullValues = {"null"})
void shouldNotCallSetCaseManagementLocationFormattedWhenEitherIdIsNull(Integer epimsId, Integer regionId) {

//Given
when(pcsCase.getCaseManagementLocation()).thenReturn(epimsId);
when(pcsCase.getRegionId()).thenReturn(regionId);

//When
underTest.setCaseFields(pcsCase);

// Then
verify(pcsCase, never()).setCaseManagementLocationFormatted(anyString());
}
}
Loading