diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/PCSCaseView.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/PCSCaseView.java index bf3d8e6bbc..67c12b6cea 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/PCSCaseView.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/PCSCaseView.java @@ -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; @@ -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; @@ -68,7 +68,7 @@ public class PCSCaseView implements CaseView { private final RentArrearsView rentArrearsView; private final NoticeOfPossessionView noticeOfPossessionView; private final StatementOfTruthView statementOfTruthView; - private final CaseNameHmctsFormatter caseNameHmctsFormatter; + private final CaseFieldsView caseFieldsView; /** @@ -83,7 +83,7 @@ public PCSCase getCase(CaseViewRequest request) { boolean hasUnsubmittedCaseData = caseHasUnsubmittedData(caseReference, state); - caseNameHmctsFormatter.setCaseNameHmctsField(pcsCase); + caseFieldsView.setCaseFields(pcsCase); setMarkdownFields(pcsCase, hasUnsubmittedCaseData); diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/PCSCase.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/PCSCase.java index bcf12830fc..51e0ef2d04 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/PCSCase.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/PCSCase.java @@ -128,6 +128,11 @@ public class PCSCase { ) private Integer caseManagementLocation; + @CCD( + label = "Region Id" + ) + private Integer regionId; + @CCD(label = "Party") private List> parties; @@ -521,4 +526,10 @@ public class PCSCase { ) private String caseNamePublic; + @CCD( + label = "CaseManagementLocation", + access = {GlobalSearchAccess.class} + ) + private String caseManagementLocationFormatted; + } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/globalsearch/CaseNameHmctsFormatter.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/globalsearch/CaseFieldsView.java similarity index 50% rename from src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/globalsearch/CaseNameHmctsFormatter.java rename to src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/globalsearch/CaseFieldsView.java index f554dd7189..57736f2ab2 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/globalsearch/CaseNameHmctsFormatter.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/globalsearch/CaseFieldsView.java @@ -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; @@ -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> defendants = pcsCase.getAllDefendants(); final List> claimants = pcsCase.getAllClaimants(); @@ -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> 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> 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"); } @@ -66,4 +82,8 @@ private String getFormattedDefendantName(final List> defendants private boolean isDefendantNameKnown(final List> defendants) { return defendants.getFirst().getValue().getNameKnown() == VerticalYesNo.YES; } + + private String getFormattedValue(int region, int epimsId) { + return "{region:%s,baseLocation:%s}".formatted(region, epimsId); + } } diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/PCSCaseViewTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/PCSCaseViewTest.java index 204263c825..325c41f5f3 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/PCSCaseViewTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/PCSCaseViewTest.java @@ -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; @@ -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; @@ -95,7 +95,7 @@ class PCSCaseViewTest { @Mock private ClaimEntity claimEntity; @Mock - private CaseNameHmctsFormatter caseNameHmctsFormatter; + private CaseFieldsView caseFieldsView; private PCSCaseView underTest; @@ -108,7 +108,7 @@ void setUp() { caseTitleService, claimView, tenancyLicenceView, claimGroundsView, rentDetailsView, alternativesToPossessionView, housingActWalesView, asbProhibitedConductView, rentArrearsView, noticeOfPossessionView, - statementOfTruthView, caseNameHmctsFormatter + statementOfTruthView, caseFieldsView ); } @@ -335,14 +335,14 @@ void shouldSetCaseFieldsInViewHelpers() { } @Test - void shouldSetCaseNameHmctsField() { + void shouldSetCaseFields() { // When - doNothing().when(caseNameHmctsFormatter).setCaseNameHmctsField(any(PCSCase.class)); + doNothing().when(caseFieldsView).setCaseFields(any(PCSCase.class)); PCSCase pcsCase = underTest.getCase(request(CASE_REFERENCE, DEFAULT_STATE)); // Then - verify(caseNameHmctsFormatter).setCaseNameHmctsField(pcsCase); + verify(caseFieldsView).setCaseFields(pcsCase); } private AddressUK stubAddressEntityModelMapper(AddressEntity addressEntity) { diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/globalsearch/CaseNameHmctsFormatterTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/globalsearch/CaseFieldsViewTest.java similarity index 74% rename from src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/globalsearch/CaseNameHmctsFormatterTest.java rename to src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/globalsearch/CaseFieldsViewTest.java index 2503ae7948..921c66ba94 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/globalsearch/CaseNameHmctsFormatterTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/globalsearch/CaseFieldsViewTest.java @@ -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; @@ -14,11 +16,13 @@ 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"; @@ -26,7 +30,7 @@ class CaseNameHmctsFormatterTest { @Mock private PCSCase pcsCase; - private CaseNameHmctsFormatter underTest; + private CaseFieldsView underTest; @Mock private ListValue defendantPartyListValue; @@ -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); @@ -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"); @@ -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); @@ -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"); @@ -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); @@ -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"); @@ -102,6 +112,7 @@ 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); @@ -109,11 +120,45 @@ void shouldSetCaseNameWhenClaimantIsCitizenAndDefendantUnkown() { 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()); + } }