diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/CaseType.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/CaseType.java index 67e53526ba..24da7bdc54 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/CaseType.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/CaseType.java @@ -74,6 +74,14 @@ public void configure(final ConfigBuilder builder) { .label("nextStepsMarkdownLabel", null, "${nextStepsMarkdown}") .field("nextStepsMarkdown", NEVER_SHOW); + buildCasePartiesTab(builder); + + buildCaseDetailsTab(builder); + + builder.tab("caseFileView", "Case File View") + .showCondition(ShowConditions.stateNotEquals(AWAITING_SUBMISSION_TO_HMCTS)) + .field(PCSCase::getCaseFileView, null, "#ARGUMENT(CaseFileView)"); + buildSummaryTab(builder); builder.tab("CaseHistory", "History") @@ -89,17 +97,11 @@ public void configure(final ConfigBuilder builder) { .showCondition(ShowConditions.stateNotEquals(AWAITING_SUBMISSION_TO_HMCTS)) .field("waysToPay"); - builder.tab("caseFileView", "Case File View") - .showCondition(ShowConditions.stateNotEquals(AWAITING_SUBMISSION_TO_HMCTS)) - .field(PCSCase::getCaseFileView, null, "#ARGUMENT(CaseFileView)"); - builder.tab("caseLinks", "Linked Cases") .forRoles(UserRole.PCS_SOLICITOR) .field(PCSCase::getLinkedCasesComponentLauncher, null, "#ARGUMENT(LinkedCases)") .field(PCSCase::getCaseLinks, "LinkedCasesComponentLauncher!=\"\"", "#ARGUMENT(LinkedCases)"); - buildCasePartiesTab(builder); - configureCaseFileCategories(builder); } @@ -152,4 +154,54 @@ private void buildSummaryTab(ConfigBuilder builder) { "## Notice") .field("summaryTab_NoticeDetails"); } + + private void buildCaseDetailsTab(ConfigBuilder builder) { + builder.tab("caseDetails", "Case Details") + .label("Case details", null, "### Case details") + .field("detailsTab_ClaimDetails") + .field("detailsTab_PropertyAddress") + .field("detailsTab_GroundsForPossessionDetails") + .field("detailsTab_DateClaimSubmitted") + .field("detailsTab_TenancyLicenceDetails") + .field("detailsTab_NoticeDetails") + .field("detailsTab_ActionsTakenDetails") + .field("detailsTab_RentArrearsDetails") + .field("detailsTab_ReasonsForPossessionDetails") + .field("detailsTab_ApplicationsDetails") + .label( + "Claimant Details", + "detailsTab_ClaimantInformation!=\"\"", + "### Claimant Details" + ) + .field("detailsTab_ClaimantInformation") + .field("detailsTab_ClaimantAddress") + .field("detailsTab_ClaimantContactDetails") + .field("detailsTab_ClaimantCircumstances") + .label( + "Defendant Details", + "detailsTab_DefendantInformationDetails!=\"\"", + "### Defendant Details" + ) + .field("detailsTab_DefendantInformationDetails") + .field("detailsTab_AdditionalDefendants") + .field("detailsTab_DefendantCircumstanceDetails") + .label( + "Underlessee or mortgagee", + "detailsTab_MortgageDetails!=\"\"", + "### Underlessee or mortgagee entitled to claim relief against forfeiture" + ) + .field("detailsTab_MortgageDetails") + .label( + "Demotion of tenancy", + "detailsTab_DemotionOfTenancyDetails!=\"\"", + "### Demotion of tenancy" + ) + .field("detailsTab_DemotionOfTenancyDetails") + .label( + "Suspension of right to buy", + "detailsTab_SuspensionOfRightToBuyDetails!=\"\"", + "### Suspension of right to buy" + ) + .field("detailsTab_SuspensionOfRightToBuyDetails"); + } } 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 aa8c175992..25d0b194e8 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 @@ -39,6 +39,7 @@ import uk.gov.hmcts.reform.pcs.ccd.domain.respondpossessionclaim.PossessionClaimResponse; import uk.gov.hmcts.reform.pcs.ccd.domain.statementoftruth.StatementOfTruthDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.CasePartiesTab; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details.CaseDetailsTab; import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.summary.SummaryTab; import uk.gov.hmcts.reform.pcs.ccd.domain.wales.ASBQuestionsDetailsWales; import uk.gov.hmcts.reform.pcs.ccd.domain.wales.EstateManagementGroundsWales; @@ -612,4 +613,8 @@ public class PCSCase { @JsonUnwrapped(prefix = "summaryTab_") @CCD(searchable = false) private SummaryTab summaryTab; + + @JsonUnwrapped(prefix = "detailsTab_") + @CCD + private CaseDetailsTab caseDetailsTab; } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/ActionsTakenTabDetails.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/ActionsTakenTabDetails.java new file mode 100644 index 0000000000..6cd15b8342 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/ActionsTakenTabDetails.java @@ -0,0 +1,26 @@ +package uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import uk.gov.hmcts.ccd.sdk.api.CCD; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ActionsTakenTabDetails { + + @CCD(label = "Pre-action protocol followed?") + private String preactionProtocolFollowed; + + @CCD(label = "Explain why you have not followed the pre-action protocol") + private String preActionProtocolIncompleteExplanation; + + @CCD(label = "Mediation attempted?") + private String mediationAttempted; + + @CCD(label = "Settlement attempted?") + private String settlementAttempted; +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/ApplicationsTabDetails.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/ApplicationsTabDetails.java new file mode 100644 index 0000000000..d72ec86ecd --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/ApplicationsTabDetails.java @@ -0,0 +1,17 @@ +package uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import uk.gov.hmcts.ccd.sdk.api.CCD; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ApplicationsTabDetails { + + @CCD(label = "Are you planning to make an application at the same time as your claim?") + private String planToMakeGeneralApplication; +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/CaseDetailsTab.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/CaseDetailsTab.java new file mode 100644 index 0000000000..70dd5050ba --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/CaseDetailsTab.java @@ -0,0 +1,87 @@ +package uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import uk.gov.hmcts.ccd.sdk.api.CCD; +import uk.gov.hmcts.ccd.sdk.type.AddressUK; +import uk.gov.hmcts.ccd.sdk.type.ListValue; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.AdditionalDefendantInformationTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.ClaimantInformationTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.DefendantInformationTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.GroundsForPossessionTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.ReasonsForPossessionTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.RentArrearsTabDetails; + +import java.util.List; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonNaming(PropertyNamingStrategies.UpperCamelCaseStrategy.class) +public class CaseDetailsTab { + + @CCD(label = "Claim details") + private ClaimTabDetails claimDetails; + + @CCD(label = "Address of property to be repossessed") + private AddressUK propertyAddress; + + @CCD(label = "Grounds for possession") + private GroundsForPossessionTabDetails groundsForPossessionDetails; + + @CCD(label = "Date claim Submitted") + private String dateClaimSubmitted; + + @CCD(label = "Tenancy, occupation contract or licence details") + private TenancyLicenceTabDetails tenancyLicenceDetails; + + @CCD(label = "Notice details") + private NoticeTabDetails noticeDetails; + + @CCD(label = "Actions already taken") + private ActionsTakenTabDetails actionsTakenDetails; + + @CCD(label = "Details of rent arrears") + private RentArrearsTabDetails rentArrearsDetails; + + @CCD(label = "Reasons for possession") + private ReasonsForPossessionTabDetails reasonsForPossessionDetails; + + @CCD(label = "Applications") + private ApplicationsTabDetails applicationsDetails; + + @CCD(label = "Claimant") + private ClaimantInformationTabDetails claimantInformation; + + @CCD(label = "Claimant address for service") + private AddressUK claimantAddress; + + @CCD(label = "Claimant contact details") + private ClaimantContactTabDetails claimantContactDetails; + + @CCD(label = "Claimant circumstances") + private ClaimantCircumstancesTabDetails claimantCircumstances; + + @CCD(label = "Defendant 1") + private DefendantInformationTabDetails defendantInformationDetails; + + @CCD(label = "Additional defendant") + private List> additionalDefendants; + + @CCD(label = "Defendants’ circumstances") + private DefendantCircumstanceTabDetails defendantCircumstanceDetails; + + @CCD(label = "Underlessee or mortgagee") + private List> mortgageDetails; + + @CCD(label = "Demotion of tenancy claim") + private DemotionOfTenancyTabDetails demotionOfTenancyDetails; + + @CCD(label = "Suspension of right to buy") + private SuspensionOfRightToBuyTabDetails suspensionOfRightToBuyDetails; +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/ClaimTabDetails.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/ClaimTabDetails.java new file mode 100644 index 0000000000..24b45af39b --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/ClaimTabDetails.java @@ -0,0 +1,19 @@ +package uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import uk.gov.hmcts.ccd.sdk.api.CCD; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ClaimTabDetails { + @CCD(label = "Claimant type") + private String claimantType; + + @CCD(label = "Claim against trespassers?") + private String trespassClaim; +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/ClaimantCircumstancesTabDetails.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/ClaimantCircumstancesTabDetails.java new file mode 100644 index 0000000000..3cc4465dec --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/ClaimantCircumstancesTabDetails.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import uk.gov.hmcts.ccd.sdk.api.CCD; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ClaimantCircumstancesTabDetails { + + @CCD(label = "Is there any information you’d like to provide about ${claimantNamePossessiveForm} circumstances?") + private String claimantCircumstancesGiven; + + @CCD(label = "Claimant circumstances") + private String claimantCircumstancesDetails; +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/ClaimantContactTabDetails.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/ClaimantContactTabDetails.java new file mode 100644 index 0000000000..d5f7f90525 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/ClaimantContactTabDetails.java @@ -0,0 +1,24 @@ +package uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details; + + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import uk.gov.hmcts.ccd.sdk.api.CCD; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ClaimantContactTabDetails { + + @CCD(label = "Email address for notifications") + private String emailAddress; + + @CCD(label = "Do you want to provide a phone number for urgent updates about your case?") + private String phoneNumberProvided; + + @CCD(label = "Contact phone number") + private String phoneNumber; +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/DefendantCircumstanceTabDetails.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/DefendantCircumstanceTabDetails.java new file mode 100644 index 0000000000..d33229e7c0 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/DefendantCircumstanceTabDetails.java @@ -0,0 +1,23 @@ +package uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import uk.gov.hmcts.ccd.sdk.api.CCD; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +public class DefendantCircumstanceTabDetails { + + @CCD( + label = "Is there any information you're required to provide, or you want to provide, " + + "about the defendants’ circumstances?" + ) + private String defendantCircumstancesGiven; + + @CCD(label = "Defendants’ circumstances") + private String defendantCircumstances; +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/DemotionOfTenancyTabDetails.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/DemotionOfTenancyTabDetails.java new file mode 100644 index 0000000000..d8d0255fdb --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/DemotionOfTenancyTabDetails.java @@ -0,0 +1,31 @@ +package uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import uk.gov.hmcts.ccd.sdk.api.CCD; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +public class DemotionOfTenancyTabDetails { + + @CCD( + label = "Section of the Housing Act demotion of tenancy claim made under" + ) + private String housingAct; + + @CCD( + label = "Have you served the defendants with a statement of the express terms which will " + + "apply to the demoted tenancy?" + ) + private String statementOfExpressTermsServed; + + @CCD(label = "Details of terms") + private String terms; + + @CCD(label = "Reasons for requesting a demotion of tenancy order") + private String reasons; +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/NoticeTabDetails.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/NoticeTabDetails.java new file mode 100644 index 0000000000..bc601b71d7 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/NoticeTabDetails.java @@ -0,0 +1,45 @@ +package uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import uk.gov.hmcts.ccd.sdk.api.CCD; +import uk.gov.hmcts.ccd.sdk.type.Document; +import uk.gov.hmcts.ccd.sdk.type.ListValue; + +import java.util.List; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +public class NoticeTabDetails { + + @CCD(label = "Has notice been served?") + private String noticeServed; + + @CCD(label = "Date and time notice served (if applicable)") + private String noticeDate; + + @CCD(label = "Method of service") + private String noticeMethod; + + @CCD(label = "Name of person document was left with") + private String noticePersonName; + + @CCD(label = "Email address the document sent to") + private String noticeEmailAddress; + + @CCD(label = "Explain what the other means were") + private String noticeOtherExplanation; + + @CCD(label = "Are you able to upload a copy of the notice you served?") + private String noticeUploaded; + + @CCD(label = "Notice or certificate of service") + private List> noticeDocuments; + + @CCD(label = "Details of why you cannot upload a copy") + private String reasonsForNoNoticeDocument; +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/SuspensionOfRightToBuyTabDetails.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/SuspensionOfRightToBuyTabDetails.java new file mode 100644 index 0000000000..d0aa356cbf --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/SuspensionOfRightToBuyTabDetails.java @@ -0,0 +1,20 @@ +package uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import uk.gov.hmcts.ccd.sdk.api.CCD; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +public class SuspensionOfRightToBuyTabDetails { + + @CCD(label = "Section of the Housing Act suspension of right to buy claim made under") + private String housingAct; + + @CCD(label = "Reasons for requesting suspension of right to buy order") + private String reasons; +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/TenancyLicenceTabDetails.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/TenancyLicenceTabDetails.java new file mode 100644 index 0000000000..f32c4fe5af --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/TenancyLicenceTabDetails.java @@ -0,0 +1,33 @@ +package uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import uk.gov.hmcts.ccd.sdk.api.CCD; +import uk.gov.hmcts.ccd.sdk.type.Document; +import uk.gov.hmcts.ccd.sdk.type.ListValue; + +import java.util.List; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TenancyLicenceTabDetails { + + @CCD(label = "Tenancy, occupation contract or licence agreement type") + private String typeOfTenancyLicence; + + @CCD(label = "Tenancy, occupation contract or licence start date") + private String tenancyLicenceDate; + + @CCD(label = "Do you have a copy of the tenancy or licence agreement?") + private String hasCopyOfTenancyLicence; + + @CCD(label = "Details of why you do not have a copy") + private String reasonsForNoTenancyLicenceDocuments; + + @CCD(label = "Tenancy, occupation contract or licence agreement") + private List> tenancyLicenceDocuments; +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/UnderlesseeOrMortgageInformationTabDetails.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/UnderlesseeOrMortgageInformationTabDetails.java new file mode 100644 index 0000000000..811d24d8b6 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/details/UnderlesseeOrMortgageInformationTabDetails.java @@ -0,0 +1,27 @@ +package uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import uk.gov.hmcts.ccd.sdk.api.CCD; +import uk.gov.hmcts.ccd.sdk.type.AddressUK; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +public class UnderlesseeOrMortgageInformationTabDetails { + + @CCD(label = "Underlessee or mortgagee’s name known?") + private String nameKnown; + + @CCD(label = "Name") + private String name; + + @CCD(label = "Underlessee or mortgagee’s address for service known?") + private String addressKnown; + + @CCD(label = "Underlessee or mortgagee address for service address") + private AddressUK address; +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/AdditionalDefendantInformationTabDetails.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/AdditionalDefendantInformationTabDetails.java index 6d784b3485..b7ad6d5744 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/AdditionalDefendantInformationTabDetails.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/AdditionalDefendantInformationTabDetails.java @@ -13,12 +13,18 @@ @AllArgsConstructor public class AdditionalDefendantInformationTabDetails { + @CCD(label = "Additional defendant's name known?") + private String nameKnown; + @CCD(label = "First name") private String firstName; @CCD(label = "Last name") private String lastName; + @CCD(label = "Additional defendant's correspondence address known") + private String addressKnown; + @CCD(label = "Additional defendant address for service") private AddressUK addressForService; } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/DefendantInformationTabDetails.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/DefendantInformationTabDetails.java index cc779e9fb4..f252079557 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/DefendantInformationTabDetails.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/DefendantInformationTabDetails.java @@ -13,12 +13,18 @@ @AllArgsConstructor public class DefendantInformationTabDetails { + @CCD(label = "Defendant 1's name known?") + private String nameKnown; + @CCD(label = "First name") private String firstName; @CCD(label = "Last name") private String lastName; + @CCD(label = "Defendant 1's correspondence address known") + private String addressKnown; + @CCD(label = "Defendant 1 address for service") private AddressUK addressForService; } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/GroundsForPossessionTabDetails.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/GroundsForPossessionTabDetails.java index 7a58cde8de..4aabe89729 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/GroundsForPossessionTabDetails.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/GroundsForPossessionTabDetails.java @@ -16,4 +16,7 @@ public class GroundsForPossessionTabDetails { @CCD(label = "Grounds", typeOverride = TextArea) private String grounds; + + @CCD(label = "Description of other grounds") + private String otherGroundsDescription; } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/ReasonsForPossessionTabDetails.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/ReasonsForPossessionTabDetails.java index 207b7661c1..4353339ba1 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/ReasonsForPossessionTabDetails.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/ReasonsForPossessionTabDetails.java @@ -173,4 +173,10 @@ public class ReasonsForPossessionTabDetails { @CCD(label = "Additional reasons for possession") private String additionalReasonsForPossession; + + @CCD(label = "Do you have any additional reasons for possession?") + private String hasAdditionalReasons; + + @CCD(label = "Details of additional reasons") + private String additionalReasonsDetails; } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/RentArrearsTabDetails.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/RentArrearsTabDetails.java index 62fb94e805..3647a3ac52 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/RentArrearsTabDetails.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/tabs/shared/RentArrearsTabDetails.java @@ -5,6 +5,10 @@ import lombok.Data; import lombok.NoArgsConstructor; import uk.gov.hmcts.ccd.sdk.api.CCD; +import uk.gov.hmcts.ccd.sdk.type.Document; +import uk.gov.hmcts.ccd.sdk.type.ListValue; + +import java.util.List; @Builder @Data @@ -18,9 +22,24 @@ public class RentArrearsTabDetails { @CCD(label = "How rent is calculated") private String calculationFrequency; + @CCD(label = "Frequency") + private String frequency; + @CCD(label = "Daily rate") private String dailyRate; + @CCD(label = "Previous steps taken to recover rent arrears?") + private String stepsToRecoverArrears; + + @CCD(label = "Details of previous steps taken") + private String stepsToRecoverArrearsDetails; + + @CCD(label = "Rent statement") + private List> rentStatement; + + @CCD(label = "Rent statement") + private String rentStatementPlaceholder; + @CCD(label = "Rent arrears total at the time of claim issue") private String arrearsTotal; diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/AlternativesToPossessionView.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/AlternativesToPossessionView.java index 2baf4f2282..dd2b94ca9e 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/AlternativesToPossessionView.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/AlternativesToPossessionView.java @@ -2,6 +2,7 @@ import org.springframework.stereotype.Component; import uk.gov.hmcts.ccd.sdk.type.YesOrNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.AlternativesToPossession; import uk.gov.hmcts.reform.pcs.ccd.domain.DemotionOfTenancy; import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; import uk.gov.hmcts.reform.pcs.ccd.domain.SuspensionOfRightToBuy; @@ -9,8 +10,12 @@ import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity; import uk.gov.hmcts.reform.pcs.ccd.entity.claim.PossessionAlternativesEntity; +import java.util.HashSet; import java.util.Optional; +import java.util.Set; +import static uk.gov.hmcts.reform.pcs.ccd.domain.AlternativesToPossession.DEMOTION_OF_TENANCY; +import static uk.gov.hmcts.reform.pcs.ccd.domain.AlternativesToPossession.SUSPENSION_OF_RIGHT_TO_BUY; import static uk.gov.hmcts.reform.pcs.ccd.util.YesOrNoConverter.toVerticalYesNo; @Component @@ -30,12 +35,15 @@ private static Optional getMainClaim(PcsCaseEntity pcsCaseEntity) { private static void setPossessionAlternativesFields(PCSCase pcsCase, PossessionAlternativesEntity possessionAlternatives) { + Set alternativesToPossession = new HashSet<>(); + if (possessionAlternatives.getSuspensionOfRTB() == YesOrNo.YES) { SuspensionOfRightToBuy suspensionOfRightToBuy = SuspensionOfRightToBuy.builder() .housingAct(possessionAlternatives.getSuspensionOfRTBHousingActSection()) .reason(possessionAlternatives.getSuspensionOfRTBReason()) .build(); pcsCase.setSuspensionOfRightToBuy(suspensionOfRightToBuy); + alternativesToPossession.add(SUSPENSION_OF_RIGHT_TO_BUY); } if (possessionAlternatives.getDotRequested() == YesOrNo.YES) { @@ -47,7 +55,10 @@ private static void setPossessionAlternativesFields(PCSCase pcsCase, .statementOfExpressTermsDetails(possessionAlternatives.getDotStatementDetails()) .build(); pcsCase.setDemotionOfTenancy(demotionOfTenancy); + alternativesToPossession.add(DEMOTION_OF_TENANCY); } + + pcsCase.setAlternativesToPossession(alternativesToPossession); } } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseDetailsTabView.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseDetailsTabView.java new file mode 100644 index 0000000000..4ca0d0d0ac --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseDetailsTabView.java @@ -0,0 +1,521 @@ +package uk.gov.hmcts.reform.pcs.ccd.view; + +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import uk.gov.hmcts.ccd.sdk.type.AddressUK; +import uk.gov.hmcts.ccd.sdk.type.ListValue; +import uk.gov.hmcts.ccd.sdk.type.YesOrNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.AlternativesToPossession; +import uk.gov.hmcts.reform.pcs.ccd.domain.ClaimantCircumstances; +import uk.gov.hmcts.reform.pcs.ccd.domain.ClaimantContactPreferences; +import uk.gov.hmcts.reform.pcs.ccd.domain.ClaimantType; +import uk.gov.hmcts.reform.pcs.ccd.domain.DefendantCircumstances; +import uk.gov.hmcts.reform.pcs.ccd.domain.DemotionOfTenancy; +import uk.gov.hmcts.reform.pcs.ccd.domain.DemotionOfTenancyHousingAct; +import uk.gov.hmcts.reform.pcs.ccd.domain.NoticeServedDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.NoticeServiceMethod; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.Party; +import uk.gov.hmcts.reform.pcs.ccd.domain.SuspensionOfRightToBuy; +import uk.gov.hmcts.reform.pcs.ccd.domain.SuspensionOfRightToBuyHousingAct; +import uk.gov.hmcts.reform.pcs.ccd.domain.TenancyLicenceDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.TenancyLicenceType; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.AssuredAdditionalOtherGround; +import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.ClaimGroundSummary; +import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.IntroductoryDemotedOrOtherGrounds; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details.ActionsTakenTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details.ApplicationsTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details.CaseDetailsTab; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details.ClaimTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details.ClaimantCircumstancesTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details.ClaimantContactTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details.DefendantCircumstanceTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details.DemotionOfTenancyTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details.NoticeTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details.SuspensionOfRightToBuyTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details.TenancyLicenceTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details.UnderlesseeOrMortgageInformationTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.AdditionalDefendantInformationTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.ClaimantInformationTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.DefendantInformationTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.GroundsForPossessionTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.ReasonsForPossessionTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.RentArrearsTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.AdditionalDefendantInformationTabDetailsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.ClaimantInformationTabDetailsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.DefendantInformationTabDetailsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.GroundsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.ReasonsForPossessionTabDetailsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.RentArrearsTabDetailsBuilder; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Locale; +import java.util.Set; + +import static uk.gov.hmcts.reform.pcs.ccd.domain.AlternativesToPossession.DEMOTION_OF_TENANCY; +import static uk.gov.hmcts.reform.pcs.ccd.domain.AlternativesToPossession.SUSPENSION_OF_RIGHT_TO_BUY; +import static uk.gov.hmcts.reform.pcs.ccd.domain.TenancyLicenceType.ASSURED_TENANCY; +import static uk.gov.hmcts.reform.pcs.ccd.domain.TenancyLicenceType.DEMOTED_TENANCY; +import static uk.gov.hmcts.reform.pcs.ccd.domain.TenancyLicenceType.INTRODUCTORY_TENANCY; +import static uk.gov.hmcts.reform.pcs.ccd.domain.TenancyLicenceType.OTHER; +import static uk.gov.hmcts.reform.pcs.config.ClockConfiguration.UK_ZONE_ID; + +@AllArgsConstructor +@Component +public class CaseDetailsTabView { + + private static final String NO_ANSWER = " "; + private static final DateTimeFormatter DATE_FORMATTER = + DateTimeFormatter.ofPattern("d MMMM yyyy", Locale.UK); + private static final DateTimeFormatter SUBMITTED_DATE_FORMATTER = + DateTimeFormatter.ofPattern("d MMMM yyyy, h:mm:ssa", Locale.UK); + + private final GroundsBuilder groundsBuilder; + private final RentArrearsTabDetailsBuilder rentArrearsTabDetailsBuilder; + private final ReasonsForPossessionTabDetailsBuilder reasonsForPossessionTabDetailsBuilder; + private final ClaimantInformationTabDetailsBuilder claimantInformationTabDetailsBuilder; + private final DefendantInformationTabDetailsBuilder defendantInformationTabDetailsBuilder; + private final AdditionalDefendantInformationTabDetailsBuilder additionalDefendantInformationTabDetailsBuilder; + + public CaseDetailsTab buildCaseDetailsTab(PCSCase pcsCase) { + ClaimTabDetails claimTabDetails = buildClaimTabDetails(pcsCase); + GroundsForPossessionTabDetails groundsForPossessionTabDetails = buildGroundsForPossessionTabDetails(pcsCase); + TenancyLicenceTabDetails tenancyLicenceTabDetails = buildTenancyLicenceTabDetails(pcsCase); + NoticeTabDetails noticeTabDetails = buildNoticeTabDetails(pcsCase); + ActionsTakenTabDetails actionsTakenTabDetails = buildActionsTakenTabDetails(pcsCase); + RentArrearsTabDetails rentArrearsTabDetails = + rentArrearsTabDetailsBuilder.buildDetailedRentArrearsTabDetails(pcsCase); + ReasonsForPossessionTabDetails reasonsForPossessionTabDetails = + reasonsForPossessionTabDetailsBuilder.buildDetailsReasonsForPossession(pcsCase); + ApplicationsTabDetails applicationsTabDetails = buildApplicationsTabDetails(pcsCase); + ClaimantInformationTabDetails claimantInformationTabDetails = buildClaimantInformationTabDetails(pcsCase); + DefendantInformationTabDetails defendantInformationTabDetails = + defendantInformationTabDetailsBuilder.buildDetailedDefendantDetails(pcsCase); + List> underlesseeMortgageTabDetailsList = + buildUnderlesseeMortgageTabDetailsList(pcsCase); + DemotionOfTenancyTabDetails demotionOfTenancyTabDetails = buildDemotionOfTenancyTabDetails(pcsCase); + SuspensionOfRightToBuyTabDetails suspensionOfRightToBuyTabDetails = + buildSuspensionOfRightToBuyTabDetails(pcsCase); + String dateSubmitted = formatSubmittedDate(pcsCase.getDateSubmitted()); + + CaseDetailsTab caseDetailsTab = CaseDetailsTab.builder() + .claimDetails(claimTabDetails) + .propertyAddress(pcsCase.getPropertyAddress()) + .groundsForPossessionDetails(groundsForPossessionTabDetails) + .tenancyLicenceDetails(tenancyLicenceTabDetails) + .noticeDetails(noticeTabDetails) + .actionsTakenDetails(actionsTakenTabDetails) + .rentArrearsDetails(rentArrearsTabDetails) + .reasonsForPossessionDetails(reasonsForPossessionTabDetails) + .applicationsDetails(applicationsTabDetails) + .claimantInformation(claimantInformationTabDetails) + .defendantInformationDetails(defendantInformationTabDetails) + .mortgageDetails(underlesseeMortgageTabDetailsList) + .demotionOfTenancyDetails(demotionOfTenancyTabDetails) + .suspensionOfRightToBuyDetails(suspensionOfRightToBuyTabDetails) + .dateClaimSubmitted(dateSubmitted != null ? dateSubmitted : NO_ANSWER) + .build(); + + if (claimantInformationTabDetails != null) { + caseDetailsTab.setClaimantAddress(getClaimantAddress(pcsCase)); + caseDetailsTab.setClaimantContactDetails(buildClaimantContactTabDetails(pcsCase)); + caseDetailsTab.setClaimantCircumstances(buildClaimantCircumstancesTabDetails(pcsCase)); + } + + if (defendantInformationTabDetails != null) { + List> additionalDefendantInformationTabDetails = + additionalDefendantInformationTabDetailsBuilder.buildDetailedAdditionalDefendantsDetails(pcsCase); + caseDetailsTab.setAdditionalDefendants(additionalDefendantInformationTabDetails); + caseDetailsTab.setDefendantCircumstanceDetails(buildDefendantCircumstanceTabDetails(pcsCase)); + } + return caseDetailsTab; + } + + private ClaimTabDetails buildClaimTabDetails(PCSCase pcsCase) { + String claimantType = pcsCase.getClaimantType() != null + ? ClaimantType.fromName(pcsCase.getClaimantType().getValueCode()).getLabel() : NO_ANSWER; + VerticalYesNo trespassClaim = pcsCase.getClaimAgainstTrespassers(); + + return ClaimTabDetails.builder() + .claimantType(claimantType) + .trespassClaim(trespassClaim != null ? trespassClaim.getLabel() : NO_ANSWER) + .build(); + } + + private GroundsForPossessionTabDetails buildGroundsForPossessionTabDetails(PCSCase pcsCase) { + List> groundSummaries = pcsCase.getClaimGroundSummaries(); + if (CollectionUtils.isEmpty(groundSummaries)) { + return GroundsForPossessionTabDetails.builder() + .grounds(NO_ANSWER) + .build(); + } + + TenancyLicenceDetails tenancyLicenceDetails = pcsCase.getTenancyLicenceDetails(); + TenancyLicenceType tenancyType = tenancyLicenceDetails != null + ? tenancyLicenceDetails.getTypeOfTenancyLicence() : null; + String otherGroundsDescription = ""; + + if (tenancyType == INTRODUCTORY_TENANCY || tenancyType == DEMOTED_TENANCY || tenancyType == OTHER) { + otherGroundsDescription = groundSummaries.stream().filter( + claimGroundSummaryListValue -> { + ClaimGroundSummary claimGroundSummary = claimGroundSummaryListValue.getValue(); + return claimGroundSummary.getCode().equals(IntroductoryDemotedOrOtherGrounds.OTHER.name()); + }) + .map(ListValue::getValue) + .map(ClaimGroundSummary::getDescription) + .findFirst() + .orElse(""); + } else if (tenancyType == ASSURED_TENANCY) { + otherGroundsDescription = groundSummaries.stream().filter( + claimGroundSummaryListValue -> { + ClaimGroundSummary claimGroundSummary = claimGroundSummaryListValue.getValue(); + return claimGroundSummary.getCode().equals(AssuredAdditionalOtherGround.OTHER.name()); + }) + .map(ListValue::getValue) + .map(ClaimGroundSummary::getDescription) + .findFirst() + .orElse(""); + } + + return GroundsForPossessionTabDetails + .builder() + .grounds(groundsBuilder.getGrounds(pcsCase)) + .otherGroundsDescription(otherGroundsDescription) + .build(); + } + + private TenancyLicenceTabDetails buildTenancyLicenceTabDetails(PCSCase pcsCase) { + TenancyLicenceDetails tenancyLicenceDetails = pcsCase.getTenancyLicenceDetails(); + if (tenancyLicenceDetails == null) { + return TenancyLicenceTabDetails.builder() + .typeOfTenancyLicence(NO_ANSWER) + .tenancyLicenceDate(NO_ANSWER) + .hasCopyOfTenancyLicence(NO_ANSWER) + .build(); + } + + TenancyLicenceType tenancyType = tenancyLicenceDetails.getTypeOfTenancyLicence(); + LocalDate tenancyDate = tenancyLicenceDetails.getTenancyLicenceDate(); + VerticalYesNo hasTenancyLicence = tenancyLicenceDetails.getHasCopyOfTenancyLicence(); + + return TenancyLicenceTabDetails.builder() + .typeOfTenancyLicence(tenancyType != null ? tenancyType.getLabel() : NO_ANSWER) + .tenancyLicenceDate(tenancyDate != null ? tenancyDate.format(DATE_FORMATTER) : NO_ANSWER) + .hasCopyOfTenancyLicence(hasTenancyLicence != null ? hasTenancyLicence.getLabel() : NO_ANSWER) + .tenancyLicenceDocuments(tenancyLicenceDetails.getTenancyLicenceDocuments()) + .reasonsForNoTenancyLicenceDocuments(tenancyLicenceDetails.getReasonsForNoTenancyLicenceDocuments()) + .build(); + } + + private NoticeTabDetails buildNoticeTabDetails(PCSCase pcsCase) { + if (pcsCase.getNoticeServed() == null) { + return NoticeTabDetails.builder() + .noticeServed(NO_ANSWER) + .noticeMethod(NO_ANSWER) + .noticeDate(NO_ANSWER) + .build(); + } + + YesOrNo noticeServed = pcsCase.getNoticeServed(); + NoticeTabDetails noticeTabDetails = NoticeTabDetails.builder() + .noticeServed(noticeServed.getValue()) + .noticeMethod(NO_ANSWER) + .noticeDate(NO_ANSWER) + .build(); + + NoticeServedDetails noticeServedDetails = pcsCase.getNoticeServedDetails(); + if (noticeServed == YesOrNo.YES && noticeTabDetails != null) { + NoticeServiceMethod method = noticeServedDetails.getNoticeServiceMethod(); + noticeTabDetails.setNoticeDocuments(noticeServedDetails.getNoticeDocuments()); + + if (method != null) { + noticeTabDetails.setNoticeMethod(method.getLabel()); + switch (method) { + case FIRST_CLASS_POST -> { + LocalDate date = noticeServedDetails.getNoticePostedDate(); + noticeTabDetails.setNoticeDate(date != null ? date.format(DATE_FORMATTER) : NO_ANSWER); + } + case DELIVERED_PERMITTED_PLACE -> { + LocalDate date = noticeServedDetails.getNoticeDeliveredDate(); + noticeTabDetails.setNoticeDate(date != null ? date.format(DATE_FORMATTER) : NO_ANSWER); + } + case PERSONALLY_HANDED -> { + LocalDateTime dateTime = noticeServedDetails.getNoticeHandedOverDateTime(); + String name = noticeServedDetails.getNoticePersonName(); + noticeTabDetails.setNoticeDate(dateTime != null ? dateTime.format(DATE_FORMATTER) : NO_ANSWER); + noticeTabDetails.setNoticePersonName(name != null ? name : NO_ANSWER); + } + case EMAIL -> { + LocalDateTime dateTime = noticeServedDetails.getNoticeEmailSentDateTime(); + String emailAddress = noticeServedDetails.getNoticeEmailAddress(); + noticeTabDetails.setNoticeDate(dateTime != null ? dateTime.format(DATE_FORMATTER) : NO_ANSWER); + noticeTabDetails.setNoticeEmailAddress(emailAddress != null ? emailAddress : NO_ANSWER); + } + case OTHER_ELECTRONIC -> { + LocalDateTime dateTime = noticeServedDetails.getNoticeOtherElectronicDateTime(); + noticeTabDetails.setNoticeDate(dateTime != null ? dateTime.format(DATE_FORMATTER) : NO_ANSWER); + } + case OTHER -> { + LocalDateTime dateTime = noticeServedDetails.getNoticeOtherDateTime(); + String explanation = noticeServedDetails.getNoticeOtherExplanation(); + noticeTabDetails.setNoticeDate(dateTime != null ? dateTime.format(DATE_FORMATTER) : NO_ANSWER); + noticeTabDetails.setNoticeOtherExplanation(explanation != null ? explanation : NO_ANSWER); + } + }; + } + } + + return noticeTabDetails; + } + + private ActionsTakenTabDetails buildActionsTakenTabDetails(PCSCase pcsCase) { + VerticalYesNo preactionProtocol = pcsCase.getPreActionProtocolCompleted(); + VerticalYesNo mediationAttempted = pcsCase.getMediationAttempted(); + VerticalYesNo settlementAttempted = pcsCase.getSettlementAttempted(); + String noPreactionExplanation = null; + + if (preactionProtocol == VerticalYesNo.NO) { + noPreactionExplanation = pcsCase.getPreActionProtocolIncompleteExplanation(); + } + + return ActionsTakenTabDetails.builder() + .preactionProtocolFollowed(preactionProtocol != null ? preactionProtocol.getLabel() : NO_ANSWER) + .preActionProtocolIncompleteExplanation(noPreactionExplanation) + .mediationAttempted(mediationAttempted != null ? mediationAttempted.getLabel() : NO_ANSWER) + .settlementAttempted(settlementAttempted != null ? settlementAttempted.getLabel() : NO_ANSWER) + .build(); + } + + private ApplicationsTabDetails buildApplicationsTabDetails(PCSCase pcsCase) { + VerticalYesNo applicationWithClaim = pcsCase.getApplicationWithClaim(); + String planToMakeGeneralApplication = applicationWithClaim != null + ? applicationWithClaim.getLabel() : NO_ANSWER; + + return ApplicationsTabDetails.builder() + .planToMakeGeneralApplication(planToMakeGeneralApplication) + .build(); + } + + private ClaimantInformationTabDetails buildClaimantInformationTabDetails(PCSCase pcsCase) { + return claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase); + } + + private AddressUK getClaimantAddress(PCSCase pcsCase) { + List> claimants = pcsCase.getAllClaimants(); + ClaimantContactPreferences claimantContactPreferences = pcsCase.getClaimantContactPreferences(); + AddressUK address = null; + + if (!CollectionUtils.isEmpty(claimants)) { + Party claimant = claimants.getFirst().getValue(); + address = claimant.getAddress(); + } else if (claimantContactPreferences != null) { + YesOrNo orgAddressFound = claimantContactPreferences.getOrgAddressFound(); + VerticalYesNo correctClaimantAddress = claimantContactPreferences.getIsCorrectClaimantContactAddress(); + if (orgAddressFound == YesOrNo.YES && correctClaimantAddress == VerticalYesNo.YES) { + address = claimantContactPreferences.getOrganisationAddress(); + } else { + address = claimantContactPreferences.getOverriddenClaimantContactAddress(); + } + } + + if (address != null) { + return address; + } + + return AddressUK.builder() + .addressLine1(NO_ANSWER) + .postTown(NO_ANSWER) + .postCode(NO_ANSWER) + .country(NO_ANSWER) + .build(); + } + + private ClaimantContactTabDetails buildClaimantContactTabDetails(PCSCase pcsCase) { + List> claimants = pcsCase.getAllClaimants(); + ClaimantContactPreferences claimantContactPreferences = pcsCase.getClaimantContactPreferences(); + String emailAddress = null; + String phoneNumber = null; + VerticalYesNo phoneNumberProvided = null; + + if (!CollectionUtils.isEmpty(claimants)) { + Party claimant = claimants.getFirst().getValue(); + emailAddress = claimant.getEmailAddress(); + phoneNumberProvided = claimant.getPhoneNumberProvided(); + + if (phoneNumberProvided == VerticalYesNo.YES) { + phoneNumber = claimant.getPhoneNumber(); + } + } else if (claimantContactPreferences != null) { + VerticalYesNo isCorrectClaimantContactEmail = claimantContactPreferences.getIsCorrectClaimantContactEmail(); + emailAddress = isCorrectClaimantContactEmail == VerticalYesNo.YES + ? claimantContactPreferences.getClaimantContactEmail() : + claimantContactPreferences.getOverriddenClaimantContactEmail(); + phoneNumberProvided = claimantContactPreferences.getClaimantProvidePhoneNumber(); + if (phoneNumberProvided == VerticalYesNo.YES) { + phoneNumber = claimantContactPreferences.getClaimantContactPhoneNumber(); + } + } + + + return ClaimantContactTabDetails.builder() + .emailAddress(emailAddress != null ? emailAddress : NO_ANSWER) + .phoneNumberProvided(phoneNumberProvided != null ? phoneNumberProvided.getLabel() : NO_ANSWER) + .phoneNumber(phoneNumber) + .build(); + } + + private ClaimantCircumstancesTabDetails buildClaimantCircumstancesTabDetails(PCSCase pcsCase) { + ClaimantCircumstances claimantCircumstances = pcsCase.getClaimantCircumstances(); + + if (claimantCircumstances == null) { + return ClaimantCircumstancesTabDetails.builder() + .claimantCircumstancesGiven(NO_ANSWER) + .build(); + } + VerticalYesNo claimantCircumstancesGiven = claimantCircumstances.getClaimantCircumstancesSelect(); + String claimantCircumstancesDetails = null; + + if (claimantCircumstancesGiven == VerticalYesNo.YES) { + claimantCircumstancesDetails = claimantCircumstances.getClaimantCircumstancesDetails(); + } + + return ClaimantCircumstancesTabDetails.builder() + .claimantCircumstancesGiven( + claimantCircumstancesGiven != null ? claimantCircumstancesGiven.getLabel() : NO_ANSWER + ) + .claimantCircumstancesDetails(claimantCircumstancesDetails) + .build(); + } + + private DefendantCircumstanceTabDetails buildDefendantCircumstanceTabDetails(PCSCase pcsCase) { + DefendantCircumstances defendantCircumstances = pcsCase.getDefendantCircumstances(); + String circumstances = null; + VerticalYesNo circumstancesGiven = null; + + if (defendantCircumstances != null) { + circumstancesGiven = defendantCircumstances.getHasDefendantCircumstancesInfo(); + circumstances = defendantCircumstances.getDefendantCircumstancesInfo(); + } + + + return DefendantCircumstanceTabDetails.builder() + .defendantCircumstancesGiven(circumstancesGiven != null ? circumstancesGiven.getLabel() : NO_ANSWER) + .defendantCircumstances(circumstances) + .build(); + } + + private List> buildUnderlesseeMortgageTabDetailsList( + PCSCase pcsCase + ) { + List> underlesseeMortgageParties = pcsCase.getAllUnderlesseeOrMortgagees(); + if (CollectionUtils.isEmpty(underlesseeMortgageParties)) { + return null; + } + + return underlesseeMortgageParties.stream() + .map(this::buildUnderlesseeMortgageTabDetails) + .toList(); + } + + private ListValue buildUnderlesseeMortgageTabDetails( + ListValue underlesseeMortgageePartyListValue + ) { + Party underlesseeMortgageeParty = underlesseeMortgageePartyListValue.getValue(); + VerticalYesNo nameKnown = underlesseeMortgageeParty.getNameKnown(); + String name = nameKnown == VerticalYesNo.YES ? underlesseeMortgageeParty.getOrgName() : null; + VerticalYesNo addressKnown = underlesseeMortgageeParty.getAddressKnown(); + AddressUK address = addressKnown == VerticalYesNo.YES ? underlesseeMortgageeParty.getAddress() : null; + + return ListValue.builder() + .value(UnderlesseeOrMortgageInformationTabDetails.builder() + .nameKnown(nameKnown.getLabel()) + .name(name) + .addressKnown(addressKnown.getLabel()) + .address(address) + .build()) + .build(); + } + + private DemotionOfTenancyTabDetails buildDemotionOfTenancyTabDetails(PCSCase pcsCase) { + Set alternativesToPossessionSet = pcsCase.getAlternativesToPossession(); + + if ( + CollectionUtils.isEmpty(alternativesToPossessionSet) + || !alternativesToPossessionSet.contains(DEMOTION_OF_TENANCY) + ) { + return null; + } + + DemotionOfTenancy demotionOfTenancy = pcsCase.getDemotionOfTenancy(); + if (demotionOfTenancy == null) { + return DemotionOfTenancyTabDetails.builder() + .housingAct(NO_ANSWER) + .statementOfExpressTermsServed(NO_ANSWER) + .reasons(NO_ANSWER) + .build(); + } + + DemotionOfTenancyHousingAct housingAct = demotionOfTenancy.getHousingAct(); + VerticalYesNo statementOfExpressTermsServed = demotionOfTenancy.getStatementOfExpressTermsServed(); + String statementOfExpressTermsDetails = null; + + if (statementOfExpressTermsServed == VerticalYesNo.YES) { + statementOfExpressTermsDetails = demotionOfTenancy.getStatementOfExpressTermsDetails(); + } + String reason = demotionOfTenancy.getReason(); + + return DemotionOfTenancyTabDetails.builder() + .housingAct(housingAct != null ? housingAct.getLabel() : NO_ANSWER) + .statementOfExpressTermsServed( + statementOfExpressTermsServed != null ? statementOfExpressTermsServed.getLabel() : NO_ANSWER + ) + .terms(statementOfExpressTermsDetails) + .reasons(reason != null ? reason : NO_ANSWER) + .build(); + } + + private SuspensionOfRightToBuyTabDetails buildSuspensionOfRightToBuyTabDetails(PCSCase pcsCase) { + Set alternativesToPossessionSet = pcsCase.getAlternativesToPossession(); + if ( + CollectionUtils.isEmpty(alternativesToPossessionSet) + || !alternativesToPossessionSet.contains(SUSPENSION_OF_RIGHT_TO_BUY) + ) { + return null; + } + + SuspensionOfRightToBuy suspensionOfRightToBuyDemotionOfTenancy = pcsCase.getSuspensionOfRightToBuy(); + if (suspensionOfRightToBuyDemotionOfTenancy == null) { + return SuspensionOfRightToBuyTabDetails.builder() + .housingAct(NO_ANSWER) + .reasons(NO_ANSWER) + .build(); + } + + SuspensionOfRightToBuyHousingAct housingAct = suspensionOfRightToBuyDemotionOfTenancy.getHousingAct(); + String reason = suspensionOfRightToBuyDemotionOfTenancy.getReason(); + + return SuspensionOfRightToBuyTabDetails.builder() + .housingAct(housingAct != null ? housingAct.getLabel() : NO_ANSWER) + .reasons(reason != null ? reason : NO_ANSWER) + .build(); + } + + private String formatSubmittedDate(LocalDateTime dateSubmitted) { + if (dateSubmitted == null) { + return null; + } + + LocalDateTime ukDateSubmitted = dateSubmitted + .atZone(ZoneId.systemDefault()) + .withZoneSameInstant(UK_ZONE_ID) + .toLocalDateTime(); + + return ukDateSubmitted.format(SUBMITTED_DATE_FORMATTER).replace("am", "AM").replace("pm", "PM"); + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseSummaryTabView.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseSummaryTabView.java index 656ccdbf8b..d2e220f51b 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseSummaryTabView.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseSummaryTabView.java @@ -1,26 +1,11 @@ package uk.gov.hmcts.reform.pcs.ccd.view; +import lombok.AllArgsConstructor; import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; -import org.springframework.util.StringUtils; -import uk.gov.hmcts.ccd.sdk.type.AddressUK; -import uk.gov.hmcts.ccd.sdk.type.ListValue; -import uk.gov.hmcts.reform.pcs.ccd.domain.AdditionalReasons; -import uk.gov.hmcts.reform.pcs.ccd.domain.ClaimantInformation; import uk.gov.hmcts.reform.pcs.ccd.domain.NoticeServedDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; -import uk.gov.hmcts.reform.pcs.ccd.domain.Party; -import uk.gov.hmcts.reform.pcs.ccd.domain.RentArrearsSection; -import uk.gov.hmcts.reform.pcs.ccd.domain.RentDetails; -import uk.gov.hmcts.reform.pcs.ccd.domain.RentPaymentFrequency; import uk.gov.hmcts.reform.pcs.ccd.domain.TenancyLicenceDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.TenancyLicenceType; -import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; -import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.ClaimGroundSummary; -import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.AdditionalDefendantInformationTabDetails; -import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.ClaimantInformationTabDetails; -import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.DefendantInformationTabDetails; -import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.RentArrearsTabDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.GroundsForPossessionTabDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.summary.NoticeTabDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.ReasonsForPossessionTabDetails; @@ -28,102 +13,53 @@ import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.summary.TenancyTabDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.wales.OccupationLicenceDetailsWales; import uk.gov.hmcts.reform.pcs.ccd.domain.wales.OccupationLicenceTypeWales; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.AdditionalDefendantInformationTabDetailsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.ClaimantInformationTabDetailsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.DefendantInformationTabDetailsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.GroundsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.ReasonsForPossessionTabDetailsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.RentArrearsTabDetailsBuilder; -import java.math.BigDecimal; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.List; import java.util.Locale; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import static uk.gov.hmcts.ccd.sdk.type.YesOrNo.NO; import static uk.gov.hmcts.reform.pcs.config.ClockConfiguration.UK_ZONE_ID; +@AllArgsConstructor @Component public class CaseSummaryTabView { private static final DateTimeFormatter SUMMARY_DATE_FORMATTER = DateTimeFormatter.ofPattern("dd/MM/yyyy"); private static final DateTimeFormatter SUBMITTED_DATE_FORMATTER = DateTimeFormatter.ofPattern("d MMMM yyyy, h:mm:ssa", Locale.UK); - private static final Pattern GROUND_REFERENCE_PATTERN = - Pattern.compile("\\(ground ([^)]+)\\)", Pattern.CASE_INSENSITIVE); - private static final Pattern SECTION_REFERENCE_PATTERN = - Pattern.compile("\\(section ([^)]+)\\)", Pattern.CASE_INSENSITIVE); - private static final Pattern SECTION_84A_CONDITION_PATTERN = - Pattern.compile("^Condition ([1-5]) of Section 84A of the Housing Act 1985$"); - private static final String ANTISOCIAL_BEHAVIOUR = "Antisocial behaviour"; - private static final String SECTION_84A_CONDITION_1_PREFIX = "Condition 1"; - private static final String SECTION_84A_CONDITION_2_PREFIX = "Condition 2"; - private static final String SECTION_84A_CONDITION_3_PREFIX = "Condition 3"; - private static final String SECTION_84A_CONDITION_4_PREFIX = "Condition 4"; - private static final String SECTION_84A_CONDITION_5_PREFIX = "Condition 5"; - private static final String BREACH_OF_THE_TENANCY = "Breach of the tenancy"; - private static final String ABSOLUTE_GROUNDS = "Absolute grounds"; - private static final String OTHER = "Other"; - private static final String OTHER_GROUNDS = "Other grounds"; - private static final String NO_GROUNDS = "No grounds"; - private static final String PARAGRAPH_25B_2_SCHEDULE_12 = "paragraph 25B(2) of Schedule 12"; - private static final String GROUND_1 = "1"; - private static final String GROUND_2 = "2"; - private static final String GROUND_2A = "2A"; - private static final String GROUND_2ZA = "2ZA"; - private static final String GROUND_3 = "3"; - private static final String GROUND_4 = "4"; - private static final String GROUND_5 = "5"; - private static final String GROUND_6 = "6"; - private static final String GROUND_7 = "7"; - private static final String GROUND_7A = "7A"; - private static final String GROUND_7B = "7B"; - private static final String GROUND_8 = "8"; - private static final String GROUND_9 = "9"; - private static final String GROUND_10 = "10"; - private static final String GROUND_10A = "10A"; - private static final String GROUND_11 = "11"; - private static final String GROUND_12 = "12"; - private static final String GROUND_13 = "13"; - private static final String GROUND_14 = "14"; - private static final String GROUND_14A = "14A"; - private static final String GROUND_14ZA = "14ZA"; - private static final String GROUND_15 = "15"; - private static final String GROUND_15A = "15A"; - private static final String GROUND_16 = "16"; - private static final String GROUND_17 = "17"; - private static final String GROUND_A = "A"; - private static final String GROUND_B = "B"; - private static final String GROUND_C = "C"; - private static final String GROUND_D = "D"; - private static final String GROUND_E = "E"; - private static final String GROUND_F = "F"; - private static final String GROUND_G = "G"; - private static final String GROUND_H = "H"; - private static final String GROUND_I = "I"; - private static final String SECTION_157 = "157"; - private static final String SECTION_170 = "170"; - private static final String SECTION_178 = "178"; - private static final String SECTION_181 = "181"; - private static final String SECTION_186 = "186"; - private static final String SECTION_187 = "187"; - private static final String SECTION_191 = "191"; - private static final String SECTION_199 = "199"; + + private final GroundsBuilder groundsBuilder; + private final RentArrearsTabDetailsBuilder rentArrearsTabDetailsBuilder; + private final ReasonsForPossessionTabDetailsBuilder reasonsForPossessionTabDetailsBuilder; + private final ClaimantInformationTabDetailsBuilder claimantInformationTabDetailsBuilder; + private final DefendantInformationTabDetailsBuilder defendantInformationTabDetailsBuilder; + private final AdditionalDefendantInformationTabDetailsBuilder additionalDefendantInformationTabDetailsBuilder; public SummaryTab buildSummaryTab(PCSCase pcsCase) { - ReasonsForPossessionTabDetails reasonsForPossession = buildReasonsForPossession(pcsCase); + ReasonsForPossessionTabDetails reasonsForPossession = + reasonsForPossessionTabDetailsBuilder.buildSummaryReasonsForPossession(pcsCase); String dateSubmitted = formatSubmittedDate(pcsCase.getDateSubmitted()); return SummaryTab.builder() .repossessedPropertyAddress(pcsCase.getPropertyAddress()) .groundsForPossession(GroundsForPossessionTabDetails.builder() - .grounds(getGrounds(pcsCase)) + .grounds(groundsBuilder.getGrounds(pcsCase)) .build()) .reasonsForPossession(reasonsForPossession) .dateClaimSubmitted(dateSubmitted) - .claimantDetails(createSummaryClaimantTabDetails(pcsCase)) - .defendantDetails(createSummaryDefendantOneDetails(pcsCase)) - .additionalDefendants(createAdditionalSummaryDefendantsDetails(pcsCase)) - .rentArrearsDetails(buildRentArrearsTabDetails(pcsCase)) + .claimantDetails(claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase)) + .defendantDetails(defendantInformationTabDetailsBuilder.buildSummaryDefendantOneDetails(pcsCase)) + .additionalDefendants( + additionalDefendantInformationTabDetailsBuilder.buildSummaryAdditionalDefendantsDetails(pcsCase) + ) + .rentArrearsDetails(rentArrearsTabDetailsBuilder.buildRentArrearsTabDetails(pcsCase)) .tenancyDetails(buildTenancyTabDetails(pcsCase)) .noticeDetails(buildNoticeTabDetails(pcsCase)) .build(); @@ -142,278 +78,6 @@ private String formatSubmittedDate(LocalDateTime dateSubmitted) { return ukDateSubmitted.format(SUBMITTED_DATE_FORMATTER).replace("am", "AM").replace("pm", "PM"); } - private ClaimantInformationTabDetails createSummaryClaimantTabDetails(PCSCase pcsCase) { - String claimantName = getSummaryClaimantName(pcsCase); - if (claimantName == null) { - return null; - } - - return ClaimantInformationTabDetails.builder() - .claimantName(claimantName) - .build(); - } - - private String getSummaryClaimantName(PCSCase pcsCase) { - ClaimantInformation claimantInformation = pcsCase.getClaimantInformation(); - if (claimantInformation != null) { - if (claimantInformation.getOrgNameFound() == NO) { - return claimantInformation.getFallbackClaimantName(); - } - - if (claimantInformation.getIsClaimantNameCorrect() == VerticalYesNo.NO) { - return claimantInformation.getOverriddenClaimantName(); - } - - if (claimantInformation.getClaimantName() != null) { - return claimantInformation.getClaimantName(); - } - } - - if (CollectionUtils.isEmpty(pcsCase.getAllClaimants())) { - return null; - } - - return pcsCase.getAllClaimants().getFirst().getValue().getOrgName(); - } - - private DefendantInformationTabDetails createSummaryDefendantOneDetails(PCSCase pcsCase) { - if (CollectionUtils.isEmpty(pcsCase.getAllDefendants())) { - return null; - } - - return createSummaryDefendantDetails(pcsCase.getAllDefendants().getFirst().getValue(), pcsCase); - } - - private List> createAdditionalSummaryDefendantsDetails( - PCSCase pcsCase) { - if (CollectionUtils.isEmpty(pcsCase.getAllDefendants()) || pcsCase.getAllDefendants().size() < 2) { - return null; - } - - return pcsCase.getAllDefendants().stream() - .skip(1) - .map(ListValue::getValue) - .map(defendant -> createAdditionalSummaryDefendantDetails(defendant, pcsCase)) - .filter(defendantDetails -> defendantDetails != null) - .map(defendantDetails -> ListValue.builder() - .value(defendantDetails) - .build()) - .toList(); - } - - private AdditionalDefendantInformationTabDetails createAdditionalSummaryDefendantDetails(Party defendant, - PCSCase pcsCase) { - AddressUK addressForService = getSummaryDefendantAddressForService(defendant, pcsCase); - - if (defendant.getNameKnown() != VerticalYesNo.YES && addressForService == null) { - return null; - } - - return AdditionalDefendantInformationTabDetails.builder() - .firstName(getDefendantFirstName(defendant)) - .lastName(getDefendantLastName(defendant)) - .addressForService(addressForService) - .build(); - } - - private DefendantInformationTabDetails createSummaryDefendantDetails(Party defendant, PCSCase pcsCase) { - AddressUK addressForService = getSummaryDefendantAddressForService(defendant, pcsCase); - - if (defendant.getNameKnown() != VerticalYesNo.YES && addressForService == null) { - return null; - } - - return DefendantInformationTabDetails.builder() - .firstName(getDefendantFirstName(defendant)) - .lastName(getDefendantLastName(defendant)) - .addressForService(addressForService) - .build(); - } - - private String getDefendantFirstName(Party defendant) { - return defendant.getNameKnown() == VerticalYesNo.YES ? defendant.getFirstName() : CaseTabView.NAME_UNKNOWN; - } - - private String getDefendantLastName(Party defendant) { - return defendant.getNameKnown() == VerticalYesNo.YES ? defendant.getLastName() : CaseTabView.NAME_UNKNOWN; - } - - private AddressUK getSummaryDefendantAddressForService(Party defendant, PCSCase pcsCase) { - if (defendant.getAddressKnown() != VerticalYesNo.YES) { - return pcsCase.getPropertyAddress(); - } - - return defendant.getAddress() != null ? defendant.getAddress() : pcsCase.getPropertyAddress(); - } - - private ReasonsForPossessionTabDetails buildReasonsForPossession(PCSCase pcsCase) { - AdditionalReasons additionalReasons = pcsCase.getAdditionalReasonsForPossession(); - ReasonsForPossessionTabDetails reasonsForPossession = - buildReasonsForPossessionFromGroundSummaries(pcsCase); - String additionalReasonsText = additionalReasons == null - || additionalReasons.getHasReasons() != VerticalYesNo.YES ? null : additionalReasons.getReasons(); - - if (reasonsForPossession == null && additionalReasonsText == null) { - return null; - } - - if (reasonsForPossession == null) { - reasonsForPossession = ReasonsForPossessionTabDetails.builder().build(); - } - - reasonsForPossession.setAdditionalReasonsForPossession(additionalReasonsText); - return reasonsForPossession; - } - - private ReasonsForPossessionTabDetails buildReasonsForPossessionFromGroundSummaries(PCSCase pcsCase) { - if (CollectionUtils.isEmpty(pcsCase.getClaimGroundSummaries())) { - return null; - } - - ReasonsForPossessionTabDetails reasonsForPossession = ReasonsForPossessionTabDetails.builder().build(); - boolean hasReason = false; - - for (ListValue listValue : pcsCase.getClaimGroundSummaries()) { - ClaimGroundSummary summary = listValue.getValue(); - if (summary == null || !StringUtils.hasText(summary.getReason())) { - continue; - } - - setGroundReason(reasonsForPossession, summary.getLabel(), summary.getReason()); - hasReason = true; - } - - return hasReason ? reasonsForPossession : null; - } - - private void setGroundReason(ReasonsForPossessionTabDetails reasonsForPossession, - String groundLabel, - String reason) { - Matcher groundMatcher = GROUND_REFERENCE_PATTERN.matcher(groundLabel); - if (groundMatcher.find()) { - setGroundNumberReason(reasonsForPossession, groundMatcher.group(1), reason); - return; - } - - Matcher sectionMatcher = SECTION_REFERENCE_PATTERN.matcher(groundLabel); - if (sectionMatcher.find()) { - setSectionReason(reasonsForPossession, sectionMatcher.group(1), reason); - return; - } - - if (groundLabel.startsWith(SECTION_84A_CONDITION_1_PREFIX)) { - reasonsForPossession.setCondition1OfSection84A(reason); - } else if (groundLabel.startsWith(SECTION_84A_CONDITION_2_PREFIX)) { - reasonsForPossession.setCondition2OfSection84A(reason); - } else if (groundLabel.startsWith(SECTION_84A_CONDITION_3_PREFIX)) { - reasonsForPossession.setCondition3OfSection84A(reason); - } else if (groundLabel.startsWith(SECTION_84A_CONDITION_4_PREFIX)) { - reasonsForPossession.setCondition4OfSection84A(reason); - } else if (groundLabel.startsWith(SECTION_84A_CONDITION_5_PREFIX)) { - reasonsForPossession.setCondition5OfSection84A(reason); - } else if (ANTISOCIAL_BEHAVIOUR.equals(groundLabel)) { - reasonsForPossession.setAntisocialBehaviour(reason); - } else if (BREACH_OF_THE_TENANCY.equals(groundLabel)) { - reasonsForPossession.setBreachOfTheTenancy(reason); - } else if (ABSOLUTE_GROUNDS.equals(groundLabel)) { - reasonsForPossession.setAbsoluteGrounds(reason); - } else if (OTHER.equals(groundLabel) || OTHER_GROUNDS.equals(groundLabel)) { - reasonsForPossession.setOtherGrounds(reason); - } else if (NO_GROUNDS.equals(groundLabel)) { - reasonsForPossession.setNoGrounds(reason); - } else if (groundLabel.contains(PARAGRAPH_25B_2_SCHEDULE_12)) { - reasonsForPossession.setParagraph25B2Schedule12(reason); - } - } - - private void setGroundNumberReason(ReasonsForPossessionTabDetails reasonsForPossession, - String ground, - String reason) { - switch (ground) { - case GROUND_1 -> reasonsForPossession.setGround1(reason); - case GROUND_2 -> reasonsForPossession.setGround2(reason); - case GROUND_2A -> reasonsForPossession.setGround2A(reason); - case GROUND_2ZA -> reasonsForPossession.setGround2ZA(reason); - case GROUND_3 -> reasonsForPossession.setGround3(reason); - case GROUND_4 -> reasonsForPossession.setGround4(reason); - case GROUND_5 -> reasonsForPossession.setGround5(reason); - case GROUND_6 -> reasonsForPossession.setGround6(reason); - case GROUND_7 -> reasonsForPossession.setGround7(reason); - case GROUND_7A -> reasonsForPossession.setGround7A(reason); - case GROUND_7B -> reasonsForPossession.setGround7B(reason); - case GROUND_8 -> reasonsForPossession.setGround8(reason); - case GROUND_9 -> reasonsForPossession.setGround9(reason); - case GROUND_10 -> reasonsForPossession.setGround10(reason); - case GROUND_10A -> reasonsForPossession.setGround10A(reason); - case GROUND_11 -> reasonsForPossession.setGround11(reason); - case GROUND_12 -> reasonsForPossession.setGround12(reason); - case GROUND_13 -> reasonsForPossession.setGround13(reason); - case GROUND_14 -> reasonsForPossession.setGround14(reason); - case GROUND_14A -> reasonsForPossession.setGround14A(reason); - case GROUND_14ZA -> reasonsForPossession.setGround14ZA(reason); - case GROUND_15 -> reasonsForPossession.setGround15(reason); - case GROUND_15A -> reasonsForPossession.setGround15A(reason); - case GROUND_16 -> reasonsForPossession.setGround16(reason); - case GROUND_17 -> reasonsForPossession.setGround17(reason); - case GROUND_A -> reasonsForPossession.setGroundA(reason); - case GROUND_B -> reasonsForPossession.setGroundB(reason); - case GROUND_C -> reasonsForPossession.setGroundC(reason); - case GROUND_D -> reasonsForPossession.setGroundD(reason); - case GROUND_E -> reasonsForPossession.setGroundE(reason); - case GROUND_F -> reasonsForPossession.setGroundF(reason); - case GROUND_G -> reasonsForPossession.setGroundG(reason); - case GROUND_H -> reasonsForPossession.setGroundH(reason); - case GROUND_I -> reasonsForPossession.setGroundI(reason); - default -> { - } - } - } - - private void setSectionReason(ReasonsForPossessionTabDetails reasonsForPossession, - String section, - String reason) { - switch (section) { - case SECTION_157 -> reasonsForPossession.setSection157(reason); - case SECTION_170 -> reasonsForPossession.setSection170(reason); - case SECTION_178 -> reasonsForPossession.setSection178(reason); - case SECTION_181 -> reasonsForPossession.setSection181(reason); - case SECTION_186 -> reasonsForPossession.setSection186(reason); - case SECTION_187 -> reasonsForPossession.setSection187(reason); - case SECTION_191 -> reasonsForPossession.setSection191(reason); - case SECTION_199 -> reasonsForPossession.setSection199(reason); - default -> { - } - } - } - - private RentArrearsTabDetails buildRentArrearsTabDetails(PCSCase pcsCase) { - RentDetails rentDetails = pcsCase.getRentDetails(); - RentArrearsSection rentArrears = pcsCase.getRentArrears(); - - String rentAmount = rentDetails == null ? null : formatMoney(rentDetails.getCurrentRent()); - String calculationFrequency = getRentCalculationFrequency(rentDetails); - String dailyRate = getDailyRate(rentDetails); - String arrearsTotal = rentArrears == null ? null : formatMoney(rentArrears.getTotal()); - String judgmentRequested = pcsCase.getArrearsJudgmentWanted() == null - ? null : pcsCase.getArrearsJudgmentWanted().getLabel(); - - if (rentAmount == null - && calculationFrequency == null - && dailyRate == null - && arrearsTotal == null - && judgmentRequested == null) { - return null; - } - - return RentArrearsTabDetails.builder() - .rentAmount(rentAmount) - .calculationFrequency(calculationFrequency) - .dailyRate(dailyRate) - .arrearsTotal(arrearsTotal) - .judgmentRequested(judgmentRequested) - .build(); - } - private TenancyTabDetails buildTenancyTabDetails(PCSCase pcsCase) { TenancyLicenceDetails tenancyLicenceDetails = pcsCase.getTenancyLicenceDetails(); OccupationLicenceDetailsWales occupationLicenceDetailsWales = pcsCase.getOccupationLicenceDetailsWales(); @@ -473,97 +137,4 @@ private NoticeTabDetails buildNoticeTabDetails(PCSCase pcsCase) { .noticeServedDate(noticeServedDetails.getNoticeEmailSentDateTime().format(SUMMARY_DATE_FORMATTER)) .build(); } - - private String getRentCalculationFrequency(RentDetails rentDetails) { - if (rentDetails == null || rentDetails.getFrequency() == null) { - return null; - } - - if (rentDetails.getFrequency() == RentPaymentFrequency.OTHER && rentDetails.getOtherFrequency() != null) { - return rentDetails.getOtherFrequency(); - } - - return rentDetails.getFrequency().getLabel(); - } - - private String getDailyRate(RentDetails rentDetails) { - if (rentDetails == null) { - return null; - } - - if (rentDetails.getPerDayCorrect() == VerticalYesNo.NO && rentDetails.getAmendedDailyCharge() != null) { - return formatMoney(rentDetails.getAmendedDailyCharge()); - } - - if (rentDetails.getDailyCharge() != null) { - return formatMoney(rentDetails.getDailyCharge()); - } - - if (rentDetails.getFormattedCalculatedDailyCharge() != null) { - return rentDetails.getFormattedCalculatedDailyCharge(); - } - - return formatMoney(rentDetails.getCalculatedDailyCharge()); - } - - private String formatMoney(BigDecimal amount) { - if (amount == null) { - return null; - } - - if (amount.stripTrailingZeros().scale() <= 0) { - amount = amount.stripTrailingZeros(); - } - - return "£" + amount.toPlainString(); - } - - private String getGrounds(PCSCase pcsCase) { - if (CollectionUtils.isEmpty(pcsCase.getClaimGroundSummaries())) { - return null; - } - - List grounds = new ArrayList<>(pcsCase.getClaimGroundSummaries().stream() - .map(ListValue::getValue) - .map(ClaimGroundSummary::getLabel) - .toList()); - - groupSection84AConditions(grounds); - - return grounds.stream() - .reduce((firstGround, secondGround) -> firstGround + "\n" + secondGround) - .orElse(null); - } - - private void groupSection84AConditions(List grounds) { - List section84AConditions = grounds.stream() - .filter(this::isSection84ACondition) - .sorted(this::compareSection84AConditions) - .toList(); - - if (section84AConditions.isEmpty()) { - return; - } - - int antisocialIndex = grounds.indexOf(ANTISOCIAL_BEHAVIOUR); - int groupIndex = antisocialIndex >= 0 ? antisocialIndex : grounds.indexOf(section84AConditions.getFirst()); - grounds.set(groupIndex, ANTISOCIAL_BEHAVIOUR + ": " + String.join(", ", section84AConditions)); - grounds.removeAll(section84AConditions); - } - - private boolean isSection84ACondition(String label) { - return SECTION_84A_CONDITION_PATTERN.matcher(label).matches(); - } - - private int compareSection84AConditions(String firstCondition, String secondCondition) { - return Integer.compare( - getSection84AConditionNumber(firstCondition), - getSection84AConditionNumber(secondCondition) - ); - } - - private int getSection84AConditionNumber(String label) { - Matcher matcher = SECTION_84A_CONDITION_PATTERN.matcher(label); - return matcher.matches() ? Integer.parseInt(matcher.group(1)) : 0; - } } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseTabView.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseTabView.java index 329e80d0e0..6ff8c8ae81 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseTabView.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseTabView.java @@ -5,33 +5,47 @@ import org.springframework.util.CollectionUtils; import uk.gov.hmcts.ccd.sdk.type.AddressUK; import uk.gov.hmcts.ccd.sdk.type.ListValue; +import uk.gov.hmcts.reform.pcs.ccd.domain.AlternativesToPossession; import uk.gov.hmcts.reform.pcs.ccd.domain.DefendantDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.DemotionOfTenancy; import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; import uk.gov.hmcts.reform.pcs.ccd.domain.Party; +import uk.gov.hmcts.reform.pcs.ccd.domain.SuspensionOfRightToBuy; +import uk.gov.hmcts.reform.pcs.ccd.domain.SuspensionOfRightToBuyDemotionOfTenancy; +import uk.gov.hmcts.reform.pcs.ccd.domain.UnderlesseeMortgageeDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.ClaimGroundSummary; import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.CasePartiesTab; import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.ClaimantTabDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.DefendantTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details.CaseDetailsTab; import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.summary.SummaryTab; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.ClaimGroundSummaryBuilder; import java.util.ArrayList; import java.util.List; +import java.util.Set; + +import static uk.gov.hmcts.reform.pcs.ccd.domain.AlternativesToPossession.DEMOTION_OF_TENANCY; +import static uk.gov.hmcts.reform.pcs.ccd.domain.AlternativesToPossession.SUSPENSION_OF_RIGHT_TO_BUY; @Component @AllArgsConstructor public class CaseTabView { - static final String NAME_UNKNOWN = "Person unknown"; + public static final String NAME_UNKNOWN = "Person unknown"; private final ClaimGroundSummaryBuilder claimGroundSummaryBuilder; private final CaseSummaryTabView caseSummaryTabView; + private final CaseDetailsTabView caseDetailsTabView; public void setCaseTabFields(PCSCase pcsCase) { CasePartiesTab casePartiesTab = buildCasePartiesTab(pcsCase); SummaryTab summaryTab = caseSummaryTabView.buildSummaryTab(pcsCase); + CaseDetailsTab detailsTab = caseDetailsTabView.buildCaseDetailsTab(pcsCase); pcsCase.setCasePartiesTab(casePartiesTab); pcsCase.setSummaryTab(summaryTab); + pcsCase.setCaseDetailsTab(detailsTab); } public void setDraftCaseTabFields(PCSCase pcsCase, PCSCase draftCaseData) { @@ -39,12 +53,38 @@ public void setDraftCaseTabFields(PCSCase pcsCase, PCSCase draftCaseData) { draftCaseData.setAllDefendants(buildDefendants(draftCaseData)); } + if (CollectionUtils.isEmpty(draftCaseData.getAllUnderlesseeOrMortgagees())) { + draftCaseData.setAllUnderlesseeOrMortgagees(buildUnderlesseeOrMortgageParties(draftCaseData)); + } + + Set alternativesToPossessionSet = draftCaseData.getAlternativesToPossession(); + SuspensionOfRightToBuyDemotionOfTenancy suspensionOfRightToBuyDemotionOfTenancy = + draftCaseData.getSuspensionOfRightToBuyDemotionOfTenancy(); + + if ( + suspensionOfRightToBuyDemotionOfTenancy != null + && !CollectionUtils.isEmpty(alternativesToPossessionSet) + && alternativesToPossessionSet.containsAll(Set.of(SUSPENSION_OF_RIGHT_TO_BUY, DEMOTION_OF_TENANCY)) + ) { + DemotionOfTenancy demotionOfTenancy = draftCaseData.getDemotionOfTenancy(); + if (demotionOfTenancy == null) { + demotionOfTenancy = DemotionOfTenancy.builder().build(); + draftCaseData.setDemotionOfTenancy(demotionOfTenancy); + } + + setDemotionOfTenancy(suspensionOfRightToBuyDemotionOfTenancy, demotionOfTenancy); + draftCaseData.setSuspensionOfRightToBuy( + buildSuspensionOfRightToBuyHousingAct(suspensionOfRightToBuyDemotionOfTenancy) + ); + } + List> draftGrounds = claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData); draftCaseData.setClaimGroundSummaries(draftGrounds); setCaseTabFields(draftCaseData); pcsCase.setSummaryTab(draftCaseData.getSummaryTab()); + pcsCase.setCaseDetailsTab(draftCaseData.getCaseDetailsTab()); } private List> buildDefendants(PCSCase draftCaseData) { @@ -74,6 +114,63 @@ private ListValue buildDefendant(DefendantDetails defendant) { .build(); } + private List> buildUnderlesseeOrMortgageParties(PCSCase draftCaseData) { + UnderlesseeMortgageeDetails underlesseeOrMortgagee1 = draftCaseData.getUnderlesseeOrMortgagee1(); + + if (underlesseeOrMortgagee1 == null) { + return null; + } + + List> underlesseeMortgageParties = new ArrayList<>(); + underlesseeMortgageParties.add(buildUnderlesseeOrMortgageParty(underlesseeOrMortgagee1)); + + List> additionalUnderlesseeOrMortgagee = + draftCaseData.getAdditionalUnderlesseeOrMortgagee(); + if (!CollectionUtils.isEmpty(additionalUnderlesseeOrMortgagee)) { + underlesseeMortgageParties.addAll( + additionalUnderlesseeOrMortgagee.stream() + .map(this::buildUnderlesseeOrMortgageParty) + .toList() + ); + } + + return underlesseeMortgageParties; + } + + private ListValue buildUnderlesseeOrMortgageParty( + ListValue underlesseeMortgageeDetails + ) { + return buildUnderlesseeOrMortgageParty(underlesseeMortgageeDetails.getValue()); + } + + private ListValue buildUnderlesseeOrMortgageParty(UnderlesseeMortgageeDetails underlesseeMortgageeDetails) { + return ListValue.builder() + .value(Party.builder() + .nameKnown(underlesseeMortgageeDetails.getNameKnown()) + .orgName(underlesseeMortgageeDetails.getName()) + .addressKnown(underlesseeMortgageeDetails.getAddressKnown()) + .address(underlesseeMortgageeDetails.getAddress()) + .build()) + .build(); + } + + private void setDemotionOfTenancy( + SuspensionOfRightToBuyDemotionOfTenancy suspensionOfRightToBuyDemotionOfTenancy, + DemotionOfTenancy demotionOfTenancy + ) { + demotionOfTenancy.setHousingAct(suspensionOfRightToBuyDemotionOfTenancy.getDemotionOfTenancyActs()); + demotionOfTenancy.setReason(suspensionOfRightToBuyDemotionOfTenancy.getDemotionOrderReason()); + } + + private SuspensionOfRightToBuy buildSuspensionOfRightToBuyHousingAct( + SuspensionOfRightToBuyDemotionOfTenancy suspensionOfRightToBuyDemotionOfTenancy + ) { + return SuspensionOfRightToBuy.builder() + .housingAct(suspensionOfRightToBuyDemotionOfTenancy.getSuspensionOfRightToBuyActs()) + .reason(suspensionOfRightToBuyDemotionOfTenancy.getSuspensionOrderReason()) + .build(); + } + private CasePartiesTab buildCasePartiesTab(PCSCase pcsCase) { CasePartiesTab tab = CasePartiesTab.builder().build(); diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/NoticeOfPossessionView.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/NoticeOfPossessionView.java index 274e159638..a18a129b74 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/NoticeOfPossessionView.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/NoticeOfPossessionView.java @@ -1,15 +1,20 @@ package uk.gov.hmcts.reform.pcs.ccd.view; import org.springframework.stereotype.Component; +import uk.gov.hmcts.ccd.sdk.type.Document; +import uk.gov.hmcts.ccd.sdk.type.ListValue; +import uk.gov.hmcts.reform.pcs.ccd.domain.DocumentType; import uk.gov.hmcts.reform.pcs.ccd.domain.NoticeServedDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.NoticeServiceMethod; import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; import uk.gov.hmcts.reform.pcs.ccd.domain.WalesNoticeDetails; import uk.gov.hmcts.reform.pcs.ccd.entity.ClaimEntity; +import uk.gov.hmcts.reform.pcs.ccd.entity.DocumentEntity; import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity; import uk.gov.hmcts.reform.pcs.ccd.entity.claim.NoticeOfPossessionEntity; import uk.gov.hmcts.reform.pcs.postcodecourt.model.LegislativeCountry; +import java.util.List; import java.util.Optional; @Component @@ -18,15 +23,20 @@ public class NoticeOfPossessionView { public void setCaseFields(PCSCase pcsCase, PcsCaseEntity pcsCaseEntity) { getMainClaim(pcsCaseEntity) .map(ClaimEntity::getNoticeOfPossession) - .ifPresent(noticeOfPossession -> setNoticeOfPossessionFields(pcsCase, noticeOfPossession)); + .ifPresent(noticeOfPossession -> + setNoticeOfPossessionFields(pcsCase, noticeOfPossession, pcsCaseEntity)); } - private void setNoticeOfPossessionFields(PCSCase pcsCase, NoticeOfPossessionEntity noticeOfPossessionEntity) { + private void setNoticeOfPossessionFields(PCSCase pcsCase, NoticeOfPossessionEntity noticeOfPossessionEntity, + PcsCaseEntity pcsCaseEntity) { NoticeServedDetails noticeServedDetails = new NoticeServedDetails(); NoticeServiceMethod servingMethod = noticeOfPossessionEntity.getServingMethod(); noticeServedDetails.setNoticeServiceMethod(servingMethod); + List> documents = getNoticeStatement(pcsCaseEntity); + noticeServedDetails.setNoticeDocuments(documents); + if (pcsCase.getLegislativeCountry() == LegislativeCountry.WALES) { WalesNoticeDetails walesNoticeDetails = WalesNoticeDetails.builder() .noticeServed(noticeOfPossessionEntity.getNoticeServed()) @@ -72,4 +82,31 @@ private static Optional getMainClaim(PcsCaseEntity pcsCaseEntity) { .findFirst(); } + private static List> getNoticeStatement(PcsCaseEntity pcsCaseEntity) { + if (pcsCaseEntity.getDocuments().isEmpty()) { + return null; + } + + return pcsCaseEntity.getDocuments().stream() + .filter(NoticeOfPossessionView::isNoticeStatement) + .map(NoticeOfPossessionView::toDocument) + .toList(); + } + + private static boolean isNoticeStatement(DocumentEntity documentEntity) { + return documentEntity.getType() == DocumentType.NOTICE_FOR_SERVICE_OUT_OF_JURISDICTION; + } + + private static ListValue toDocument(DocumentEntity documentEntity) { + return ListValue.builder() + .value( + Document.builder() + .url(documentEntity.getUrl()) + .filename(documentEntity.getFileName()) + .binaryUrl(documentEntity.getBinaryUrl()) + .categoryId(documentEntity.getCategoryId()) + .build() + ).build(); + } + } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/RentArrearsView.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/RentArrearsView.java index 2dddb15f9b..f0597cda92 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/RentArrearsView.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/RentArrearsView.java @@ -1,11 +1,17 @@ package uk.gov.hmcts.reform.pcs.ccd.view; import org.springframework.stereotype.Component; +import uk.gov.hmcts.ccd.sdk.type.Document; +import uk.gov.hmcts.ccd.sdk.type.ListValue; +import uk.gov.hmcts.reform.pcs.ccd.domain.DocumentType; import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; import uk.gov.hmcts.reform.pcs.ccd.domain.RentArrearsSection; import uk.gov.hmcts.reform.pcs.ccd.entity.ClaimEntity; +import uk.gov.hmcts.reform.pcs.ccd.entity.DocumentEntity; import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity; import uk.gov.hmcts.reform.pcs.ccd.entity.claim.RentArrearsEntity; + +import java.util.List; import java.util.Optional; @Component @@ -14,15 +20,19 @@ public class RentArrearsView { public void setCaseFields(PCSCase pcsCase, PcsCaseEntity pcsCaseEntity) { getMainClaim(pcsCaseEntity) .map(ClaimEntity::getRentArrears) - .ifPresent(rentArrearsEntity -> setRentArrearsFields(pcsCase, rentArrearsEntity)); + .ifPresent(rentArrearsEntity -> + setRentArrearsFields(pcsCase, rentArrearsEntity, pcsCaseEntity)); } - private void setRentArrearsFields(PCSCase pcsCase, RentArrearsEntity rentArrearsEntity) { + private void setRentArrearsFields(PCSCase pcsCase, RentArrearsEntity rentArrearsEntity, + PcsCaseEntity pcsCaseEntity) { RentArrearsSection rentArrears = new RentArrearsSection(); + List> documents = getRentStatement(pcsCaseEntity); rentArrears.setTotal(rentArrearsEntity.getTotalRentArrears()); rentArrears.setRecoveryAttempted(rentArrearsEntity.getRecoveryAttempted()); rentArrears.setRecoveryAttemptDetails(rentArrearsEntity.getRecoveryAttemptDetails()); + rentArrears.setStatementDocuments(documents); pcsCase.setRentArrears(rentArrears); @@ -34,4 +44,31 @@ private static Optional getMainClaim(PcsCaseEntity pcsCaseEntity) { .findFirst(); } + private static List> getRentStatement(PcsCaseEntity pcsCaseEntity) { + if (pcsCaseEntity.getDocuments().isEmpty()) { + return null; + } + + return pcsCaseEntity.getDocuments().stream() + .filter(RentArrearsView::isRentStatement) + .map(RentArrearsView::toDocument) + .toList(); + } + + private static boolean isRentStatement(DocumentEntity documentEntity) { + return documentEntity.getType() == DocumentType.RENT_STATEMENT; + } + + private static ListValue toDocument(DocumentEntity documentEntity) { + return ListValue.builder() + .value( + Document.builder() + .url(documentEntity.getUrl()) + .filename(documentEntity.getFileName()) + .binaryUrl(documentEntity.getBinaryUrl()) + .categoryId(documentEntity.getCategoryId()) + .build() + ).build(); + } + } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/RentDetailsView.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/RentDetailsView.java index 3e9d0ff21b..188805317f 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/RentDetailsView.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/RentDetailsView.java @@ -1,6 +1,7 @@ package uk.gov.hmcts.reform.pcs.ccd.view; import org.springframework.stereotype.Component; +import uk.gov.hmcts.ccd.sdk.type.YesOrNo; import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; import uk.gov.hmcts.reform.pcs.ccd.domain.RentDetails; import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity; @@ -22,6 +23,7 @@ public void setCaseFields(PCSCase pcsCase, PcsCaseEntity pcsCaseEntity) { .build(); pcsCase.setRentDetails(rentDetails); + pcsCase.setShowRentSectionPage(YesOrNo.YES); } } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/TenancyLicenceView.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/TenancyLicenceView.java index 615b2af92e..283d22d68f 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/TenancyLicenceView.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/TenancyLicenceView.java @@ -1,16 +1,22 @@ package uk.gov.hmcts.reform.pcs.ccd.view; import org.springframework.stereotype.Component; +import uk.gov.hmcts.ccd.sdk.type.Document; +import uk.gov.hmcts.ccd.sdk.type.ListValue; import uk.gov.hmcts.reform.pcs.ccd.domain.CombinedLicenceType; +import uk.gov.hmcts.reform.pcs.ccd.domain.DocumentType; import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; import uk.gov.hmcts.reform.pcs.ccd.domain.TenancyLicenceDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.TenancyLicenceType; import uk.gov.hmcts.reform.pcs.ccd.domain.wales.OccupationLicenceDetailsWales; import uk.gov.hmcts.reform.pcs.ccd.domain.wales.OccupationLicenceTypeWales; +import uk.gov.hmcts.reform.pcs.ccd.entity.DocumentEntity; import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity; import uk.gov.hmcts.reform.pcs.ccd.entity.TenancyLicenceEntity; import uk.gov.hmcts.reform.pcs.postcodecourt.model.LegislativeCountry; +import java.util.List; + @Component public class TenancyLicenceView { @@ -24,11 +30,13 @@ public void setCaseFields(PCSCase pcsCase, PcsCaseEntity pcsCaseEntity) { if (pcsCase.getLegislativeCountry() == LegislativeCountry.WALES) { setOccupationLicenceFields(pcsCase, tenancyLicence); } else { - setTenancyLicenceFields(pcsCase, tenancyLicence); + setTenancyLicenceFields(pcsCase, tenancyLicence, pcsCaseEntity); } } - private static void setTenancyLicenceFields(PCSCase pcsCase, TenancyLicenceEntity tenancyLicence) { + private static void setTenancyLicenceFields(PCSCase pcsCase, TenancyLicenceEntity tenancyLicence, + PcsCaseEntity pcsCaseEntity) { + List> documents = getTenancyLicenceDocument(pcsCaseEntity); CombinedLicenceType combinedLicenceType = tenancyLicence.getType(); TenancyLicenceDetails tenancyLicenceDetails = TenancyLicenceDetails.builder() .typeOfTenancyLicence(TenancyLicenceType.from(combinedLicenceType)) @@ -36,6 +44,7 @@ private static void setTenancyLicenceFields(PCSCase pcsCase, TenancyLicenceEntit .detailsOfOtherTypeOfTenancyLicence(tenancyLicence.getOtherTypeDetails()) .hasCopyOfTenancyLicence(tenancyLicence.getHasCopyOfTenancyLicence()) .reasonsForNoTenancyLicenceDocuments(tenancyLicence.getReasonsForNoTenancyLicence()) + .tenancyLicenceDocuments(documents) .build(); pcsCase.setTenancyLicenceDetails(tenancyLicenceDetails); @@ -53,4 +62,31 @@ private static void setOccupationLicenceFields(PCSCase pcsCase, TenancyLicenceEn pcsCase.setOccupationLicenceDetailsWales(occupationLicence); } + private static List> getTenancyLicenceDocument(PcsCaseEntity pcsCaseEntity) { + if (pcsCaseEntity.getDocuments().isEmpty()) { + return null; + } + + return pcsCaseEntity.getDocuments().stream() + .filter(TenancyLicenceView::isTenancyLicence) + .map(TenancyLicenceView::toDocument) + .toList(); + } + + private static boolean isTenancyLicence(DocumentEntity documentEntity) { + return documentEntity.getType() == DocumentType.TENANCY_LICENCE; + } + + private static ListValue toDocument(DocumentEntity documentEntity) { + return ListValue.builder() + .value( + Document.builder() + .url(documentEntity.getUrl()) + .filename(documentEntity.getFileName()) + .binaryUrl(documentEntity.getBinaryUrl()) + .categoryId(documentEntity.getCategoryId()) + .build() + ).build(); + } + } diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/AdditionalDefendantInformationTabDetailsBuilder.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/AdditionalDefendantInformationTabDetailsBuilder.java new file mode 100644 index 0000000000..df98d5dc51 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/AdditionalDefendantInformationTabDetailsBuilder.java @@ -0,0 +1,91 @@ +package uk.gov.hmcts.reform.pcs.ccd.view.builder; + +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import uk.gov.hmcts.ccd.sdk.type.AddressUK; +import uk.gov.hmcts.ccd.sdk.type.ListValue; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.Party; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.AdditionalDefendantInformationTabDetails; + +import java.util.List; +import java.util.Objects; + +@Component +public class AdditionalDefendantInformationTabDetailsBuilder extends DefendantInformationBuilder { + public List> buildSummaryAdditionalDefendantsDetails( + PCSCase pcsCase) { + if (CollectionUtils.isEmpty(pcsCase.getAllDefendants()) || pcsCase.getAllDefendants().size() < 2) { + return null; + } + + return pcsCase.getAllDefendants().stream() + .skip(1) + .map(ListValue::getValue) + .map(defendant -> createAdditionalSummaryDefendantDetails(defendant, pcsCase)) + .filter(Objects::nonNull) + .map(defendantDetails -> + ListValue.builder() + .value(defendantDetails) + .build()) + .toList(); + } + + public List> buildDetailedAdditionalDefendantsDetails( + PCSCase pcsCase) { + if (CollectionUtils.isEmpty(pcsCase.getAllDefendants()) || pcsCase.getAllDefendants().size() < 2) { + return null; + } + + return pcsCase.getAllDefendants().stream() + .skip(1) + .map(ListValue::getValue) + .map(defendant -> createAdditionalDetailedDefendantDetails(defendant, pcsCase)) + .filter(Objects::nonNull) + .map(defendantDetails -> + ListValue.builder() + .value(defendantDetails) + .build()) + .toList(); + } + + private AdditionalDefendantInformationTabDetails createAdditionalSummaryDefendantDetails(Party defendant, + PCSCase pcsCase) { + AddressUK addressForService = getDefendantAddressForService(defendant, pcsCase); + + if (defendant.getNameKnown() != VerticalYesNo.YES && addressForService == null) { + return null; + } + + return AdditionalDefendantInformationTabDetails.builder() + .firstName(getDefendantFirstName(defendant)) + .lastName(getDefendantLastName(defendant)) + .addressForService(addressForService) + .build(); + } + + private AdditionalDefendantInformationTabDetails createAdditionalDetailedDefendantDetails(Party defendant, + PCSCase pcsCase) { + VerticalYesNo nameKnown = defendant.getNameKnown(); + VerticalYesNo addressKnown = defendant.getAddressKnown(); + + AdditionalDefendantInformationTabDetails additionalDefendantInformationTabDetails = + AdditionalDefendantInformationTabDetails.builder() + .nameKnown(nameKnown != null ? nameKnown.getLabel() : null) + .addressKnown(addressKnown != null ? addressKnown.getLabel() : null) + .build(); + + if (nameKnown == VerticalYesNo.YES) { + additionalDefendantInformationTabDetails.setFirstName(getDefendantFirstName(defendant)); + additionalDefendantInformationTabDetails.setLastName(getDefendantLastName(defendant)); + } + + if (addressKnown == VerticalYesNo.YES) { + AddressUK addressForService = getDefendantAddressForService(defendant, pcsCase); + additionalDefendantInformationTabDetails.setAddressForService(addressForService); + } + + return additionalDefendantInformationTabDetails; + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/ClaimGroundSummaryBuilder.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ClaimGroundSummaryBuilder.java similarity index 94% rename from src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/ClaimGroundSummaryBuilder.java rename to src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ClaimGroundSummaryBuilder.java index 86adadb10b..d6338b8cec 100644 --- a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/ClaimGroundSummaryBuilder.java +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ClaimGroundSummaryBuilder.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.pcs.ccd.view; +package uk.gov.hmcts.reform.pcs.ccd.view.builder; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -12,7 +12,9 @@ import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.AssuredAdditionalOtherGround; import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.AssuredDiscretionaryGround; import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.AssuredMandatoryGround; +import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.AssuredNoArrearsPossessionGrounds; import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.AssuredRentArrearsGround; +import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.AssuredRentArrearsPossessionGrounds; import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.ClaimGroundSummary; import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.IntroductoryDemotedOtherGroundReason; import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.IntroductoryDemotedOtherGroundsForPossession; @@ -283,12 +285,33 @@ private void addGrounds(List> summaries, .code(((Enum) ground).name()) .label(ground.getLabel()) .reason(getDraftReason(draftCaseData, ground)) + .description(getDescription(draftCaseData, ground)) .build()) .map(summary -> ListValue.builder().value(summary).build()) .forEach(summaries::add); } } + private String getDescription(PCSCase draftCaseData, PossessionGroundEnum ground) { + if (ground == IntroductoryDemotedOrOtherGrounds.OTHER) { + IntroductoryDemotedOtherGroundsForPossession otherGroundsForPossession = + draftCaseData.getIntroductoryDemotedOrOtherGroundsForPossession(); + return otherGroundsForPossession != null ? otherGroundsForPossession.getOtherGroundDescription() : null; + } + + if (ground == AssuredAdditionalOtherGround.OTHER) { + if (draftCaseData.getClaimDueToRentArrears() == YesOrNo.YES) { + AssuredRentArrearsPossessionGrounds grounds = draftCaseData.getAssuredRentArrearsPossessionGrounds(); + return grounds != null ? grounds.getAdditionalOtherGroundDescription() : null; + } else { + AssuredNoArrearsPossessionGrounds grounds = draftCaseData.getNoRentArrearsGroundsOptions(); + return grounds != null ? grounds.getOtherGroundDescription() : null; + } + } + + return null; + } + private String getDraftReason(PCSCase draftCaseData, PossessionGroundEnum ground) { String reason = getAssuredDraftReason(draftCaseData, ground); if (reason != null) { diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ClaimantInformationTabDetailsBuilder.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ClaimantInformationTabDetailsBuilder.java new file mode 100644 index 0000000000..9b1a8882b8 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ClaimantInformationTabDetailsBuilder.java @@ -0,0 +1,48 @@ +package uk.gov.hmcts.reform.pcs.ccd.view.builder; + +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import uk.gov.hmcts.reform.pcs.ccd.domain.ClaimantInformation; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.ClaimantInformationTabDetails; + +import static uk.gov.hmcts.ccd.sdk.type.YesOrNo.NO; + +@Component +public class ClaimantInformationTabDetailsBuilder { + + public ClaimantInformationTabDetails createSummaryClaimantTabDetails(PCSCase pcsCase) { + String claimantName = getSummaryClaimantName(pcsCase); + if (claimantName == null) { + return null; + } + + return ClaimantInformationTabDetails.builder() + .claimantName(claimantName) + .build(); + } + + private String getSummaryClaimantName(PCSCase pcsCase) { + ClaimantInformation claimantInformation = pcsCase.getClaimantInformation(); + if (claimantInformation != null) { + if (claimantInformation.getOrgNameFound() == NO) { + return claimantInformation.getFallbackClaimantName(); + } + + if (claimantInformation.getIsClaimantNameCorrect() == VerticalYesNo.NO) { + return claimantInformation.getOverriddenClaimantName(); + } + + if (claimantInformation.getClaimantName() != null) { + return claimantInformation.getClaimantName(); + } + } + + if (CollectionUtils.isEmpty(pcsCase.getAllClaimants())) { + return null; + } + + return pcsCase.getAllClaimants().getFirst().getValue().getOrgName(); + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/DefendantInformationBuilder.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/DefendantInformationBuilder.java new file mode 100644 index 0000000000..5cf49a9f10 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/DefendantInformationBuilder.java @@ -0,0 +1,26 @@ +package uk.gov.hmcts.reform.pcs.ccd.view.builder; + + +import uk.gov.hmcts.ccd.sdk.type.AddressUK; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.Party; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; +import uk.gov.hmcts.reform.pcs.ccd.view.CaseTabView; + +public class DefendantInformationBuilder { + protected AddressUK getDefendantAddressForService(Party defendant, PCSCase pcsCase) { + if (defendant.getAddressKnown() != VerticalYesNo.YES) { + return pcsCase.getPropertyAddress(); + } + + return defendant.getAddress() != null ? defendant.getAddress() : pcsCase.getPropertyAddress(); + } + + protected String getDefendantFirstName(Party defendant) { + return defendant.getNameKnown() == VerticalYesNo.YES ? defendant.getFirstName() : CaseTabView.NAME_UNKNOWN; + } + + protected String getDefendantLastName(Party defendant) { + return defendant.getNameKnown() == VerticalYesNo.YES ? defendant.getLastName() : CaseTabView.NAME_UNKNOWN; + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/DefendantInformationTabDetailsBuilder.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/DefendantInformationTabDetailsBuilder.java new file mode 100644 index 0000000000..ed815d8bc8 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/DefendantInformationTabDetailsBuilder.java @@ -0,0 +1,65 @@ +package uk.gov.hmcts.reform.pcs.ccd.view.builder; + +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import uk.gov.hmcts.ccd.sdk.type.AddressUK; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.Party; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.DefendantInformationTabDetails; + +@Component +public class DefendantInformationTabDetailsBuilder extends DefendantInformationBuilder { + + public DefendantInformationTabDetails buildSummaryDefendantOneDetails(PCSCase pcsCase) { + if (CollectionUtils.isEmpty(pcsCase.getAllDefendants())) { + return null; + } + + return createSummaryDefendantDetails(pcsCase.getAllDefendants().getFirst().getValue(), pcsCase); + } + + public DefendantInformationTabDetails buildDetailedDefendantDetails(PCSCase pcsCase) { + if (CollectionUtils.isEmpty(pcsCase.getAllDefendants())) { + return null; + } + + return createDetailedDefendantDetails(pcsCase.getAllDefendants().getFirst().getValue(), pcsCase); + } + + private DefendantInformationTabDetails createSummaryDefendantDetails(Party defendant, PCSCase pcsCase) { + AddressUK addressForService = getDefendantAddressForService(defendant, pcsCase); + + if (defendant.getNameKnown() != VerticalYesNo.YES && addressForService == null) { + return null; + } + + return DefendantInformationTabDetails.builder() + .firstName(getDefendantFirstName(defendant)) + .lastName(getDefendantLastName(defendant)) + .addressForService(addressForService) + .build(); + } + + private DefendantInformationTabDetails createDetailedDefendantDetails(Party defendant, PCSCase pcsCase) { + VerticalYesNo nameKnown = defendant.getNameKnown(); + VerticalYesNo addressKnown = defendant.getAddressKnown(); + + DefendantInformationTabDetails defendantInformationTabDetails = DefendantInformationTabDetails.builder() + .nameKnown(nameKnown != null ? nameKnown.getLabel() : null) + .addressKnown(addressKnown != null ? addressKnown.getLabel() : null) + .build(); + + if (nameKnown == VerticalYesNo.YES) { + defendantInformationTabDetails.setFirstName(getDefendantFirstName(defendant)); + defendantInformationTabDetails.setLastName(getDefendantLastName(defendant)); + } + + if (addressKnown == VerticalYesNo.YES) { + AddressUK addressForService = getDefendantAddressForService(defendant, pcsCase); + defendantInformationTabDetails.setAddressForService(addressForService); + } + + return defendantInformationTabDetails; + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/GroundsBuilder.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/GroundsBuilder.java new file mode 100644 index 0000000000..18035e93ba --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/GroundsBuilder.java @@ -0,0 +1,69 @@ +package uk.gov.hmcts.reform.pcs.ccd.view.builder; + +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import uk.gov.hmcts.ccd.sdk.type.ListValue; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.ClaimGroundSummary; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +@Component +public class GroundsBuilder { + + private static final String ANTISOCIAL_BEHAVIOUR = "Antisocial behaviour"; + private static final Pattern SECTION_84A_CONDITION_PATTERN = + Pattern.compile("^Condition ([1-5]) of Section 84A of the Housing Act 1985$"); + + public String getGrounds(PCSCase pcsCase) { + if (CollectionUtils.isEmpty(pcsCase.getClaimGroundSummaries())) { + return null; + } + + List grounds = new ArrayList<>(pcsCase.getClaimGroundSummaries().stream() + .map(ListValue::getValue) + .map(ClaimGroundSummary::getLabel) + .toList()); + + groupSection84AConditions(grounds); + + return grounds.stream() + .reduce((firstGround, secondGround) -> firstGround + "\n" + secondGround) + .orElse(null); + } + + private void groupSection84AConditions(List grounds) { + List section84AConditions = grounds.stream() + .filter(this::isSection84ACondition) + .sorted(this::compareSection84AConditions) + .toList(); + + if (section84AConditions.isEmpty()) { + return; + } + + int antisocialIndex = grounds.indexOf(ANTISOCIAL_BEHAVIOUR); + int groupIndex = antisocialIndex >= 0 ? antisocialIndex : grounds.indexOf(section84AConditions.getFirst()); + grounds.set(groupIndex, ANTISOCIAL_BEHAVIOUR + ": " + String.join(", ", section84AConditions)); + grounds.removeAll(section84AConditions); + } + + private boolean isSection84ACondition(String label) { + return SECTION_84A_CONDITION_PATTERN.matcher(label).matches(); + } + + private int compareSection84AConditions(String firstCondition, String secondCondition) { + return Integer.compare( + getSection84AConditionNumber(firstCondition), + getSection84AConditionNumber(secondCondition) + ); + } + + private int getSection84AConditionNumber(String label) { + Matcher matcher = SECTION_84A_CONDITION_PATTERN.matcher(label); + return matcher.matches() ? Integer.parseInt(matcher.group(1)) : 0; + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ReasonsForPossessionTabDetailsBuilder.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ReasonsForPossessionTabDetailsBuilder.java new file mode 100644 index 0000000000..15d17cfd49 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ReasonsForPossessionTabDetailsBuilder.java @@ -0,0 +1,239 @@ +package uk.gov.hmcts.reform.pcs.ccd.view.builder; + +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; +import uk.gov.hmcts.ccd.sdk.type.ListValue; +import uk.gov.hmcts.reform.pcs.ccd.domain.AdditionalReasons; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.ClaimGroundSummary; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.ReasonsForPossessionTabDetails; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +@Component +public class ReasonsForPossessionTabDetailsBuilder { + + private static final Pattern GROUND_REFERENCE_PATTERN = + Pattern.compile("\\(ground ([^)]+)\\)", Pattern.CASE_INSENSITIVE); + private static final Pattern SECTION_REFERENCE_PATTERN = + Pattern.compile("\\(section ([^)]+)\\)", Pattern.CASE_INSENSITIVE); + private static final String ANTISOCIAL_BEHAVIOUR = "Antisocial behaviour"; + private static final String SECTION_84A_CONDITION_1_PREFIX = "Condition 1"; + private static final String SECTION_84A_CONDITION_2_PREFIX = "Condition 2"; + private static final String SECTION_84A_CONDITION_3_PREFIX = "Condition 3"; + private static final String SECTION_84A_CONDITION_4_PREFIX = "Condition 4"; + private static final String SECTION_84A_CONDITION_5_PREFIX = "Condition 5"; + private static final String BREACH_OF_THE_TENANCY = "Breach of the tenancy"; + private static final String ABSOLUTE_GROUNDS = "Absolute grounds"; + private static final String OTHER = "Other"; + private static final String OTHER_GROUNDS = "Other grounds"; + private static final String NO_GROUNDS = "No grounds"; + private static final String PARAGRAPH_25B_2_SCHEDULE_12 = "paragraph 25B(2) of Schedule 12"; + private static final String GROUND_1 = "1"; + private static final String GROUND_2 = "2"; + private static final String GROUND_2A = "2A"; + private static final String GROUND_2ZA = "2ZA"; + private static final String GROUND_3 = "3"; + private static final String GROUND_4 = "4"; + private static final String GROUND_5 = "5"; + private static final String GROUND_6 = "6"; + private static final String GROUND_7 = "7"; + private static final String GROUND_7A = "7A"; + private static final String GROUND_7B = "7B"; + private static final String GROUND_8 = "8"; + private static final String GROUND_9 = "9"; + private static final String GROUND_10 = "10"; + private static final String GROUND_10A = "10A"; + private static final String GROUND_11 = "11"; + private static final String GROUND_12 = "12"; + private static final String GROUND_13 = "13"; + private static final String GROUND_14 = "14"; + private static final String GROUND_14A = "14A"; + private static final String GROUND_14ZA = "14ZA"; + private static final String GROUND_15 = "15"; + private static final String GROUND_15A = "15A"; + private static final String GROUND_16 = "16"; + private static final String GROUND_17 = "17"; + private static final String GROUND_A = "A"; + private static final String GROUND_B = "B"; + private static final String GROUND_C = "C"; + private static final String GROUND_D = "D"; + private static final String GROUND_E = "E"; + private static final String GROUND_F = "F"; + private static final String GROUND_G = "G"; + private static final String GROUND_H = "H"; + private static final String GROUND_I = "I"; + private static final String SECTION_157 = "157"; + private static final String SECTION_170 = "170"; + private static final String SECTION_178 = "178"; + private static final String SECTION_181 = "181"; + private static final String SECTION_186 = "186"; + private static final String SECTION_187 = "187"; + private static final String SECTION_191 = "191"; + private static final String SECTION_199 = "199"; + + public ReasonsForPossessionTabDetails buildSummaryReasonsForPossession(PCSCase pcsCase) { + AdditionalReasons additionalReasons = pcsCase.getAdditionalReasonsForPossession(); + ReasonsForPossessionTabDetails reasonsForPossession = + buildReasonsForPossessionFromGroundSummaries(pcsCase); + String additionalReasonsText = additionalReasons == null + || additionalReasons.getHasReasons() != VerticalYesNo.YES ? null : additionalReasons.getReasons(); + + if (reasonsForPossession == null && additionalReasonsText == null) { + return null; + } + + if (reasonsForPossession == null) { + reasonsForPossession = ReasonsForPossessionTabDetails.builder().build(); + } + + reasonsForPossession.setAdditionalReasonsForPossession(additionalReasonsText); + return reasonsForPossession; + } + + public ReasonsForPossessionTabDetails buildDetailsReasonsForPossession(PCSCase pcsCase) { + ReasonsForPossessionTabDetails reasonsForPossession = + buildReasonsForPossessionFromGroundSummaries(pcsCase); + + if (reasonsForPossession == null) { + return null; + } + + AdditionalReasons additionalReasons = pcsCase.getAdditionalReasonsForPossession(); + + if (additionalReasons != null) { + VerticalYesNo hasReasons = additionalReasons.getHasReasons(); + reasonsForPossession.setHasAdditionalReasons(hasReasons != null ? hasReasons.getLabel() : null); + + if (hasReasons == VerticalYesNo.YES) { + reasonsForPossession.setAdditionalReasonsDetails(additionalReasons.getReasons()); + } + } + + return reasonsForPossession; + } + + private ReasonsForPossessionTabDetails buildReasonsForPossessionFromGroundSummaries(PCSCase pcsCase) { + if (CollectionUtils.isEmpty(pcsCase.getClaimGroundSummaries())) { + return null; + } + + ReasonsForPossessionTabDetails reasonsForPossession = ReasonsForPossessionTabDetails.builder().build(); + boolean hasReason = false; + + for (ListValue listValue : pcsCase.getClaimGroundSummaries()) { + ClaimGroundSummary summary = listValue.getValue(); + if (summary == null || !StringUtils.hasText(summary.getReason())) { + continue; + } + + setGroundReason(reasonsForPossession, summary.getLabel(), summary.getReason()); + hasReason = true; + } + + return hasReason ? reasonsForPossession : null; + } + + private void setGroundReason(ReasonsForPossessionTabDetails reasonsForPossession, + String groundLabel, + String reason) { + Matcher groundMatcher = GROUND_REFERENCE_PATTERN.matcher(groundLabel); + if (groundMatcher.find()) { + setGroundNumberReason(reasonsForPossession, groundMatcher.group(1), reason); + return; + } + + Matcher sectionMatcher = SECTION_REFERENCE_PATTERN.matcher(groundLabel); + if (sectionMatcher.find()) { + setSectionReason(reasonsForPossession, sectionMatcher.group(1), reason); + return; + } + + if (groundLabel.startsWith(SECTION_84A_CONDITION_1_PREFIX)) { + reasonsForPossession.setCondition1OfSection84A(reason); + } else if (groundLabel.startsWith(SECTION_84A_CONDITION_2_PREFIX)) { + reasonsForPossession.setCondition2OfSection84A(reason); + } else if (groundLabel.startsWith(SECTION_84A_CONDITION_3_PREFIX)) { + reasonsForPossession.setCondition3OfSection84A(reason); + } else if (groundLabel.startsWith(SECTION_84A_CONDITION_4_PREFIX)) { + reasonsForPossession.setCondition4OfSection84A(reason); + } else if (groundLabel.startsWith(SECTION_84A_CONDITION_5_PREFIX)) { + reasonsForPossession.setCondition5OfSection84A(reason); + } else if (ANTISOCIAL_BEHAVIOUR.equals(groundLabel)) { + reasonsForPossession.setAntisocialBehaviour(reason); + } else if (BREACH_OF_THE_TENANCY.equals(groundLabel)) { + reasonsForPossession.setBreachOfTheTenancy(reason); + } else if (ABSOLUTE_GROUNDS.equals(groundLabel)) { + reasonsForPossession.setAbsoluteGrounds(reason); + } else if (OTHER.equals(groundLabel) || OTHER_GROUNDS.equals(groundLabel)) { + reasonsForPossession.setOtherGrounds(reason); + } else if (NO_GROUNDS.equals(groundLabel)) { + reasonsForPossession.setNoGrounds(reason); + } else if (groundLabel.contains(PARAGRAPH_25B_2_SCHEDULE_12)) { + reasonsForPossession.setParagraph25B2Schedule12(reason); + } + } + + private void setGroundNumberReason(ReasonsForPossessionTabDetails reasonsForPossession, + String ground, + String reason) { + switch (ground) { + case GROUND_1 -> reasonsForPossession.setGround1(reason); + case GROUND_2 -> reasonsForPossession.setGround2(reason); + case GROUND_2A -> reasonsForPossession.setGround2A(reason); + case GROUND_2ZA -> reasonsForPossession.setGround2ZA(reason); + case GROUND_3 -> reasonsForPossession.setGround3(reason); + case GROUND_4 -> reasonsForPossession.setGround4(reason); + case GROUND_5 -> reasonsForPossession.setGround5(reason); + case GROUND_6 -> reasonsForPossession.setGround6(reason); + case GROUND_7 -> reasonsForPossession.setGround7(reason); + case GROUND_7A -> reasonsForPossession.setGround7A(reason); + case GROUND_7B -> reasonsForPossession.setGround7B(reason); + case GROUND_8 -> reasonsForPossession.setGround8(reason); + case GROUND_9 -> reasonsForPossession.setGround9(reason); + case GROUND_10 -> reasonsForPossession.setGround10(reason); + case GROUND_10A -> reasonsForPossession.setGround10A(reason); + case GROUND_11 -> reasonsForPossession.setGround11(reason); + case GROUND_12 -> reasonsForPossession.setGround12(reason); + case GROUND_13 -> reasonsForPossession.setGround13(reason); + case GROUND_14 -> reasonsForPossession.setGround14(reason); + case GROUND_14A -> reasonsForPossession.setGround14A(reason); + case GROUND_14ZA -> reasonsForPossession.setGround14ZA(reason); + case GROUND_15 -> reasonsForPossession.setGround15(reason); + case GROUND_15A -> reasonsForPossession.setGround15A(reason); + case GROUND_16 -> reasonsForPossession.setGround16(reason); + case GROUND_17 -> reasonsForPossession.setGround17(reason); + case GROUND_A -> reasonsForPossession.setGroundA(reason); + case GROUND_B -> reasonsForPossession.setGroundB(reason); + case GROUND_C -> reasonsForPossession.setGroundC(reason); + case GROUND_D -> reasonsForPossession.setGroundD(reason); + case GROUND_E -> reasonsForPossession.setGroundE(reason); + case GROUND_F -> reasonsForPossession.setGroundF(reason); + case GROUND_G -> reasonsForPossession.setGroundG(reason); + case GROUND_H -> reasonsForPossession.setGroundH(reason); + case GROUND_I -> reasonsForPossession.setGroundI(reason); + default -> { + } + } + } + + private void setSectionReason(ReasonsForPossessionTabDetails reasonsForPossession, + String section, + String reason) { + switch (section) { + case SECTION_157 -> reasonsForPossession.setSection157(reason); + case SECTION_170 -> reasonsForPossession.setSection170(reason); + case SECTION_178 -> reasonsForPossession.setSection178(reason); + case SECTION_181 -> reasonsForPossession.setSection181(reason); + case SECTION_186 -> reasonsForPossession.setSection186(reason); + case SECTION_187 -> reasonsForPossession.setSection187(reason); + case SECTION_191 -> reasonsForPossession.setSection191(reason); + case SECTION_199 -> reasonsForPossession.setSection199(reason); + default -> { + } + } + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/RentArrearsTabDetailsBuilder.java b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/RentArrearsTabDetailsBuilder.java new file mode 100644 index 0000000000..784207ef97 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/RentArrearsTabDetailsBuilder.java @@ -0,0 +1,168 @@ +package uk.gov.hmcts.reform.pcs.ccd.view.builder; + +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import uk.gov.hmcts.ccd.sdk.type.Document; +import uk.gov.hmcts.ccd.sdk.type.ListValue; +import uk.gov.hmcts.ccd.sdk.type.YesOrNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.RentArrearsSection; +import uk.gov.hmcts.reform.pcs.ccd.domain.RentDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.RentPaymentFrequency; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.RentArrearsTabDetails; + +import java.math.BigDecimal; +import java.util.List; + +@Component +public class RentArrearsTabDetailsBuilder { + + private static final String NO_ANSWER = " "; + + public RentArrearsTabDetails buildRentArrearsTabDetails(PCSCase pcsCase) { + RentDetails rentDetails = pcsCase.getRentDetails(); + RentArrearsSection rentArrears = pcsCase.getRentArrears(); + + String rentAmount = rentDetails == null ? null : formatMoney(rentDetails.getCurrentRent()); + String calculationFrequency = getRentCalculationFrequency(rentDetails); + String dailyRate = getDailyRate(rentDetails); + String arrearsTotal = rentArrears == null ? null : formatMoney(rentArrears.getTotal()); + String judgmentRequested = pcsCase.getArrearsJudgmentWanted() == null + ? null : pcsCase.getArrearsJudgmentWanted().getLabel(); + + if (rentAmount == null + && calculationFrequency == null + && dailyRate == null + && arrearsTotal == null + && judgmentRequested == null) { + return null; + } + + return RentArrearsTabDetails.builder() + .rentAmount(rentAmount) + .calculationFrequency(calculationFrequency) + .dailyRate(dailyRate) + .arrearsTotal(arrearsTotal) + .judgmentRequested(judgmentRequested) + .build(); + } + + public RentArrearsTabDetails buildDetailedRentArrearsTabDetails(PCSCase pcsCase) { + if (pcsCase.getShowRentSectionPage() != YesOrNo.YES) { + return null; + } + + String judgmentRequested = pcsCase.getArrearsJudgmentWanted() == null + ? NO_ANSWER : pcsCase.getArrearsJudgmentWanted().getLabel(); + + RentArrearsTabDetails rentArrearsTabDetails; + RentDetails rentDetails = pcsCase.getRentDetails(); + RentArrearsSection rentArrears = pcsCase.getRentArrears(); + + if (rentDetails != null) { + String rentAmount = formatMoney(rentDetails.getCurrentRent()); + String calculationFrequency = getRentCalculationFrequencyDetailed(rentDetails); + String dailyRate = getDailyRate(rentDetails); + + String frequency = null; + if (rentDetails.getFrequency() == RentPaymentFrequency.OTHER) { + frequency = rentDetails.getOtherFrequency(); + } + + rentArrearsTabDetails = RentArrearsTabDetails.builder() + .rentAmount(rentAmount != null ? rentAmount : NO_ANSWER) + .calculationFrequency(calculationFrequency != null ? calculationFrequency : NO_ANSWER) + .dailyRate(dailyRate != null ? dailyRate : NO_ANSWER) + .judgmentRequested(judgmentRequested) + .frequency(frequency) + .build(); + } else { + rentArrearsTabDetails = RentArrearsTabDetails.builder() + .rentAmount(NO_ANSWER) + .calculationFrequency(NO_ANSWER) + .dailyRate(NO_ANSWER) + .judgmentRequested(judgmentRequested) + .build(); + } + + if (rentArrears != null) { + VerticalYesNo recoveryAttempted = rentArrears.getRecoveryAttempted(); + rentArrearsTabDetails + .setStepsToRecoverArrears(recoveryAttempted != null ? recoveryAttempted.getLabel() : NO_ANSWER); + + if (recoveryAttempted == VerticalYesNo.YES) { + String details = rentArrears.getRecoveryAttemptDetails(); + rentArrearsTabDetails.setStepsToRecoverArrearsDetails(details != null ? details : NO_ANSWER); + } + + String arrearsTotal = formatMoney(rentArrears.getTotal()); + rentArrearsTabDetails.setArrearsTotal(arrearsTotal != null ? arrearsTotal : NO_ANSWER); + + List> documents = rentArrears.getStatementDocuments(); + if (CollectionUtils.isEmpty(documents)) { + rentArrearsTabDetails.setRentStatementPlaceholder(NO_ANSWER); + } else { + rentArrearsTabDetails.setRentStatement(documents); + } + } else { + rentArrearsTabDetails.setStepsToRecoverArrears(NO_ANSWER); + rentArrearsTabDetails.setRentStatementPlaceholder(NO_ANSWER); + rentArrearsTabDetails.setArrearsTotal(NO_ANSWER); + } + + return rentArrearsTabDetails; + } + + private String getDailyRate(RentDetails rentDetails) { + if (rentDetails == null) { + return null; + } + + if (rentDetails.getPerDayCorrect() == VerticalYesNo.NO && rentDetails.getAmendedDailyCharge() != null) { + return formatMoney(rentDetails.getAmendedDailyCharge()); + } + + if (rentDetails.getDailyCharge() != null) { + return formatMoney(rentDetails.getDailyCharge()); + } + + if (rentDetails.getFormattedCalculatedDailyCharge() != null) { + return rentDetails.getFormattedCalculatedDailyCharge(); + } + + return formatMoney(rentDetails.getCalculatedDailyCharge()); + } + + private String formatMoney(BigDecimal amount) { + if (amount == null) { + return null; + } + + if (amount.stripTrailingZeros().scale() <= 0) { + amount = amount.stripTrailingZeros(); + } + + return "£" + amount.toPlainString(); + } + + private String getRentCalculationFrequency(RentDetails rentDetails) { + if (rentDetails == null || rentDetails.getFrequency() == null) { + return null; + } + + if (rentDetails.getFrequency() == RentPaymentFrequency.OTHER && rentDetails.getOtherFrequency() != null) { + return rentDetails.getOtherFrequency(); + } + + return rentDetails.getFrequency().getLabel(); + } + + private String getRentCalculationFrequencyDetailed(RentDetails rentDetails) { + if (rentDetails == null || rentDetails.getFrequency() == null) { + return null; + } + + return rentDetails.getFrequency().getLabel(); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/CaseTypeTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/CaseTypeTest.java index 131bf2efc9..fad9f29a59 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/CaseTypeTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/CaseTypeTest.java @@ -69,6 +69,7 @@ void shouldConfigureCaseTypeTabs() { final Tab.TabBuilder caseLinksTabBuilder = Tab.TabBuilder.builder(PCSCase.class, utils); final Tab.TabBuilder caseFileViewTabBuilder = Tab.TabBuilder.builder(PCSCase.class, utils); final Tab.TabBuilder casePartiesTabBuilder = Tab.TabBuilder.builder(PCSCase.class, utils); + final Tab.TabBuilder caseDetailsTabBuilder = Tab.TabBuilder.builder(PCSCase.class, utils); final Search.SearchBuilder searchBuilder = Search.SearchBuilder.builder(PCSCase.class, utils); final SearchCases.SearchCasesBuilder searchCasesBuilder = @@ -86,6 +87,7 @@ void shouldConfigureCaseTypeTabs() { when(builder.tab("caseLinks", "Linked Cases")).thenReturn(caseLinksTabBuilder); when(builder.tab("caseFileView", "Case File View")).thenReturn(caseFileViewTabBuilder); when(builder.tab("caseParties", "Case Parties")).thenReturn(casePartiesTabBuilder); + when(builder.tab("caseDetails", "Case Details")).thenReturn(caseDetailsTabBuilder); when(builder.categories(UserRole.PCS_SOLICITOR)) .thenReturn(CaseCategory.CaseCategoryBuilder.builder(UserRole.PCS_SOLICITOR)); @@ -99,6 +101,7 @@ void shouldConfigureCaseTypeTabs() { final Tab caseLinksTab = caseLinksTabBuilder.build(); final Tab casePartiesTab = casePartiesTabBuilder.build(); final Tab caseFileViewTab = caseFileViewTabBuilder.build(); + final Tab caseDetailsTab = caseDetailsTabBuilder.build(); // Then assertThat(nextStepsTab.getFields()).extracting(TabField::getId).contains("nextStepsMarkdown"); @@ -110,5 +113,6 @@ void shouldConfigureCaseTypeTabs() { .contains("LinkedCasesComponentLauncher!=\"\""); assertThat(caseFileViewTab.getFields().size()).isEqualTo(1); assertThat(casePartiesTab.getFields()).extracting(TabField::getId).contains("casePartiesTab_ClaimantDetails"); + assertThat(caseDetailsTab.getFields()).extracting(TabField::getId).contains("detailsTab_ClaimDetails"); } } diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/DraftCaseJsonMergerTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/DraftCaseJsonMergerTest.java index 199fbeb5ea..23b418bd03 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/DraftCaseJsonMergerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/DraftCaseJsonMergerTest.java @@ -94,6 +94,7 @@ void shouldKeepExistingFieldsWhenMerging() throws JsonProcessingException { "enforcementOrder.rawWarrantDetails.vulnerablePeoplePresent", "enforcementOrder.rawWarrantDetails.vulnerableAdultsChildren", "summaryTab", + "caseDetailsTab", "casePartiesTab.claimantDetails.emailAddress", "casePartiesTab.claimantDetails.name", "casePartiesTab.claimantDetails.serviceAddress", diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseDetailsTabViewTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseDetailsTabViewTest.java new file mode 100644 index 0000000000..91f72a30ed --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseDetailsTabViewTest.java @@ -0,0 +1,715 @@ +package uk.gov.hmcts.reform.pcs.ccd.view; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.hmcts.ccd.sdk.type.AddressUK; +import uk.gov.hmcts.ccd.sdk.type.ListValue; +import uk.gov.hmcts.ccd.sdk.type.YesOrNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.AdditionalReasons; +import uk.gov.hmcts.reform.pcs.ccd.domain.ClaimantCircumstances; +import uk.gov.hmcts.reform.pcs.ccd.domain.ClaimantContactPreferences; +import uk.gov.hmcts.reform.pcs.ccd.domain.DefendantCircumstances; +import uk.gov.hmcts.reform.pcs.ccd.domain.DemotionOfTenancy; +import uk.gov.hmcts.reform.pcs.ccd.domain.DemotionOfTenancyHousingAct; +import uk.gov.hmcts.reform.pcs.ccd.domain.NoticeServedDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.NoticeServiceMethod; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.Party; +import uk.gov.hmcts.reform.pcs.ccd.domain.RentArrearsSection; +import uk.gov.hmcts.reform.pcs.ccd.domain.RentDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.RentPaymentFrequency; +import uk.gov.hmcts.reform.pcs.ccd.domain.SuspensionOfRightToBuy; +import uk.gov.hmcts.reform.pcs.ccd.domain.SuspensionOfRightToBuyHousingAct; +import uk.gov.hmcts.reform.pcs.ccd.domain.TenancyLicenceDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.TenancyLicenceType; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.AssuredAdditionalOtherGround; +import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.ClaimGroundSummary; +import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.IntroductoryDemotedOrOtherGrounds; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details.CaseDetailsTab; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.AdditionalDefendantInformationTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.ClaimantInformationTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.DefendantInformationTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.ReasonsForPossessionTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.RentArrearsTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.type.DynamicStringList; +import uk.gov.hmcts.reform.pcs.ccd.type.DynamicStringListElement; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.AdditionalDefendantInformationTabDetailsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.ClaimantInformationTabDetailsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.DefendantInformationTabDetailsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.GroundsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.ReasonsForPossessionTabDetailsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.RentArrearsTabDetailsBuilder; + +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Set; +import java.util.TimeZone; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.pcs.ccd.domain.AlternativesToPossession.DEMOTION_OF_TENANCY; +import static uk.gov.hmcts.reform.pcs.ccd.domain.AlternativesToPossession.SUSPENSION_OF_RIGHT_TO_BUY; +import static uk.gov.hmcts.reform.pcs.ccd.domain.ClaimantType.PROVIDER_OF_SOCIAL_HOUSING; + +@ExtendWith(MockitoExtension.class) +public class CaseDetailsTabViewTest { + + private final String noAnswer = " "; + + @Mock + private GroundsBuilder groundsBuilder; + + @Mock + private RentArrearsTabDetailsBuilder rentArrearsTabDetailsBuilder; + + @Mock + private ReasonsForPossessionTabDetailsBuilder reasonsForPossessionTabDetailsBuilder; + + @Mock + private ClaimantInformationTabDetailsBuilder claimantInformationTabDetailsBuilder; + + @Mock + private DefendantInformationTabDetailsBuilder defendantInformationTabDetailsBuilder; + + @Mock + private AdditionalDefendantInformationTabDetailsBuilder additionalDefendantInformationTabDetailsBuilder; + + @InjectMocks + private CaseDetailsTabView caseDetailsTabView; + + @Test + void shouldSetCaseDetailsTabFields() { + AddressUK propertyAddress = AddressUK.builder().postCode("SW1A 1AA").build(); + AddressUK defendantAddress = AddressUK.builder().postCode("E1 1AA").build(); + AddressUK underlesseeAddress = AddressUK.builder().postCode("CV1 1DF").build(); + AddressUK claimantAddress = AddressUK.builder().postCode("L2 3RT").build(); + PCSCase pcsCase = PCSCase.builder() + .claimantType( + DynamicStringList.builder().value( + DynamicStringListElement.builder().code(PROVIDER_OF_SOCIAL_HOUSING.name()).build()) + .build()) + .claimAgainstTrespassers(VerticalYesNo.YES) + .propertyAddress(propertyAddress) + .dateSubmitted(LocalDateTime.of(2026, 1, 11, 17, 2, 31)) + .claimGroundSummaries(List.of( + listValue(ClaimGroundSummary.builder() + .label("Rent arrears (ground 10)") + .reason("Ground 10 reason") + .code("ABSOLUTE_GROUNDS") + .build()), + listValue(ClaimGroundSummary.builder() + .label("Condition 1 of Section 84A of the Housing Act 1985") + .reason("Condition 1 reason") + .code("ABSOLUTE_GROUNDS") + .build()) + )) + .additionalReasonsForPossession(AdditionalReasons.builder() + .hasReasons(VerticalYesNo.YES) + .reasons("Additional reasons") + .build()) + .allClaimants( + List.of(listValue( + Party.builder() + .orgName("Claimant") + .address(claimantAddress) + .emailAddress("claimant@email.com") + .phoneNumberProvided(VerticalYesNo.YES) + .phoneNumber("phone number") + .build() + )) + ) + .claimantCircumstances( + ClaimantCircumstances.builder() + .claimantCircumstancesSelect(VerticalYesNo.YES) + .claimantCircumstancesDetails("claimant circumstances") + .build() + ) + .allDefendants(List.of( + listValue(Party.builder() + .nameKnown(VerticalYesNo.YES) + .firstName("Defendant") + .lastName("One") + .addressKnown(VerticalYesNo.YES) + .build()), + listValue(Party.builder() + .nameKnown(VerticalYesNo.YES) + .firstName("Defendant") + .lastName("Two") + .addressKnown(VerticalYesNo.YES) + .address(defendantAddress) + .build()), + listValue(Party.builder() + .nameKnown(VerticalYesNo.NO) + .addressKnown(VerticalYesNo.NO) + .build()) + )) + .defendantCircumstances( + DefendantCircumstances.builder() + .hasDefendantCircumstancesInfo(VerticalYesNo.YES) + .defendantCircumstancesInfo("defendant circumstances") + .build() + ) + .rentDetails(RentDetails.builder() + .currentRent(new BigDecimal("100.00")) + .frequency(RentPaymentFrequency.OTHER) + .otherFrequency("Every 4 weeks") + .perDayCorrect(VerticalYesNo.NO) + .amendedDailyCharge(new BigDecimal("12.30")) + .build()) + .rentArrears(RentArrearsSection.builder() + .total(new BigDecimal("450.75")) + .build()) + .arrearsJudgmentWanted(VerticalYesNo.YES) + .tenancyLicenceDetails(TenancyLicenceDetails.builder() + .typeOfTenancyLicence(TenancyLicenceType.OTHER) + .tenancyLicenceDate(LocalDate.of(2024, 4, 16)) + .hasCopyOfTenancyLicence(VerticalYesNo.NO) + .reasonsForNoTenancyLicenceDocuments("Reasons") + .build()) + .noticeServed(YesOrNo.YES) + .noticeServedDetails(NoticeServedDetails.builder() + .noticeServiceMethod(NoticeServiceMethod.EMAIL) + .noticeEmailSentDateTime(LocalDateTime.of(2026, 5, 11, 17, 2)) + .build()) + .preActionProtocolCompleted(VerticalYesNo.NO) + .preActionProtocolIncompleteExplanation("preaction explanation") + .mediationAttempted(VerticalYesNo.YES) + .settlementAttempted(VerticalYesNo.YES) + .applicationWithClaim(VerticalYesNo.YES) + .allUnderlesseeOrMortgagees(List.of( + listValue( + Party.builder() + .nameKnown(VerticalYesNo.YES) + .orgName("underlessee name") + .addressKnown(VerticalYesNo.YES) + .address(underlesseeAddress) + .build() + ) + )) + .alternativesToPossession(Set.of(DEMOTION_OF_TENANCY, SUSPENSION_OF_RIGHT_TO_BUY)) + .demotionOfTenancy( + DemotionOfTenancy.builder() + .housingAct(DemotionOfTenancyHousingAct.SECTION_6A_2) + .statementOfExpressTermsServed(VerticalYesNo.YES) + .statementOfExpressTermsDetails("terms") + .reason("demotion reason") + .build() + ) + .suspensionOfRightToBuy( + SuspensionOfRightToBuy.builder() + .housingAct(SuspensionOfRightToBuyHousingAct.SECTION_6A_2) + .reason("suspension reason") + .build() + ) + .build(); + + when(groundsBuilder.getGrounds(pcsCase)).thenReturn( + "Rent arrears (ground 10)\n" + + "Antisocial behaviour: Condition 1 of Section 84A of the Housing Act 1985" + ); + + when(rentArrearsTabDetailsBuilder.buildDetailedRentArrearsTabDetails(pcsCase)).thenReturn( + RentArrearsTabDetails.builder() + .rentAmount("£100") + .calculationFrequency("Every 4 weeks") + .dailyRate("£12.30") + .arrearsTotal("£450.75") + .judgmentRequested("Yes") + .build() + ); + + when(reasonsForPossessionTabDetailsBuilder.buildDetailsReasonsForPossession(pcsCase)).thenReturn( + ReasonsForPossessionTabDetails.builder() + .ground10("Ground 10 reason") + .condition1OfSection84A("Condition 1 reason") + .additionalReasonsForPossession("Additional reasons") + .build() + ); + + when(claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase)).thenReturn( + ClaimantInformationTabDetails.builder() + .claimantName("Claimant") + .build() + ); + + when(defendantInformationTabDetailsBuilder.buildDetailedDefendantDetails(pcsCase)).thenReturn( + DefendantInformationTabDetails.builder() + .nameKnown("Yes") + .firstName("Defendant") + .lastName("One") + .addressKnown("Yes") + .addressForService(propertyAddress) + .build() + ); + + when(additionalDefendantInformationTabDetailsBuilder.buildDetailedAdditionalDefendantsDetails(pcsCase)) + .thenReturn( + List.of( + listValue( + AdditionalDefendantInformationTabDetails.builder() + .nameKnown("Yes") + .firstName("Defendant") + .lastName("Two") + .addressKnown("Yes") + .addressForService(defendantAddress) + .build() + ), + listValue( + AdditionalDefendantInformationTabDetails.builder() + .nameKnown("No") + .addressKnown("No") + .build() + ) + ) + ); + + // When + CaseDetailsTab caseDetailsTab = caseDetailsTabView.buildCaseDetailsTab(pcsCase); + + assertThat(caseDetailsTab.getPropertyAddress()).isEqualTo(propertyAddress); + assertThat(caseDetailsTab.getGroundsForPossessionDetails().getGrounds()) + .isEqualTo( + "Rent arrears (ground 10)\n" + + "Antisocial behaviour: Condition 1 of Section 84A of the Housing Act 1985" + ); + assertThat(caseDetailsTab.getReasonsForPossessionDetails().getGround10()) + .isEqualTo("Ground 10 reason"); + assertThat(caseDetailsTab.getReasonsForPossessionDetails().getCondition1OfSection84A()) + .isEqualTo("Condition 1 reason"); + assertThat(caseDetailsTab.getReasonsForPossessionDetails().getAdditionalReasonsForPossession()) + .isEqualTo("Additional reasons"); + assertThat(caseDetailsTab.getDateClaimSubmitted()).isEqualTo("11 January 2026, 5:02:31PM"); + assertThat(caseDetailsTab.getClaimantInformation().getClaimantName()).isEqualTo("Claimant"); + assertThat(caseDetailsTab.getDefendantInformationDetails().getFirstName()).isEqualTo("Defendant"); + assertThat(caseDetailsTab.getDefendantInformationDetails().getLastName()).isEqualTo("One"); + assertThat(caseDetailsTab.getDefendantInformationDetails().getAddressForService()).isEqualTo(propertyAddress); + assertThat(caseDetailsTab.getAdditionalDefendants()).hasSize(2); + assertThat(caseDetailsTab.getAdditionalDefendants().getFirst().getValue().getFirstName()) + .isEqualTo("Defendant"); + assertThat(caseDetailsTab.getAdditionalDefendants().getFirst().getValue().getLastName()).isEqualTo("Two"); + assertThat(caseDetailsTab.getAdditionalDefendants().getFirst().getValue().getAddressForService()) + .isEqualTo(defendantAddress); + assertThat(caseDetailsTab.getAdditionalDefendants().get(1).getValue().getNameKnown()) + .isEqualTo("No"); + assertThat(caseDetailsTab.getAdditionalDefendants().get(1).getValue().getAddressKnown()) + .isEqualTo("No"); + assertThat(caseDetailsTab.getRentArrearsDetails().getRentAmount()).isEqualTo("£100"); + assertThat(caseDetailsTab.getRentArrearsDetails().getCalculationFrequency()).isEqualTo("Every 4 weeks"); + assertThat(caseDetailsTab.getRentArrearsDetails().getDailyRate()).isEqualTo("£12.30"); + assertThat(caseDetailsTab.getRentArrearsDetails().getArrearsTotal()).isEqualTo("£450.75"); + assertThat(caseDetailsTab.getRentArrearsDetails().getJudgmentRequested()).isEqualTo("Yes"); + assertThat(caseDetailsTab.getTenancyLicenceDetails().getTypeOfTenancyLicence()) + .isEqualTo("Other"); + assertThat(caseDetailsTab.getTenancyLicenceDetails().getTenancyLicenceDate()) + .isEqualTo("16 April 2024"); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeDate()) + .isEqualTo("11 May 2026"); + assertThat(caseDetailsTab.getTenancyLicenceDetails().getHasCopyOfTenancyLicence()) + .isEqualTo("No"); + assertThat(caseDetailsTab.getTenancyLicenceDetails().getReasonsForNoTenancyLicenceDocuments()) + .isEqualTo("Reasons"); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeMethod()).isEqualTo("By email"); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeServed()).isEqualTo("Yes"); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeDate()).isEqualTo("11 May 2026"); + assertThat(caseDetailsTab.getApplicationsDetails().getPlanToMakeGeneralApplication()).isEqualTo("Yes"); + assertThat(caseDetailsTab.getActionsTakenDetails().getPreactionProtocolFollowed()).isEqualTo("No"); + assertThat(caseDetailsTab.getActionsTakenDetails().getPreActionProtocolIncompleteExplanation()) + .isEqualTo("preaction explanation"); + assertThat(caseDetailsTab.getActionsTakenDetails().getMediationAttempted()).isEqualTo("Yes"); + assertThat(caseDetailsTab.getActionsTakenDetails().getSettlementAttempted()).isEqualTo("Yes"); + assertThat(caseDetailsTab.getMortgageDetails()).hasSize(1); + assertThat(caseDetailsTab.getMortgageDetails().getFirst().getValue().getNameKnown()).isEqualTo("Yes"); + assertThat(caseDetailsTab.getMortgageDetails().getFirst().getValue().getName()) + .isEqualTo("underlessee name"); + assertThat(caseDetailsTab.getMortgageDetails().getFirst().getValue().getAddressKnown()) + .isEqualTo("Yes"); + assertThat(caseDetailsTab.getMortgageDetails().getFirst().getValue().getAddress()) + .isEqualTo(underlesseeAddress); + assertThat(caseDetailsTab.getSuspensionOfRightToBuyDetails().getHousingAct()) + .isEqualTo(SuspensionOfRightToBuyHousingAct.SECTION_6A_2.getLabel()); + assertThat(caseDetailsTab.getSuspensionOfRightToBuyDetails().getReasons()) + .isEqualTo("suspension reason"); + assertThat(caseDetailsTab.getDemotionOfTenancyDetails().getHousingAct()) + .isEqualTo(DemotionOfTenancyHousingAct.SECTION_6A_2.getLabel()); + assertThat(caseDetailsTab.getDemotionOfTenancyDetails().getReasons()) + .isEqualTo("demotion reason"); + assertThat(caseDetailsTab.getClaimantAddress()).isEqualTo(claimantAddress); + assertThat(caseDetailsTab.getClaimantContactDetails().getEmailAddress()).isEqualTo("claimant@email.com"); + assertThat(caseDetailsTab.getClaimantContactDetails().getPhoneNumberProvided()).isEqualTo("Yes"); + assertThat(caseDetailsTab.getClaimantContactDetails().getPhoneNumber()).isEqualTo("phone number"); + assertThat(caseDetailsTab.getClaimantCircumstances().getClaimantCircumstancesGiven()).isEqualTo("Yes"); + assertThat(caseDetailsTab.getClaimantCircumstances().getClaimantCircumstancesDetails()) + .isEqualTo("claimant circumstances"); + assertThat(caseDetailsTab.getDefendantCircumstanceDetails().getDefendantCircumstancesGiven()) + .isEqualTo("Yes"); + assertThat(caseDetailsTab.getDefendantCircumstanceDetails().getDefendantCircumstances()) + .isEqualTo("defendant circumstances"); + } + + @Test + void shouldSetCaseDetailsTabFieldsWithNoData() { + PCSCase pcsCase = PCSCase.builder() + .build(); + + // When + CaseDetailsTab caseDetailsTab = caseDetailsTabView.buildCaseDetailsTab(pcsCase); + + assertThat(caseDetailsTab.getPropertyAddress()).isNull(); + assertThat(caseDetailsTab.getGroundsForPossessionDetails().getGrounds()).isEqualTo(noAnswer); + assertThat(caseDetailsTab.getReasonsForPossessionDetails()).isNull(); + assertThat(caseDetailsTab.getDateClaimSubmitted()).isEqualTo(noAnswer); + assertThat(caseDetailsTab.getClaimantInformation()).isNull(); + assertThat(caseDetailsTab.getDefendantInformationDetails()).isNull(); + assertThat(caseDetailsTab.getAdditionalDefendants()).isNull(); + assertThat(caseDetailsTab.getRentArrearsDetails()).isNull(); + assertThat(caseDetailsTab.getTenancyLicenceDetails().getTypeOfTenancyLicence()) + .isEqualTo(noAnswer); + assertThat(caseDetailsTab.getTenancyLicenceDetails().getTenancyLicenceDate()) + .isEqualTo(noAnswer); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeDate()) + .isEqualTo(noAnswer); + assertThat(caseDetailsTab.getTenancyLicenceDetails().getHasCopyOfTenancyLicence()) + .isEqualTo(noAnswer); + assertThat(caseDetailsTab.getTenancyLicenceDetails().getReasonsForNoTenancyLicenceDocuments()) + .isNull(); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeMethod()).isEqualTo(noAnswer); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeServed()).isEqualTo(noAnswer); + assertThat(caseDetailsTab.getApplicationsDetails().getPlanToMakeGeneralApplication()).isEqualTo(noAnswer); + assertThat(caseDetailsTab.getActionsTakenDetails().getPreactionProtocolFollowed()).isEqualTo(noAnswer); + assertThat(caseDetailsTab.getActionsTakenDetails().getPreActionProtocolIncompleteExplanation()) + .isNull(); + assertThat(caseDetailsTab.getActionsTakenDetails().getMediationAttempted()).isEqualTo(noAnswer); + assertThat(caseDetailsTab.getActionsTakenDetails().getSettlementAttempted()).isEqualTo(noAnswer); + assertThat(caseDetailsTab.getMortgageDetails()).isNull(); + assertThat(caseDetailsTab.getSuspensionOfRightToBuyDetails()).isNull(); + assertThat(caseDetailsTab.getDemotionOfTenancyDetails()).isNull(); + assertThat(caseDetailsTab.getClaimantCircumstances()).isNull(); + assertThat(caseDetailsTab.getDefendantCircumstanceDetails()).isNull(); + assertThat(caseDetailsTab.getClaimantContactDetails()).isNull(); + assertThat(caseDetailsTab.getClaimantAddress()).isNull(); + } + + @Test + void shouldSetPlaceholderValuesIfOnlyAlternativesToPossessionIsSet() { + // Given + PCSCase pcsCase = PCSCase.builder() + .alternativesToPossession(Set.of(DEMOTION_OF_TENANCY, SUSPENSION_OF_RIGHT_TO_BUY)) + .build(); + + // When + CaseDetailsTab caseDetailsTab = caseDetailsTabView.buildCaseDetailsTab(pcsCase); + + // Then + assertThat(caseDetailsTab.getSuspensionOfRightToBuyDetails().getHousingAct()) + .isEqualTo(noAnswer); + assertThat(caseDetailsTab.getSuspensionOfRightToBuyDetails().getReasons()) + .isEqualTo(noAnswer); + assertThat(caseDetailsTab.getDemotionOfTenancyDetails().getHousingAct()) + .isEqualTo(noAnswer); + assertThat(caseDetailsTab.getDemotionOfTenancyDetails().getReasons()) + .isEqualTo(noAnswer); + } + + @Test + void shouldSetOtherGroundsDescriptionAssuredTenancy() { + PCSCase pcsCase = PCSCase.builder() + .tenancyLicenceDetails(TenancyLicenceDetails.builder() + .typeOfTenancyLicence(TenancyLicenceType.ASSURED_TENANCY) + .tenancyLicenceDate(LocalDate.of(2024, 4, 16)) + .hasCopyOfTenancyLicence(VerticalYesNo.NO) + .reasonsForNoTenancyLicenceDocuments("Reasons") + .build()) + .claimGroundSummaries(List.of( + listValue(ClaimGroundSummary.builder() + .label("Other") + .reason("Other reason") + .description("description") + .code(AssuredAdditionalOtherGround.OTHER.name()) + .build()) + )) + .build(); + + // When + CaseDetailsTab caseDetailsTab = caseDetailsTabView.buildCaseDetailsTab(pcsCase); + + assertThat(caseDetailsTab.getGroundsForPossessionDetails().getOtherGroundsDescription()) + .isEqualTo("description"); + } + + @Test + void shouldSetOtherGroundsDescriptionOtherTenancy() { + PCSCase pcsCase = PCSCase.builder() + .tenancyLicenceDetails(TenancyLicenceDetails.builder() + .typeOfTenancyLicence(TenancyLicenceType.OTHER) + .tenancyLicenceDate(LocalDate.of(2024, 4, 16)) + .hasCopyOfTenancyLicence(VerticalYesNo.NO) + .reasonsForNoTenancyLicenceDocuments("Reasons") + .build()) + .claimGroundSummaries(List.of( + listValue(ClaimGroundSummary.builder() + .label("Other") + .reason("Other reason") + .description("description") + .code(IntroductoryDemotedOrOtherGrounds.OTHER.name()) + .build()) + )) + .build(); + + // When + CaseDetailsTab caseDetailsTab = caseDetailsTabView.buildCaseDetailsTab(pcsCase); + + // Then + assertThat(caseDetailsTab.getGroundsForPossessionDetails().getOtherGroundsDescription()) + .isEqualTo("description"); + } + + @Test + void shouldUseClaimantContactPreferencesIfAllClaimantsIsNotSet() { + // Given + AddressUK claimantAddress = AddressUK.builder().postCode("L2 3RT").build(); + PCSCase pcsCase = PCSCase.builder() + .claimantContactPreferences( + ClaimantContactPreferences.builder() + .orgAddressFound(YesOrNo.YES) + .isCorrectClaimantContactAddress(VerticalYesNo.YES) + .organisationAddress(claimantAddress) + .isCorrectClaimantContactEmail(VerticalYesNo.YES) + .claimantContactEmail("claimant@email.com") + .claimantProvidePhoneNumber(VerticalYesNo.YES) + .claimantContactPhoneNumber("phone number") + .build() + ) + .build(); + + when(claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase)).thenReturn( + ClaimantInformationTabDetails.builder() + .claimantName("Claimant") + .build() + ); + + // When + CaseDetailsTab caseDetailsTab = caseDetailsTabView.buildCaseDetailsTab(pcsCase); + + // Then + assertThat(caseDetailsTab.getClaimantAddress()).isEqualTo(claimantAddress); + assertThat(caseDetailsTab.getClaimantContactDetails().getEmailAddress()).isEqualTo("claimant@email.com"); + assertThat(caseDetailsTab.getClaimantContactDetails().getPhoneNumber()).isEqualTo("phone number"); + } + + @Test + void shouldUseOverwrittenAddressAndEmail() { + // Given + AddressUK claimantAddress = AddressUK.builder().postCode("L2 3RT").build(); + PCSCase pcsCase = PCSCase.builder() + .claimantContactPreferences( + ClaimantContactPreferences.builder() + .orgAddressFound(YesOrNo.YES) + .isCorrectClaimantContactAddress(VerticalYesNo.NO) + .overriddenClaimantContactAddress(claimantAddress) + .isCorrectClaimantContactEmail(VerticalYesNo.NO) + .overriddenClaimantContactEmail("claimant@email.com") + .claimantProvidePhoneNumber(VerticalYesNo.NO) + .claimantContactPhoneNumber("phone number") + .build() + ) + .build(); + + when(claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase)).thenReturn( + ClaimantInformationTabDetails.builder() + .claimantName("Claimant") + .build() + ); + + // When + CaseDetailsTab caseDetailsTab = caseDetailsTabView.buildCaseDetailsTab(pcsCase); + + // Then + assertThat(caseDetailsTab.getClaimantAddress()).isEqualTo(claimantAddress); + assertThat(caseDetailsTab.getClaimantContactDetails().getEmailAddress()).isEqualTo("claimant@email.com"); + assertThat(caseDetailsTab.getClaimantContactDetails().getPhoneNumberProvided()).isEqualTo("No"); + } + + @Test + void shouldUsePlaceholderValuesIfClaimantDetailsIsNotSet() { + PCSCase pcsCase = PCSCase.builder().build(); + + when(claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase)).thenReturn( + ClaimantInformationTabDetails.builder() + .claimantName("Claimant") + .build() + ); + + // When + CaseDetailsTab caseDetailsTab = caseDetailsTabView.buildCaseDetailsTab(pcsCase); + + // Then + assertThat(caseDetailsTab.getClaimantAddress().getAddressLine1()).isEqualTo(noAnswer); + assertThat(caseDetailsTab.getClaimantAddress().getPostTown()).isEqualTo(noAnswer); + assertThat(caseDetailsTab.getClaimantAddress().getCountry()).isEqualTo(noAnswer); + assertThat(caseDetailsTab.getClaimantAddress().getPostCode()).isEqualTo(noAnswer); + assertThat(caseDetailsTab.getClaimantContactDetails().getEmailAddress()).isEqualTo(noAnswer); + assertThat(caseDetailsTab.getClaimantContactDetails().getPhoneNumberProvided()).isEqualTo(noAnswer); + assertThat(caseDetailsTab.getClaimantContactDetails().getPhoneNumber()).isNull(); + assertThat(caseDetailsTab.getClaimantCircumstances().getClaimantCircumstancesGiven()).isEqualTo(noAnswer); + assertThat(caseDetailsTab.getClaimantCircumstances().getClaimantCircumstancesDetails()).isNull(); + } + + @Test + void shouldSetNoticeDetailsForFirstClassPost() { + // Given + PCSCase pcsCase = PCSCase.builder() + .noticeServed(YesOrNo.YES) + .noticeServedDetails(NoticeServedDetails.builder() + .noticeServiceMethod(NoticeServiceMethod.FIRST_CLASS_POST) + .noticePostedDate(LocalDate.of(2026, 5, 11)) + .build()) + .build(); + + // When + CaseDetailsTab caseDetailsTab = caseDetailsTabView.buildCaseDetailsTab(pcsCase); + + // Then + assertThat(caseDetailsTab.getNoticeDetails().getNoticeMethod()) + .isEqualTo(NoticeServiceMethod.FIRST_CLASS_POST.getLabel()); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeServed()).isEqualTo("Yes"); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeDate()).isEqualTo("11 May 2026"); + } + + @Test + void shouldSetNoticeDetailsForPermittedPlace() { + // Given + PCSCase pcsCase = PCSCase.builder() + .noticeServed(YesOrNo.YES) + .noticeServedDetails(NoticeServedDetails.builder() + .noticeServiceMethod(NoticeServiceMethod.DELIVERED_PERMITTED_PLACE) + .noticeDeliveredDate(LocalDate.of(2026, 5, 11)) + .build()) + .build(); + + // When + CaseDetailsTab caseDetailsTab = caseDetailsTabView.buildCaseDetailsTab(pcsCase); + + // Then + assertThat(caseDetailsTab.getNoticeDetails().getNoticeMethod()) + .isEqualTo(NoticeServiceMethod.DELIVERED_PERMITTED_PLACE.getLabel()); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeServed()).isEqualTo("Yes"); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeDate()).isEqualTo("11 May 2026"); + } + + @Test + void shouldSetNoticeDetailsForPersonallyHanded() { + // Given + PCSCase pcsCase = PCSCase.builder() + .noticeServed(YesOrNo.YES) + .noticeServedDetails(NoticeServedDetails.builder() + .noticeServiceMethod(NoticeServiceMethod.PERSONALLY_HANDED) + .noticeHandedOverDateTime(LocalDateTime.of(2026, 5, 11, 9, 0, 0)) + .noticePersonName("Notice name") + .build()) + .build(); + + // When + CaseDetailsTab caseDetailsTab = caseDetailsTabView.buildCaseDetailsTab(pcsCase); + + // Then + assertThat(caseDetailsTab.getNoticeDetails().getNoticeMethod()) + .isEqualTo(NoticeServiceMethod.PERSONALLY_HANDED.getLabel()); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeServed()).isEqualTo("Yes"); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeDate()).isEqualTo("11 May 2026"); + assertThat(caseDetailsTab.getNoticeDetails().getNoticePersonName()).isEqualTo("Notice name"); + } + + @Test + void shouldSetNoticeDetailsForOtherElectronic() { + // Given + PCSCase pcsCase = PCSCase.builder() + .noticeServed(YesOrNo.YES) + .noticeServedDetails(NoticeServedDetails.builder() + .noticeServiceMethod(NoticeServiceMethod.OTHER_ELECTRONIC) + .noticeOtherElectronicDateTime(LocalDateTime.of(2026, 5, 11, 9, 0, 0)) + .build()) + .build(); + + // When + CaseDetailsTab caseDetailsTab = caseDetailsTabView.buildCaseDetailsTab(pcsCase); + + // Then + assertThat(caseDetailsTab.getNoticeDetails().getNoticeMethod()) + .isEqualTo(NoticeServiceMethod.OTHER_ELECTRONIC.getLabel()); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeServed()).isEqualTo("Yes"); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeDate()).isEqualTo("11 May 2026"); + } + + @Test + void shouldSetNoticeDetailsForOther() { + // Given + PCSCase pcsCase = PCSCase.builder() + .noticeServed(YesOrNo.YES) + .noticeServedDetails(NoticeServedDetails.builder() + .noticeServiceMethod(NoticeServiceMethod.OTHER) + .noticeOtherDateTime(LocalDateTime.of(2026, 5, 11, 9, 0, 0)) + .build()) + .build(); + + // When + CaseDetailsTab caseDetailsTab = caseDetailsTabView.buildCaseDetailsTab(pcsCase); + + // Then + assertThat(caseDetailsTab.getNoticeDetails().getNoticeMethod()) + .isEqualTo(NoticeServiceMethod.OTHER.getLabel()); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeServed()).isEqualTo("Yes"); + assertThat(caseDetailsTab.getNoticeDetails().getNoticeDate()).isEqualTo("11 May 2026"); + } + + @Test + void shouldDisplaySubmittedDateInUkTimeWhenServerTimezoneIsUtc() { + // Given + TimeZone originalTimeZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + PCSCase pcsCase = PCSCase.builder() + .dateSubmitted(LocalDateTime.of(2026, 7, 11, 17, 2, 31)) + .build(); + + try { + // When + CaseDetailsTab caseDetailsTab = caseDetailsTabView.buildCaseDetailsTab(pcsCase); + + // Then + assertThat(caseDetailsTab.getDateClaimSubmitted()).isEqualTo("11 July 2026, 6:02:31PM"); + } finally { + TimeZone.setDefault(originalTimeZone); + } + } + + @Test + void shouldDisplaySubmittedDateInGmtOutsideBritishSummerTimeWhenServerTimezoneIsUtc() { + // Given + TimeZone originalTimeZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + PCSCase pcsCase = PCSCase.builder() + .dateSubmitted(LocalDateTime.of(2026, 1, 11, 17, 2, 31)) + .build(); + + try { + // When + CaseDetailsTab caseDetailsTab = caseDetailsTabView.buildCaseDetailsTab(pcsCase); + + // Then + assertThat(caseDetailsTab.getDateClaimSubmitted()).isEqualTo("11 January 2026, 5:02:31PM"); + } finally { + TimeZone.setDefault(originalTimeZone); + } + } + + private static ListValue listValue(T value) { + return ListValue.builder() + .value(value) + .build(); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseSummaryTabViewTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseSummaryTabViewTest.java index a164621549..3ca985137f 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseSummaryTabViewTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseSummaryTabViewTest.java @@ -1,7 +1,10 @@ package uk.gov.hmcts.reform.pcs.ccd.view; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -20,11 +23,20 @@ import uk.gov.hmcts.reform.pcs.ccd.domain.TenancyLicenceType; import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.ClaimGroundSummary; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.AdditionalDefendantInformationTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.ClaimantInformationTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.DefendantInformationTabDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.RentArrearsTabDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.ReasonsForPossessionTabDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.summary.SummaryTab; import uk.gov.hmcts.reform.pcs.ccd.domain.wales.OccupationLicenceDetailsWales; import uk.gov.hmcts.reform.pcs.ccd.domain.wales.OccupationLicenceTypeWales; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.AdditionalDefendantInformationTabDetailsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.ClaimantInformationTabDetailsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.DefendantInformationTabDetailsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.GroundsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.ReasonsForPossessionTabDetailsBuilder; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.RentArrearsTabDetailsBuilder; import java.math.BigDecimal; import java.time.LocalDate; @@ -34,15 +46,31 @@ import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; +@ExtendWith(MockitoExtension.class) public class CaseSummaryTabViewTest { - private CaseSummaryTabView underTest; + @Mock + private GroundsBuilder groundsBuilder; - @BeforeEach - void setUp() { - underTest = new CaseSummaryTabView(); - } + @Mock + private RentArrearsTabDetailsBuilder rentArrearsTabDetailsBuilder; + + @Mock + private ReasonsForPossessionTabDetailsBuilder reasonsForPossessionTabDetailsBuilder; + + @Mock + private ClaimantInformationTabDetailsBuilder claimantInformationTabDetailsBuilder; + + @Mock + private DefendantInformationTabDetailsBuilder defendantInformationTabDetailsBuilder; + + @Mock + private AdditionalDefendantInformationTabDetailsBuilder additionalDefendantInformationTabDetailsBuilder; + + @InjectMocks + private CaseSummaryTabView underTest; @Test void shouldSetSummaryTabFields() { @@ -110,6 +138,63 @@ void shouldSetSummaryTabFields() { .build()) .build(); + when(groundsBuilder.getGrounds(pcsCase)).thenReturn( + "Rent arrears (ground 10)\n" + + "Antisocial behaviour: Condition 1 of Section 84A of the Housing Act 1985" + ); + + when(rentArrearsTabDetailsBuilder.buildRentArrearsTabDetails(pcsCase)).thenReturn( + RentArrearsTabDetails.builder() + .rentAmount("£100") + .calculationFrequency("Every 4 weeks") + .dailyRate("£12.30") + .arrearsTotal("£450.75") + .judgmentRequested("Yes") + .build() + ); + + when(reasonsForPossessionTabDetailsBuilder.buildSummaryReasonsForPossession(pcsCase)).thenReturn( + ReasonsForPossessionTabDetails.builder() + .ground10("Ground 10 reason") + .condition1OfSection84A("Condition 1 reason") + .additionalReasonsForPossession("Additional reasons") + .build() + ); + + when(claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase)).thenReturn( + ClaimantInformationTabDetails.builder() + .claimantName("Fallback claimant") + .build() + ); + + when(defendantInformationTabDetailsBuilder.buildSummaryDefendantOneDetails(pcsCase)).thenReturn( + DefendantInformationTabDetails.builder() + .firstName("Defendant") + .lastName("One") + .addressForService(propertyAddress) + .build() + ); + + when(additionalDefendantInformationTabDetailsBuilder.buildSummaryAdditionalDefendantsDetails(pcsCase)) + .thenReturn( + List.of( + listValue( + AdditionalDefendantInformationTabDetails.builder() + .firstName("Defendant") + .lastName("Two") + .addressForService(defendantAddress) + .build() + ), + listValue( + AdditionalDefendantInformationTabDetails.builder() + .firstName(CaseTabView.NAME_UNKNOWN) + .lastName(CaseTabView.NAME_UNKNOWN) + .addressForService(propertyAddress) + .build() + ) + ) + ); + // When SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); @@ -160,6 +245,14 @@ void shouldDisplaySubmittedDateInUkTimeWhenServerTimezoneIsUk() { .dateSubmitted(LocalDateTime.of(2026, 7, 11, 17, 2, 31)) .build(); + when(groundsBuilder.getGrounds(pcsCase)).thenReturn(null); + when(rentArrearsTabDetailsBuilder.buildRentArrearsTabDetails(pcsCase)).thenReturn(null); + when(reasonsForPossessionTabDetailsBuilder.buildSummaryReasonsForPossession(pcsCase)).thenReturn(null); + when(claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase)).thenReturn(null); + when(defendantInformationTabDetailsBuilder.buildSummaryDefendantOneDetails(pcsCase)).thenReturn(null); + when(additionalDefendantInformationTabDetailsBuilder.buildSummaryAdditionalDefendantsDetails(pcsCase)) + .thenReturn(null); + try { // When SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); @@ -211,53 +304,6 @@ void shouldDisplaySubmittedDateInGmtOutsideBritishSummerTimeWhenServerTimezoneIs } } - @Test - void shouldSetSummaryClaimantNameFromOverriddenName() { - // Given - PCSCase pcsCase = PCSCase.builder() - .claimantInformation(ClaimantInformation.builder() - .isClaimantNameCorrect(VerticalYesNo.NO) - .overriddenClaimantName("Overridden claimant") - .build()) - .build(); - - // When - SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); - - // Then - assertThat(summaryTab.getClaimantDetails().getClaimantName()).isEqualTo("Overridden claimant"); - } - - @Test - void shouldSetSummaryClaimantNameFromClaimantInformationName() { - // Given - PCSCase pcsCase = PCSCase.builder() - .claimantInformation(ClaimantInformation.builder() - .claimantName("Claimant information name") - .build()) - .build(); - - // When - SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); - - // Then - assertThat(summaryTab.getClaimantDetails().getClaimantName()).isEqualTo("Claimant information name"); - } - - @Test - void shouldSetSummaryClaimantNameFromAllClaimants() { - // Given - PCSCase pcsCase = PCSCase.builder() - .allClaimants(List.of(listValue(Party.builder().orgName("Claimant party").build()))) - .build(); - - // When - SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); - - // Then - assertThat(summaryTab.getClaimantDetails().getClaimantName()).isEqualTo("Claimant party"); - } - @Test void shouldNotSetEmptySummarySections() { // Given @@ -268,6 +314,14 @@ void shouldNotSetEmptySummarySections() { .build()))) .build(); + when(groundsBuilder.getGrounds(pcsCase)).thenReturn(null); + when(rentArrearsTabDetailsBuilder.buildRentArrearsTabDetails(pcsCase)).thenReturn(null); + when(reasonsForPossessionTabDetailsBuilder.buildSummaryReasonsForPossession(pcsCase)).thenReturn(null); + when(claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase)).thenReturn(null); + when(defendantInformationTabDetailsBuilder.buildSummaryDefendantOneDetails(pcsCase)).thenReturn(null); + when(additionalDefendantInformationTabDetailsBuilder.buildSummaryAdditionalDefendantsDetails(pcsCase)) + .thenReturn(null); + // When SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); @@ -283,416 +337,6 @@ void shouldNotSetEmptySummarySections() { assertThat(summaryTab.getNoticeDetails()).isNull(); } - @Test - void shouldSetUnknownDefendantNameWhenNameNotKnownButAddressKnown() { - // Given - AddressUK address = AddressUK.builder().postCode("SW1A 1AA").build(); - PCSCase pcsCase = PCSCase.builder() - .allDefendants(List.of(listValue(Party.builder() - .nameKnown(VerticalYesNo.NO) - .addressKnown(VerticalYesNo.YES) - .address(address) - .build()))) - .build(); - - // When - SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); - - // Then - assertThat(summaryTab.getDefendantDetails().getFirstName()).isEqualTo(CaseTabView.NAME_UNKNOWN); - assertThat(summaryTab.getDefendantDetails().getLastName()).isEqualTo(CaseTabView.NAME_UNKNOWN); - assertThat(summaryTab.getDefendantDetails().getAddressForService()).isEqualTo(address); - } - - @Test - void shouldDefaultDefendantAddressForServiceToPropertyAddressWhenAddressNotKnown() { - // Given - AddressUK propertyAddress = AddressUK.builder().postCode("SW1A 1AA").build(); - PCSCase pcsCase = PCSCase.builder() - .propertyAddress(propertyAddress) - .allDefendants(List.of(listValue(Party.builder() - .nameKnown(VerticalYesNo.NO) - .addressKnown(VerticalYesNo.NO) - .build()))) - .build(); - - // When - SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); - - // Then - assertThat(summaryTab.getDefendantDetails().getFirstName()).isEqualTo(CaseTabView.NAME_UNKNOWN); - assertThat(summaryTab.getDefendantDetails().getLastName()).isEqualTo(CaseTabView.NAME_UNKNOWN); - assertThat(summaryTab.getDefendantDetails().getAddressForService()).isEqualTo(propertyAddress); - } - - @Test - void shouldSetUnknownAdditionalDefendantNameWhenNameNotKnownButAddressKnown() { - // Given - AddressUK address = AddressUK.builder().postCode("SW1A 1AA").build(); - PCSCase pcsCase = PCSCase.builder() - .allDefendants(List.of( - listValue(Party.builder() - .nameKnown(VerticalYesNo.YES) - .firstName("Defendant") - .lastName("One") - .build()), - listValue(Party.builder() - .nameKnown(VerticalYesNo.NO) - .addressKnown(VerticalYesNo.YES) - .address(address) - .build()) - )) - .build(); - - // When - SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); - - // Then - assertThat(summaryTab.getAdditionalDefendants()).hasSize(1); - assertThat(summaryTab.getAdditionalDefendants().getFirst().getValue().getFirstName()) - .isEqualTo(CaseTabView.NAME_UNKNOWN); - assertThat(summaryTab.getAdditionalDefendants().getFirst().getValue().getLastName()) - .isEqualTo(CaseTabView.NAME_UNKNOWN); - assertThat(summaryTab.getAdditionalDefendants().getFirst().getValue().getAddressForService()) - .isEqualTo(address); - } - - @Test - void shouldDefaultAdditionalDefendantAddressForServiceToPropertyAddressWhenAddressNotKnown() { - // Given - AddressUK propertyAddress = AddressUK.builder().postCode("SW1A 1AA").build(); - PCSCase pcsCase = PCSCase.builder() - .propertyAddress(propertyAddress) - .allDefendants(List.of( - listValue(Party.builder() - .nameKnown(VerticalYesNo.YES) - .firstName("Defendant") - .lastName("One") - .build()), - listValue(Party.builder() - .nameKnown(VerticalYesNo.NO) - .addressKnown(VerticalYesNo.NO) - .build()) - )) - .build(); - - // When - SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); - - // Then - assertThat(summaryTab.getAdditionalDefendants()).hasSize(1); - assertThat(summaryTab.getAdditionalDefendants().getFirst().getValue().getFirstName()) - .isEqualTo(CaseTabView.NAME_UNKNOWN); - assertThat(summaryTab.getAdditionalDefendants().getFirst().getValue().getLastName()) - .isEqualTo(CaseTabView.NAME_UNKNOWN); - assertThat(summaryTab.getAdditionalDefendants().getFirst().getValue().getAddressForService()) - .isEqualTo(propertyAddress); - } - - @Test - void shouldSetEachGroundReasonInSummaryTab() { - // Given - PCSCase pcsCase = PCSCase.builder() - .claimGroundSummaries(List.of( - listValue(ClaimGroundSummary.builder() - .label("Antisocial behaviour") - .reason("Antisocial reason") - .build()), - listValue(ClaimGroundSummary.builder() - .label("Premium paid in connection with mutual exchange (ground 6)") - .reason("Premium reason") - .build()), - listValue(ClaimGroundSummary.builder() - .label("Offence during a riot (ground 2ZA)") - .reason("Riot reason") - .build()), - listValue(ClaimGroundSummary.builder() - .label("Condition 1 of Section 84A of the Housing Act 1985") - .reason("Condition 1 reason") - .build()), - listValue(ClaimGroundSummary.builder() - .label("Landlord’s works (ground 10)") - .reason("Works reason") - .build()), - listValue(ClaimGroundSummary.builder() - .label("Housing association special circumstances accommodation (ground 14)") - .reason("Housing reason") - .build()) - )) - .build(); - - // When - ReasonsForPossessionTabDetails reasons = underTest.buildSummaryTab(pcsCase).getReasonsForPossession(); - - // Then - assertThat(reasons.getAntisocialBehaviour()).isEqualTo("Antisocial reason"); - assertThat(reasons.getGround6()).isEqualTo("Premium reason"); - assertThat(reasons.getGround2ZA()).isEqualTo("Riot reason"); - assertThat(reasons.getCondition1OfSection84A()).isEqualTo("Condition 1 reason"); - assertThat(reasons.getGround10()).isEqualTo("Works reason"); - assertThat(reasons.getGround14()).isEqualTo("Housing reason"); - } - - @Test - void shouldGroupSection84AConditionsUnderAntisocialBehaviourInGrounds() { - // Given - PCSCase pcsCase = PCSCase.builder() - .claimGroundSummaries(List.of( - groundSummary("Antisocial behaviour", "Antisocial reason"), - groundSummary("Nuisance, annoyance, illegal or immoral use of the property (ground 2)", - "Nuisance reason"), - groundSummary("Condition 3 of Section 84A of the Housing Act 1985", "Condition 3 reason"), - groundSummary("Condition 1 of Section 84A of the Housing Act 1985", "Condition 1 reason"), - groundSummary("Condition 5 of Section 84A of the Housing Act 1985", "Condition 5 reason"), - groundSummary("Condition 2 of Section 84A of the Housing Act 1985", "Condition 2 reason"), - groundSummary("Condition 4 of Section 84A of the Housing Act 1985", "Condition 4 reason"), - groundSummary("Landlord’s works (ground 10)", "Works reason") - )) - .build(); - - // When - SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); - - // Then - assertThat(summaryTab.getGroundsForPossession().getGrounds()).isEqualTo(String.join("\n", - "Antisocial behaviour: " + String.join(", ", - "Condition 1 of Section 84A of the Housing Act 1985", - "Condition 2 of Section 84A of the Housing Act 1985", - "Condition 3 of Section 84A of the Housing Act 1985", - "Condition 4 of Section 84A of the Housing Act 1985", - "Condition 5 of Section 84A of the Housing Act 1985" - ), - "Nuisance, annoyance, illegal or immoral use of the property (ground 2)", - "Landlord’s works (ground 10)" - )); - } - - @Test - void shouldGroupSection84AConditionsUnderAntisocialBehaviourWhenParentGroundIsMissing() { - // Given - PCSCase pcsCase = PCSCase.builder() - .claimGroundSummaries(List.of( - groundSummary("Condition 2 of Section 84A of the Housing Act 1985", "Condition 2 reason"), - groundSummary("Condition 1 of Section 84A of the Housing Act 1985", "Condition 1 reason"), - groundSummary("Landlord’s works (ground 10)", "Works reason") - )) - .build(); - - // When - SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); - - // Then - assertThat(summaryTab.getGroundsForPossession().getGrounds()).isEqualTo(String.join("\n", - "Antisocial behaviour: " + String.join(", ", - "Condition 1 of Section 84A of the Housing Act 1985", - "Condition 2 of Section 84A of the Housing Act 1985" - ), - "Landlord’s works (ground 10)" - )); - } - - @Test - void shouldSetEachGroundNumberReasonInSummaryTab() { - // Given - PCSCase pcsCase = PCSCase.builder() - .claimGroundSummaries(List.of( - groundSummary("Ground label (ground 1)", "Reason 1"), - groundSummary("Ground label (ground 2)", "Reason 2"), - groundSummary("Ground label (ground 2A)", "Reason 2A"), - groundSummary("Ground label (ground 2ZA)", "Reason 2ZA"), - groundSummary("Ground label (ground 3)", "Reason 3"), - groundSummary("Ground label (ground 4)", "Reason 4"), - groundSummary("Ground label (ground 5)", "Reason 5"), - groundSummary("Ground label (ground 6)", "Reason 6"), - groundSummary("Ground label (ground 7)", "Reason 7"), - groundSummary("Ground label (ground 7A)", "Reason 7A"), - groundSummary("Ground label (ground 7B)", "Reason 7B"), - groundSummary("Ground label (ground 8)", "Reason 8"), - groundSummary("Ground label (ground 9)", "Reason 9"), - groundSummary("Ground label (ground 10)", "Reason 10"), - groundSummary("Ground label (ground 10A)", "Reason 10A"), - groundSummary("Ground label (ground 11)", "Reason 11"), - groundSummary("Ground label (ground 12)", "Reason 12"), - groundSummary("Ground label (ground 13)", "Reason 13"), - groundSummary("Ground label (ground 14)", "Reason 14"), - groundSummary("Ground label (ground 14A)", "Reason 14A"), - groundSummary("Ground label (ground 14ZA)", "Reason 14ZA"), - groundSummary("Ground label (ground 15)", "Reason 15"), - groundSummary("Ground label (ground 15A)", "Reason 15A"), - groundSummary("Ground label (ground 16)", "Reason 16"), - groundSummary("Ground label (ground 17)", "Reason 17"), - groundSummary("Ground label (ground A)", "Reason A"), - groundSummary("Ground label (ground B)", "Reason B"), - groundSummary("Ground label (ground C)", "Reason C"), - groundSummary("Ground label (ground D)", "Reason D"), - groundSummary("Ground label (ground E)", "Reason E"), - groundSummary("Ground label (ground F)", "Reason F"), - groundSummary("Ground label (ground G)", "Reason G"), - groundSummary("Ground label (ground H)", "Reason H"), - groundSummary("Ground label (ground I)", "Reason I"), - groundSummary("Ground label (ground Z)", "Unmapped reason") - )) - .build(); - - // When - ReasonsForPossessionTabDetails reasons = underTest.buildSummaryTab(pcsCase).getReasonsForPossession(); - - // Then - assertThat(reasons.getGround1()).isEqualTo("Reason 1"); - assertThat(reasons.getGround2()).isEqualTo("Reason 2"); - assertThat(reasons.getGround2A()).isEqualTo("Reason 2A"); - assertThat(reasons.getGround2ZA()).isEqualTo("Reason 2ZA"); - assertThat(reasons.getGround3()).isEqualTo("Reason 3"); - assertThat(reasons.getGround4()).isEqualTo("Reason 4"); - assertThat(reasons.getGround5()).isEqualTo("Reason 5"); - assertThat(reasons.getGround6()).isEqualTo("Reason 6"); - assertThat(reasons.getGround7()).isEqualTo("Reason 7"); - assertThat(reasons.getGround7A()).isEqualTo("Reason 7A"); - assertThat(reasons.getGround7B()).isEqualTo("Reason 7B"); - assertThat(reasons.getGround8()).isEqualTo("Reason 8"); - assertThat(reasons.getGround9()).isEqualTo("Reason 9"); - assertThat(reasons.getGround10()).isEqualTo("Reason 10"); - assertThat(reasons.getGround10A()).isEqualTo("Reason 10A"); - assertThat(reasons.getGround11()).isEqualTo("Reason 11"); - assertThat(reasons.getGround12()).isEqualTo("Reason 12"); - assertThat(reasons.getGround13()).isEqualTo("Reason 13"); - assertThat(reasons.getGround14()).isEqualTo("Reason 14"); - assertThat(reasons.getGround14A()).isEqualTo("Reason 14A"); - assertThat(reasons.getGround14ZA()).isEqualTo("Reason 14ZA"); - assertThat(reasons.getGround15()).isEqualTo("Reason 15"); - assertThat(reasons.getGround15A()).isEqualTo("Reason 15A"); - assertThat(reasons.getGround16()).isEqualTo("Reason 16"); - assertThat(reasons.getGround17()).isEqualTo("Reason 17"); - assertThat(reasons.getGroundA()).isEqualTo("Reason A"); - assertThat(reasons.getGroundB()).isEqualTo("Reason B"); - assertThat(reasons.getGroundC()).isEqualTo("Reason C"); - assertThat(reasons.getGroundD()).isEqualTo("Reason D"); - assertThat(reasons.getGroundE()).isEqualTo("Reason E"); - assertThat(reasons.getGroundF()).isEqualTo("Reason F"); - assertThat(reasons.getGroundG()).isEqualTo("Reason G"); - assertThat(reasons.getGroundH()).isEqualTo("Reason H"); - assertThat(reasons.getGroundI()).isEqualTo("Reason I"); - } - - @Test - void shouldSetEachSectionReasonInSummaryTab() { - // Given - PCSCase pcsCase = PCSCase.builder() - .claimGroundSummaries(List.of( - groundSummary("Ground label (section 157)", "Reason 157"), - groundSummary("Ground label (section 170)", "Reason 170"), - groundSummary("Ground label (section 178)", "Reason 178"), - groundSummary("Ground label (section 181)", "Reason 181"), - groundSummary("Ground label (section 186)", "Reason 186"), - groundSummary("Ground label (section 187)", "Reason 187"), - groundSummary("Ground label (section 191)", "Reason 191"), - groundSummary("Ground label (section 199)", "Reason 199"), - groundSummary("Ground label (section 999)", "Unmapped reason") - )) - .build(); - - // When - ReasonsForPossessionTabDetails reasons = underTest.buildSummaryTab(pcsCase).getReasonsForPossession(); - - // Then - assertThat(reasons.getSection157()).isEqualTo("Reason 157"); - assertThat(reasons.getSection170()).isEqualTo("Reason 170"); - assertThat(reasons.getSection178()).isEqualTo("Reason 178"); - assertThat(reasons.getSection181()).isEqualTo("Reason 181"); - assertThat(reasons.getSection186()).isEqualTo("Reason 186"); - assertThat(reasons.getSection187()).isEqualTo("Reason 187"); - assertThat(reasons.getSection191()).isEqualTo("Reason 191"); - assertThat(reasons.getSection199()).isEqualTo("Reason 199"); - } - - @Test - void shouldSetNonNumberedGroundReasonsInSummaryTab() { - // Given - PCSCase pcsCase = PCSCase.builder() - .claimGroundSummaries(List.of( - groundSummary("Condition 1 of Section 84A of the Housing Act 1985", "Condition 1 reason"), - groundSummary("Condition 2 of Section 84A of the Housing Act 1985", "Condition 2 reason"), - groundSummary("Condition 3 of Section 84A of the Housing Act 1985", "Condition 3 reason"), - groundSummary("Condition 4 of Section 84A of the Housing Act 1985", "Condition 4 reason"), - groundSummary("Condition 5 of Section 84A of the Housing Act 1985", "Condition 5 reason"), - groundSummary("Antisocial behaviour", "Antisocial reason"), - groundSummary("Breach of the tenancy", "Breach reason"), - groundSummary("Absolute grounds", "Absolute reason"), - groundSummary("Other", "Other reason"), - groundSummary("Other grounds", "Other grounds reason"), - groundSummary("No grounds", "No grounds reason"), - groundSummary("Converted contract paragraph 25B(2) of Schedule 12", "Paragraph reason"), - groundSummary("Unmapped label", "Unmapped reason") - )) - .build(); - - // When - ReasonsForPossessionTabDetails reasons = underTest.buildSummaryTab(pcsCase).getReasonsForPossession(); - - // Then - assertThat(reasons.getCondition1OfSection84A()).isEqualTo("Condition 1 reason"); - assertThat(reasons.getCondition2OfSection84A()).isEqualTo("Condition 2 reason"); - assertThat(reasons.getCondition3OfSection84A()).isEqualTo("Condition 3 reason"); - assertThat(reasons.getCondition4OfSection84A()).isEqualTo("Condition 4 reason"); - assertThat(reasons.getCondition5OfSection84A()).isEqualTo("Condition 5 reason"); - assertThat(reasons.getAntisocialBehaviour()).isEqualTo("Antisocial reason"); - assertThat(reasons.getBreachOfTheTenancy()).isEqualTo("Breach reason"); - assertThat(reasons.getAbsoluteGrounds()).isEqualTo("Absolute reason"); - assertThat(reasons.getOtherGrounds()).isEqualTo("Other grounds reason"); - assertThat(reasons.getNoGrounds()).isEqualTo("No grounds reason"); - assertThat(reasons.getParagraph25B2Schedule12()).isEqualTo("Paragraph reason"); - } - - @Test - void shouldSetRentArrearsDetailsFromStandardFrequencyAndDailyCharge() { - // Given - PCSCase pcsCase = PCSCase.builder() - .rentDetails(RentDetails.builder() - .frequency(RentPaymentFrequency.WEEKLY) - .dailyCharge(new BigDecimal("1.50")) - .build()) - .build(); - - // When - RentArrearsTabDetails rentArrearsDetails = underTest.buildSummaryTab(pcsCase).getRentArrearsDetails(); - - // Then - assertThat(rentArrearsDetails.getCalculationFrequency()).isEqualTo("Weekly"); - assertThat(rentArrearsDetails.getDailyRate()).isEqualTo("£1.50"); - } - - @Test - void shouldSetRentArrearsDetailsFromFormattedCalculatedDailyCharge() { - // Given - PCSCase pcsCase = PCSCase.builder() - .rentDetails(RentDetails.builder() - .formattedCalculatedDailyCharge("£2.34") - .build()) - .build(); - - // When - SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); - - // Then - assertThat(summaryTab.getRentArrearsDetails().getDailyRate()).isEqualTo("£2.34"); - } - - @Test - void shouldSetRentArrearsDetailsFromCalculatedDailyCharge() { - // Given - PCSCase pcsCase = PCSCase.builder() - .rentDetails(RentDetails.builder() - .calculatedDailyCharge(new BigDecimal("3.40")) - .build()) - .build(); - - // When - SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); - - // Then - assertThat(summaryTab.getRentArrearsDetails().getDailyRate()).isEqualTo("£3.40"); - } - @Test void shouldSetTenancyDetailsFromTenancyLicenceTypeLabel() { // Given @@ -702,6 +346,14 @@ void shouldSetTenancyDetailsFromTenancyLicenceTypeLabel() { .build()) .build(); + when(groundsBuilder.getGrounds(pcsCase)).thenReturn(null); + when(rentArrearsTabDetailsBuilder.buildRentArrearsTabDetails(pcsCase)).thenReturn(null); + when(reasonsForPossessionTabDetailsBuilder.buildSummaryReasonsForPossession(pcsCase)).thenReturn(null); + when(claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase)).thenReturn(null); + when(defendantInformationTabDetailsBuilder.buildSummaryDefendantOneDetails(pcsCase)).thenReturn(null); + when(additionalDefendantInformationTabDetailsBuilder.buildSummaryAdditionalDefendantsDetails(pcsCase)) + .thenReturn(null); + // When SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); @@ -746,6 +398,14 @@ void shouldSetTenancyDetailsFromWalesOccupationLicenceTypeLabelWhenEnglandTenanc .build()) .build(); + when(groundsBuilder.getGrounds(pcsCase)).thenReturn(null); + when(rentArrearsTabDetailsBuilder.buildRentArrearsTabDetails(pcsCase)).thenReturn(null); + when(reasonsForPossessionTabDetailsBuilder.buildSummaryReasonsForPossession(pcsCase)).thenReturn(null); + when(claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase)).thenReturn(null); + when(defendantInformationTabDetailsBuilder.buildSummaryDefendantOneDetails(pcsCase)).thenReturn(null); + when(additionalDefendantInformationTabDetailsBuilder.buildSummaryAdditionalDefendantsDetails(pcsCase)) + .thenReturn(null); + // When SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); @@ -764,6 +424,14 @@ void shouldSetTenancyDetailsFromWalesOtherOccupationLicenceType() { .build()) .build(); + when(groundsBuilder.getGrounds(pcsCase)).thenReturn(null); + when(rentArrearsTabDetailsBuilder.buildRentArrearsTabDetails(pcsCase)).thenReturn(null); + when(reasonsForPossessionTabDetailsBuilder.buildSummaryReasonsForPossession(pcsCase)).thenReturn(null); + when(claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase)).thenReturn(null); + when(defendantInformationTabDetailsBuilder.buildSummaryDefendantOneDetails(pcsCase)).thenReturn(null); + when(additionalDefendantInformationTabDetailsBuilder.buildSummaryAdditionalDefendantsDetails(pcsCase)) + .thenReturn(null); + // When SummaryTab summaryTab = underTest.buildSummaryTab(pcsCase); diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseTabViewTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseTabViewTest.java index fd96d71b3f..6550ee75ed 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseTabViewTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/CaseTabViewTest.java @@ -1,39 +1,54 @@ package uk.gov.hmcts.reform.pcs.ccd.view; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.Mock; import uk.gov.hmcts.ccd.sdk.type.AddressUK; import uk.gov.hmcts.ccd.sdk.type.ListValue; import uk.gov.hmcts.reform.pcs.ccd.domain.DefendantDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.DemotionOfTenancy; +import uk.gov.hmcts.reform.pcs.ccd.domain.DemotionOfTenancyHousingAct; import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; import uk.gov.hmcts.reform.pcs.ccd.domain.Party; +import uk.gov.hmcts.reform.pcs.ccd.domain.SuspensionOfRightToBuy; +import uk.gov.hmcts.reform.pcs.ccd.domain.SuspensionOfRightToBuyDemotionOfTenancy; +import uk.gov.hmcts.reform.pcs.ccd.domain.SuspensionOfRightToBuyHousingAct; +import uk.gov.hmcts.reform.pcs.ccd.domain.UnderlesseeMortgageeDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.ClaimGroundSummary; import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.ClaimantTabDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.DefendantTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.details.CaseDetailsTab; import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.summary.SummaryTab; +import uk.gov.hmcts.reform.pcs.ccd.view.builder.ClaimGroundSummaryBuilder; import java.util.ArrayList; import java.util.List; +import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.pcs.ccd.domain.AlternativesToPossession.DEMOTION_OF_TENANCY; +import static uk.gov.hmcts.reform.pcs.ccd.domain.AlternativesToPossession.SUSPENSION_OF_RIGHT_TO_BUY; @ExtendWith(MockitoExtension.class) class CaseTabViewTest { - private CaseTabView underTest; - @Mock private ClaimGroundSummaryBuilder claimGroundSummaryBuilder; - @BeforeEach - void setUp() { - underTest = new CaseTabView(claimGroundSummaryBuilder, new CaseSummaryTabView()); - } + @Mock + private CaseSummaryTabView caseSummaryTabView; + + @Mock + private CaseDetailsTabView caseDetailsTabView; + + @InjectMocks + private CaseTabView underTest; @Test void shouldSetClaimantDetailsInCasePartiesTab() { @@ -265,43 +280,41 @@ void shouldNotSetCasePartiesTabWithNoData() { } @Test - void shouldSetDraftSummaryTabFieldsUsingDraftDataOnly() { + void shouldSetTabFieldsUsingDraftDataOnly() { // Given - AddressUK propertyAddress = AddressUK.builder().postCode("SW1A 1AA").build(); - PCSCase pcsCase = PCSCase.builder() - .propertyAddress(propertyAddress) - .build(); - PCSCase draftCaseData = PCSCase.builder() - .propertyAddress(propertyAddress) - .build(); + PCSCase draftCaseData = PCSCase.builder().build(); + when(caseSummaryTabView.buildSummaryTab(draftCaseData)).thenReturn( + SummaryTab.builder().build() + ); + when(caseDetailsTabView.buildCaseDetailsTab(draftCaseData)).thenReturn( + CaseDetailsTab.builder().build() + ); when(claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData)).thenReturn(List.of()); + PCSCase pcsCase = PCSCase.builder().build(); + // When underTest.setDraftCaseTabFields(pcsCase, draftCaseData); // Then SummaryTab summaryTab = pcsCase.getSummaryTab(); - assertThat(summaryTab.getRepossessedPropertyAddress()).isEqualTo(propertyAddress); - assertThat(summaryTab.getClaimantDetails()).isNull(); - assertThat(summaryTab.getDefendantDetails()).isNull(); - assertThat(summaryTab.getGroundsForPossession().getGrounds()).isNull(); + CaseDetailsTab caseDetailsTab = pcsCase.getCaseDetailsTab(); + assertThat(summaryTab).isNotNull(); + assertThat(caseDetailsTab).isNotNull(); + verify(caseSummaryTabView, times(1)).buildSummaryTab(draftCaseData); + verify(caseDetailsTabView, times(1)).buildCaseDetailsTab(draftCaseData); + verify(caseSummaryTabView, times(0)).buildSummaryTab(pcsCase); + verify(caseDetailsTabView, times(0)).buildCaseDetailsTab(pcsCase); } @Test - void shouldSetDraftSummaryTabFieldsUsingDraftDefendantsAndGrounds() { + void shouldSetDraftTabFieldsUsingDraftDefendantsAndGrounds() { // Given AddressUK submittedPropertyAddress = AddressUK.builder().postCode("SW1A 1AA").build(); AddressUK draftPropertyAddress = AddressUK.builder().postCode("E1 1AA").build(); AddressUK defendantOneAddress = AddressUK.builder().postCode("M1 1AA").build(); AddressUK additionalDefendantAddress = AddressUK.builder().postCode("B1 1AA").build(); - PCSCase pcsCase = PCSCase.builder() - .propertyAddress(submittedPropertyAddress) - .allClaimants(List.of(listValue(Party.builder().orgName("Submitted claimant").build()))) - .claimGroundSummaries(List.of( - listValue(ClaimGroundSummary.builder().label("Submitted ground").build()) - )) - .build(); PCSCase draftCaseData = PCSCase.builder() .propertyAddress(draftPropertyAddress) .allClaimants(List.of(listValue(Party.builder().orgName("Draft claimant").build()))) @@ -327,25 +340,51 @@ void shouldSetDraftSummaryTabFieldsUsingDraftDefendantsAndGrounds() { listValue(ClaimGroundSummary.builder().label("Draft ground").build()) ); + when(caseSummaryTabView.buildSummaryTab(draftCaseData)).thenReturn( + SummaryTab.builder().build() + ); + when(caseDetailsTabView.buildCaseDetailsTab(draftCaseData)).thenReturn( + CaseDetailsTab.builder().build() + ); when(claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData)).thenReturn(draftGrounds); + PCSCase pcsCase = PCSCase.builder() + .propertyAddress(submittedPropertyAddress) + .allClaimants(List.of(listValue(Party.builder().orgName("Submitted claimant").build()))) + .claimGroundSummaries(List.of( + listValue(ClaimGroundSummary.builder().label("Submitted ground").build()) + )) + .build(); + // When underTest.setDraftCaseTabFields(pcsCase, draftCaseData); // Then SummaryTab summaryTab = pcsCase.getSummaryTab(); - assertThat(summaryTab.getRepossessedPropertyAddress()).isEqualTo(draftPropertyAddress); - assertThat(summaryTab.getClaimantDetails().getClaimantName()).isEqualTo("Draft claimant"); - assertThat(summaryTab.getDefendantDetails().getFirstName()).isEqualTo("Draft"); - assertThat(summaryTab.getDefendantDetails().getLastName()).isEqualTo("Defendant"); - assertThat(summaryTab.getDefendantDetails().getAddressForService()).isEqualTo(defendantOneAddress); - assertThat(summaryTab.getAdditionalDefendants()).hasSize(1); - assertThat(summaryTab.getAdditionalDefendants().getFirst().getValue().getFirstName()).isEqualTo("Additional"); - assertThat(summaryTab.getAdditionalDefendants().getFirst().getValue().getLastName()).isEqualTo("Defendant"); - assertThat(summaryTab.getAdditionalDefendants().getFirst().getValue().getAddressForService()) - .isEqualTo(additionalDefendantAddress); - assertThat(summaryTab.getGroundsForPossession().getGrounds()).isEqualTo("Draft ground"); + CaseDetailsTab caseDetailsTab = pcsCase.getCaseDetailsTab(); + assertThat(summaryTab).isNotNull(); + assertThat(caseDetailsTab).isNotNull(); + verify(caseSummaryTabView, times(1)).buildSummaryTab(draftCaseData); + verify(caseDetailsTabView, times(1)).buildCaseDetailsTab(draftCaseData); + verify(caseSummaryTabView, times(0)).buildSummaryTab(pcsCase); + verify(caseDetailsTabView, times(0)).buildCaseDetailsTab(pcsCase); + assertThat(draftCaseData.getAllDefendants()).hasSize(2); + Party firstDefendant = draftCaseData.getAllDefendants().getFirst().getValue(); + Party secondDefendant = draftCaseData.getAllDefendants().getLast().getValue(); + assertThat(firstDefendant.getNameKnown()).isEqualTo(VerticalYesNo.YES); + assertThat(firstDefendant.getFirstName()).isEqualTo("Draft"); + assertThat(firstDefendant.getLastName()).isEqualTo("Defendant"); + assertThat(firstDefendant.getAddressKnown()).isEqualTo(VerticalYesNo.YES); + assertThat(firstDefendant.getAddress()).isEqualTo(defendantOneAddress); + assertThat(secondDefendant.getNameKnown()).isEqualTo(VerticalYesNo.YES); + assertThat(secondDefendant.getFirstName()).isEqualTo("Additional"); + assertThat(secondDefendant.getLastName()).isEqualTo("Defendant"); + assertThat(secondDefendant.getAddressKnown()).isEqualTo(VerticalYesNo.YES); + assertThat(secondDefendant.getAddress()).isEqualTo(additionalDefendantAddress); + assertThat(draftCaseData.getClaimGroundSummaries()).hasSize(1); + assertThat(draftCaseData.getClaimGroundSummaries().getFirst().getValue().getLabel()) + .isEqualTo("Draft ground"); } @Test @@ -353,9 +392,6 @@ void shouldSetDraftDefendantWhenNoAdditionalDefendantHasBeenSelected() { // Given AddressUK propertyAddress = AddressUK.builder().postCode("SW1A 1AA").build(); AddressUK defendantAddress = AddressUK.builder().postCode("M1 1AA").build(); - PCSCase pcsCase = PCSCase.builder() - .propertyAddress(propertyAddress) - .build(); PCSCase draftCaseData = PCSCase.builder() .propertyAddress(propertyAddress) .defendant1(DefendantDetails.builder() @@ -368,12 +404,31 @@ void shouldSetDraftDefendantWhenNoAdditionalDefendantHasBeenSelected() { .addAnotherDefendant(VerticalYesNo.NO) .build(); + when(caseSummaryTabView.buildSummaryTab(draftCaseData)).thenReturn( + SummaryTab.builder().build() + ); + when(caseDetailsTabView.buildCaseDetailsTab(draftCaseData)).thenReturn( + CaseDetailsTab.builder().build() + ); when(claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData)).thenReturn(List.of()); + PCSCase pcsCase = PCSCase.builder() + .propertyAddress(propertyAddress) + .build(); + // When underTest.setDraftCaseTabFields(pcsCase, draftCaseData); // Then + SummaryTab summaryTab = pcsCase.getSummaryTab(); + CaseDetailsTab caseDetailsTab = pcsCase.getCaseDetailsTab(); + assertThat(summaryTab).isNotNull(); + assertThat(caseDetailsTab).isNotNull(); + verify(caseSummaryTabView, times(1)).buildSummaryTab(draftCaseData); + verify(caseDetailsTabView, times(1)).buildCaseDetailsTab(draftCaseData); + verify(caseSummaryTabView, times(0)).buildSummaryTab(pcsCase); + verify(caseDetailsTabView, times(0)).buildCaseDetailsTab(pcsCase); + assertThat(draftCaseData.getAllDefendants()).hasSize(1); Party defendant = draftCaseData.getAllDefendants().getFirst().getValue(); assertThat(defendant.getNameKnown()).isEqualTo(VerticalYesNo.YES); @@ -381,16 +436,12 @@ void shouldSetDraftDefendantWhenNoAdditionalDefendantHasBeenSelected() { assertThat(defendant.getLastName()).isEqualTo("Defendant"); assertThat(defendant.getAddressKnown()).isEqualTo(VerticalYesNo.YES); assertThat(defendant.getAddress()).isEqualTo(defendantAddress); - assertThat(pcsCase.getSummaryTab().getAdditionalDefendants()).isNull(); } @Test void shouldNotSetAdditionalDraftDefendantsWhenAdditionalDefendantListIsEmpty() { // Given AddressUK propertyAddress = AddressUK.builder().postCode("SW1A 1AA").build(); - PCSCase pcsCase = PCSCase.builder() - .propertyAddress(propertyAddress) - .build(); PCSCase draftCaseData = PCSCase.builder() .propertyAddress(propertyAddress) .defendant1(DefendantDetails.builder() @@ -403,17 +454,35 @@ void shouldNotSetAdditionalDraftDefendantsWhenAdditionalDefendantListIsEmpty() { .additionalDefendants(List.of()) .build(); + when(caseSummaryTabView.buildSummaryTab(draftCaseData)).thenReturn( + SummaryTab.builder().build() + ); + when(caseDetailsTabView.buildCaseDetailsTab(draftCaseData)).thenReturn( + CaseDetailsTab.builder().build() + ); when(claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData)).thenReturn(List.of()); + PCSCase pcsCase = PCSCase.builder() + .propertyAddress(propertyAddress) + .build(); + // When underTest.setDraftCaseTabFields(pcsCase, draftCaseData); // Then + SummaryTab summaryTab = pcsCase.getSummaryTab(); + CaseDetailsTab caseDetailsTab = pcsCase.getCaseDetailsTab(); + assertThat(summaryTab).isNotNull(); + assertThat(caseDetailsTab).isNotNull(); + verify(caseSummaryTabView, times(1)).buildSummaryTab(draftCaseData); + verify(caseDetailsTabView, times(1)).buildCaseDetailsTab(draftCaseData); + verify(caseSummaryTabView, times(0)).buildSummaryTab(pcsCase); + verify(caseDetailsTabView, times(0)).buildCaseDetailsTab(pcsCase); assertThat(draftCaseData.getAllDefendants()).hasSize(1); - assertThat(pcsCase.getSummaryTab().getDefendantDetails().getFirstName()).isEqualTo("Only"); - assertThat(pcsCase.getSummaryTab().getDefendantDetails().getLastName()).isEqualTo("Defendant"); - assertThat(pcsCase.getSummaryTab().getDefendantDetails().getAddressForService()).isEqualTo(propertyAddress); - assertThat(pcsCase.getSummaryTab().getAdditionalDefendants()).isNull(); + Party defendant = draftCaseData.getAllDefendants().getFirst().getValue(); + assertThat(defendant.getFirstName()).isEqualTo("Only"); + assertThat(defendant.getLastName()).isEqualTo("Defendant"); + assertThat(defendant.getAddress()).isNull(); } @Test @@ -427,23 +496,399 @@ void shouldNotOverwriteExistingDraftDefendantsWhenDefendantOneIsMissing() { .lastName("Defendant") .build()) ); - PCSCase pcsCase = PCSCase.builder() - .propertyAddress(propertyAddress) - .build(); PCSCase draftCaseData = PCSCase.builder() .propertyAddress(propertyAddress) .allDefendants(existingDefendants) .build(); + when(caseSummaryTabView.buildSummaryTab(draftCaseData)).thenReturn( + SummaryTab.builder().build() + ); + when(caseDetailsTabView.buildCaseDetailsTab(draftCaseData)).thenReturn( + CaseDetailsTab.builder().build() + ); when(claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData)).thenReturn(List.of()); + PCSCase pcsCase = PCSCase.builder() + .propertyAddress(propertyAddress) + .build(); + // When underTest.setDraftCaseTabFields(pcsCase, draftCaseData); // Then + SummaryTab summaryTab = pcsCase.getSummaryTab(); + CaseDetailsTab caseDetailsTab = pcsCase.getCaseDetailsTab(); + assertThat(summaryTab).isNotNull(); + assertThat(caseDetailsTab).isNotNull(); + verify(caseSummaryTabView, times(1)).buildSummaryTab(draftCaseData); + verify(caseDetailsTabView, times(1)).buildCaseDetailsTab(draftCaseData); + verify(caseSummaryTabView, times(0)).buildSummaryTab(pcsCase); + verify(caseDetailsTabView, times(0)).buildCaseDetailsTab(pcsCase); + assertThat(draftCaseData.getAllDefendants()).isSameAs(existingDefendants); - assertThat(pcsCase.getSummaryTab().getDefendantDetails().getFirstName()).isEqualTo("Existing"); - assertThat(pcsCase.getSummaryTab().getDefendantDetails().getLastName()).isEqualTo("Defendant"); + } + + @Test + void shouldSetDraftUnderlesseeOrMortgagePartiesWhenThereIsMoreThanOneParty() { + // Given + String name1 = "name1"; + AddressUK address1 = AddressUK.builder().build(); + UnderlesseeMortgageeDetails underlesseeMortgageeDetails1 = UnderlesseeMortgageeDetails.builder() + .nameKnown(VerticalYesNo.YES) + .name(name1) + .addressKnown(VerticalYesNo.YES) + .address(address1) + .build(); + + UnderlesseeMortgageeDetails underlesseeMortgageeDetails2 = UnderlesseeMortgageeDetails.builder() + .nameKnown(VerticalYesNo.NO) + .addressKnown(VerticalYesNo.NO) + .build(); + + PCSCase draftCaseData = PCSCase.builder() + .underlesseeOrMortgagee1(underlesseeMortgageeDetails1) + .additionalUnderlesseeOrMortgagee(List.of(listValue(underlesseeMortgageeDetails2))) + .build(); + + when(caseSummaryTabView.buildSummaryTab(draftCaseData)).thenReturn( + SummaryTab.builder().build() + ); + when(caseDetailsTabView.buildCaseDetailsTab(draftCaseData)).thenReturn( + CaseDetailsTab.builder().build() + ); + when(claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData)).thenReturn(List.of()); + + PCSCase pcsCase = PCSCase.builder().build(); + + // When + underTest.setDraftCaseTabFields(pcsCase, draftCaseData); + + // Then + SummaryTab summaryTab = pcsCase.getSummaryTab(); + CaseDetailsTab caseDetailsTab = pcsCase.getCaseDetailsTab(); + assertThat(summaryTab).isNotNull(); + assertThat(caseDetailsTab).isNotNull(); + verify(caseSummaryTabView, times(1)).buildSummaryTab(draftCaseData); + verify(caseDetailsTabView, times(1)).buildCaseDetailsTab(draftCaseData); + verify(caseSummaryTabView, times(0)).buildSummaryTab(pcsCase); + verify(caseDetailsTabView, times(0)).buildCaseDetailsTab(pcsCase); + + List> allUnderlesseeOrMortgagees = draftCaseData.getAllUnderlesseeOrMortgagees(); + assertThat(allUnderlesseeOrMortgagees).hasSize(2); + Party party1 = allUnderlesseeOrMortgagees.getFirst().getValue(); + assertThat(party1.getNameKnown()).isEqualTo(VerticalYesNo.YES); + assertThat(party1.getOrgName()).isEqualTo(name1); + assertThat(party1.getAddressKnown()).isEqualTo(VerticalYesNo.YES); + assertThat(party1.getAddress()).isEqualTo(address1); + + Party party2 = allUnderlesseeOrMortgagees.getLast().getValue(); + assertThat(party2.getNameKnown()).isEqualTo(VerticalYesNo.NO); + assertThat(party2.getOrgName()).isNull(); + assertThat(party2.getAddressKnown()).isEqualTo(VerticalYesNo.NO); + assertThat(party2.getAddress()).isNull(); + } + + @Test + void shouldSetDraftUnderlesseeOrMortgagePartiesWhenThereIsOnlyOneParty() { + // Given + String name1 = "name1"; + AddressUK address1 = AddressUK.builder().build(); + UnderlesseeMortgageeDetails underlesseeMortgageeDetails1 = UnderlesseeMortgageeDetails.builder() + .nameKnown(VerticalYesNo.YES) + .name(name1) + .addressKnown(VerticalYesNo.YES) + .address(address1) + .build(); + + PCSCase draftCaseData = PCSCase.builder() + .underlesseeOrMortgagee1(underlesseeMortgageeDetails1) + .build(); + + when(caseSummaryTabView.buildSummaryTab(draftCaseData)).thenReturn( + SummaryTab.builder().build() + ); + when(caseDetailsTabView.buildCaseDetailsTab(draftCaseData)).thenReturn( + CaseDetailsTab.builder().build() + ); + when(claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData)).thenReturn(List.of()); + + PCSCase pcsCase = PCSCase.builder().build(); + + // When + underTest.setDraftCaseTabFields(pcsCase, draftCaseData); + + // Then + SummaryTab summaryTab = pcsCase.getSummaryTab(); + CaseDetailsTab caseDetailsTab = pcsCase.getCaseDetailsTab(); + assertThat(summaryTab).isNotNull(); + assertThat(caseDetailsTab).isNotNull(); + verify(caseSummaryTabView, times(1)).buildSummaryTab(draftCaseData); + verify(caseDetailsTabView, times(1)).buildCaseDetailsTab(draftCaseData); + verify(caseSummaryTabView, times(0)).buildSummaryTab(pcsCase); + verify(caseDetailsTabView, times(0)).buildCaseDetailsTab(pcsCase); + + List> allUnderlesseeOrMortgagees = draftCaseData.getAllUnderlesseeOrMortgagees(); + assertThat(allUnderlesseeOrMortgagees).hasSize(1); + Party party1 = allUnderlesseeOrMortgagees.getFirst().getValue(); + assertThat(party1.getNameKnown()).isEqualTo(VerticalYesNo.YES); + assertThat(party1.getOrgName()).isEqualTo(name1); + assertThat(party1.getAddressKnown()).isEqualTo(VerticalYesNo.YES); + assertThat(party1.getAddress()).isEqualTo(address1); + } + + @Test + void shouldNotSetDraftUnderlesseeOrMortgagePartiesWhenThereIsNoParties() { + // Given + PCSCase draftCaseData = PCSCase.builder().build(); + + when(caseSummaryTabView.buildSummaryTab(draftCaseData)).thenReturn( + SummaryTab.builder().build() + ); + when(caseDetailsTabView.buildCaseDetailsTab(draftCaseData)).thenReturn( + CaseDetailsTab.builder().build() + ); + when(claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData)).thenReturn(List.of()); + + PCSCase pcsCase = PCSCase.builder().build(); + + // When + underTest.setDraftCaseTabFields(pcsCase, draftCaseData); + + // Then + SummaryTab summaryTab = pcsCase.getSummaryTab(); + CaseDetailsTab caseDetailsTab = pcsCase.getCaseDetailsTab(); + assertThat(summaryTab).isNotNull(); + assertThat(caseDetailsTab).isNotNull(); + verify(caseSummaryTabView, times(1)).buildSummaryTab(draftCaseData); + verify(caseDetailsTabView, times(1)).buildCaseDetailsTab(draftCaseData); + verify(caseSummaryTabView, times(0)).buildSummaryTab(pcsCase); + verify(caseDetailsTabView, times(0)).buildCaseDetailsTab(pcsCase); + + List> allUnderlesseeOrMortgagees = draftCaseData.getAllUnderlesseeOrMortgagees(); + assertThat(allUnderlesseeOrMortgagees).isNull(); + } + + @Test + void shouldNotSetDraftUnderlesseeOrMortgagePartiesWhenUnderlesseeMortgageeDetails1IsNotSet() { + // Given + UnderlesseeMortgageeDetails additionalUnderlesseeMortgageeDetails = UnderlesseeMortgageeDetails.builder() + .nameKnown(VerticalYesNo.NO) + .addressKnown(VerticalYesNo.NO) + .build(); + + PCSCase draftCaseData = PCSCase.builder() + .additionalUnderlesseeOrMortgagee(List.of(listValue(additionalUnderlesseeMortgageeDetails))) + .build(); + + when(caseSummaryTabView.buildSummaryTab(draftCaseData)).thenReturn( + SummaryTab.builder().build() + ); + when(caseDetailsTabView.buildCaseDetailsTab(draftCaseData)).thenReturn( + CaseDetailsTab.builder().build() + ); + when(claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData)).thenReturn(List.of()); + + PCSCase pcsCase = PCSCase.builder().build(); + + // When + underTest.setDraftCaseTabFields(pcsCase, draftCaseData); + + // Then + SummaryTab summaryTab = pcsCase.getSummaryTab(); + CaseDetailsTab caseDetailsTab = pcsCase.getCaseDetailsTab(); + assertThat(summaryTab).isNotNull(); + assertThat(caseDetailsTab).isNotNull(); + verify(caseSummaryTabView, times(1)).buildSummaryTab(draftCaseData); + verify(caseDetailsTabView, times(1)).buildCaseDetailsTab(draftCaseData); + verify(caseSummaryTabView, times(0)).buildSummaryTab(pcsCase); + verify(caseDetailsTabView, times(0)).buildCaseDetailsTab(pcsCase); + + List> allUnderlesseeOrMortgagees = draftCaseData.getAllUnderlesseeOrMortgagees(); + assertThat(allUnderlesseeOrMortgagees).isNull(); + } + + @Test + void shouldSetSuspensionOfRightToBuyAndDemotionOfTenancyDraftDataWhenBothSelected() { + // Given + String suspensionReason = "Suspension reason"; + String demotionReason = "Demotion reason"; + SuspensionOfRightToBuyDemotionOfTenancy suspensionOfRightToBuyDemotionOfTenancy = + SuspensionOfRightToBuyDemotionOfTenancy.builder() + .suspensionOfRightToBuyActs(SuspensionOfRightToBuyHousingAct.SECTION_6A_2) + .suspensionOrderReason(suspensionReason) + .demotionOfTenancyActs(DemotionOfTenancyHousingAct.SECTION_6A_2) + .demotionOrderReason(demotionReason) + .build(); + + PCSCase draftCaseData = PCSCase.builder() + .suspensionOfRightToBuyDemotionOfTenancy(suspensionOfRightToBuyDemotionOfTenancy) + .alternativesToPossession(Set.of(SUSPENSION_OF_RIGHT_TO_BUY, DEMOTION_OF_TENANCY)) + .build(); + + when(caseSummaryTabView.buildSummaryTab(draftCaseData)).thenReturn( + SummaryTab.builder().build() + ); + when(caseDetailsTabView.buildCaseDetailsTab(draftCaseData)).thenReturn( + CaseDetailsTab.builder().build() + ); + when(claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData)).thenReturn(List.of()); + + PCSCase pcsCase = PCSCase.builder().build(); + + // When + underTest.setDraftCaseTabFields(pcsCase, draftCaseData); + + // Then + SummaryTab summaryTab = pcsCase.getSummaryTab(); + CaseDetailsTab caseDetailsTab = pcsCase.getCaseDetailsTab(); + assertThat(summaryTab).isNotNull(); + assertThat(caseDetailsTab).isNotNull(); + verify(caseSummaryTabView, times(1)).buildSummaryTab(draftCaseData); + verify(caseDetailsTabView, times(1)).buildCaseDetailsTab(draftCaseData); + verify(caseSummaryTabView, times(0)).buildSummaryTab(pcsCase); + verify(caseDetailsTabView, times(0)).buildCaseDetailsTab(pcsCase); + + SuspensionOfRightToBuy suspensionOfRightToBuy = draftCaseData.getSuspensionOfRightToBuy(); + assertThat(suspensionOfRightToBuy.getHousingAct()).isEqualTo(SuspensionOfRightToBuyHousingAct.SECTION_6A_2); + assertThat(suspensionOfRightToBuy.getReason()).isEqualTo(suspensionReason); + + DemotionOfTenancy demotionOfTenancy = draftCaseData.getDemotionOfTenancy(); + assertThat(demotionOfTenancy.getHousingAct()).isEqualTo(DemotionOfTenancyHousingAct.SECTION_6A_2); + assertThat(demotionOfTenancy.getReason()).isEqualTo(demotionReason); + } + + @Test + void shouldNotSetSuspensionOfRightToBuyAndDemotionOfTenancyDraftDataWhenOnlyDemotionSelected() { + // Given + String suspensionReason = "Suspension reason"; + String demotionReason = "Demotion reason"; + SuspensionOfRightToBuyDemotionOfTenancy suspensionOfRightToBuyDemotionOfTenancy = + SuspensionOfRightToBuyDemotionOfTenancy.builder() + .suspensionOfRightToBuyActs(SuspensionOfRightToBuyHousingAct.SECTION_6A_2) + .suspensionOrderReason(suspensionReason) + .demotionOfTenancyActs(DemotionOfTenancyHousingAct.SECTION_6A_2) + .demotionOrderReason(demotionReason) + .build(); + + PCSCase draftCaseData = PCSCase.builder() + .suspensionOfRightToBuyDemotionOfTenancy(suspensionOfRightToBuyDemotionOfTenancy) + .alternativesToPossession(Set.of(DEMOTION_OF_TENANCY)) + .build(); + + when(caseSummaryTabView.buildSummaryTab(draftCaseData)).thenReturn( + SummaryTab.builder().build() + ); + when(caseDetailsTabView.buildCaseDetailsTab(draftCaseData)).thenReturn( + CaseDetailsTab.builder().build() + ); + when(claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData)).thenReturn(List.of()); + + PCSCase pcsCase = PCSCase.builder().build(); + + // When + underTest.setDraftCaseTabFields(pcsCase, draftCaseData); + + // Then + SummaryTab summaryTab = pcsCase.getSummaryTab(); + CaseDetailsTab caseDetailsTab = pcsCase.getCaseDetailsTab(); + assertThat(summaryTab).isNotNull(); + assertThat(caseDetailsTab).isNotNull(); + verify(caseSummaryTabView, times(1)).buildSummaryTab(draftCaseData); + verify(caseDetailsTabView, times(1)).buildCaseDetailsTab(draftCaseData); + verify(caseSummaryTabView, times(0)).buildSummaryTab(pcsCase); + verify(caseDetailsTabView, times(0)).buildCaseDetailsTab(pcsCase); + + SuspensionOfRightToBuy suspensionOfRightToBuy = draftCaseData.getSuspensionOfRightToBuy(); + assertThat(suspensionOfRightToBuy).isNull(); + + DemotionOfTenancy demotionOfTenancy = draftCaseData.getDemotionOfTenancy(); + assertThat(demotionOfTenancy).isNull(); + } + + @Test + void shouldNotSetSuspensionOfRightToBuyAndDemotionOfTenancyDraftDataWhenOnlySuspensionSelected() { + // Given + String suspensionReason = "Suspension reason"; + String demotionReason = "Demotion reason"; + SuspensionOfRightToBuyDemotionOfTenancy suspensionOfRightToBuyDemotionOfTenancy = + SuspensionOfRightToBuyDemotionOfTenancy.builder() + .suspensionOfRightToBuyActs(SuspensionOfRightToBuyHousingAct.SECTION_6A_2) + .suspensionOrderReason(suspensionReason) + .demotionOfTenancyActs(DemotionOfTenancyHousingAct.SECTION_6A_2) + .demotionOrderReason(demotionReason) + .build(); + + PCSCase draftCaseData = PCSCase.builder() + .suspensionOfRightToBuyDemotionOfTenancy(suspensionOfRightToBuyDemotionOfTenancy) + .alternativesToPossession(Set.of(SUSPENSION_OF_RIGHT_TO_BUY)) + .build(); + + when(caseSummaryTabView.buildSummaryTab(draftCaseData)).thenReturn( + SummaryTab.builder().build() + ); + when(caseDetailsTabView.buildCaseDetailsTab(draftCaseData)).thenReturn( + CaseDetailsTab.builder().build() + ); + when(claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData)).thenReturn(List.of()); + + PCSCase pcsCase = PCSCase.builder().build(); + + // When + underTest.setDraftCaseTabFields(pcsCase, draftCaseData); + + // Then + SummaryTab summaryTab = pcsCase.getSummaryTab(); + CaseDetailsTab caseDetailsTab = pcsCase.getCaseDetailsTab(); + assertThat(summaryTab).isNotNull(); + assertThat(caseDetailsTab).isNotNull(); + verify(caseSummaryTabView, times(1)).buildSummaryTab(draftCaseData); + verify(caseDetailsTabView, times(1)).buildCaseDetailsTab(draftCaseData); + verify(caseSummaryTabView, times(0)).buildSummaryTab(pcsCase); + verify(caseDetailsTabView, times(0)).buildCaseDetailsTab(pcsCase); + + SuspensionOfRightToBuy suspensionOfRightToBuy = draftCaseData.getSuspensionOfRightToBuy(); + assertThat(suspensionOfRightToBuy).isNull(); + + DemotionOfTenancy demotionOfTenancy = draftCaseData.getDemotionOfTenancy(); + assertThat(demotionOfTenancy).isNull(); + } + + @Test + void shouldNotSetSuspensionOfRightToBuyAndDemotionOfTenancyDraftDataWithNoData() { + // Given + PCSCase draftCaseData = PCSCase.builder() + .alternativesToPossession(Set.of(SUSPENSION_OF_RIGHT_TO_BUY, DEMOTION_OF_TENANCY)) + .build(); + + when(caseSummaryTabView.buildSummaryTab(draftCaseData)).thenReturn( + SummaryTab.builder().build() + ); + when(caseDetailsTabView.buildCaseDetailsTab(draftCaseData)).thenReturn( + CaseDetailsTab.builder().build() + ); + when(claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData)).thenReturn(List.of()); + + PCSCase pcsCase = PCSCase.builder().build(); + + // When + underTest.setDraftCaseTabFields(pcsCase, draftCaseData); + + // Then + SummaryTab summaryTab = pcsCase.getSummaryTab(); + CaseDetailsTab caseDetailsTab = pcsCase.getCaseDetailsTab(); + assertThat(summaryTab).isNotNull(); + assertThat(caseDetailsTab).isNotNull(); + verify(caseSummaryTabView, times(1)).buildSummaryTab(draftCaseData); + verify(caseDetailsTabView, times(1)).buildCaseDetailsTab(draftCaseData); + verify(caseSummaryTabView, times(0)).buildSummaryTab(pcsCase); + verify(caseDetailsTabView, times(0)).buildCaseDetailsTab(pcsCase); + + SuspensionOfRightToBuy suspensionOfRightToBuy = draftCaseData.getSuspensionOfRightToBuy(); + assertThat(suspensionOfRightToBuy).isNull(); + + DemotionOfTenancy demotionOfTenancy = draftCaseData.getDemotionOfTenancy(); + assertThat(demotionOfTenancy).isNull(); } private static ListValue listValue(T value) { diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/NoticeOfPossessionViewTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/NoticeOfPossessionViewTest.java index 72e376005b..3d1d503c9c 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/NoticeOfPossessionViewTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/NoticeOfPossessionViewTest.java @@ -8,10 +8,12 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.ccd.sdk.type.YesOrNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.DocumentType; import uk.gov.hmcts.reform.pcs.ccd.domain.NoticeServedDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; import uk.gov.hmcts.reform.pcs.ccd.domain.WalesNoticeDetails; import uk.gov.hmcts.reform.pcs.ccd.entity.ClaimEntity; +import uk.gov.hmcts.reform.pcs.ccd.entity.DocumentEntity; import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity; import uk.gov.hmcts.reform.pcs.ccd.entity.claim.NoticeOfPossessionEntity; import uk.gov.hmcts.reform.pcs.postcodecourt.model.LegislativeCountry; @@ -258,4 +260,29 @@ void shouldSetNoticeServedDateAndDetailsForOther() { assertThat(noticeServedDetails.getNoticeOtherExplanation()).isEqualTo(otherExplanation); } + @Test + void shouldSetNoticeDocumentIfPresent() { + // Given + LocalDate postedDate = mock(LocalDate.class); + when(noticeOfPossessionEntity.getServingMethod()).thenReturn(FIRST_CLASS_POST); + when(noticeOfPossessionEntity.getNoticeDate()).thenReturn(postedDate); + when(pcsCaseEntity.getDocuments()).thenReturn( + List.of( + DocumentEntity.builder() + .type(DocumentType.NOTICE_FOR_SERVICE_OUT_OF_JURISDICTION) + .build() + ) + ); + + // When + underTest.setCaseFields(pcsCase, pcsCaseEntity); + + // Then + verify(pcsCase).setNoticeServedDetails(noticeServedDetailsCaptor.capture()); + + NoticeServedDetails noticeServedDetails = noticeServedDetailsCaptor.getValue(); + assertThat(noticeServedDetails.getNoticeServiceMethod()).isEqualTo(FIRST_CLASS_POST); + assertThat(noticeServedDetails.getNoticePostedDate()).isSameAs(postedDate); + assertThat(noticeServedDetails.getNoticeDocuments()).hasSize(1); + } } diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/RentArrearsViewTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/RentArrearsViewTest.java index bd1e036153..fc75a92453 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/RentArrearsViewTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/RentArrearsViewTest.java @@ -6,10 +6,12 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.hmcts.reform.pcs.ccd.domain.DocumentType; import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; import uk.gov.hmcts.reform.pcs.ccd.domain.RentArrearsSection; import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; import uk.gov.hmcts.reform.pcs.ccd.entity.ClaimEntity; +import uk.gov.hmcts.reform.pcs.ccd.entity.DocumentEntity; import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity; import uk.gov.hmcts.reform.pcs.ccd.entity.claim.RentArrearsEntity; @@ -80,6 +82,13 @@ void shouldSetRentArrearsFields() { when(rentArrearsEntity.getArrearsJudgmentWanted()).thenReturn(VerticalYesNo.YES); when(rentArrearsEntity.getRecoveryAttempted()).thenReturn(VerticalYesNo.YES); when(rentArrearsEntity.getRecoveryAttemptDetails()).thenReturn(details); + when(pcsCaseEntity.getDocuments()).thenReturn( + List.of( + DocumentEntity.builder() + .type(DocumentType.RENT_STATEMENT) + .build() + ) + ); // When underTest.setCaseFields(pcsCase, pcsCaseEntity); @@ -93,6 +102,7 @@ void shouldSetRentArrearsFields() { assertThat(rentArrears.getTotal()).isEqualTo(totalRentArrears); assertThat(rentArrears.getRecoveryAttempted()).isEqualTo(VerticalYesNo.YES); assertThat(rentArrears.getRecoveryAttemptDetails()).isEqualTo(details); + assertThat(rentArrears.getStatementDocuments()).hasSize(1); verify(pcsCase).setArrearsJudgmentWanted(VerticalYesNo.YES); } diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/RentDetailsViewTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/RentDetailsViewTest.java index 8da11d7874..bde8e4111a 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/RentDetailsViewTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/RentDetailsViewTest.java @@ -6,6 +6,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import uk.gov.hmcts.ccd.sdk.type.YesOrNo; import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; import uk.gov.hmcts.reform.pcs.ccd.domain.RentDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.RentPaymentFrequency; @@ -73,6 +74,7 @@ void shouldSetRentDetailsFields() { = ArgumentCaptor.forClass(RentDetails.class); verify(pcsCase).setRentDetails(rentDetailsCaptor.capture()); + verify(pcsCase).setShowRentSectionPage(YesOrNo.YES); RentDetails rentDetails = rentDetailsCaptor.getValue(); assertThat(rentDetails.getCurrentRent()).isEqualTo(rentAmount); diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/TenancyLicenceViewTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/TenancyLicenceViewTest.java index 4db5afb0bc..5709495c3b 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/TenancyLicenceViewTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/TenancyLicenceViewTest.java @@ -7,17 +7,20 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.pcs.ccd.domain.CombinedLicenceType; +import uk.gov.hmcts.reform.pcs.ccd.domain.DocumentType; import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; import uk.gov.hmcts.reform.pcs.ccd.domain.TenancyLicenceDetails; import uk.gov.hmcts.reform.pcs.ccd.domain.TenancyLicenceType; import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; import uk.gov.hmcts.reform.pcs.ccd.domain.wales.OccupationLicenceDetailsWales; import uk.gov.hmcts.reform.pcs.ccd.domain.wales.OccupationLicenceTypeWales; +import uk.gov.hmcts.reform.pcs.ccd.entity.DocumentEntity; import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity; import uk.gov.hmcts.reform.pcs.ccd.entity.TenancyLicenceEntity; import uk.gov.hmcts.reform.pcs.postcodecourt.model.LegislativeCountry; import java.time.LocalDate; +import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -70,6 +73,13 @@ void shouldSetTenancyLicenceFieldsForNonWales() { when(tenancyLicenceEntity.getStartDate()).thenReturn(tenancyStartDate); when(tenancyLicenceEntity.getHasCopyOfTenancyLicence()).thenReturn(hasCopyOfTenancyLicence); when(tenancyLicenceEntity.getReasonsForNoTenancyLicence()).thenReturn(reasonsForNoTenancyLicence); + when(pcsCaseEntity.getDocuments()).thenReturn( + List.of( + DocumentEntity.builder() + .type(DocumentType.TENANCY_LICENCE) + .build() + ) + ); // When underTest.setCaseFields(pcsCase, pcsCaseEntity); @@ -88,6 +98,7 @@ void shouldSetTenancyLicenceFieldsForNonWales() { assertThat(tenancyLicenceDetails.getHasCopyOfTenancyLicence()).isEqualTo(hasCopyOfTenancyLicence); assertThat(tenancyLicenceDetails.getReasonsForNoTenancyLicenceDocuments()) .isEqualTo(reasonsForNoTenancyLicence); + assertThat(tenancyLicenceDetails.getTenancyLicenceDocuments()).hasSize(1); } @Test diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/AdditionalDefendantInformationTabDetailsBuilderTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/AdditionalDefendantInformationTabDetailsBuilderTest.java new file mode 100644 index 0000000000..e210ff7c8d --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/AdditionalDefendantInformationTabDetailsBuilderTest.java @@ -0,0 +1,293 @@ +package uk.gov.hmcts.reform.pcs.ccd.view.builder; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.ccd.sdk.type.AddressUK; +import uk.gov.hmcts.ccd.sdk.type.ListValue; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.Party; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.AdditionalDefendantInformationTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.view.CaseTabView; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class AdditionalDefendantInformationTabDetailsBuilderTest { + + private AdditionalDefendantInformationTabDetailsBuilder additionalDefendantInformationTabDetailsBuilder; + + @BeforeEach + void setUp() { + additionalDefendantInformationTabDetailsBuilder = new AdditionalDefendantInformationTabDetailsBuilder(); + } + + @Test + void shouldSetAdditionalDefendantsInSummaryTabWhenThereIsMoreThanOneDefendant() { + // Given + AddressUK address = AddressUK.builder().postCode("SW1A 1AA").build(); + String firstName = "Defendant2"; + String lastName = "Two"; + PCSCase pcsCase = PCSCase.builder() + .allDefendants(List.of( + listValue(Party.builder() + .nameKnown(VerticalYesNo.YES) + .firstName("Defendant") + .lastName("One") + .build()), + listValue(Party.builder() + .nameKnown(VerticalYesNo.YES) + .firstName(firstName) + .lastName(lastName) + .addressKnown(VerticalYesNo.YES) + .address(address) + .build()) + )) + .build(); + + // When + List> additionalDefendants = + additionalDefendantInformationTabDetailsBuilder.buildSummaryAdditionalDefendantsDetails(pcsCase); + + // Then + assertThat(additionalDefendants).hasSize(1); + assertThat(additionalDefendants.getFirst().getValue().getNameKnown()).isNull(); + assertThat(additionalDefendants.getFirst().getValue().getFirstName()) + .isEqualTo(firstName); + assertThat(additionalDefendants.getFirst().getValue().getLastName()) + .isEqualTo(lastName); + assertThat(additionalDefendants.getFirst().getValue().getAddressKnown()).isNull(); + assertThat(additionalDefendants.getFirst().getValue().getAddressForService()) + .isEqualTo(address); + } + + @Test + void shouldNotSetAdditionalDefendantsInSummaryTabWhenThereIsOnlyOneDefendant() { + // Given + AddressUK address = AddressUK.builder().postCode("SW1A 1AA").build(); + PCSCase pcsCase = PCSCase.builder() + .allDefendants(List.of( + listValue(Party.builder() + .nameKnown(VerticalYesNo.YES) + .firstName("Defendant") + .lastName("One") + .build()) + )) + .build(); + + // When + List> additionalDefendants = + additionalDefendantInformationTabDetailsBuilder.buildSummaryAdditionalDefendantsDetails(pcsCase); + + // Then + assertThat(additionalDefendants).isNull(); + } + + @Test + void shouldSetUnknownAdditionalDefendantNameWhenNameNotKnownButAddressKnownInSummaryTab() { + // Given + AddressUK address = AddressUK.builder().postCode("SW1A 1AA").build(); + PCSCase pcsCase = PCSCase.builder() + .allDefendants(List.of( + listValue(Party.builder() + .nameKnown(VerticalYesNo.YES) + .firstName("Defendant") + .lastName("One") + .build()), + listValue(Party.builder() + .nameKnown(VerticalYesNo.NO) + .addressKnown(VerticalYesNo.YES) + .address(address) + .build()) + )) + .build(); + + // When + List> additionalDefendants = + additionalDefendantInformationTabDetailsBuilder.buildSummaryAdditionalDefendantsDetails(pcsCase); + + // Then + assertThat(additionalDefendants).hasSize(1); + assertThat(additionalDefendants.getFirst().getValue().getNameKnown()).isNull(); + assertThat(additionalDefendants.getFirst().getValue().getFirstName()) + .isEqualTo(CaseTabView.NAME_UNKNOWN); + assertThat(additionalDefendants.getFirst().getValue().getLastName()) + .isEqualTo(CaseTabView.NAME_UNKNOWN); + assertThat(additionalDefendants.getFirst().getValue().getAddressKnown()).isNull(); + assertThat(additionalDefendants.getFirst().getValue().getAddressForService()) + .isEqualTo(address); + } + + @Test + void shouldDefaultAdditionalDefendantAddressForServiceToPropertyAddressWhenAddressNotKnownInSummaryTab() { + // Given + AddressUK propertyAddress = AddressUK.builder().postCode("SW1A 1AA").build(); + PCSCase pcsCase = PCSCase.builder() + .propertyAddress(propertyAddress) + .allDefendants(List.of( + listValue(Party.builder() + .nameKnown(VerticalYesNo.YES) + .firstName("Defendant") + .lastName("One") + .build()), + listValue(Party.builder() + .nameKnown(VerticalYesNo.NO) + .addressKnown(VerticalYesNo.NO) + .build()) + )) + .build(); + + // When + List> additionalDefendants = + additionalDefendantInformationTabDetailsBuilder.buildSummaryAdditionalDefendantsDetails(pcsCase); + + // Then + assertThat(additionalDefendants).hasSize(1); + assertThat(additionalDefendants.getFirst().getValue().getNameKnown()).isNull(); + assertThat(additionalDefendants.getFirst().getValue().getFirstName()) + .isEqualTo(CaseTabView.NAME_UNKNOWN); + assertThat(additionalDefendants.getFirst().getValue().getLastName()) + .isEqualTo(CaseTabView.NAME_UNKNOWN); + assertThat(additionalDefendants.getFirst().getValue().getAddressKnown()).isNull(); + assertThat(additionalDefendants.getFirst().getValue().getAddressForService()) + .isEqualTo(propertyAddress); + } + + @Test + void shouldSetAdditionalDefendantsInDetailsTabWhenThereIsMoreThanOneDefendant() { + // Given + AddressUK address = AddressUK.builder().postCode("SW1A 1AA").build(); + String firstName = "Defendant2"; + String lastName = "Two"; + PCSCase pcsCase = PCSCase.builder() + .allDefendants(List.of( + listValue(Party.builder() + .nameKnown(VerticalYesNo.YES) + .firstName("Defendant") + .lastName("One") + .build()), + listValue(Party.builder() + .nameKnown(VerticalYesNo.YES) + .firstName(firstName) + .lastName(lastName) + .addressKnown(VerticalYesNo.YES) + .address(address) + .build()) + )) + .build(); + + // When + List> additionalDefendants = + additionalDefendantInformationTabDetailsBuilder.buildDetailedAdditionalDefendantsDetails(pcsCase); + + // Then + assertThat(additionalDefendants).hasSize(1); + assertThat(additionalDefendants.getFirst().getValue().getNameKnown()) + .isEqualTo("Yes"); + assertThat(additionalDefendants.getFirst().getValue().getFirstName()) + .isEqualTo(firstName); + assertThat(additionalDefendants.getFirst().getValue().getLastName()) + .isEqualTo(lastName); + assertThat(additionalDefendants.getFirst().getValue().getAddressKnown()) + .isEqualTo("Yes"); + assertThat(additionalDefendants.getFirst().getValue().getAddressForService()) + .isEqualTo(address); + } + + @Test + void shouldNotSetAdditionalDefendantsInDetailsTabWhenThereIsOnlyOneDefendant() { + // Given + AddressUK address = AddressUK.builder().postCode("SW1A 1AA").build(); + PCSCase pcsCase = PCSCase.builder() + .allDefendants(List.of( + listValue(Party.builder() + .nameKnown(VerticalYesNo.YES) + .firstName("Defendant") + .lastName("One") + .build()) + )) + .build(); + + // When + List> additionalDefendants = + additionalDefendantInformationTabDetailsBuilder.buildDetailedAdditionalDefendantsDetails(pcsCase); + + // Then + assertThat(additionalDefendants).isNull(); + } + + @Test + void shouldSetUnknownAdditionalDefendantNameToNullWhenNameNotKnownButAddressKnownInDetailsTab() { + // Given + AddressUK address = AddressUK.builder().postCode("SW1A 1AA").build(); + PCSCase pcsCase = PCSCase.builder() + .allDefendants(List.of( + listValue(Party.builder() + .nameKnown(VerticalYesNo.YES) + .firstName("Defendant") + .lastName("One") + .build()), + listValue(Party.builder() + .nameKnown(VerticalYesNo.NO) + .addressKnown(VerticalYesNo.YES) + .address(address) + .build()) + )) + .build(); + + // When + List> additionalDefendants = + additionalDefendantInformationTabDetailsBuilder.buildDetailedAdditionalDefendantsDetails(pcsCase); + + // Then + assertThat(additionalDefendants).hasSize(1); + assertThat(additionalDefendants.getFirst().getValue().getNameKnown()) + .isEqualTo("No"); + assertThat(additionalDefendants.getFirst().getValue().getFirstName()).isNull(); + assertThat(additionalDefendants.getFirst().getValue().getLastName()).isNull(); + assertThat(additionalDefendants.getFirst().getValue().getAddressKnown()) + .isEqualTo("Yes"); + assertThat(additionalDefendants.getFirst().getValue().getAddressForService()).isEqualTo(address); + } + + @Test + void shouldDefaultAdditionalDefendantAddressForServiceToNullWhenAddressNotKnownInDetailsTab() { + // Given + AddressUK propertyAddress = AddressUK.builder().postCode("SW1A 1AA").build(); + PCSCase pcsCase = PCSCase.builder() + .propertyAddress(propertyAddress) + .allDefendants(List.of( + listValue(Party.builder() + .nameKnown(VerticalYesNo.YES) + .firstName("Defendant") + .lastName("One") + .build()), + listValue(Party.builder() + .nameKnown(VerticalYesNo.NO) + .addressKnown(VerticalYesNo.NO) + .build()) + )) + .build(); + + // When + List> additionalDefendants = + additionalDefendantInformationTabDetailsBuilder.buildDetailedAdditionalDefendantsDetails(pcsCase); + + // Then + assertThat(additionalDefendants).hasSize(1); + assertThat(additionalDefendants.getFirst().getValue().getNameKnown()) + .isEqualTo("No"); + assertThat(additionalDefendants.getFirst().getValue().getFirstName()).isNull(); + assertThat(additionalDefendants.getFirst().getValue().getLastName()).isNull(); + assertThat(additionalDefendants.getFirst().getValue().getAddressKnown()) + .isEqualTo("No"); + assertThat(additionalDefendants.getFirst().getValue().getAddressForService()).isNull(); + } + + private static ListValue listValue(T value) { + return ListValue.builder() + .value(value) + .build(); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/ClaimGroundSummaryBuilderTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ClaimGroundSummaryBuilderTest.java similarity index 91% rename from src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/ClaimGroundSummaryBuilderTest.java rename to src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ClaimGroundSummaryBuilderTest.java index d3fca5f0b9..e8264c8c16 100644 --- a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/ClaimGroundSummaryBuilderTest.java +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ClaimGroundSummaryBuilderTest.java @@ -1,4 +1,4 @@ -package uk.gov.hmcts.reform.pcs.ccd.view; +package uk.gov.hmcts.reform.pcs.ccd.view.builder; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -43,6 +43,7 @@ import uk.gov.hmcts.reform.pcs.ccd.domain.wales.SecureContractDiscretionaryGroundsWales; import uk.gov.hmcts.reform.pcs.ccd.domain.wales.SecureContractMandatoryGroundsWales; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -666,6 +667,101 @@ void shouldReturnEmptyClaimGroundSummariesForIntroductoryDraftWithoutSelectedGro assertThat(summaries).isEmpty(); } + @Test + void shouldAddDescriptionForIntroductoryDemotedOrOtherGrounds() { + // Given + String description = "Other description"; + Set introductoryDemotedOrOtherGrounds = new HashSet<>(); + introductoryDemotedOrOtherGrounds.add(IntroductoryDemotedOrOtherGrounds.OTHER); + IntroductoryDemotedOtherGroundsForPossession introductoryDemotedOtherGroundsForPossession = + IntroductoryDemotedOtherGroundsForPossession.builder() + .hasIntroductoryDemotedOtherGroundsForPossession(VerticalYesNo.YES) + .introductoryDemotedOrOtherGrounds(introductoryDemotedOrOtherGrounds) + .otherGroundDescription(description) + .build(); + + PCSCase draftCaseData = PCSCase.builder() + .tenancyLicenceDetails( + TenancyLicenceDetails.builder() + .typeOfTenancyLicence(TenancyLicenceType.INTRODUCTORY_TENANCY) + .build()) + .introductoryDemotedOrOtherGroundsForPossession(introductoryDemotedOtherGroundsForPossession) + .build(); + + // When + List> summaries = + claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData); + + // Then + assertThat(summaries.size()).isEqualTo(1); + ClaimGroundSummary claimGroundSummary = summaries.getFirst().getValue(); + assertThat(claimGroundSummary.getDescription()).isEqualTo(description); + } + + @Test + void shouldAddDescriptionForAssuredAdditionalOtherGroundWithRentArrears() { + // Given + String description = "Other description"; + Set additionalOtherGround = new HashSet<>(); + additionalOtherGround.add(AssuredAdditionalOtherGround.OTHER); + + AssuredRentArrearsPossessionGrounds assuredRentArrearsPossessionGrounds = + AssuredRentArrearsPossessionGrounds.builder() + .additionalOtherGround(additionalOtherGround) + .additionalOtherGroundDescription(description) + .build(); + + PCSCase draftCaseData = PCSCase.builder() + .tenancyLicenceDetails( + TenancyLicenceDetails.builder() + .typeOfTenancyLicence(TenancyLicenceType.ASSURED_TENANCY) + .build()) + .assuredRentArrearsPossessionGrounds(assuredRentArrearsPossessionGrounds) + .claimDueToRentArrears(YesOrNo.YES) + .build(); + + // When + List> summaries = + claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData); + + // Then + assertThat(summaries.size()).isEqualTo(1); + ClaimGroundSummary claimGroundSummary = summaries.getFirst().getValue(); + assertThat(claimGroundSummary.getDescription()).isEqualTo(description); + } + + @Test + void shouldAddDescriptionForAssuredAdditionalOtherGroundWithNoRentArrears() { + // Given + String description = "Other description"; + Set additionalOtherGround = new HashSet<>(); + additionalOtherGround.add(AssuredAdditionalOtherGround.OTHER); + + AssuredNoArrearsPossessionGrounds assuredNoRentArrearsPossessionGrounds = + AssuredNoArrearsPossessionGrounds.builder() + .otherGround(additionalOtherGround) + .otherGroundDescription(description) + .build(); + + PCSCase draftCaseData = PCSCase.builder() + .tenancyLicenceDetails( + TenancyLicenceDetails.builder() + .typeOfTenancyLicence(TenancyLicenceType.ASSURED_TENANCY) + .build()) + .noRentArrearsGroundsOptions(assuredNoRentArrearsPossessionGrounds) + .claimDueToRentArrears(YesOrNo.NO) + .build(); + + // When + List> summaries = + claimGroundSummaryBuilder.buildClaimGroundSummariesFromDraft(draftCaseData); + + // Then + assertThat(summaries.size()).isEqualTo(1); + ClaimGroundSummary claimGroundSummary = summaries.getFirst().getValue(); + assertThat(claimGroundSummary.getDescription()).isEqualTo(description); + } + private static Stream introductoryDemotedOrOtherTenancyDrafts() { return Stream.of( Arguments.of( diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ClaimantInformationTabDetailsBuilderTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ClaimantInformationTabDetailsBuilderTest.java new file mode 100644 index 0000000000..9400490ba0 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ClaimantInformationTabDetailsBuilderTest.java @@ -0,0 +1,112 @@ +package uk.gov.hmcts.reform.pcs.ccd.view.builder; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.ccd.sdk.type.ListValue; +import uk.gov.hmcts.ccd.sdk.type.YesOrNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.ClaimantInformation; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.Party; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.ClaimantInformationTabDetails; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ClaimantInformationTabDetailsBuilderTest { + + private ClaimantInformationTabDetailsBuilder claimantInformationTabDetailsBuilder; + + @BeforeEach + void setUp() { + claimantInformationTabDetailsBuilder = new ClaimantInformationTabDetailsBuilder(); + } + + @Test + void shouldSetSummaryClaimantNameFromFallbackName() { + // Given + PCSCase pcsCase = PCSCase.builder() + .claimantInformation(ClaimantInformation.builder() + .orgNameFound(YesOrNo.NO) + .fallbackClaimantName("Fallback claimant") + .build()) + .build(); + + // When + ClaimantInformationTabDetails claimantInformationTabDetails = + claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase); + + // Then + assertThat(claimantInformationTabDetails.getClaimantName()).isEqualTo("Fallback claimant"); + } + + @Test + void shouldSetSummaryClaimantNameFromOverriddenName() { + // Given + PCSCase pcsCase = PCSCase.builder() + .claimantInformation(ClaimantInformation.builder() + .isClaimantNameCorrect(VerticalYesNo.NO) + .overriddenClaimantName("Overridden claimant") + .build()) + .build(); + + // When + ClaimantInformationTabDetails claimantInformationTabDetails = + claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase); + + // Then + assertThat(claimantInformationTabDetails.getClaimantName()).isEqualTo("Overridden claimant"); + } + + @Test + void shouldSetSummaryClaimantNameFromClaimantInformationName() { + // Given + PCSCase pcsCase = PCSCase.builder() + .claimantInformation(ClaimantInformation.builder() + .claimantName("Claimant information name") + .build()) + .build(); + + // When + ClaimantInformationTabDetails claimantInformationTabDetails = + claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase); + + // Then + assertThat(claimantInformationTabDetails.getClaimantName()).isEqualTo("Claimant information name"); + } + + @Test + void shouldSetSummaryClaimantNameFromAllClaimants() { + // Given + PCSCase pcsCase = PCSCase.builder() + .allClaimants(List.of(listValue(Party.builder().orgName("Claimant party").build()))) + .build(); + + // When + ClaimantInformationTabDetails claimantInformationTabDetails = + claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase); + + // Then + assertThat(claimantInformationTabDetails.getClaimantName()).isEqualTo("Claimant party"); + } + + @Test + void shouldReturnNullWithNoClaimantData() { + // Given + PCSCase pcsCase = PCSCase.builder().build(); + + // When + ClaimantInformationTabDetails claimantInformationTabDetails = + claimantInformationTabDetailsBuilder.createSummaryClaimantTabDetails(pcsCase); + + // Then + assertThat(claimantInformationTabDetails).isNull(); + } + + private static ListValue listValue(T value) { + return ListValue.builder() + .value(value) + .build(); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/DefendantInformationTabDetailsBuilderTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/DefendantInformationTabDetailsBuilderTest.java new file mode 100644 index 0000000000..237385d58e --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/DefendantInformationTabDetailsBuilderTest.java @@ -0,0 +1,217 @@ +package uk.gov.hmcts.reform.pcs.ccd.view.builder; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.ccd.sdk.type.AddressUK; +import uk.gov.hmcts.ccd.sdk.type.ListValue; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.Party; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.DefendantInformationTabDetails; +import uk.gov.hmcts.reform.pcs.ccd.view.CaseTabView; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DefendantInformationTabDetailsBuilderTest { + + private DefendantInformationTabDetailsBuilder defendantInformationTabDetailsBuilder; + + @BeforeEach + void setUp() { + defendantInformationTabDetailsBuilder = new DefendantInformationTabDetailsBuilder(); + } + + @Test + void shouldSetDefendantInSummaryTabWhenThereIsAtLeastOneDefendant() { + // Given + AddressUK address = AddressUK.builder().postCode("SW1A 1AA").build(); + String firstName = "Defendant"; + String lastName = "One"; + PCSCase pcsCase = PCSCase.builder() + .allDefendants(List.of( + listValue(Party.builder() + .nameKnown(VerticalYesNo.YES) + .firstName(firstName) + .lastName(lastName) + .addressKnown(VerticalYesNo.YES) + .address(address) + .build()), + listValue(Party.builder() + .nameKnown(VerticalYesNo.NO) + .addressKnown(VerticalYesNo.NO) + .build()) + )) + .build(); + + // When + DefendantInformationTabDetails defendantInformationTabDetails = defendantInformationTabDetailsBuilder + .buildSummaryDefendantOneDetails(pcsCase); + + // Then + assertThat(defendantInformationTabDetails.getNameKnown()).isNull(); + assertThat(defendantInformationTabDetails.getFirstName()).isEqualTo(firstName); + assertThat(defendantInformationTabDetails.getLastName()).isEqualTo(lastName); + assertThat(defendantInformationTabDetails.getAddressKnown()).isNull(); + assertThat(defendantInformationTabDetails.getAddressForService()).isEqualTo(address); + } + + @Test + void shouldNotSetDefendantInSummaryTabWhenThereIsNoDefendants() { + PCSCase pcsCase = PCSCase.builder().build(); + // When + DefendantInformationTabDetails defendantInformationTabDetails = defendantInformationTabDetailsBuilder + .buildSummaryDefendantOneDetails(pcsCase); + + // Then + assertThat(defendantInformationTabDetails).isNull(); + } + + @Test + void shouldSetUnknownDefendantNameWhenNameNotKnownButAddressKnownInSummaryTab() { + // Given + AddressUK address = AddressUK.builder().postCode("SW1A 1AA").build(); + PCSCase pcsCase = PCSCase.builder() + .allDefendants(List.of(listValue(Party.builder() + .nameKnown(VerticalYesNo.NO) + .addressKnown(VerticalYesNo.YES) + .address(address) + .build()))) + .build(); + + // When + DefendantInformationTabDetails defendantInformationTabDetails = defendantInformationTabDetailsBuilder + .buildSummaryDefendantOneDetails(pcsCase); + + // Then + assertThat(defendantInformationTabDetails.getNameKnown()).isNull(); + assertThat(defendantInformationTabDetails.getFirstName()).isEqualTo(CaseTabView.NAME_UNKNOWN); + assertThat(defendantInformationTabDetails.getLastName()).isEqualTo(CaseTabView.NAME_UNKNOWN); + assertThat(defendantInformationTabDetails.getAddressKnown()).isNull(); + assertThat(defendantInformationTabDetails.getAddressForService()).isEqualTo(address); + } + + @Test + void shouldDefaultDefendantAddressForServiceToPropertyAddressWhenAddressNotKnownInSummaryTab() { + // Given + AddressUK propertyAddress = AddressUK.builder().postCode("SW1A 1AA").build(); + PCSCase pcsCase = PCSCase.builder() + .propertyAddress(propertyAddress) + .allDefendants(List.of(listValue(Party.builder() + .nameKnown(VerticalYesNo.NO) + .addressKnown(VerticalYesNo.NO) + .build()))) + .build(); + + // When + DefendantInformationTabDetails defendantInformationTabDetails = defendantInformationTabDetailsBuilder + .buildSummaryDefendantOneDetails(pcsCase); + + // Then + assertThat(defendantInformationTabDetails.getNameKnown()).isNull(); + assertThat(defendantInformationTabDetails.getFirstName()).isEqualTo(CaseTabView.NAME_UNKNOWN); + assertThat(defendantInformationTabDetails.getLastName()).isEqualTo(CaseTabView.NAME_UNKNOWN); + assertThat(defendantInformationTabDetails.getAddressKnown()).isNull(); + assertThat(defendantInformationTabDetails.getAddressForService()).isEqualTo(propertyAddress); + } + + @Test + void shouldSetDefendantInDetailsTabWhenThereIsAtLeastOneDefendant() { + // Given + AddressUK address = AddressUK.builder().postCode("SW1A 1AA").build(); + String firstName = "Defendant"; + String lastName = "One"; + PCSCase pcsCase = PCSCase.builder() + .allDefendants(List.of( + listValue(Party.builder() + .nameKnown(VerticalYesNo.YES) + .firstName(firstName) + .lastName(lastName) + .addressKnown(VerticalYesNo.YES) + .address(address) + .build()), + listValue(Party.builder() + .nameKnown(VerticalYesNo.NO) + .addressKnown(VerticalYesNo.NO) + .build()) + )) + .build(); + + // When + DefendantInformationTabDetails defendantInformationTabDetails = defendantInformationTabDetailsBuilder + .buildDetailedDefendantDetails(pcsCase); + + // Then + assertThat(defendantInformationTabDetails.getNameKnown()).isEqualTo("Yes"); + assertThat(defendantInformationTabDetails.getFirstName()).isEqualTo(firstName); + assertThat(defendantInformationTabDetails.getLastName()).isEqualTo(lastName); + assertThat(defendantInformationTabDetails.getAddressKnown()).isEqualTo("Yes"); + assertThat(defendantInformationTabDetails.getAddressForService()).isEqualTo(address); + } + + @Test + void shouldNotSetDefendantInDetailsTabWhenThereIsNoDefendants() { + PCSCase pcsCase = PCSCase.builder().build(); + // When + DefendantInformationTabDetails defendantInformationTabDetails = defendantInformationTabDetailsBuilder + .buildDetailedDefendantDetails(pcsCase); + + // Then + assertThat(defendantInformationTabDetails).isNull(); + } + + @Test + void shouldSetUnknownDefendantNameWhenNameNotKnownButAddressKnownInDetailsTab() { + // Given + AddressUK address = AddressUK.builder().postCode("SW1A 1AA").build(); + PCSCase pcsCase = PCSCase.builder() + .allDefendants(List.of(listValue(Party.builder() + .nameKnown(VerticalYesNo.NO) + .addressKnown(VerticalYesNo.YES) + .address(address) + .build()))) + .build(); + + // When + DefendantInformationTabDetails defendantInformationTabDetails = defendantInformationTabDetailsBuilder + .buildDetailedDefendantDetails(pcsCase); + + // Then + assertThat(defendantInformationTabDetails.getNameKnown()).isEqualTo("No"); + assertThat(defendantInformationTabDetails.getFirstName()).isNull(); + assertThat(defendantInformationTabDetails.getLastName()).isNull(); + assertThat(defendantInformationTabDetails.getAddressKnown()).isEqualTo("Yes"); + assertThat(defendantInformationTabDetails.getAddressForService()).isEqualTo(address); + } + + @Test + void shouldDefaultDefendantAddressForServiceToPropertyAddressWhenAddressNotKnownInDetailsTab() { + // Given + AddressUK propertyAddress = AddressUK.builder().postCode("SW1A 1AA").build(); + PCSCase pcsCase = PCSCase.builder() + .propertyAddress(propertyAddress) + .allDefendants(List.of(listValue(Party.builder() + .nameKnown(VerticalYesNo.NO) + .addressKnown(VerticalYesNo.NO) + .build()))) + .build(); + + // When + DefendantInformationTabDetails defendantInformationTabDetails = defendantInformationTabDetailsBuilder + .buildDetailedDefendantDetails(pcsCase); + + // Then + assertThat(defendantInformationTabDetails.getNameKnown()).isEqualTo("No"); + assertThat(defendantInformationTabDetails.getFirstName()).isNull(); + assertThat(defendantInformationTabDetails.getLastName()).isNull(); + assertThat(defendantInformationTabDetails.getAddressKnown()).isEqualTo("No"); + assertThat(defendantInformationTabDetails.getAddressForService()).isNull(); + } + + private static ListValue listValue(T value) { + return ListValue.builder() + .value(value) + .build(); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/GroundsBuilderTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/GroundsBuilderTest.java new file mode 100644 index 0000000000..f48541c6c1 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/GroundsBuilderTest.java @@ -0,0 +1,98 @@ +package uk.gov.hmcts.reform.pcs.ccd.view.builder; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.ccd.sdk.type.ListValue; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.ClaimGroundSummary; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class GroundsBuilderTest { + + private GroundsBuilder groundsBuilder; + + @BeforeEach + void setUp() { + groundsBuilder = new GroundsBuilder(); + } + + @Test + void shouldGroupSection84AConditionsUnderAntisocialBehaviourInGrounds() { + // Given + PCSCase pcsCase = PCSCase.builder() + .claimGroundSummaries(List.of( + groundSummary("Antisocial behaviour", "Antisocial reason"), + groundSummary("Nuisance, annoyance, illegal or immoral use of the property (ground 2)", + "Nuisance reason"), + groundSummary("Condition 3 of Section 84A of the Housing Act 1985", "Condition 3 reason"), + groundSummary("Condition 1 of Section 84A of the Housing Act 1985", "Condition 1 reason"), + groundSummary("Condition 5 of Section 84A of the Housing Act 1985", "Condition 5 reason"), + groundSummary("Condition 2 of Section 84A of the Housing Act 1985", "Condition 2 reason"), + groundSummary("Condition 4 of Section 84A of the Housing Act 1985", "Condition 4 reason"), + groundSummary("Landlord’s works (ground 10)", "Works reason") + )) + .build(); + + // When + String grounds = groundsBuilder.getGrounds(pcsCase); + + // Then + assertThat(grounds).isEqualTo(String.join( + "\n", + "Antisocial behaviour: " + String.join( + ", ", + "Condition 1 of Section 84A of the Housing Act 1985", + "Condition 2 of Section 84A of the Housing Act 1985", + "Condition 3 of Section 84A of the Housing Act 1985", + "Condition 4 of Section 84A of the Housing Act 1985", + "Condition 5 of Section 84A of the Housing Act 1985" + ), + "Nuisance, annoyance, illegal or immoral use of the property (ground 2)", + "Landlord’s works (ground 10)" + )); + } + + @Test + void shouldGroupSection84AConditionsUnderAntisocialBehaviourWhenParentGroundIsMissing() { + // Given + PCSCase pcsCase = PCSCase.builder() + .claimGroundSummaries(List.of( + groundSummary("Condition 2 of Section 84A of the Housing Act 1985", "Condition 2 reason"), + groundSummary("Condition 1 of Section 84A of the Housing Act 1985", "Condition 1 reason"), + groundSummary("Landlord’s works (ground 10)", "Works reason") + )) + .build(); + + // When + String grounds = groundsBuilder.getGrounds(pcsCase); + + // Then + assertThat(grounds).isEqualTo(String.join( + "\n", + "Antisocial behaviour: " + String.join( + ", ", + "Condition 1 of Section 84A of the Housing Act 1985", + "Condition 2 of Section 84A of the Housing Act 1985" + ), + "Landlord’s works (ground 10)" + )); + } + + private static ListValue listValue(T value) { + return ListValue.builder() + .value(value) + .build(); + } + + + + private static ListValue groundSummary(String label, String reason) { + return listValue(ClaimGroundSummary.builder() + .label(label) + .reason(reason) + .build()); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ReasonsForPossessionTabDetailsBuilderTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ReasonsForPossessionTabDetailsBuilderTest.java new file mode 100644 index 0000000000..be62be4f24 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/ReasonsForPossessionTabDetailsBuilderTest.java @@ -0,0 +1,291 @@ +package uk.gov.hmcts.reform.pcs.ccd.view.builder; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.ccd.sdk.type.ListValue; +import uk.gov.hmcts.reform.pcs.ccd.domain.AdditionalReasons; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.ClaimGroundSummary; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.ReasonsForPossessionTabDetails; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ReasonsForPossessionTabDetailsBuilderTest { + + private ReasonsForPossessionTabDetailsBuilder reasonsForPossessionTabDetailsBuilder; + + @BeforeEach + void setUp() { + reasonsForPossessionTabDetailsBuilder = new ReasonsForPossessionTabDetailsBuilder(); + } + + @Test + void shouldSetEachGroundReason() { + // Given + PCSCase pcsCase = PCSCase.builder() + .claimGroundSummaries(List.of( + listValue(ClaimGroundSummary.builder() + .label("Antisocial behaviour") + .reason("Antisocial reason") + .build()), + listValue(ClaimGroundSummary.builder() + .label("Premium paid in connection with mutual exchange (ground 6)") + .reason("Premium reason") + .build()), + listValue(ClaimGroundSummary.builder() + .label("Offence during a riot (ground 2ZA)") + .reason("Riot reason") + .build()), + listValue(ClaimGroundSummary.builder() + .label("Condition 1 of Section 84A of the Housing Act 1985") + .reason("Condition 1 reason") + .build()), + listValue(ClaimGroundSummary.builder() + .label("Landlord’s works (ground 10)") + .reason("Works reason") + .build()), + listValue(ClaimGroundSummary.builder() + .label("Housing association special circumstances accommodation (ground 14)") + .reason("Housing reason") + .build()) + )) + .build(); + + // When + ReasonsForPossessionTabDetails reasons = reasonsForPossessionTabDetailsBuilder + .buildSummaryReasonsForPossession(pcsCase); + + // Then + assertThat(reasons.getAntisocialBehaviour()).isEqualTo("Antisocial reason"); + assertThat(reasons.getGround6()).isEqualTo("Premium reason"); + assertThat(reasons.getGround2ZA()).isEqualTo("Riot reason"); + assertThat(reasons.getCondition1OfSection84A()).isEqualTo("Condition 1 reason"); + assertThat(reasons.getGround10()).isEqualTo("Works reason"); + assertThat(reasons.getGround14()).isEqualTo("Housing reason"); + } + + @Test + void shouldSetEachGroundNumberReason() { + // Given + PCSCase pcsCase = PCSCase.builder() + .claimGroundSummaries(List.of( + groundSummary("Ground label (ground 1)", "Reason 1"), + groundSummary("Ground label (ground 2)", "Reason 2"), + groundSummary("Ground label (ground 2A)", "Reason 2A"), + groundSummary("Ground label (ground 2ZA)", "Reason 2ZA"), + groundSummary("Ground label (ground 3)", "Reason 3"), + groundSummary("Ground label (ground 4)", "Reason 4"), + groundSummary("Ground label (ground 5)", "Reason 5"), + groundSummary("Ground label (ground 6)", "Reason 6"), + groundSummary("Ground label (ground 7)", "Reason 7"), + groundSummary("Ground label (ground 7A)", "Reason 7A"), + groundSummary("Ground label (ground 7B)", "Reason 7B"), + groundSummary("Ground label (ground 8)", "Reason 8"), + groundSummary("Ground label (ground 9)", "Reason 9"), + groundSummary("Ground label (ground 10)", "Reason 10"), + groundSummary("Ground label (ground 10A)", "Reason 10A"), + groundSummary("Ground label (ground 11)", "Reason 11"), + groundSummary("Ground label (ground 12)", "Reason 12"), + groundSummary("Ground label (ground 13)", "Reason 13"), + groundSummary("Ground label (ground 14)", "Reason 14"), + groundSummary("Ground label (ground 14A)", "Reason 14A"), + groundSummary("Ground label (ground 14ZA)", "Reason 14ZA"), + groundSummary("Ground label (ground 15)", "Reason 15"), + groundSummary("Ground label (ground 15A)", "Reason 15A"), + groundSummary("Ground label (ground 16)", "Reason 16"), + groundSummary("Ground label (ground 17)", "Reason 17"), + groundSummary("Ground label (ground A)", "Reason A"), + groundSummary("Ground label (ground B)", "Reason B"), + groundSummary("Ground label (ground C)", "Reason C"), + groundSummary("Ground label (ground D)", "Reason D"), + groundSummary("Ground label (ground E)", "Reason E"), + groundSummary("Ground label (ground F)", "Reason F"), + groundSummary("Ground label (ground G)", "Reason G"), + groundSummary("Ground label (ground H)", "Reason H"), + groundSummary("Ground label (ground I)", "Reason I"), + groundSummary("Ground label (ground Z)", "Unmapped reason") + )) + .build(); + + // When + ReasonsForPossessionTabDetails reasons = reasonsForPossessionTabDetailsBuilder + .buildSummaryReasonsForPossession(pcsCase); + + // Then + assertThat(reasons.getGround1()).isEqualTo("Reason 1"); + assertThat(reasons.getGround2()).isEqualTo("Reason 2"); + assertThat(reasons.getGround2A()).isEqualTo("Reason 2A"); + assertThat(reasons.getGround2ZA()).isEqualTo("Reason 2ZA"); + assertThat(reasons.getGround3()).isEqualTo("Reason 3"); + assertThat(reasons.getGround4()).isEqualTo("Reason 4"); + assertThat(reasons.getGround5()).isEqualTo("Reason 5"); + assertThat(reasons.getGround6()).isEqualTo("Reason 6"); + assertThat(reasons.getGround7()).isEqualTo("Reason 7"); + assertThat(reasons.getGround7A()).isEqualTo("Reason 7A"); + assertThat(reasons.getGround7B()).isEqualTo("Reason 7B"); + assertThat(reasons.getGround8()).isEqualTo("Reason 8"); + assertThat(reasons.getGround9()).isEqualTo("Reason 9"); + assertThat(reasons.getGround10()).isEqualTo("Reason 10"); + assertThat(reasons.getGround10A()).isEqualTo("Reason 10A"); + assertThat(reasons.getGround11()).isEqualTo("Reason 11"); + assertThat(reasons.getGround12()).isEqualTo("Reason 12"); + assertThat(reasons.getGround13()).isEqualTo("Reason 13"); + assertThat(reasons.getGround14()).isEqualTo("Reason 14"); + assertThat(reasons.getGround14A()).isEqualTo("Reason 14A"); + assertThat(reasons.getGround14ZA()).isEqualTo("Reason 14ZA"); + assertThat(reasons.getGround15()).isEqualTo("Reason 15"); + assertThat(reasons.getGround15A()).isEqualTo("Reason 15A"); + assertThat(reasons.getGround16()).isEqualTo("Reason 16"); + assertThat(reasons.getGround17()).isEqualTo("Reason 17"); + assertThat(reasons.getGroundA()).isEqualTo("Reason A"); + assertThat(reasons.getGroundB()).isEqualTo("Reason B"); + assertThat(reasons.getGroundC()).isEqualTo("Reason C"); + assertThat(reasons.getGroundD()).isEqualTo("Reason D"); + assertThat(reasons.getGroundE()).isEqualTo("Reason E"); + assertThat(reasons.getGroundF()).isEqualTo("Reason F"); + assertThat(reasons.getGroundG()).isEqualTo("Reason G"); + assertThat(reasons.getGroundH()).isEqualTo("Reason H"); + assertThat(reasons.getGroundI()).isEqualTo("Reason I"); + } + + @Test + void shouldSetEachSectionReason() { + // Given + PCSCase pcsCase = PCSCase.builder() + .claimGroundSummaries(List.of( + groundSummary("Ground label (section 157)", "Reason 157"), + groundSummary("Ground label (section 170)", "Reason 170"), + groundSummary("Ground label (section 178)", "Reason 178"), + groundSummary("Ground label (section 181)", "Reason 181"), + groundSummary("Ground label (section 186)", "Reason 186"), + groundSummary("Ground label (section 187)", "Reason 187"), + groundSummary("Ground label (section 191)", "Reason 191"), + groundSummary("Ground label (section 199)", "Reason 199"), + groundSummary("Ground label (section 999)", "Unmapped reason") + )) + .build(); + + // When + ReasonsForPossessionTabDetails reasons = reasonsForPossessionTabDetailsBuilder + .buildSummaryReasonsForPossession(pcsCase); + + // Then + assertThat(reasons.getSection157()).isEqualTo("Reason 157"); + assertThat(reasons.getSection170()).isEqualTo("Reason 170"); + assertThat(reasons.getSection178()).isEqualTo("Reason 178"); + assertThat(reasons.getSection181()).isEqualTo("Reason 181"); + assertThat(reasons.getSection186()).isEqualTo("Reason 186"); + assertThat(reasons.getSection187()).isEqualTo("Reason 187"); + assertThat(reasons.getSection191()).isEqualTo("Reason 191"); + assertThat(reasons.getSection199()).isEqualTo("Reason 199"); + } + + @Test + void shouldSetNonNumberedGroundReasons() { + // Given + PCSCase pcsCase = PCSCase.builder() + .claimGroundSummaries(List.of( + groundSummary("Condition 1 of Section 84A of the Housing Act 1985", "Condition 1 reason"), + groundSummary("Condition 2 of Section 84A of the Housing Act 1985", "Condition 2 reason"), + groundSummary("Condition 3 of Section 84A of the Housing Act 1985", "Condition 3 reason"), + groundSummary("Condition 4 of Section 84A of the Housing Act 1985", "Condition 4 reason"), + groundSummary("Condition 5 of Section 84A of the Housing Act 1985", "Condition 5 reason"), + groundSummary("Antisocial behaviour", "Antisocial reason"), + groundSummary("Breach of the tenancy", "Breach reason"), + groundSummary("Absolute grounds", "Absolute reason"), + groundSummary("Other", "Other reason"), + groundSummary("Other grounds", "Other grounds reason"), + groundSummary("No grounds", "No grounds reason"), + groundSummary("Converted contract paragraph 25B(2) of Schedule 12", "Paragraph reason"), + groundSummary("Unmapped label", "Unmapped reason") + )) + .build(); + + // When + ReasonsForPossessionTabDetails reasons = reasonsForPossessionTabDetailsBuilder + .buildSummaryReasonsForPossession(pcsCase); + + // Then + assertThat(reasons.getCondition1OfSection84A()).isEqualTo("Condition 1 reason"); + assertThat(reasons.getCondition2OfSection84A()).isEqualTo("Condition 2 reason"); + assertThat(reasons.getCondition3OfSection84A()).isEqualTo("Condition 3 reason"); + assertThat(reasons.getCondition4OfSection84A()).isEqualTo("Condition 4 reason"); + assertThat(reasons.getCondition5OfSection84A()).isEqualTo("Condition 5 reason"); + assertThat(reasons.getAntisocialBehaviour()).isEqualTo("Antisocial reason"); + assertThat(reasons.getBreachOfTheTenancy()).isEqualTo("Breach reason"); + assertThat(reasons.getAbsoluteGrounds()).isEqualTo("Absolute reason"); + assertThat(reasons.getOtherGrounds()).isEqualTo("Other grounds reason"); + assertThat(reasons.getNoGrounds()).isEqualTo("No grounds reason"); + assertThat(reasons.getParagraph25B2Schedule12()).isEqualTo("Paragraph reason"); + } + + @Test + void shouldSetAdditionalReasonInSummaryTab() { + // Given + PCSCase pcsCase = PCSCase.builder() + .claimGroundSummaries(List.of( + groundSummary("Condition 1 of Section 84A of the Housing Act 1985", "Condition 1 reason") + )) + .additionalReasonsForPossession( + AdditionalReasons.builder() + .hasReasons(VerticalYesNo.YES) + .reasons("Additional reason") + .build() + ) + .build(); + + // When + ReasonsForPossessionTabDetails reasons = reasonsForPossessionTabDetailsBuilder + .buildSummaryReasonsForPossession(pcsCase); + + // Then + assertThat(reasons.getCondition1OfSection84A()).isEqualTo("Condition 1 reason"); + assertThat(reasons.getHasAdditionalReasons()).isNull(); + assertThat(reasons.getAdditionalReasonsForPossession()).isEqualTo("Additional reason"); + assertThat(reasons.getAdditionalReasonsDetails()).isNull(); + } + + @Test + void shouldSetAdditionalReasonInDetailsTab() { + // Given + PCSCase pcsCase = PCSCase.builder() + .claimGroundSummaries(List.of( + groundSummary("Condition 1 of Section 84A of the Housing Act 1985", "Condition 1 reason") + )) + .additionalReasonsForPossession( + AdditionalReasons.builder() + .hasReasons(VerticalYesNo.YES) + .reasons("Additional reason") + .build() + ) + .build(); + + // When + ReasonsForPossessionTabDetails reasons = reasonsForPossessionTabDetailsBuilder + .buildDetailsReasonsForPossession(pcsCase); + + // Then + assertThat(reasons.getCondition1OfSection84A()).isEqualTo("Condition 1 reason"); + assertThat(reasons.getHasAdditionalReasons()).isEqualTo("Yes"); + assertThat(reasons.getAdditionalReasonsForPossession()).isNull(); + assertThat(reasons.getAdditionalReasonsDetails()).isEqualTo("Additional reason"); + } + + private static ListValue listValue(T value) { + return ListValue.builder() + .value(value) + .build(); + } + + + + private static ListValue groundSummary(String label, String reason) { + return listValue(ClaimGroundSummary.builder() + .label(label) + .reason(reason) + .build()); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/RentArrearsTabDetailsBuilderTest.java b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/RentArrearsTabDetailsBuilderTest.java new file mode 100644 index 0000000000..143510fa10 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/pcs/ccd/view/builder/RentArrearsTabDetailsBuilderTest.java @@ -0,0 +1,337 @@ +package uk.gov.hmcts.reform.pcs.ccd.view.builder; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.ccd.sdk.type.Document; +import uk.gov.hmcts.ccd.sdk.type.ListValue; +import uk.gov.hmcts.ccd.sdk.type.YesOrNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; +import uk.gov.hmcts.reform.pcs.ccd.domain.RentArrearsSection; +import uk.gov.hmcts.reform.pcs.ccd.domain.RentDetails; +import uk.gov.hmcts.reform.pcs.ccd.domain.RentPaymentFrequency; +import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo; +import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.shared.RentArrearsTabDetails; + +import java.math.BigDecimal; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class RentArrearsTabDetailsBuilderTest { + + private RentArrearsTabDetailsBuilder rentArrearsTabDetailsBuilder; + + @BeforeEach + void setUp() { + rentArrearsTabDetailsBuilder = new RentArrearsTabDetailsBuilder(); + } + + @Test + void shouldSetRentArrearsDetailsFromStandardFrequencyAndDailyCharge() { + // Given + PCSCase pcsCase = PCSCase.builder() + .rentDetails(RentDetails.builder() + .frequency(RentPaymentFrequency.WEEKLY) + .dailyCharge(new BigDecimal("1.50")) + .build()) + .build(); + + // When + RentArrearsTabDetails rentArrearsDetails = rentArrearsTabDetailsBuilder.buildRentArrearsTabDetails(pcsCase); + + // Then + assertThat(rentArrearsDetails.getCalculationFrequency()).isEqualTo("Weekly"); + assertThat(rentArrearsDetails.getDailyRate()).isEqualTo("£1.50"); + } + + @Test + void shouldSetRentArrearsDetailsFromFormattedCalculatedDailyCharge() { + // Given + PCSCase pcsCase = PCSCase.builder() + .rentDetails(RentDetails.builder() + .formattedCalculatedDailyCharge("£2.34") + .build()) + .build(); + + // When + RentArrearsTabDetails rentArrearsDetails = rentArrearsTabDetailsBuilder.buildRentArrearsTabDetails(pcsCase); + + // Then + assertThat(rentArrearsDetails.getDailyRate()).isEqualTo("£2.34"); + } + + @Test + void shouldSetRentArrearsDetailsFromCalculatedDailyCharge() { + // Given + PCSCase pcsCase = PCSCase.builder() + .rentDetails(RentDetails.builder() + .calculatedDailyCharge(new BigDecimal("3.40")) + .build()) + .build(); + + // When + RentArrearsTabDetails rentArrearsDetails = rentArrearsTabDetailsBuilder.buildRentArrearsTabDetails(pcsCase); + + // Then + assertThat(rentArrearsDetails.getDailyRate()).isEqualTo("£3.40"); + } + + @Test + void shouldSetCalculationFrequencyInRentArrearsWhenFrequencyIsOther() { + // Given + PCSCase pcsCase = PCSCase.builder() + .showRentSectionPage(YesOrNo.YES) + .rentDetails( + RentDetails.builder() + .currentRent(new BigDecimal("4.00")) + .frequency(RentPaymentFrequency.OTHER) + .otherFrequency("Other frequency") + .calculatedDailyCharge(new BigDecimal("3.40")) + .build()) + .arrearsJudgmentWanted(VerticalYesNo.YES) + .rentArrears( + RentArrearsSection.builder() + .recoveryAttempted(VerticalYesNo.YES) + .recoveryAttemptDetails("recovery details") + .total(new BigDecimal("100.00")) + .statementDocuments( + List.of( + ListValue.builder() + .value(Document.builder().build()) + .build()) + ) + .build() + ) + .build(); + + // When + RentArrearsTabDetails rentArrearsDetails = rentArrearsTabDetailsBuilder + .buildRentArrearsTabDetails(pcsCase); + + // Then + assertThat(rentArrearsDetails.getCalculationFrequency()).isEqualTo("Other frequency"); + } + + @Test + void shouldNotBuildRentArrearsWithNoRentArrears() { + // Given + PCSCase pcsCase = PCSCase.builder().build(); + + // When + RentArrearsTabDetails rentArrearsDetails = rentArrearsTabDetailsBuilder + .buildRentArrearsTabDetails(pcsCase); + + // Then + assertThat(rentArrearsDetails).isNull(); + } + + @Test + void shouldNotBuildRentArrearsWithRentArrearsDataNotSet() { + // Given + PCSCase pcsCase = PCSCase.builder() + .rentDetails(RentDetails.builder().build()) + .rentArrears(RentArrearsSection.builder().build()) + .build(); + + // When + RentArrearsTabDetails rentArrearsDetails = rentArrearsTabDetailsBuilder + .buildRentArrearsTabDetails(pcsCase); + + // Then + assertThat(rentArrearsDetails).isNull(); + } + + @Test + void shouldBuildDetailedRentArrearsForCaseDetailsTab() { + // Given + PCSCase pcsCase = PCSCase.builder() + .showRentSectionPage(YesOrNo.YES) + .rentDetails( + RentDetails.builder() + .currentRent(new BigDecimal("4.00")) + .frequency(RentPaymentFrequency.WEEKLY) + .calculatedDailyCharge(new BigDecimal("3.40")) + .build()) + .arrearsJudgmentWanted(VerticalYesNo.YES) + .rentArrears( + RentArrearsSection.builder() + .recoveryAttempted(VerticalYesNo.YES) + .recoveryAttemptDetails("recovery details") + .total(new BigDecimal("100.00")) + .statementDocuments( + List.of( + ListValue.builder() + .value(Document.builder().build()) + .build()) + ) + .build() + ) + .build(); + + // When + RentArrearsTabDetails rentArrearsDetails = rentArrearsTabDetailsBuilder + .buildDetailedRentArrearsTabDetails(pcsCase); + + // Then + assertThat(rentArrearsDetails.getRentAmount()).isEqualTo("£4"); + assertThat(rentArrearsDetails.getCalculationFrequency()).isEqualTo("Weekly"); + assertThat(rentArrearsDetails.getFrequency()).isNull(); + assertThat(rentArrearsDetails.getDailyRate()).isEqualTo("£3.40"); + assertThat(rentArrearsDetails.getArrearsTotal()).isEqualTo("£100"); + assertThat(rentArrearsDetails.getStepsToRecoverArrears()).isEqualTo("Yes"); + assertThat(rentArrearsDetails.getStepsToRecoverArrearsDetails()).isEqualTo("recovery details"); + assertThat(rentArrearsDetails.getRentStatement()).hasSize(1); + assertThat(rentArrearsDetails.getRentStatementPlaceholder()).isNull(); + assertThat(rentArrearsDetails.getJudgmentRequested()).isEqualTo("Yes"); + } + + @Test + void shouldUsePlaceholderInDetailedRentArrearsWhenNoDocumentsUploaded() { + // Given + PCSCase pcsCase = PCSCase.builder() + .showRentSectionPage(YesOrNo.YES) + .rentDetails( + RentDetails.builder() + .currentRent(new BigDecimal("4.00")) + .frequency(RentPaymentFrequency.WEEKLY) + .calculatedDailyCharge(new BigDecimal("3.40")) + .build()) + .arrearsJudgmentWanted(VerticalYesNo.YES) + .rentArrears( + RentArrearsSection.builder() + .recoveryAttempted(VerticalYesNo.YES) + .recoveryAttemptDetails("recovery details") + .total(new BigDecimal("100.00")) + .build() + ) + .build(); + + // When + RentArrearsTabDetails rentArrearsDetails = rentArrearsTabDetailsBuilder + .buildDetailedRentArrearsTabDetails(pcsCase); + + // Then + assertThat(rentArrearsDetails.getRentStatement()).isNull(); + assertThat(rentArrearsDetails.getRentStatementPlaceholder()).isEqualTo(" "); + } + + @Test + void shouldSetFrequencyInDetailedRentArrearsWhenCalculationFrequencyIsOther() { + // Given + PCSCase pcsCase = PCSCase.builder() + .showRentSectionPage(YesOrNo.YES) + .rentDetails( + RentDetails.builder() + .currentRent(new BigDecimal("4.00")) + .frequency(RentPaymentFrequency.OTHER) + .otherFrequency("Other frequency") + .calculatedDailyCharge(new BigDecimal("3.40")) + .build()) + .arrearsJudgmentWanted(VerticalYesNo.YES) + .rentArrears( + RentArrearsSection.builder() + .recoveryAttempted(VerticalYesNo.YES) + .recoveryAttemptDetails("recovery details") + .total(new BigDecimal("100.00")) + .statementDocuments( + List.of( + ListValue.builder() + .value(Document.builder().build()) + .build()) + ) + .build() + ) + .build(); + + // When + RentArrearsTabDetails rentArrearsDetails = rentArrearsTabDetailsBuilder + .buildDetailedRentArrearsTabDetails(pcsCase); + + // Then + assertThat(rentArrearsDetails.getCalculationFrequency()).isEqualTo("Other"); + assertThat(rentArrearsDetails.getFrequency()).isEqualTo("Other frequency"); + } + + @Test + void shouldUsePlaceholderInDetailedRentArrearsWhenRentDetailsIsNull() { + // Given + PCSCase pcsCase = PCSCase.builder().showRentSectionPage(YesOrNo.YES).build(); + + // When + RentArrearsTabDetails rentArrearsDetails = rentArrearsTabDetailsBuilder + .buildDetailedRentArrearsTabDetails(pcsCase); + + // Then + assertThat(rentArrearsDetails.getRentAmount()).isEqualTo(" "); + assertThat(rentArrearsDetails.getCalculationFrequency()).isEqualTo(" "); + assertThat(rentArrearsDetails.getFrequency()).isNull(); + assertThat(rentArrearsDetails.getDailyRate()).isEqualTo(" "); + assertThat(rentArrearsDetails.getArrearsTotal()).isEqualTo(" "); + assertThat(rentArrearsDetails.getStepsToRecoverArrears()).isEqualTo(" "); + assertThat(rentArrearsDetails.getStepsToRecoverArrearsDetails()).isNull(); + assertThat(rentArrearsDetails.getRentStatement()).isNull(); + assertThat(rentArrearsDetails.getRentStatementPlaceholder()).isEqualTo(" "); + assertThat(rentArrearsDetails.getJudgmentRequested()).isEqualTo(" "); + } + + @Test + void shouldNotBuildDetailedRentArrearsWhenRentSectionPageIsNo() { + // Given + PCSCase pcsCase = PCSCase.builder() + .showRentSectionPage(YesOrNo.NO) + .rentDetails( + RentDetails.builder() + .currentRent(new BigDecimal("4.00")) + .frequency(RentPaymentFrequency.WEEKLY) + .calculatedDailyCharge(new BigDecimal("3.40")) + .build()) + .arrearsJudgmentWanted(VerticalYesNo.YES) + .rentArrears( + RentArrearsSection.builder() + .recoveryAttempted(VerticalYesNo.YES) + .recoveryAttemptDetails("recovery details") + .total(new BigDecimal("100.00")) + .statementDocuments( + List.of( + ListValue.builder() + .value(Document.builder().build()) + .build()) + ) + .build() + ) + .build(); + + // When + RentArrearsTabDetails rentArrearsDetails = rentArrearsTabDetailsBuilder + .buildDetailedRentArrearsTabDetails(pcsCase); + + // Then + assertThat(rentArrearsDetails).isNull(); + } + + @Test + void shouldBuildDetailedRentArrearsWithPlaceholdersWhenRentArrearsDataNotSet() { + // Given + PCSCase pcsCase = PCSCase.builder() + .showRentSectionPage(YesOrNo.YES) + .rentDetails(RentDetails.builder().build()) + .rentArrears(RentArrearsSection.builder().build()) + .build(); + + // When + RentArrearsTabDetails rentArrearsDetails = rentArrearsTabDetailsBuilder + .buildDetailedRentArrearsTabDetails(pcsCase); + + // Then + assertThat(rentArrearsDetails.getRentAmount()).isEqualTo(" "); + assertThat(rentArrearsDetails.getCalculationFrequency()).isEqualTo(" "); + assertThat(rentArrearsDetails.getFrequency()).isNull(); + assertThat(rentArrearsDetails.getDailyRate()).isEqualTo(" "); + assertThat(rentArrearsDetails.getArrearsTotal()).isEqualTo(" "); + assertThat(rentArrearsDetails.getStepsToRecoverArrears()).isEqualTo(" "); + assertThat(rentArrearsDetails.getStepsToRecoverArrearsDetails()).isNull(); + assertThat(rentArrearsDetails.getRentStatement()).isNull(); + assertThat(rentArrearsDetails.getRentStatementPlaceholder()).isEqualTo(" "); + assertThat(rentArrearsDetails.getJudgmentRequested()).isEqualTo(" "); + } +}