diff --git a/Jenkinsfile_nightly b/Jenkinsfile_nightly index f884081495b..4f66e24d074 100644 --- a/Jenkinsfile_nightly +++ b/Jenkinsfile_nightly @@ -14,6 +14,8 @@ properties([ description: 'The URL of service auth provider'), string(name: 'CCD_DATA_STORE_URL', defaultValue: 'http://ccd-data-store-api-aat.service.core-compute-aat.internal', description: 'The URL of ccd data store'), + string(name: 'AAC_API_URL', defaultValue: 'http://aac-manage-case-assignment-aat.service.core-compute-aat.internal', + description: 'The URL of AAC service'), string(name: 'CIVIL_SERVICE_URL', defaultValue: 'http://civil-service-aat.service.core-compute-aat.internal', description: 'The URL of civil service'), string(name: 'WAIT_FOR_TIMEOUT_MS', @@ -60,6 +62,7 @@ withNightlyPipeline(type, product, component) { env.URL_FOR_SECURITY_SCAN = params.CIVIL_SERVICE_URL env.TESTS_FOR_ACCESSIBILITY = true env.NIGHTLY_RUN = true + env.AAC_API_URL = params.AAC_API_URL overrideVaultEnvironments([ 'aat': params.ENVIRONMENT ]) diff --git a/build.gradle b/build.gradle index 6a518150b2d..7035befae45 100644 --- a/build.gradle +++ b/build.gradle @@ -369,7 +369,7 @@ configurations.all { } dependencies { - implementation 'com.github.hmcts:civil-commons:1.0.31' + implementation 'com.github.hmcts:civil-commons:1.0.33' implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web' implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator' implementation group: 'org.springframework.boot', name: 'spring-boot-starter-aop' diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01067.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01067.docx index 3709881c7dc..bf518dcc5e4 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01067.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01067.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01068.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01068.docx index 557a8691293..07e3a3b1e8c 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01068.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01068.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01069.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01069.docx index 3f2fc16c7d3..8a359232e14 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01069.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01069.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01070.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01070.docx index f2a28ab1f0b..3e9445b398d 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01070.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01070.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01071.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01071.docx index 1d62230dd42..57e6930dbe3 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01071.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01071.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01072.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01072.docx index 0696e523827..d8f67ebaeec 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01072.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01072.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01073.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01073.docx index 227acaf6816..75da4c61c2c 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01073.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01073.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01074.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01074.docx index 411e406ef56..d0ee5a8ec54 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01074.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01074.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01075.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01075.docx index 4b1f0db4c2a..6cd12684e8a 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01075.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01075.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01076.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01076.docx index 6ba92f63f35..8c4163027d4 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01076.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01076.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01077.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01077.docx index 5ea73c5f3b1..d042f3bedbe 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01077.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01077.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01078.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01078.docx index 8b1a1541fc9..40d0ed38627 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01078.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01078.docx differ diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/civil/controllers/cases/CasesControllerTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/civil/controllers/cases/CasesControllerTest.java index 4f9174d907a..627fda38600 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/civil/controllers/cases/CasesControllerTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/civil/controllers/cases/CasesControllerTest.java @@ -12,13 +12,12 @@ import uk.gov.hmcts.reform.civil.exceptions.CaseDataInvalidException; import uk.gov.hmcts.reform.civil.exceptions.CaseNotFoundException; import uk.gov.hmcts.reform.civil.exceptions.UserNotFoundOnCaseException; -import uk.gov.hmcts.reform.civil.exceptions.CaseNotFoundException; -import uk.gov.hmcts.reform.civil.exceptions.UserNotFoundOnCaseException; import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.bulkclaims.CaseworkerSubmitEventDTo; import uk.gov.hmcts.reform.civil.model.citizenui.DashboardClaimInfo; import uk.gov.hmcts.reform.civil.model.citizenui.DashboardResponse; +import uk.gov.hmcts.reform.civil.model.citizenui.dto.ExtendedDeadlineDto; import uk.gov.hmcts.reform.civil.model.citizenui.dto.EventDto; import uk.gov.hmcts.reform.civil.model.repaymentplan.ClaimantProposedPlan; import uk.gov.hmcts.reform.civil.service.CoreCaseDataService; @@ -42,6 +41,7 @@ import java.util.Map; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; @@ -228,10 +228,10 @@ void shouldSubmitEventSuccessfully() { @SneakyThrows void shouldCalculateDeadlineSuccessfully() { LocalDate extensionDate = LocalDate.of(2022, 6, 6); - when(deadlineExtensionCalculatorService.calculateExtendedDeadline(any())).thenReturn(extensionDate); + when(deadlineExtensionCalculatorService.calculateExtendedDeadline(any(), anyInt())).thenReturn(extensionDate); doPost( BEARER_TOKEN, - extensionDate, + ExtendedDeadlineDto.builder().responseDate(extensionDate).plusDays(5).build(), CALCULATE_DEADLINE_URL ) .andExpect(content().json(toJson(extensionDate))) diff --git a/src/main/java/uk/gov/hmcts/reform/civil/controllers/cases/CasesController.java b/src/main/java/uk/gov/hmcts/reform/civil/controllers/cases/CasesController.java index 47814b87877..b83ea9be12c 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/controllers/cases/CasesController.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/controllers/cases/CasesController.java @@ -24,6 +24,7 @@ import uk.gov.hmcts.reform.civil.exceptions.CaseDataInvalidException; import uk.gov.hmcts.reform.civil.model.bulkclaims.CaseworkerSubmitEventDTo; import uk.gov.hmcts.reform.civil.model.citizenui.DashboardResponse; +import uk.gov.hmcts.reform.civil.model.citizenui.dto.ExtendedDeadlineDto; import uk.gov.hmcts.reform.civil.model.citizenui.dto.EventDto; import uk.gov.hmcts.reform.civil.model.citizenui.dto.RepaymentDecisionType; import uk.gov.hmcts.reform.civil.model.repaymentplan.ClaimantProposedPlan; @@ -174,8 +175,9 @@ public ResponseEntity submitEvent( @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "401", description = "Not Authorized")}) - public ResponseEntity calculateNewResponseDeadline(@RequestBody LocalDate extendedDeadline) { - LocalDate calculatedDeadline = deadlineExtensionCalculatorService.calculateExtendedDeadline(extendedDeadline); + public ResponseEntity calculateNewResponseDeadline(@RequestBody ExtendedDeadlineDto deadlineDateDetails) { + LocalDate calculatedDeadline = deadlineExtensionCalculatorService.calculateExtendedDeadline( + deadlineDateDetails.getResponseDate(), deadlineDateDetails.getPlusDays()); return new ResponseEntity<>(calculatedDeadline, HttpStatus.OK); } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/enums/caseprogression/BundleFileNameList.java b/src/main/java/uk/gov/hmcts/reform/civil/enums/caseprogression/BundleFileNameList.java index 9847205b2b4..ec628a0643f 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/enums/caseprogression/BundleFileNameList.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/enums/caseprogression/BundleFileNameList.java @@ -26,7 +26,8 @@ public enum BundleFileNameList { QUESTIONS_TO("Questions to %s %s"), REPLIES_FROM("Replies from %s %s"), JOINT_STATEMENTS_OF_EXPERTS("Joint statement of experts %s %s %s"), - SKELETON_ARGUMENT("%s Skeleton argument %s"); + SKELETON_ARGUMENT("%s Skeleton argument %s"), + PARTICULARS_OF_CLAIM("Particulars Of Claim %s"); String displayName; public String getDisplayName() { diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/TriggerGenAppLocationUpdateCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/TriggerGenAppLocationUpdateCallbackHandler.java index 6b392415a0c..6a7c730596d 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/TriggerGenAppLocationUpdateCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/TriggerGenAppLocationUpdateCallbackHandler.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Map; +import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRIGGER_LOCATION_UPDATE; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRIGGER_UPDATE_GA_LOCATION; @@ -44,9 +45,10 @@ public List handledEvents() { private CallbackResponse triggerGaEvent(CallbackParams callbackParams) { CaseData caseData = callbackParams.getCaseData(); + String authToken = callbackParams.getParams().get(BEARER_TOKEN).toString(); try { if (caseData.getGeneralApplications() != null && !caseData.getGeneralApplications().isEmpty()) { - caseData = helperService.updateApplicationLocationDetailsInClaim(caseData); + caseData = helperService.updateApplicationLocationDetailsInClaim(caseData, authToken); helperService.triggerEvent(caseData, TRIGGER_LOCATION_UPDATE); } } catch (Exception e) { diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/ClaimantResponseConfirmsToProceedRespondentNotificationHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/ClaimantResponseConfirmsToProceedRespondentNotificationHandler.java index fb660ca4694..3f80be153d4 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/ClaimantResponseConfirmsToProceedRespondentNotificationHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/ClaimantResponseConfirmsToProceedRespondentNotificationHandler.java @@ -9,14 +9,20 @@ import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; +import uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.SmallClaimMedicalLRspec; import uk.gov.hmcts.reform.civil.notify.NotificationService; -import uk.gov.hmcts.reform.civil.service.OrganisationService; +import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; import uk.gov.hmcts.reform.civil.prd.model.Organisation; +import uk.gov.hmcts.reform.civil.service.OrganisationService; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; +import java.util.stream.Stream; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIMANT_CONFIRMS_TO_PROCEED; @@ -70,7 +76,7 @@ public List handledEvents() { private CallbackResponse notifyRespondentSolicitorForClaimantConfirmsToProceed(CallbackParams callbackParams) { CaseData caseData = callbackParams.getCaseData(); - String template = null; + String template; var recipient = isCcNotification(callbackParams) ? caseData.getApplicantSolicitor1UserDetails().getEmail() : caseData.getRespondentSolicitor1EmailAddress(); @@ -103,9 +109,7 @@ private CallbackResponse notifyRespondentSolicitorForClaimantConfirmsToProceed(C return AboutToStartOrSubmitCallbackResponse.builder().build(); } if (SPEC_CLAIM.equals(caseData.getCaseAccessCategory())) { - template = isCcNotification(callbackParams) - ? notificationsProperties.getClaimantSolicitorConfirmsToProceedSpec() - : notificationsProperties.getRespondentSolicitorNotifyToProceedSpec(); + template = getSpecTemplate(callbackParams, caseData); } else { template = notificationsProperties.getClaimantSolicitorConfirmsToProceed(); } @@ -123,6 +127,50 @@ private CallbackResponse notifyRespondentSolicitorForClaimantConfirmsToProceed(C return AboutToStartOrSubmitCallbackResponse.builder().build(); } + private String getSpecTemplate(CallbackParams callbackParams, CaseData caseData) { + String template; + if (isCcNotification(callbackParams)) { + if (rejectedAll(caseData) && mediationRejected(caseData)) { + template = notificationsProperties.getClaimantSolicitorConfirmsToProceedSpecWithAction(); + } else { + template = notificationsProperties.getClaimantSolicitorConfirmsToProceedSpec(); + } + } else { + if (rejectedAll(caseData) && mediationRejected(caseData)) { + template = notificationsProperties.getRespondentSolicitorNotifyToProceedSpecWithAction(); + } else { + template = notificationsProperties.getRespondentSolicitorNotifyToProceedSpec(); + } + } + return template; + } + + /** + * Consider that reject all is true if any respondent rejected all the claim. + * + * @param caseData the case data of a spec claim + * @return true if and only if at least one respondent rejected all the claim + */ + private boolean rejectedAll(CaseData caseData) { + return caseData.getRespondent1ClaimResponseTypeForSpec() == RespondentResponseTypeSpec.FULL_DEFENCE + || caseData.getRespondent2ClaimResponseTypeForSpec() == RespondentResponseTypeSpec.FULL_DEFENCE; + } + + /** + * Mediation is applicable only when all parties are willing to try it. + * + * @param caseData a spec claim + * @return true if and only if at least one party did not agree to mediation + */ + private boolean mediationRejected(CaseData caseData) { + return Stream.of( + caseData.getResponseClaimMediationSpecRequired(), + caseData.getResponseClaimMediationSpec2Required(), + Optional.ofNullable(caseData.getApplicant1ClaimMediationSpecRequired()) + .map(SmallClaimMedicalLRspec::getHasAgreedFreeMediation).orElse(null) + ).filter(Objects::nonNull).anyMatch(YesOrNo.NO::equals); + } + @Override public Map addProperties(CaseData caseData) { return Map.of( @@ -158,12 +206,12 @@ private boolean isRespondentSolicitor2Notification(CallbackParams callbackParams } //finding legal org name - private String getLegalOrganisationName(CaseData caseData, CaseEvent caseEvent) { + private String getLegalOrganisationName(CaseData caseData, CaseEvent caseEvent) { String organisationID; if (caseEvent.equals(NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIMANT_CONFIRMS_TO_PROCEED_CC)) { organisationID = caseData.getApplicant1OrganisationPolicy().getOrganisation().getOrganisationID(); } else { - organisationID = caseEvent.equals(NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIMANT_CONFIRMS_TO_PROCEED) + organisationID = caseEvent.equals(NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIMANT_CONFIRMS_TO_PROCEED) ? caseData.getRespondent1OrganisationPolicy().getOrganisation().getOrganisationID() : caseData.getRespondent2OrganisationPolicy().getOrganisation().getOrganisationID(); } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/DefendantResponseApplicantNotificationHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/DefendantResponseApplicantNotificationHandler.java index b047d927cf9..cf52061b65c 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/DefendantResponseApplicantNotificationHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/DefendantResponseApplicantNotificationHandler.java @@ -33,7 +33,9 @@ import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.ONE_V_TWO_TWO_LEGAL_REP; import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.TWO_V_ONE; import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.getMultiPartyScenario; +import static uk.gov.hmcts.reform.civil.enums.RespondentResponsePartAdmissionPaymentTimeLRspec.BY_SET_DATE; import static uk.gov.hmcts.reform.civil.enums.RespondentResponsePartAdmissionPaymentTimeLRspec.IMMEDIATELY; +import static uk.gov.hmcts.reform.civil.enums.RespondentResponsePartAdmissionPaymentTimeLRspec.SUGGESTION_OF_REPAYMENT_PLAN; import static uk.gov.hmcts.reform.civil.utils.PartyUtils.buildPartiesReferences; import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getPartyNameBasedOnType; @@ -159,7 +161,11 @@ private void sendNotificationToSolicitorSpec(CaseData caseData, String recipient String.format(REFERENCE_TEMPLATE, caseData.getLegacyCaseReference()) ); } else if (caseEvent.equals(NOTIFY_APPLICANT_SOLICITOR1_FOR_DEFENDANT_RESPONSE_CC)) { - emailTemplate = notificationsProperties.getRespondentSolicitorDefendantResponseForSpec(); + if (MultiPartyScenario.getMultiPartyScenario(caseData).equals(ONE_V_TWO_TWO_LEGAL_REP)) { + emailTemplate = notificationsProperties.getRespondentSolicitorDefendantResponseForSpec(); + } else { + emailTemplate = getTemplateForSpecOtherThan1v2DS(caseData); + } if (caseData.getRespondent1ResponseDate() == null || !MultiPartyScenario.getMultiPartyScenario(caseData) .equals(ONE_V_TWO_TWO_LEGAL_REP)) { notificationService.sendMail( @@ -171,7 +177,11 @@ private void sendNotificationToSolicitorSpec(CaseData caseData, String recipient } } else { - emailTemplate = notificationsProperties.getRespondentSolicitorDefendantResponseForSpec(); + if (MultiPartyScenario.getMultiPartyScenario(caseData).equals(ONE_V_TWO_TWO_LEGAL_REP)) { + emailTemplate = notificationsProperties.getRespondentSolicitorDefendantResponseForSpec(); + } else { + emailTemplate = getTemplateForSpecOtherThan1v2DS(caseData); + } notificationService.sendMail( recipient, emailTemplate, @@ -181,6 +191,23 @@ private void sendNotificationToSolicitorSpec(CaseData caseData, String recipient } } + private String getTemplateForSpecOtherThan1v2DS(CaseData caseData) { + + String emailTemplate; + if ((caseData.getDefenceAdmitPartPaymentTimeRouteRequired() == IMMEDIATELY + || caseData.getDefenceAdmitPartPaymentTimeRouteRequired() == BY_SET_DATE + || caseData.getDefenceAdmitPartPaymentTimeRouteRequired() == SUGGESTION_OF_REPAYMENT_PLAN) + && + (RespondentResponseTypeSpec.PART_ADMISSION.equals(caseData.getRespondent1ClaimResponseTypeForSpec())) + ) { + emailTemplate = notificationsProperties.getRespondentSolicitorDefResponseSpecWithClaimantAction(); + } else { + emailTemplate = notificationsProperties.getRespondentSolicitorDefendantResponseForSpec(); + } + + return emailTemplate; + } + @Override public Map addProperties(CaseData caseData) { if (getMultiPartyScenario(caseData).equals(ONE_V_ONE) || getMultiPartyScenario(caseData).equals(TWO_V_ONE)) { @@ -216,10 +243,10 @@ public Map addPropertiesSpec(CaseData caseData, CaseEvent caseEv + " " + caseData.getRespondToClaimAdmitPartLRspec().getWhenWillThisAmountBePaid().getMonth() + " " + caseData.getRespondToClaimAdmitPartLRspec().getWhenWillThisAmountBePaid().getYear(); return Map.of( - CLAIM_LEGAL_ORG_NAME_SPEC, getLegalOrganisationName(caseData, caseEvent), - CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(), - RESPONDENT_NAME, getPartyNameBasedOnType(caseData.getApplicant1()), - WHEN_WILL_BE_PAID_IMMEDIATELY, shouldBePaidBy + CLAIM_LEGAL_ORG_NAME_SPEC, getLegalOrganisationName(caseData, caseEvent), + CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(), + RESPONDENT_NAME, getPartyNameBasedOnType(caseData.getApplicant1()), + WHEN_WILL_BE_PAID_IMMEDIATELY, shouldBePaidBy ); } else { return Map.of( diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotificationData.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotificationData.java index d55b1b7339b..811456c2cc9 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotificationData.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotificationData.java @@ -84,6 +84,9 @@ public interface NotificationData { String OTHER_SOL_NAME = "other solicitor name"; String EXTERNAL_ID = "externalId"; + // evidence upload + String UPLOADED_DOCUMENTS = "uploaded documents"; + Map addProperties(CaseData caseData); } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ClaimantResponseCuiCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ClaimantResponseCuiCallbackHandler.java index 8ae14dc9eee..b42f274c8df 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ClaimantResponseCuiCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ClaimantResponseCuiCallbackHandler.java @@ -13,6 +13,8 @@ import uk.gov.hmcts.reform.civil.enums.CaseState; import uk.gov.hmcts.reform.civil.model.BusinessProcess; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.service.citizenui.ResponseOneVOneShowTagService; +import uk.gov.hmcts.reform.civil.service.citizen.UpdateCaseManagementDetailsService; import java.time.LocalDateTime; import java.util.Collections; @@ -31,12 +33,15 @@ public class ClaimantResponseCuiCallbackHandler extends CallbackHandler { private static final List EVENTS = Collections.singletonList(CLAIMANT_RESPONSE_CUI); + private final ResponseOneVOneShowTagService responseOneVOneService; + private final ObjectMapper objectMapper; + private final UpdateCaseManagementDetailsService updateCaseManagementLocationDetailsService; @Override protected Map callbacks() { return Map.of( - callbackKey(ABOUT_TO_START), this::emptyCallbackResponse, + callbackKey(ABOUT_TO_START), this::populateCaseData, callbackKey(ABOUT_TO_SUBMIT), this::aboutToSubmit, callbackKey(SUBMITTED), this::emptySubmittedCallbackResponse ); @@ -47,16 +52,28 @@ public List handledEvents() { return EVENTS; } + private CallbackResponse populateCaseData(CallbackParams callbackParams) { + var caseData = callbackParams.getCaseData(); + CaseData.CaseDataBuilder updatedCaseData = caseData.toBuilder(); + updatedCaseData.showResponseOneVOneFlag(responseOneVOneService.setUpOneVOneFlow(caseData)); + + return AboutToStartOrSubmitCallbackResponse.builder() + .data(updatedCaseData.build().toMap(objectMapper)) + .build(); + } + private CallbackResponse aboutToSubmit(CallbackParams callbackParams) { CaseData caseData = callbackParams.getCaseData(); - CaseData updatedData = caseData.toBuilder() - .applicant1ResponseDate(LocalDateTime.now()) - .businessProcess(BusinessProcess.ready(CLAIMANT_RESPONSE_CUI)) - .build(); + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant1ResponseDate(LocalDateTime.now()) + .businessProcess(BusinessProcess.ready(CLAIMANT_RESPONSE_CUI)); + + updateCaseManagementLocationDetailsService.updateCaseManagementDetails(builder, callbackParams); + CaseData updatedData = builder.build(); AboutToStartOrSubmitCallbackResponse.AboutToStartOrSubmitCallbackResponseBuilder response = - AboutToStartOrSubmitCallbackResponse.builder() - .data(updatedData.toMap(objectMapper)); + AboutToStartOrSubmitCallbackResponse.builder() + .data(updatedData.toMap(objectMapper)); updateClaimEndState(response, updatedData); @@ -64,11 +81,13 @@ private CallbackResponse aboutToSubmit(CallbackParams callbackParams) { } private void updateClaimEndState(AboutToStartOrSubmitCallbackResponse.AboutToStartOrSubmitCallbackResponseBuilder response, CaseData updatedData) { - if (updatedData.hasClaimantAgreedToFreeMediation()) { response.state(CaseState.IN_MEDIATION.name()); + } else if (updatedData.hasApplicantRejectedRepaymentPlan() && updatedData.getRespondent1().isCompanyOROrganisation()) { + response.state(CaseState.PROCEEDS_IN_HERITAGE_SYSTEM.name()); } else { response.state(CaseState.JUDICIAL_REFERRAL.name()); } } + } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateSDOCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateSDOCallbackHandler.java index 6aae628746a..32770c5f47a 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateSDOCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateSDOCallbackHandler.java @@ -98,6 +98,9 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED; import static uk.gov.hmcts.reform.civil.callback.CallbackVersion.V_1; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_SDO; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; +import static uk.gov.hmcts.reform.civil.enums.sdo.OrderDetailsPagesSectionsToggle.SHOW; +import static uk.gov.hmcts.reform.civil.enums.sdo.OrderType.DISPOSAL; import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.DATE; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element; import static uk.gov.hmcts.reform.civil.utils.HearingUtils.getHearingNotes; @@ -219,7 +222,7 @@ private CallbackResponse prePopulateOrderDetailsPages(CallbackParams callbackPar updatedData.fastTrackMethodInPerson(locationsList); updatedData.smallClaimsMethodInPerson(locationsList); - List checkList = List.of(OrderDetailsPagesSectionsToggle.SHOW); + List checkList = List.of(SHOW); setCheckList(updatedData, checkList); DisposalHearingJudgesRecital tempDisposalHearingJudgesRecital = DisposalHearingJudgesRecital.builder() @@ -711,17 +714,21 @@ private DynamicList getLocationList(CallbackParams callbackParams, )); DynamicList locationsList; if (matchingLocation.isPresent()) { - locationsList = DynamicList.fromList(locations, LocationRefDataService::getDisplayEntry, + locationsList = DynamicList.fromList(locations, this::getLocationEpimms, LocationRefDataService::getDisplayEntry, matchingLocation.get(), true ); } else { - locationsList = DynamicList.fromList(locations, LocationRefDataService::getDisplayEntry, + locationsList = DynamicList.fromList(locations, this::getLocationEpimms, LocationRefDataService::getDisplayEntry, null, true ); } return locationsList; } + private String getLocationEpimms(LocationRefData location) { + return location.getEpimmsId(); + } + private CallbackResponse setOrderDetailsFlags(CallbackParams callbackParams) { CaseData caseData = callbackParams.getCaseData(); CaseData.CaseDataBuilder updatedData = caseData.toBuilder(); @@ -732,9 +739,9 @@ private CallbackResponse setOrderDetailsFlags(CallbackParams callbackParams) { updatedData.setFastTrackFlag(YesOrNo.NO).build(); if (SdoHelper.isSmallClaimsTrack(caseData)) { - updatedData.setSmallClaimsFlag(YesOrNo.YES).build(); + updatedData.setSmallClaimsFlag(YES).build(); } else if (SdoHelper.isFastTrack(caseData)) { - updatedData.setFastTrackFlag(YesOrNo.YES).build(); + updatedData.setFastTrackFlag(YES).build(); } return AboutToStartOrSubmitCallbackResponse.builder() @@ -836,18 +843,38 @@ private CallbackResponse submitSDO(CallbackParams callbackParams) { dataBuilder.hearingNotes(getHearingNotes(caseData)); - if (featureToggleService.isLocationWhiteListedForCaseProgression( - caseData.getCaseManagementLocation().getBaseLocation())) { - log.info("Case {} is whitelisted for case progression.", caseData.getCcdCaseReference()); - } else { - log.info("Case {} is NOT whitelisted for case progression.", caseData.getCcdCaseReference()); + if (featureToggleService.isEarlyAdoptersEnabled()) { + if (featureToggleService.isLocationWhiteListedForCaseProgression( + getEpimmsId(caseData))) { + log.info("Case {} is whitelisted for case progression.", caseData.getCcdCaseReference()); + dataBuilder.eaCourtLocation(YES); + } else { + log.info("Case {} is NOT whitelisted for case progression.", caseData.getCcdCaseReference()); + dataBuilder.eaCourtLocation(YesOrNo.NO); + } } + System.out.println("before about to submit"); + return AboutToStartOrSubmitCallbackResponse.builder() .data(dataBuilder.build().toMap(objectMapper)) .build(); } + private String getEpimmsId(CaseData caseData) { + + if (caseData.getOrderType() != null && caseData.getOrderType().equals(DISPOSAL)) { + return caseData.getDisposalHearingMethodInPerson().getValue().getCode(); + } + if (SdoHelper.isFastTrack(caseData)) { + return caseData.getFastTrackMethodInPerson().getValue().getCode(); + } + if (SdoHelper.isSmallClaimsTrack(caseData)) { + return caseData.getSmallClaimsMethodInPerson().getValue().getCode(); + } + throw new IllegalArgumentException("Could not determine claim track"); + } + private boolean nonNull(Object object) { if (object != null) { return true; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadHandlerBase.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadHandlerBase.java index 3de0019be4b..5277c8351c6 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadHandlerBase.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadHandlerBase.java @@ -2,6 +2,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; @@ -44,6 +45,7 @@ import uk.gov.hmcts.reform.civil.utils.ElementUtils; import uk.gov.hmcts.reform.idam.client.models.UserInfo; +import static java.lang.String.format; import static java.util.Objects.nonNull; import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START; @@ -116,22 +118,39 @@ abstract class EvidenceUploadHandlerBase extends CallbackHandler { protected static final String RESPONDENT_ONE_PRE_TRIAL_SUMMARY = "RespondentOnePreTrialSummary"; protected static final String RESPONDENT_ONE_TRIAL_SKELETON = "RespondentOneTrialSkeleton"; protected static final String RESPONDENT_ONE_PRECEDENT_H = "RespondentOneUploadedPrecedentH"; - protected static final String RESPONDENT_ONE_ANY_PRECEDENT_H = "respondentOneAnyPrecedentH"; protected static final String RESPONDENT_TWO_DISCLOSURE_LIST = "RespondentTwoDisclosureList"; protected static final String RESPONDENT_TWO_PRE_TRIAL_SUMMARY = "RespondentTwoPreTrialSummary"; protected static final String RESPONDENT_TWO_TRIAL_SKELETON = "RespondentTwoTrialSkeleton"; protected static final String RESPONDENT_TWO_PRECEDENT_H = "RespondentTwoUploadedPrecedentH"; - protected static final String RESPONDENT_TWO_ANY_PRECEDENT_H = "respondentTwoAnyPrecedentH"; + protected static final String RESPONDENT_ONE_SCHEDULE_OF_COSTS = "RespondentSchedulesOfCost"; + protected static final String RESPONDENT_TWO_SCHEDULE_OF_COSTS = "RespondentTwoSchedulesOfCost"; protected static final String APPLICANT_DISCLOSURE_LIST = "ApplicantDisclosureList"; protected static final String APPLICANT_PRE_TRIAL_SUMMARY = "ApplicantPreTrialSummary"; protected static final String APPLICANT_TRIAL_SKELETON = "ApplicantTrialSkeleton"; protected static final String APPLICANT_PRECEDENT_H = "ApplicantUploadedPrecedentH"; - protected static final String APPLICANT_ANY_PRECEDENT_H = "ApplicantAnyPrecedentH"; protected static final String APPLICANT_TWO_DISCLOSURE_LIST = "ApplicantTwoDisclosureList"; protected static final String APPLICANT_TWO_PRE_TRIAL_SUMMARY = "ApplicantTwoPreTrialSummary"; protected static final String APPLICANT_TWO_TRIAL_SKELETON = "ApplicantTwoTrialSkeleton"; protected static final String APPLICANT_TWO_PRECEDENT_H = "ApplicantTwoUploadedPrecedentH"; - protected static final String APPLICANT_TWO_ANY_PRECEDENT_H = "ApplicantTwoAnyPrecedentH"; + protected static final String APPLICANT_SCHEDULE_OF_COSTS = "ApplicantSchedulesOfCost"; + protected static final String APPLICANT_TWO_SCHEDULE_OF_COSTS = "ApplicantTwoSchedulesOfCost"; + // Notification Strings used for email + protected static StringBuilder notificationString = new StringBuilder(); + protected static final String DISCLOSURE_LIST_TEXT = "%s - Disclosure list"; + protected static final String DISCLOSURE_TEXT = "%s - Documents for disclosure"; + protected static final String WITNESS_STATEMENT_TEXT = "%s - Witness statement"; + protected static final String WITNESS_SUMMARY_TEXT = "%s - Witness summary"; + protected static final String WITNESS_HEARSAY_TEXT = "%s - Notice of the intention to rely on hearsay evidence"; + protected static final String WITNESS_REFERRED_TEXT = "%s - Documents referred to in the statement"; + protected static final String EXPERT_REPORT_TEXT = "%s - Expert's report"; + protected static final String EXPERT_JOINT_STATEMENT_TEXT = "%s - Joint Statement of Experts / Single Joint Expert Report"; + protected static final String EXPERT_QUESTIONS_TEXT = "%s - Questions for other party's expert or joint experts"; + protected static final String EXPERT_ANSWERS_TEXT = "%s - Answer to questions asked"; + protected static final String PRE_TRIAL_SUMMARY_TEXT = "%s - Case Summary"; + protected static final String TRIAL_SKELETON_TEXT = "%s - Skeleton argument"; + protected static final String TRIAL_AUTHORITIES_TEXT = "%s - Authorities"; + protected static final String TRIAL_COSTS_TEXT = "%s - Costs"; + protected static final String TRIAL_DOC_CORRESPONDENCE_TEXT = "%s - Documentary evidence for trial"; protected static final String OPTION_APP1 = "Claimant 1 - "; protected static final String OPTION_APP2 = "Claimant 2 - "; @@ -166,8 +185,6 @@ protected EvidenceUploadHandlerBase(UserService userService, CoreCaseUserService abstract void applyDocumentUploadDate(CaseData.CaseDataBuilder caseDataBuilder, LocalDateTime now); - abstract void updateDocumentListUploadedAfterBundle(CaseData.CaseDataBuilder caseDataBuilder, CaseData caseData); - @Override public List handledEvents() { return events; @@ -208,6 +225,11 @@ CallbackResponse setOptions(CallbackParams callbackParams) { caseDataBuilder.caseProgAllocatedTrack(getAllocatedTrack(caseData.getClaimValue().toPounds(), caseData.getClaimType()).name()); } caseDataBuilder.evidenceUploadOptions(DynamicList.fromList(dynamicListOptions)); + // was unable to null value properly in EvidenceUploadNotificationEventHandler after emails are sent, + // so do it here if required. + if (nonNull(caseData.getNotificationText()) && caseData.getNotificationText().equals("NULLED")) { + caseDataBuilder.notificationText(null); + } return AboutToStartOrSubmitCallbackResponse.builder() .data(caseDataBuilder.build().toMap(objectMapper)) .build(); @@ -399,14 +421,23 @@ void checkDateCorrectness(Time time, List errors, List> d } public void setCategoryIdAndRenameDoc(List> documentUpload, Function, - Document> documentExtractor, String theID) { + Document> documentExtractor, String theID, String docNotificationText, Function, + LocalDateTime> documentDateTimeExtractor, String claimantDefendantString) { if (documentUpload == null || documentUpload.isEmpty()) { return; } + LocalDateTime midnight = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT); renameDocuments(documentUpload, theID); documentUpload.forEach(document -> { Document documentToAddId = documentExtractor.apply(document); documentToAddId.setCategoryID(theID); + LocalDateTime dateTime = documentDateTimeExtractor.apply(document); + if (dateTime.isAfter(midnight)) { + String updateNotificationText = format(docNotificationText, claimantDefendantString); + if (!notificationString.toString().contains(updateNotificationText)) { + notificationString.append("\n").append(updateNotificationText); + } + } }); } @@ -548,92 +579,175 @@ private void renameUploadEvidenceDocumentType(final List> documen }); } - CallbackResponse documentUploadTime(CallbackParams callbackParams) { - CaseData caseData = callbackParams.getCaseData(); - CaseData.CaseDataBuilder caseDataBuilder = caseData.toBuilder(); + static void getNotificationText(CaseData caseData) { + notificationString = new StringBuilder(); + if (caseData.getNotificationText() != null) { + notificationString = new StringBuilder(caseData.getNotificationText()); + } + } - String selectedRole = getSelectedRole(callbackParams); + abstract void updateDocumentListUploadedAfterBundle(CaseData.CaseDataBuilder caseDataBuilder, CaseData caseData); - applyDocumentUploadDate(caseDataBuilder, time.now()); + private void updateDocumentListUploadedAfterBundle(CaseData caseData, CaseData.CaseDataBuilder caseDataBuilder) { if (nonNull(caseData.getCaseBundles()) && !caseData.getCaseBundles().isEmpty()) { updateDocumentListUploadedAfterBundle(caseDataBuilder, caseData); } + } + + CallbackResponse documentUploadTime(CallbackParams callbackParams) { + CaseData caseData = callbackParams.getCaseData(); + CaseData.CaseDataBuilder caseDataBuilder = caseData.toBuilder(); + // If notification has already been populated in current day, we want to append to that existing notification + getNotificationText(caseData); + applyDocumentUploadDate(caseDataBuilder, time.now()); + updateDocumentListUploadedAfterBundle(caseData, caseDataBuilder); + String selectedRole = getSelectedRole(callbackParams); if (selectedRole.equals(RESPONDENTSOLICITORONE.name()) || selectedRole.equals(SELECTED_VALUE_DEF_BOTH)) { - setCategoryIdAndRenameDoc(caseData.getDocumentDisclosureListRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_DISCLOSURE_LIST); - setCategoryIdAndRenameDoc(caseData.getDocumentForDisclosureRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_DISCLOSURE); - setCategoryIdAndRenameDoc(caseData.getDocumentWitnessStatementRes(), document -> document.getValue().getWitnessOptionDocument(), RESPONDENT_ONE_WITNESS_STATEMENT); - setCategoryIdAndRenameDoc(caseData.getDocumentWitnessSummaryRes(), document -> document.getValue().getWitnessOptionDocument(), RESPONDENT_ONE_WITNESS_SUMMARY); - setCategoryIdAndRenameDoc(caseData.getDocumentHearsayNoticeRes(), document -> document.getValue().getWitnessOptionDocument(), RESPONDENT_ONE_WITNESS_HEARSAY); - setCategoryIdAndRenameDoc(caseData.getDocumentReferredInStatementRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_WITNESS_REFERRED); - setCategoryIdAndRenameDoc(caseData.getDocumentExpertReportRes(), document -> document.getValue().getExpertDocument(), RESPONDENT_ONE_EXPERT_REPORT); - setCategoryIdAndRenameDoc(caseData.getDocumentJointStatementRes(), document -> document.getValue().getExpertDocument(), RESPONDENT_ONE_EXPERT_JOINT_STATEMENT); - setCategoryIdAndRenameDoc(caseData.getDocumentQuestionsRes(), document -> document.getValue().getExpertDocument(), RESPONDENT_ONE_EXPERT_QUESTIONS); - setCategoryIdAndRenameDoc(caseData.getDocumentAnswersRes(), document -> document.getValue().getExpertDocument(), RESPONDENT_ONE_EXPERT_ANSWERS); - setCategoryIdAndRenameDoc(caseData.getDocumentCaseSummaryRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_PRE_TRIAL_SUMMARY); - setCategoryIdAndRenameDoc(caseData.getDocumentSkeletonArgumentRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_TRIAL_SKELETON); - setCategoryIdAndRenameDoc(caseData.getDocumentAuthoritiesRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_PRECEDENT_H); - setCategoryIdAndRenameDoc(caseData.getDocumentCostsRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_ANY_PRECEDENT_H); - setCategoryIdAndRenameDoc(caseData.getDocumentEvidenceForTrialRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_TRIAL_DOC_CORRESPONDENCE); + String defendantString = "Defendant 1"; + if (selectedRole.equals(SELECTED_VALUE_DEF_BOTH)) { + defendantString = "Both defendants"; + } + setCategoryIdAndRenameDoc(caseData.getDocumentDisclosureListRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_DISCLOSURE_LIST, + DISCLOSURE_LIST_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentForDisclosureRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_DISCLOSURE, + DISCLOSURE_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentWitnessStatementRes(), document -> document.getValue().getWitnessOptionDocument(), RESPONDENT_ONE_WITNESS_STATEMENT, + WITNESS_STATEMENT_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentWitnessSummaryRes(), document -> document.getValue().getWitnessOptionDocument(), RESPONDENT_ONE_WITNESS_SUMMARY, + WITNESS_SUMMARY_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentHearsayNoticeRes(), document -> document.getValue().getWitnessOptionDocument(), RESPONDENT_ONE_WITNESS_HEARSAY, + WITNESS_HEARSAY_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentReferredInStatementRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_WITNESS_REFERRED, + WITNESS_REFERRED_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentExpertReportRes(), document -> document.getValue().getExpertDocument(), RESPONDENT_ONE_EXPERT_REPORT, + EXPERT_REPORT_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentJointStatementRes(), document -> document.getValue().getExpertDocument(), RESPONDENT_ONE_EXPERT_JOINT_STATEMENT, + EXPERT_JOINT_STATEMENT_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentQuestionsRes(), document -> document.getValue().getExpertDocument(), RESPONDENT_ONE_EXPERT_QUESTIONS, + EXPERT_QUESTIONS_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentAnswersRes(), document -> document.getValue().getExpertDocument(), RESPONDENT_ONE_EXPERT_ANSWERS, + EXPERT_ANSWERS_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentCaseSummaryRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_PRE_TRIAL_SUMMARY, + PRE_TRIAL_SUMMARY_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentSkeletonArgumentRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_TRIAL_SKELETON, + TRIAL_SKELETON_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentAuthoritiesRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_PRECEDENT_H, + TRIAL_AUTHORITIES_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentCostsRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_SCHEDULE_OF_COSTS, + TRIAL_COSTS_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentEvidenceForTrialRes(), document -> document.getValue().getDocumentUpload(), RESPONDENT_ONE_TRIAL_DOC_CORRESPONDENCE, + TRIAL_DOC_CORRESPONDENCE_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); if (selectedRole.equals(SELECTED_VALUE_DEF_BOTH)) { caseData = copyResp1ChangesToResp2(caseData, caseDataBuilder); } } if (selectedRole.equals(RESPONDENTSOLICITORTWO.name())) { - setCategoryIdAndRenameDoc(caseData.getDocumentDisclosureListRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_DISCLOSURE_LIST); - setCategoryIdAndRenameDoc(caseData.getDocumentForDisclosureRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_DISCLOSURE); - setCategoryIdAndRenameDoc(caseData.getDocumentWitnessStatementRes2(), document -> document.getValue().getWitnessOptionDocument(), RESPONDENT_TWO_WITNESS_STATEMENT); - setCategoryIdAndRenameDoc(caseData.getDocumentWitnessSummaryRes2(), document -> document.getValue().getWitnessOptionDocument(), RESPONDENT_TWO_WITNESS_SUMMARY); - setCategoryIdAndRenameDoc(caseData.getDocumentHearsayNoticeRes2(), document -> document.getValue().getWitnessOptionDocument(), RESPONDENT_TWO_WITNESS_HEARSAY); - setCategoryIdAndRenameDoc(caseData.getDocumentReferredInStatementRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_WITNESS_REFERRED); - setCategoryIdAndRenameDoc(caseData.getDocumentExpertReportRes2(), document -> document.getValue().getExpertDocument(), RESPONDENT_TWO_EXPERT_REPORT); - setCategoryIdAndRenameDoc(caseData.getDocumentJointStatementRes2(), document -> document.getValue().getExpertDocument(), RESPONDENT_TWO_EXPERT_JOINT_STATEMENT); - setCategoryIdAndRenameDoc(caseData.getDocumentQuestionsRes2(), document -> document.getValue().getExpertDocument(), RESPONDENT_TWO_EXPERT_QUESTIONS); - setCategoryIdAndRenameDoc(caseData.getDocumentAnswersRes2(), document -> document.getValue().getExpertDocument(), RESPONDENT_TWO_EXPERT_ANSWERS); - setCategoryIdAndRenameDoc(caseData.getDocumentCaseSummaryRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_PRE_TRIAL_SUMMARY); - setCategoryIdAndRenameDoc(caseData.getDocumentSkeletonArgumentRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_TRIAL_SKELETON); - setCategoryIdAndRenameDoc(caseData.getDocumentAuthoritiesRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_PRECEDENT_H); - setCategoryIdAndRenameDoc(caseData.getDocumentCostsRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_ANY_PRECEDENT_H); - setCategoryIdAndRenameDoc(caseData.getDocumentEvidenceForTrialRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_TRIAL_DOC_CORRESPONDENCE); + String defendantString = "Defendant 2"; + setCategoryIdAndRenameDoc(caseData.getDocumentDisclosureListRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_DISCLOSURE_LIST, + DISCLOSURE_LIST_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentForDisclosureRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_DISCLOSURE, + DISCLOSURE_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentWitnessStatementRes2(), document -> document.getValue().getWitnessOptionDocument(), RESPONDENT_TWO_WITNESS_STATEMENT, + WITNESS_STATEMENT_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentWitnessSummaryRes2(), document -> document.getValue().getWitnessOptionDocument(), RESPONDENT_TWO_WITNESS_SUMMARY, + WITNESS_SUMMARY_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentHearsayNoticeRes2(), document -> document.getValue().getWitnessOptionDocument(), RESPONDENT_TWO_WITNESS_HEARSAY, + WITNESS_HEARSAY_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentReferredInStatementRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_WITNESS_REFERRED, + WITNESS_REFERRED_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentExpertReportRes2(), document -> document.getValue().getExpertDocument(), RESPONDENT_TWO_EXPERT_REPORT, + EXPERT_REPORT_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentJointStatementRes2(), document -> document.getValue().getExpertDocument(), RESPONDENT_TWO_EXPERT_JOINT_STATEMENT, + EXPERT_JOINT_STATEMENT_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentQuestionsRes2(), document -> document.getValue().getExpertDocument(), RESPONDENT_TWO_EXPERT_QUESTIONS, + EXPERT_QUESTIONS_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentAnswersRes2(), document -> document.getValue().getExpertDocument(), RESPONDENT_TWO_EXPERT_ANSWERS, + EXPERT_ANSWERS_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentCaseSummaryRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_PRE_TRIAL_SUMMARY, + PRE_TRIAL_SUMMARY_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentSkeletonArgumentRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_TRIAL_SKELETON, + TRIAL_SKELETON_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentAuthoritiesRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_PRECEDENT_H, + TRIAL_AUTHORITIES_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentCostsRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_SCHEDULE_OF_COSTS, + TRIAL_COSTS_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); + setCategoryIdAndRenameDoc(caseData.getDocumentEvidenceForTrialRes2(), document -> document.getValue().getDocumentUpload(), RESPONDENT_TWO_TRIAL_DOC_CORRESPONDENCE, + TRIAL_DOC_CORRESPONDENCE_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), defendantString); } if (selectedRole.equals(CaseRole.APPLICANTSOLICITORONE.name()) || selectedRole.equals(SELECTED_VALUE_APP_BOTH)) { - setCategoryIdAndRenameDoc(caseData.getDocumentDisclosureList(), document -> document.getValue().getDocumentUpload(), APPLICANT_DISCLOSURE_LIST); - setCategoryIdAndRenameDoc(caseData.getDocumentForDisclosure(), document -> document.getValue().getDocumentUpload(), APPLICANT_DISCLOSURE); - setCategoryIdAndRenameDoc(caseData.getDocumentWitnessStatement(), document -> document.getValue().getWitnessOptionDocument(), APPLICANT_WITNESS_STATEMENT); - setCategoryIdAndRenameDoc(caseData.getDocumentWitnessSummary(), document -> document.getValue().getWitnessOptionDocument(), APPLICANT_WITNESS_SUMMARY); - setCategoryIdAndRenameDoc(caseData.getDocumentHearsayNotice(), document -> document.getValue().getWitnessOptionDocument(), APPLICANT_WITNESS_HEARSAY); - setCategoryIdAndRenameDoc(caseData.getDocumentReferredInStatement(), document -> document.getValue().getDocumentUpload(), APPLICANT_WITNESS_REFERRED); - setCategoryIdAndRenameDoc(caseData.getDocumentExpertReport(), document -> document.getValue().getExpertDocument(), APPLICANT_EXPERT_REPORT); - setCategoryIdAndRenameDoc(caseData.getDocumentJointStatement(), document -> document.getValue().getExpertDocument(), APPLICANT_EXPERT_JOINT_STATEMENT); - setCategoryIdAndRenameDoc(caseData.getDocumentQuestions(), document -> document.getValue().getExpertDocument(), APPLICANT_EXPERT_QUESTIONS); - setCategoryIdAndRenameDoc(caseData.getDocumentAnswers(), document -> document.getValue().getExpertDocument(), APPLICANT_EXPERT_ANSWERS); - setCategoryIdAndRenameDoc(caseData.getDocumentCaseSummary(), document -> document.getValue().getDocumentUpload(), APPLICANT_PRE_TRIAL_SUMMARY); - setCategoryIdAndRenameDoc(caseData.getDocumentSkeletonArgument(), document -> document.getValue().getDocumentUpload(), APPLICANT_TRIAL_SKELETON); - setCategoryIdAndRenameDoc(caseData.getDocumentAuthorities(), document -> document.getValue().getDocumentUpload(), APPLICANT_PRECEDENT_H); - setCategoryIdAndRenameDoc(caseData.getDocumentCosts(), document -> document.getValue().getDocumentUpload(), APPLICANT_ANY_PRECEDENT_H); - setCategoryIdAndRenameDoc(caseData.getDocumentEvidenceForTrial(), document -> document.getValue().getDocumentUpload(), APPLICANT_TRIAL_DOC_CORRESPONDENCE); + String claimantString = "Claimant 1"; + if (selectedRole.equals(SELECTED_VALUE_APP_BOTH)) { + claimantString = "Both claimants"; + } + setCategoryIdAndRenameDoc(caseData.getDocumentDisclosureList(), document -> document.getValue().getDocumentUpload(), APPLICANT_DISCLOSURE_LIST, + DISCLOSURE_LIST_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentForDisclosure(), document -> document.getValue().getDocumentUpload(), APPLICANT_DISCLOSURE, + DISCLOSURE_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentWitnessStatement(), document -> document.getValue().getWitnessOptionDocument(), APPLICANT_WITNESS_STATEMENT, + WITNESS_STATEMENT_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentWitnessSummary(), document -> document.getValue().getWitnessOptionDocument(), APPLICANT_WITNESS_SUMMARY, + WITNESS_SUMMARY_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentHearsayNotice(), document -> document.getValue().getWitnessOptionDocument(), APPLICANT_WITNESS_HEARSAY, + WITNESS_HEARSAY_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentReferredInStatement(), document -> document.getValue().getDocumentUpload(), APPLICANT_WITNESS_REFERRED, + WITNESS_REFERRED_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentExpertReport(), document -> document.getValue().getExpertDocument(), APPLICANT_EXPERT_REPORT, + EXPERT_REPORT_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentJointStatement(), document -> document.getValue().getExpertDocument(), APPLICANT_EXPERT_JOINT_STATEMENT, + EXPERT_JOINT_STATEMENT_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentQuestions(), document -> document.getValue().getExpertDocument(), APPLICANT_EXPERT_QUESTIONS, + EXPERT_QUESTIONS_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentAnswers(), document -> document.getValue().getExpertDocument(), APPLICANT_EXPERT_ANSWERS, + EXPERT_ANSWERS_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentCaseSummary(), document -> document.getValue().getDocumentUpload(), APPLICANT_PRE_TRIAL_SUMMARY, + PRE_TRIAL_SUMMARY_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentSkeletonArgument(), document -> document.getValue().getDocumentUpload(), APPLICANT_TRIAL_SKELETON, + TRIAL_SKELETON_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentAuthorities(), document -> document.getValue().getDocumentUpload(), APPLICANT_PRECEDENT_H, + TRIAL_AUTHORITIES_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentCosts(), document -> document.getValue().getDocumentUpload(), APPLICANT_SCHEDULE_OF_COSTS, + TRIAL_COSTS_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentEvidenceForTrial(), document -> document.getValue().getDocumentUpload(), APPLICANT_TRIAL_DOC_CORRESPONDENCE, + TRIAL_DOC_CORRESPONDENCE_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); if (selectedRole.equals(SELECTED_VALUE_APP_BOTH)) { caseData = copyApp1ChangesToApp2(caseData, caseDataBuilder); } } if (selectedRole.equals("APPLICANTSOLICITORTWO")) { - setCategoryIdAndRenameDoc(caseData.getDocumentDisclosureListApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_DISCLOSURE_LIST); - setCategoryIdAndRenameDoc(caseData.getDocumentForDisclosureApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_DISCLOSURE); - setCategoryIdAndRenameDoc(caseData.getDocumentWitnessStatementApp2(), document -> document.getValue().getWitnessOptionDocument(), APPLICANT_TWO_WITNESS_STATEMENT); - setCategoryIdAndRenameDoc(caseData.getDocumentWitnessSummaryApp2(), document -> document.getValue().getWitnessOptionDocument(), APPLICANT_TWO_WITNESS_SUMMARY); - setCategoryIdAndRenameDoc(caseData.getDocumentHearsayNoticeApp2(), document -> document.getValue().getWitnessOptionDocument(), APPLICANT_TWO_WITNESS_HEARSAY); - setCategoryIdAndRenameDoc(caseData.getDocumentReferredInStatementApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_WITNESS_REFERRED); - setCategoryIdAndRenameDoc(caseData.getDocumentExpertReportApp2(), document -> document.getValue().getExpertDocument(), APPLICANT_TWO_EXPERT_REPORT); - setCategoryIdAndRenameDoc(caseData.getDocumentJointStatementApp2(), document -> document.getValue().getExpertDocument(), APPLICANT_TWO_EXPERT_JOINT_STATEMENT); - setCategoryIdAndRenameDoc(caseData.getDocumentQuestionsApp2(), document -> document.getValue().getExpertDocument(), APPLICANT_TWO_EXPERT_QUESTIONS); - setCategoryIdAndRenameDoc(caseData.getDocumentAnswersApp2(), document -> document.getValue().getExpertDocument(), APPLICANT_TWO_EXPERT_ANSWERS); - setCategoryIdAndRenameDoc(caseData.getDocumentCaseSummaryApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_PRE_TRIAL_SUMMARY); - setCategoryIdAndRenameDoc(caseData.getDocumentSkeletonArgumentApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_TRIAL_SKELETON); - setCategoryIdAndRenameDoc(caseData.getDocumentAuthoritiesApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_PRECEDENT_H); - setCategoryIdAndRenameDoc(caseData.getDocumentCostsApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_ANY_PRECEDENT_H); - setCategoryIdAndRenameDoc(caseData.getDocumentEvidenceForTrialApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_TRIAL_DOC_CORRESPONDENCE); + String claimantString = "Claimant 2"; + setCategoryIdAndRenameDoc(caseData.getDocumentDisclosureListApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_DISCLOSURE_LIST, + DISCLOSURE_LIST_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentForDisclosureApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_DISCLOSURE, + DISCLOSURE_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentWitnessStatementApp2(), document -> document.getValue().getWitnessOptionDocument(), APPLICANT_TWO_WITNESS_STATEMENT, + WITNESS_STATEMENT_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentWitnessSummaryApp2(), document -> document.getValue().getWitnessOptionDocument(), APPLICANT_TWO_WITNESS_SUMMARY, + WITNESS_SUMMARY_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentHearsayNoticeApp2(), document -> document.getValue().getWitnessOptionDocument(), APPLICANT_TWO_WITNESS_HEARSAY, + WITNESS_HEARSAY_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentReferredInStatementApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_WITNESS_REFERRED, + WITNESS_REFERRED_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentExpertReportApp2(), document -> document.getValue().getExpertDocument(), APPLICANT_TWO_EXPERT_REPORT, + EXPERT_REPORT_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentJointStatementApp2(), document -> document.getValue().getExpertDocument(), APPLICANT_TWO_EXPERT_JOINT_STATEMENT, + EXPERT_JOINT_STATEMENT_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentQuestionsApp2(), document -> document.getValue().getExpertDocument(), APPLICANT_TWO_EXPERT_QUESTIONS, + EXPERT_QUESTIONS_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentAnswersApp2(), document -> document.getValue().getExpertDocument(), APPLICANT_TWO_EXPERT_ANSWERS, + EXPERT_ANSWERS_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentCaseSummaryApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_PRE_TRIAL_SUMMARY, + PRE_TRIAL_SUMMARY_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentSkeletonArgumentApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_TRIAL_SKELETON, + TRIAL_SKELETON_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentAuthoritiesApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_PRECEDENT_H, + TRIAL_AUTHORITIES_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentCostsApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_SCHEDULE_OF_COSTS, + TRIAL_COSTS_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); + setCategoryIdAndRenameDoc(caseData.getDocumentEvidenceForTrialApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_TRIAL_DOC_CORRESPONDENCE, + TRIAL_DOC_CORRESPONDENCE_TEXT, documentDateTime -> documentDateTime.getValue().getCreatedDatetime(), claimantString); } // null the values of the lists, so that on future retriggers of the event, they are blank @@ -651,7 +765,7 @@ CallbackResponse documentUploadTime(CallbackParams callbackParams) { caseDataBuilder.trialSelectionEvidenceSmallClaim(null); caseDataBuilder.trialSelectionEvidenceRes(null); caseDataBuilder.trialSelectionEvidenceSmallClaimRes(null); - + caseDataBuilder.notificationText(notificationString.toString()); return AboutToStartOrSubmitCallbackResponse.builder() .data(caseDataBuilder.build().toMap(objectMapper)) .build(); @@ -757,7 +871,7 @@ private CaseData copyResp1ChangesToResp2(CaseData caseData, CaseData.CaseDataBui evidenceDocToCopy = compareAndCopy(caseDataBefore.getDocumentCostsRes(), caseData.getDocumentCostsRes(), caseData.getDocumentCostsRes2()); - evidenceDocToAdd = deepCopyUploadEvidenceDocumentType(evidenceDocToCopy, RESPONDENT_TWO_ANY_PRECEDENT_H); + evidenceDocToAdd = deepCopyUploadEvidenceDocumentType(evidenceDocToCopy, RESPONDENT_TWO_SCHEDULE_OF_COSTS); builder.documentCostsRes2(evidenceDocToAdd); evidenceDocToCopy = compareAndCopy(caseDataBefore.getDocumentEvidenceForTrialRes(), @@ -869,7 +983,7 @@ private CaseData copyApp1ChangesToApp2(CaseData caseData, CaseData.CaseDataBuild evidenceDocToCopy = compareAndCopy(caseDataBefore.getDocumentCosts(), caseData.getDocumentCosts(), caseData.getDocumentCostsApp2()); - evidenceDocToAdd = deepCopyUploadEvidenceDocumentType(evidenceDocToCopy, APPLICANT_TWO_ANY_PRECEDENT_H); + evidenceDocToAdd = deepCopyUploadEvidenceDocumentType(evidenceDocToCopy, APPLICANT_TWO_SCHEDULE_OF_COSTS); builder.documentCostsApp2(evidenceDocToAdd); evidenceDocToCopy = compareAndCopy(caseDataBefore.getDocumentEvidenceForTrial(), diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadJudgeHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadJudgeHandler.java index d41aacdabc6..12ca69bdb86 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadJudgeHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadJudgeHandler.java @@ -14,6 +14,8 @@ import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.CaseNote; import uk.gov.hmcts.reform.civil.model.common.Element; +import uk.gov.hmcts.reform.civil.model.documents.DocumentAndNote; +import uk.gov.hmcts.reform.civil.model.documents.DocumentWithName; import uk.gov.hmcts.reform.civil.service.CaseNoteService; import java.util.Collections; @@ -59,7 +61,11 @@ private AboutToStartOrSubmitCallbackResponse removeCaseNoteType(CallbackParams c var caseData = callbackParams.getCaseData(); CaseData.CaseDataBuilder caseDataBuilder = caseData.toBuilder(); - caseDataBuilder.caseNoteType(null).build(); + caseDataBuilder + .caseNoteType(null) + .documentAndNameToAdd(null) + .documentAndNoteToAdd(null) + .build(); return AboutToStartOrSubmitCallbackResponse.builder() .data(caseDataBuilder.build().toMap(objectMapper)) @@ -84,6 +90,39 @@ private AboutToStartOrSubmitCallbackResponse populateSubmittedDateTime(CallbackP .build(); } + if (caseData.getCaseNoteType().equals(CaseNoteType.DOCUMENT_ONLY)) { + List> documentAndNameToAdd = caseData.getDocumentAndNameToAdd(); + List> documentAndNameCurrent = caseData.getDocumentAndName(); + + if (documentAndNameCurrent == null) { + documentAndNameCurrent = documentAndNameToAdd; + } else { + for (Element document : documentAndNameToAdd) { + documentAndNameCurrent.add(document); + } + } + caseDataBuilder + .documentAndName(documentAndNameCurrent) + .build(); + } + + if (caseData.getCaseNoteType().equals(CaseNoteType.DOCUMENT_AND_NOTE)) { + List> documentAndNoteToAdd = caseData.getDocumentAndNoteToAdd(); + List> documentAndNoteCurrent = caseData.getDocumentAndNote(); + + if (documentAndNoteCurrent == null) { + documentAndNoteCurrent = documentAndNoteToAdd; + } else { + for (Element document : documentAndNoteToAdd) { + documentAndNoteCurrent.add(document); + } + } + caseDataBuilder + .documentAndNote(documentAndNoteCurrent) + .build(); + + } + return AboutToStartOrSubmitCallbackResponse.builder() .data(caseDataBuilder.build().toMap(objectMapper)) .build(); @@ -115,16 +154,16 @@ private String getHeader(CaseData caseData) { private String getBody(CaseData caseData) { StringBuilder stringBuilder = new StringBuilder(); if (null != caseData.getCaseNoteType() && caseData.getCaseNoteType().equals(CaseNoteType.DOCUMENT_ONLY)) { - IntStream.range(0, caseData.getDocumentAndName() + IntStream.range(0, caseData.getDocumentAndNameToAdd() .size()).forEachOrdered(i -> stringBuilder.append("* ").append( - caseData.getDocumentAndName().get(i).getValue().getDocument().getDocumentFileName()).append("\n")); + caseData.getDocumentAndNameToAdd().get(i).getValue().getDocument().getDocumentFileName()).append("\n")); return format(EVIDENCE_UPLOAD_BODY_ONE, stringBuilder); } if (caseData.getCaseNoteType().equals(CaseNoteType.DOCUMENT_AND_NOTE)) { - IntStream.range(0, caseData.getDocumentAndNote() + IntStream.range(0, caseData.getDocumentAndNoteToAdd() .size()).forEachOrdered(i -> stringBuilder.append("* ").append( - caseData.getDocumentAndNote().get(i) + caseData.getDocumentAndNoteToAdd().get(i) .getValue() .getDocument() .getDocumentFileName()).append("\n")); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/GenerateDirectionOrderCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/GenerateDirectionOrderCallbackHandler.java index 877a60ee0f6..91e5960c66b 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/GenerateDirectionOrderCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/GenerateDirectionOrderCallbackHandler.java @@ -14,6 +14,7 @@ import uk.gov.hmcts.reform.civil.enums.CaseState; import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; import uk.gov.hmcts.reform.civil.enums.YesOrNo; +import uk.gov.hmcts.reform.civil.enums.finalorders.CostEnums; import uk.gov.hmcts.reform.civil.enums.finalorders.FinalOrderToggle; import uk.gov.hmcts.reform.civil.enums.finalorders.HearingLengthFinalOrderList; import uk.gov.hmcts.reform.civil.model.BusinessProcess; @@ -66,6 +67,9 @@ import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.TWO_V_ONE; import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.getMultiPartyScenario; import static uk.gov.hmcts.reform.civil.enums.caseprogression.FinalOrderSelection.ASSISTED_ORDER; +import static uk.gov.hmcts.reform.civil.enums.finalorders.CostEnums.CLAIMANT; +import static uk.gov.hmcts.reform.civil.enums.finalorders.CostEnums.STANDARD_BASIS; +import static uk.gov.hmcts.reform.civil.enums.finalorders.CostEnums.SUBJECT_DETAILED_ASSESSMENT; import static uk.gov.hmcts.reform.civil.enums.finalorders.FinalOrderRepresentationList.CLAIMANT_AND_DEFENDANT; import static uk.gov.hmcts.reform.civil.model.common.DynamicList.fromList; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element; @@ -128,7 +132,8 @@ private CallbackResponse nullPreviousSelections(CallbackParams callbackParams) { caseDataBuilder .freeFormRecordedTextArea(null) .freeFormOrderedTextArea(null) - .orderOnCourtsList(null); + .orderOnCourtsList(null) + .freeFormHearingNotes(null); // Assisted orders caseDataBuilder .finalOrderMadeSelection(null).finalOrderDateHeardComplex(null) @@ -178,7 +183,7 @@ private CallbackResponse validateFormAndGeneratePreviewDocument(CallbackParams c CaseDocument finalDocument = judgeFinalOrderGenerator.generate( caseData, callbackParams.getParams().get(BEARER_TOKEN).toString()); - caseDataBuilder.finalOrderDocument(finalDocument.getDocumentLink()); + caseDataBuilder.finalOrderDocument(finalDocument); return AboutToStartOrSubmitCallbackResponse.builder() .data(caseDataBuilder.build().toMap(objectMapper)) @@ -288,6 +293,10 @@ private DynamicList populateCurrentHearingLocation(CaseData caseData, String aut .assistedOrderCostsFirstDropdownDate(advancedDate) .assistedOrderAssessmentThirdDropdownDate(advancedDate) .makeAnOrderForCostsYesOrNo(YesOrNo.NO) + .makeAnOrderForCostsList(CLAIMANT) + .assistedOrderClaimantDefendantFirstDropdown(SUBJECT_DETAILED_ASSESSMENT) + .assistedOrderAssessmentSecondDropdownList1(STANDARD_BASIS) + .assistedOrderAssessmentSecondDropdownList2(CostEnums.NO) .build()) .publicFundingCostsProtection(YesOrNo.NO) .finalOrderAppealComplex(FinalOrderAppeal.builder() @@ -367,6 +376,14 @@ private void checkFieldDate(CaseData caseData, List errors) { .map(DatesFinalOrders::getDatesToAvoidDates).orElse(null), "Further hearing", NOT_ALLOWED_DATE_PAST, errors, true); + if (nonNull(caseData.getFinalOrderFurtherHearingComplex())) { + if (nonNull(caseData.getFinalOrderFurtherHearingComplex().getDateToDate()) + && caseData.getFinalOrderFurtherHearingComplex().getDateToDate() + .isBefore(caseData.getFinalOrderFurtherHearingComplex().getListFromDate())) { + errors.add(String.format(NOT_ALLOWED_DATE_RANGE, "Further hearing")); + } + } + validateDate(Optional.ofNullable(caseData.getAssistedOrderMakeAnOrderForCosts()) .map(AssistedOrderCostDetails::getAssistedOrderCostsFirstDropdownDate).orElse(null), "Make an order for detailed/summary costs", NOT_ALLOWED_DATE_PAST, errors, true); @@ -404,8 +421,7 @@ private void checkFieldDate(CaseData caseData, List errors) { private CallbackResponse addGeneratedDocumentToCollection(CallbackParams callbackParams) { CaseData caseData = callbackParams.getCaseData(); - CaseDocument finalDocument = judgeFinalOrderGenerator.generate( - caseData, callbackParams.getParams().get(BEARER_TOKEN).toString()); + CaseDocument finalDocument = caseData.getFinalOrderDocument(); List> finalCaseDocuments = new ArrayList<>(); finalCaseDocuments.add(element(finalDocument)); @@ -426,12 +442,22 @@ private CallbackResponse addGeneratedDocumentToCollection(CallbackParams callbac state = CASE_PROGRESSION; } - if (caseData.getFinalOrderFurtherHearingComplex() != null - && caseData.getFinalOrderFurtherHearingComplex().getHearingNotesText() != null) { - caseDataBuilder.hearingNotes(HearingNotes.builder() - .date(LocalDate.now()) - .notes(caseData.getFinalOrderFurtherHearingComplex().getHearingNotesText()) - .build()); + // populate hearing notes in listing tab with hearing notes from either assisted or freeform order, if either exist. + if (caseData.getFinalOrderSelection().equals(ASSISTED_ORDER)) { + if (caseData.getFinalOrderFurtherHearingComplex() != null + && caseData.getFinalOrderFurtherHearingComplex().getHearingNotesText() != null) { + caseDataBuilder.hearingNotes(HearingNotes.builder() + .date(LocalDate.now()) + .notes(caseData.getFinalOrderFurtherHearingComplex().getHearingNotesText()) + .build()); + } + } else { + if (nonNull(caseData.getFreeFormHearingNotes())) { + caseDataBuilder.hearingNotes(HearingNotes.builder() + .date(LocalDate.now()) + .notes(caseData.getFreeFormHearingNotes()) + .build()); + } } return AboutToStartOrSubmitCallbackResponse.builder() diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/HearingScheduledHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/HearingScheduledHandler.java index 08861a88924..f378b489e01 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/HearingScheduledHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/HearingScheduledHandler.java @@ -131,6 +131,7 @@ private DynamicList getLocationsFromList(final List locations) return fromList(locations.stream().map(location -> new StringBuilder().append(location.getSiteName()) .append(" - ").append(location.getCourtAddress()) .append(" - ").append(location.getPostcode()).toString()) + .sorted() .collect(Collectors.toList())); } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandler.java index 9183d1089c3..1ce5e75b370 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandler.java @@ -6,37 +6,75 @@ import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse; +import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse; import uk.gov.hmcts.reform.civil.callback.Callback; import uk.gov.hmcts.reform.civil.callback.CallbackException; import uk.gov.hmcts.reform.civil.callback.CallbackHandler; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; +import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.LitigationFriend; +import uk.gov.hmcts.reform.civil.model.Party; import uk.gov.hmcts.reform.civil.model.UpdateDetailsForm; +import uk.gov.hmcts.reform.civil.model.UpdatePartyDetailsForm; import uk.gov.hmcts.reform.civil.model.common.DynamicList; import uk.gov.hmcts.reform.civil.model.common.DynamicListElement; +import uk.gov.hmcts.reform.civil.model.common.Element; +import uk.gov.hmcts.reform.civil.model.dq.Expert; +import uk.gov.hmcts.reform.civil.model.dq.Witness; import uk.gov.hmcts.reform.civil.service.CoreCaseUserService; import uk.gov.hmcts.reform.civil.service.UserService; +import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser; +import uk.gov.hmcts.reform.civil.validation.PostcodeValidator; import uk.gov.hmcts.reform.idam.client.models.UserInfo; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; - +import static java.lang.String.format; +import static java.util.Optional.ofNullable; import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; +import static uk.gov.hmcts.reform.civil.callback.CallbackType.MID; import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.MANAGE_CONTACT_INFORMATION; +import static uk.gov.hmcts.reform.civil.enums.CaseCategory.SPEC_CLAIM; import static uk.gov.hmcts.reform.civil.enums.CaseState.AWAITING_APPLICANT_INTENTION; import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.ONE_V_TWO_TWO_LEGAL_REP; import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.getMultiPartyScenario; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.addApplicantExpertAndWitnessFlagsStructure; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.addRespondentDQPartiesFlagStructure; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_EXPERTS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_WITNESSES_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_EXPERTS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_WITNESSES_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_EXPERTS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_WITNESSES_ID; import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.addApplicant1Options; import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.addApplicantOptions2v1; import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.addDefendant1Options; import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.addDefendant2Options; import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.addDefendantOptions1v2SameSolicitor; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.appendUserAndType; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.mapExpertsToUpdatePartyDetailsForm; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.mapUpdatePartyDetailsFormToDQExperts; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.mapUpdatePartyDetailsFormToDQWitnesses; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.mapWitnessesToUpdatePartyDetailsForm; import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isApplicantSolicitor; import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isRespondentSolicitorOne; import static uk.gov.hmcts.reform.civil.utils.UserRoleUtils.isRespondentSolicitorTwo; @@ -47,6 +85,9 @@ public class ManageContactInformationCallbackHandler extends CallbackHandler { private static final String INVALID_CASE_STATE_ERROR = "You will be able run the manage contact information " + "event once the claimant has responded."; + private static final String CHECK_LITIGATION_FRIEND_ERROR_TITLE = "Check the litigation friend's details"; + private static final String CHECK_LITIGATION_FRIEND_ERROR = "After making these changes, please ensure that the " + + "litigation friend's contact information is also up to date."; private static final List ADMIN_ROLES = List.of( "caseworker-civil-admin"); private static final List EVENTS = List.of( @@ -56,13 +97,18 @@ public class ManageContactInformationCallbackHandler extends CallbackHandler { private final CoreCaseUserService coreCaseUserService; private final UserService userService; private final ObjectMapper objectMapper; + private final CaseDetailsConverter caseDetailsConverter; + private final CaseFlagsInitialiser caseFlagsInitialiser; + private final PostcodeValidator postcodeValidator; @Override protected Map callbacks() { return new ImmutableMap.Builder() - .put(callbackKey(ABOUT_TO_START), this::validateUserCanTriggerEvent) - .put(callbackKey(ABOUT_TO_SUBMIT), this::emptyCallbackResponse) - .put(callbackKey(SUBMITTED), this::emptyCallbackResponse) + .put(callbackKey(ABOUT_TO_START), this::prepareEvent) + .put(callbackKey(MID, "show-party-field"), this::showPartyField) + .put(callbackKey(MID, "show-warning"), this::showWarning) + .put(callbackKey(ABOUT_TO_SUBMIT), this::submitChanges) + .put(callbackKey(SUBMITTED), this::buildConfirmation) .build(); } @@ -71,7 +117,8 @@ public List handledEvents() { return EVENTS; } - private CallbackResponse validateUserCanTriggerEvent(CallbackParams callbackParams) { + private CallbackResponse prepareEvent(CallbackParams callbackParams) { + //TODO: 1v2DS/SS -> LR to show LR org 1/2 dependning on MP CaseData caseData = callbackParams.getCaseData(); String authToken = callbackParams.getParams().get(BEARER_TOKEN).toString(); @@ -146,6 +193,279 @@ private CallbackResponse validateUserCanTriggerEvent(CallbackParams callbackPara .build(); } + private List> prepareExperts(String partyId, CaseData caseData) { + if (partyId.equals(CLAIMANT_ONE_EXPERTS_ID)) { + return mapExpertsToUpdatePartyDetailsForm(caseData.getApplicant1DQ().getExperts().getDetails()); + } else if (partyId.equals(DEFENDANT_ONE_EXPERTS_ID)) { + return mapExpertsToUpdatePartyDetailsForm(caseData.getRespondent1DQ().getExperts().getDetails()); + } else if (partyId.equals(DEFENDANT_TWO_EXPERTS_ID)) { + return mapExpertsToUpdatePartyDetailsForm(caseData.getRespondent2DQ().getExperts().getDetails()); + } + return Collections.emptyList(); + } + + private List> prepareWitnesses(String partyId, CaseData caseData) { + if (partyId.equals(CLAIMANT_ONE_WITNESSES_ID)) { + return mapWitnessesToUpdatePartyDetailsForm(caseData.getApplicant1DQ().getWitnesses().getDetails()); + } else if (partyId.equals(DEFENDANT_ONE_WITNESSES_ID)) { + return mapWitnessesToUpdatePartyDetailsForm(caseData.getRespondent1DQ().getWitnesses().getDetails()); + } else if (partyId.equals(DEFENDANT_TWO_WITNESSES_ID)) { + return mapWitnessesToUpdatePartyDetailsForm(caseData.getRespondent2DQ().getWitnesses().getDetails()); + } + return Collections.emptyList(); + } + + private String getPostCode(String partyChosen, CaseData caseData) { + switch (partyChosen) { + case CLAIMANT_ONE_ID: { + return getPartyPostCode(caseData.getApplicant1()); + } + case CLAIMANT_TWO_ID: { + return getPartyPostCode(caseData.getApplicant2()); + } + case DEFENDANT_ONE_ID: { + return getPartyPostCode(caseData.getRespondent1()); + } + case DEFENDANT_TWO_ID: { + return getPartyPostCode(caseData.getRespondent2()); + } + case CLAIMANT_ONE_LITIGATION_FRIEND_ID: { + return getPartyPostCode(caseData.getApplicant1LitigationFriend()); + } + case CLAIMANT_TWO_LITIGATION_FRIEND_ID: { + return getPartyPostCode(caseData.getApplicant2LitigationFriend()); + } + case DEFENDANT_ONE_LITIGATION_FRIEND_ID: { + return getPartyPostCode(caseData.getRespondent1LitigationFriend()); + } + case DEFENDANT_TWO_LITIGATION_FRIEND_ID: { + return getPartyPostCode(caseData.getRespondent2LitigationFriend()); + } + default: { + return null; + } + } + } + + private String getPartyPostCode(Party party) { + return party.getPrimaryAddress().getPostCode(); + } + + private String getPartyPostCode(LitigationFriend party) { + return party.getPrimaryAddress().getPostCode(); + } + + private CallbackResponse showWarning(CallbackParams callbackParams) { + CaseData caseData = callbackParams.getCaseData(); + CaseData.CaseDataBuilder caseDataBuilder = caseData.toBuilder(); + String partyChosen = caseData.getUpdateDetailsForm().getPartyChosen().getValue().getCode(); + ArrayList warnings = new ArrayList<>(); + List errors = new ArrayList<>(); + + if (partyHasLitigationFriend(partyChosen, caseData)) { + warnings.add(CHECK_LITIGATION_FRIEND_ERROR_TITLE); + warnings.add(CHECK_LITIGATION_FRIEND_ERROR); + } + + if (SPEC_CLAIM.equals(caseData.getCaseAccessCategory())) { + errors = postcodeValidator.validate(getPostCode(partyChosen, caseData)); + } + + return AboutToStartOrSubmitCallbackResponse.builder() + .data(caseDataBuilder.build().toMap(objectMapper)) + .warnings(warnings) + .errors(errors) + .build(); + } + + private Boolean partyHasLitigationFriend(String partyChosen, CaseData caseData) { + if (hasLitigationFriend(CLAIMANT_ONE_ID, partyChosen, caseData.getApplicant1LitigationFriendRequired()) + || hasLitigationFriend(CLAIMANT_TWO_ID, partyChosen, caseData.getApplicant2LitigationFriendRequired()) + || hasLitigationFriend(DEFENDANT_ONE_ID, partyChosen, caseData.getRespondent1LitigationFriend()) + || hasLitigationFriend(DEFENDANT_TWO_ID, partyChosen, caseData.getRespondent2LitigationFriend()) + ) { + return true; + } + return false; + } + + private Boolean hasLitigationFriend(String id, String partyChosen, YesOrNo litigationFriend) { + return id.equals(partyChosen) && YES.equals(litigationFriend); + } + + private Boolean hasLitigationFriend(String id, String partyChosen, LitigationFriend litigationFriend) { + return id.equals(partyChosen) && litigationFriend != null; + } + + private CallbackResponse showPartyField(CallbackParams callbackParams) { + CaseData caseData = callbackParams.getCaseData(); + CaseData.CaseDataBuilder builder = caseData.toBuilder(); + + String partyChosen = caseData.getUpdateDetailsForm().getPartyChosen().getValue().getCode(); + String partyChosenType = null; + + if (isParty(partyChosen) || isLitigationFriend(partyChosen)) { + // Party fields are empty in this mid event, this is a workaround + CaseData oldCaseData = caseDetailsConverter.toCaseData(callbackParams.getRequest().getCaseDetailsBefore()); + String authToken = callbackParams.getParams().get(BEARER_TOKEN).toString(); + boolean isAdmin = isAdmin(authToken); + partyChosenType = appendUserAndType(partyChosen, oldCaseData, isAdmin); + } + + UpdateDetailsForm.UpdateDetailsFormBuilder formBuilder = caseData.getUpdateDetailsForm().toBuilder() + .partyChosenId(partyChosen) + .partyChosenType(partyChosenType) + .updateExpertsDetailsForm(prepareExperts(partyChosen, caseData)) + .updateWitnessesDetailsForm(prepareWitnesses(partyChosen, caseData)) + .build().toBuilder(); + + builder.updateDetailsForm(formBuilder.build()); + + return AboutToStartOrSubmitCallbackResponse.builder() + .data(builder.build().toMap(objectMapper)) + .build(); + } + + private Boolean isParty(String partyChosen) { + return CLAIMANT_ONE_ID.equals(partyChosen) + || CLAIMANT_TWO_ID.equals(partyChosen) + || DEFENDANT_ONE_ID.equals(partyChosen) + || DEFENDANT_TWO_ID.equals(partyChosen); + } + + private Boolean isLitigationFriend(String partyChosen) { + return CLAIMANT_ONE_LITIGATION_FRIEND_ID.equals(partyChosen) + || CLAIMANT_TWO_LITIGATION_FRIEND_ID.equals(partyChosen) + || DEFENDANT_ONE_LITIGATION_FRIEND_ID.equals(partyChosen) + || DEFENDANT_TWO_LITIGATION_FRIEND_ID.equals(partyChosen); + } + + private CallbackResponse submitChanges(CallbackParams callbackParams) { + CaseData caseData = callbackParams.getCaseData(); + CaseData.CaseDataBuilder builder = caseData.toBuilder(); + + updateExperts(caseData.getUpdateDetailsForm().getPartyChosenId(), caseData, builder); + updateWitnesses(caseData.getUpdateDetailsForm().getPartyChosenId(), caseData, builder); + + // last step before clearing update details form + caseFlagsInitialiser.initialiseCaseFlags(MANAGE_CONTACT_INFORMATION, builder); + + // clear updateDetailsForm + builder.updateDetailsForm(UpdateDetailsForm.builder().manageContactDetailsEventUsed(YES).build()); + + // update claim details tab + updateClaimDetailsTab(caseData, builder); + + return AboutToStartOrSubmitCallbackResponse.builder() + .data(builder.build().toMap(objectMapper)) + .build(); + } + + private void updateClaimDetailsTab(CaseData caseData, CaseData.CaseDataBuilder builder) { + builder.respondent1DetailsForClaimDetailsTab(caseData.getRespondent1().toBuilder().flags(null).build()); + + if (ofNullable(caseData.getRespondent2()).isPresent()) { + builder.respondent2DetailsForClaimDetailsTab(caseData.getRespondent2().toBuilder().flags(null).build()); + } + } + + // wip can't be tested yet because need to get ids from new ticket: CIV-10382 + // have to delete experts (yes/no etc) if the experts are removed, same as witnesses + + private void updateExperts(String partyId, CaseData caseData, CaseData.CaseDataBuilder builder) { + List> formData = caseData.getUpdateDetailsForm().getUpdateExpertsDetailsForm(); + List> mappedExperts; + + if (partyId.equals(CLAIMANT_ONE_EXPERTS_ID)) { + mappedExperts = mapUpdatePartyDetailsFormToDQExperts( + caseData.getApplicant1DQ().getApplicant1DQExperts().getDetails(), formData); + builder.applicant1DQ(caseData.getApplicant1DQ().toBuilder() + .applicant1DQExperts( + caseData.getApplicant1DQ().getApplicant1DQExperts().toBuilder() + .expertRequired(mappedExperts.size() >= 1 ? YES : NO) + .details(mappedExperts) + .build()) + .build()); + addApplicantExpertAndWitnessFlagsStructure(builder, caseData); + //TODO: need to add it to top level party object + } else if (partyId.equals(DEFENDANT_ONE_EXPERTS_ID)) { + mappedExperts = mapUpdatePartyDetailsFormToDQExperts( + caseData.getRespondent1DQ().getRespondent1DQExperts().getDetails(), formData); + builder.respondent1DQ(caseData.getRespondent1DQ().toBuilder() + .respondent1DQExperts( + caseData.getRespondent1DQ().getRespondent1DQExperts().toBuilder() + .expertRequired(mappedExperts.size() >= 1 ? YES : NO) + .details(mappedExperts) + .build()) + .build()); + addRespondentDQPartiesFlagStructure(builder, caseData); + //TODO: need to add it to top level party object + } else if (partyId.equals(DEFENDANT_TWO_EXPERTS_ID)) { + mappedExperts = mapUpdatePartyDetailsFormToDQExperts( + caseData.getRespondent2DQ().getRespondent2DQExperts().getDetails(), formData); + builder.respondent2DQ(caseData.getRespondent2DQ().toBuilder() + .respondent2DQExperts( + caseData.getRespondent2DQ().getRespondent2DQExperts().toBuilder() + .expertRequired(mappedExperts.size() >= 1 ? YES : NO) + .details(mappedExperts) + .build()) + .build()); + addRespondentDQPartiesFlagStructure(builder, caseData); + //TODO: need to add it to top level party object + } + + } + + private void updateWitnesses(String partyId, CaseData caseData, CaseData.CaseDataBuilder builder) { + List> formData = caseData.getUpdateDetailsForm().getUpdateWitnessesDetailsForm(); + List> mappedWitnesses; + + if (partyId.equals(CLAIMANT_ONE_WITNESSES_ID)) { + mappedWitnesses = mapUpdatePartyDetailsFormToDQWitnesses( + caseData.getApplicant1DQ().getApplicant1DQWitnesses().getDetails(), formData); + builder.applicant1DQ(caseData.getApplicant1DQ().toBuilder() + .applicant1DQWitnesses( + caseData.getApplicant1DQ().getApplicant1DQWitnesses().toBuilder() + .witnessesToAppear(mappedWitnesses.size() >= 1 ? YES : NO) + .details(mappedWitnesses) + .build()) + .build()); + addApplicantExpertAndWitnessFlagsStructure(builder, caseData); + //TODO: need to add it to top level party object + } else if (partyId.equals(DEFENDANT_ONE_WITNESSES_ID)) { + mappedWitnesses = mapUpdatePartyDetailsFormToDQWitnesses( + caseData.getRespondent1DQ().getRespondent1DQWitnesses().getDetails(), formData); + builder.respondent1DQ(caseData.getRespondent1DQ().toBuilder() + .respondent1DQWitnesses( + caseData.getRespondent1DQ().getRespondent1DQWitnesses().toBuilder() + .witnessesToAppear(mappedWitnesses.size() >= 1 ? YES : NO) + .details(mappedWitnesses) + .build()) + .build()); + addRespondentDQPartiesFlagStructure(builder, caseData); + //TODO: need to add it to top level party object + } else if (partyId.equals(DEFENDANT_TWO_WITNESSES_ID)) { + mappedWitnesses = mapUpdatePartyDetailsFormToDQWitnesses( + caseData.getRespondent2DQ().getRespondent2DQWitnesses().getDetails(), formData); + builder.respondent2DQ(caseData.getRespondent2DQ().toBuilder() + .respondent2DQWitnesses( + caseData.getRespondent2DQ().getRespondent2DQWitnesses().toBuilder() + .witnessesToAppear(mappedWitnesses.size() >= 1 ? YES : NO) + .details(mappedWitnesses) + .build()) + .build()); + addRespondentDQPartiesFlagStructure(builder, caseData); + //TODO: need to add it to top level party object + } + } + + private SubmittedCallbackResponse buildConfirmation(CallbackParams callbackParams) { + return SubmittedCallbackResponse.builder() + .confirmationHeader(format("# Contact information changed")) + .confirmationBody(format("### What happens next\nAny changes made to contact details have been updated in the Claim Details tab.")) + .build(); + } + private boolean isAwaitingClaimantIntention(CaseData caseData) { return caseData.getCcdState().equals(AWAITING_APPLICANT_INTENTION); } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestJudgementByAdmissionForSpecCuiCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestJudgementByAdmissionForSpecCuiCallbackHandler.java index 911aebf4220..aebd58fee07 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestJudgementByAdmissionForSpecCuiCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestJudgementByAdmissionForSpecCuiCallbackHandler.java @@ -64,7 +64,7 @@ private CallbackResponse validateDefaultJudgementEligibility(CallbackParams call CaseData.CaseDataBuilder caseDataBuilder = caseData.toBuilder(); ArrayList errors = new ArrayList<>(); if (caseData.isJudgementDateNotPermitted()) { - errors.add(format(NOT_VALID_DJ_BY_ADMISSION, caseData.setUpJudgementFormattedPermittedDate())); + errors.add(format(NOT_VALID_DJ_BY_ADMISSION, caseData.setUpJudgementFormattedPermittedDate(caseData.getRespondToClaimAdmitPartLRspec().getWhenWillThisAmountBePaid()))); } return AboutToStartOrSubmitCallbackResponse.builder() diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandler.java index 691bf0b241a..df862ffbf82 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandler.java @@ -20,6 +20,7 @@ import uk.gov.hmcts.reform.civil.enums.DocCategory; import uk.gov.hmcts.reform.civil.enums.MultiPartyResponseTypeFlags; import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; +import uk.gov.hmcts.reform.civil.enums.RespondentResponsePartAdmissionPaymentTimeLRspec; import uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec; import uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpecPaidStatus; import uk.gov.hmcts.reform.civil.enums.TimelineUploadTypeSpec; @@ -55,6 +56,7 @@ import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.service.Time; import uk.gov.hmcts.reform.civil.service.UserService; +import uk.gov.hmcts.reform.civil.service.citizenui.responsedeadline.DeadlineExtensionCalculatorService; import uk.gov.hmcts.reform.civil.service.flowstate.StateFlowEngine; import uk.gov.hmcts.reform.civil.utils.AssignCategoryId; import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser; @@ -164,6 +166,7 @@ public class RespondToClaimSpecCallbackHandler extends CallbackHandler private final CourtLocationUtils courtLocationUtils; private final CaseFlagsInitialiser caseFlagsInitialiser; private final AssignCategoryId assignCategoryId; + private final DeadlineExtensionCalculatorService deadlineCalculatorService; @Override public List handledEvents() { @@ -181,7 +184,7 @@ protected Map callbacks() { .put(callbackKey(MID, "upload"), this::emptyCallbackResponse) .put(callbackKey(MID, "statement-of-truth"), this::resetStatementOfTruth) .put(callbackKey(MID, "validate-payment-date"), this::validateRespondentPaymentDate) - .put(callbackKey(MID, "specCorrespondenceAddress"), this::validateCorrespondenceApplicantAddress) + .put(callbackKey(MID, "specCorrespondenceAddress"), this::validateCorrespondenceAddress) .put(callbackKey(MID, "determineLoggedInSolicitor"), this::determineLoggedInSolicitor) .put(callbackKey(MID, "track"), this::handleDefendAllClaim) .put(callbackKey(MID, "specHandleResponseType"), this::handleRespondentResponseTypeForSpec) @@ -1057,12 +1060,26 @@ private AllocatedTrack getAllocatedTrack(CaseData caseData) { ); } - private CallbackResponse validateCorrespondenceApplicantAddress(CallbackParams callbackParams) { - if (SpecJourneyConstantLRSpec.DEFENDANT_RESPONSE_SPEC.equals(callbackParams.getRequest().getEventId())) { - return validateCorrespondenceApplicantAddress(callbackParams, postcodeValidator); + private CallbackResponse validateCorrespondenceAddress(CallbackParams callbackParams) { + CaseData caseData = callbackParams.getCaseData(); + if (caseData.getIsRespondent1() == YES + && caseData.getRespondentSolicitor1ServiceAddressRequired() == NO) { + List errors = postcodeValidator.validate( + caseData.getRespondentSolicitor1ServiceAddress().getPostCode()); + + return AboutToStartOrSubmitCallbackResponse.builder() + .errors(errors) + .build(); + } else if (caseData.getIsRespondent2() == YES + && caseData.getRespondentSolicitor2ServiceAddressRequired() == NO) { + List errors = postcodeValidator.validate( + caseData.getRespondentSolicitor2ServiceAddress().getPostCode()); + + return AboutToStartOrSubmitCallbackResponse.builder() + .errors(errors) + .build(); } - return AboutToStartOrSubmitCallbackResponse.builder() - .build(); + return AboutToStartOrSubmitCallbackResponse.builder().build(); } private CallbackResponse determineLoggedInSolicitor(CallbackParams callbackParams) { @@ -1115,6 +1132,10 @@ private CallbackResponse populateRespondent1Copy(CallbackParams callbackParams) .respondent1Copy(caseData.getRespondent1()) .respondent1ClaimResponseTestForSpec(caseData.getRespondent1ClaimResponseTypeForSpec()) .respondent2ClaimResponseTestForSpec(caseData.getRespondent2ClaimResponseTypeForSpec()) + .respondentSolicitor1ServiceAddress(Address.builder().build()) + .respondentSolicitor2ServiceAddress(Address.builder().build()) + .respondentSolicitor1ServiceAddressRequired(null) + .respondentSolicitor2ServiceAddressRequired(null) .showConditionFlags(initialShowTags); updatedCaseData.respondent1DetailsForClaimDetailsTab(caseData.getRespondent1().toBuilder().flags(null).build()); @@ -1262,9 +1283,9 @@ private CallbackResponse validateUnavailableDates(CallbackParams callbackParams) } private CallbackResponse validateDateOfBirth(CallbackParams callbackParams) { - Party respondent = callbackParams.getCaseData().getRespondent1(); - if (respondent == null && callbackParams.getCaseData().getRespondent2() != null) { - respondent = callbackParams.getCaseData().getRespondent2(); + Party respondent = callbackParams.getCaseData().getRespondent1Copy(); + if (respondent == null && callbackParams.getCaseData().getRespondent2Copy() != null) { + respondent = callbackParams.getCaseData().getRespondent2Copy(); } List errors = dateOfBirthValidator.validate(respondent); @@ -1342,9 +1363,9 @@ private CallbackResponse setApplicantResponseDeadline(CallbackParams callbackPar AllocatedTrack allocatedTrack = caseData.getAllocatedTrack(); Party updatedRespondent1; - if (NO.equals(caseData.getSpecAoSApplicantCorrespondenceAddressRequired())) { + if (NO.equals(caseData.getTempCorrespondenceAddress1Required())) { updatedRespondent1 = caseData.getRespondent1().toBuilder() - .primaryAddress(caseData.getSpecAoSApplicantCorrespondenceAddressdetails()).build(); + .primaryAddress(caseData.getTempCorrespondenceAddress1()).build(); } else { updatedRespondent1 = caseData.getRespondent1().toBuilder() .primaryAddress(caseData.getRespondent1Copy().getPrimaryAddress()) @@ -1383,7 +1404,9 @@ && ofNullable(caseData.getRespondent2Copy()).isPresent()) { if (caseData.getDefenceAdmitPartPaymentTimeRouteRequired() != null && caseData.getDefenceAdmitPartPaymentTimeRouteRequired() == IMMEDIATELY && ifResponseTypeIsPartOrFullAdmission(caseData)) { - LocalDate whenBePaid = deadlinesCalculator.calculateWhenToBePaid(responseDate); + LocalDate whenBePaid = deadlineCalculatorService.calculateExtendedDeadline( + LocalDate.now(), + RespondentResponsePartAdmissionPaymentTimeLRspec.DAYS_TO_PAY_IMMEDIATELY); updatedData.respondToClaimAdmitPartLRspec(RespondToClaimAdmitPartLRspec.builder() .whenWillThisAmountBePaid(whenBePaid).build()); } @@ -1419,21 +1442,8 @@ && ifResponseTypeIsPartOrFullAdmission(caseData)) { .businessProcess(BusinessProcess.ready(DEFENDANT_RESPONSE_SPEC)); if (caseData.getRespondent2() != null && caseData.getRespondent2Copy() != null) { - Party updatedRespondent2; - - if (NO.equals(caseData.getSpecAoSRespondent2HomeAddressRequired())) { - updatedRespondent2 = caseData.getRespondent2().toBuilder() - .primaryAddress(caseData.getSpecAoSRespondent2HomeAddressDetails()).build(); - } else { - updatedRespondent2 = caseData.getRespondent2().toBuilder() - .primaryAddress(caseData.getRespondent2Copy().getPrimaryAddress()).build(); - } - - updatedData - .respondent2(updatedRespondent2.toBuilder() - .flags(caseData.getRespondent2Copy().getFlags()).build()) - .respondent2Copy(null); - updatedData.respondent2DetailsForClaimDetailsTab(updatedRespondent2.toBuilder().flags(null).build()); + Party updatedRespondent2 = applyRespondent2Address(caseData, updatedData); + updatedData.respondent2DetailsForClaimDetailsTab(updatedRespondent2); } // moving statement of truth value to correct field, this was not possible in mid event. @@ -1490,8 +1500,10 @@ && ifResponseTypeIsPartOrFullAdmission(caseData)) { .build()); } - UnavailabilityDatesUtils.rollUpUnavailabilityDatesForRespondent(updatedData, - toggleService.isUpdateContactDetailsEnabled()); + UnavailabilityDatesUtils.rollUpUnavailabilityDatesForRespondent( + updatedData, + toggleService.isUpdateContactDetailsEnabled() + ); updatedData.respondent1DetailsForClaimDetailsTab(updatedData.build().getRespondent1().toBuilder().flags(null).build()); if (ofNullable(caseData.getRespondent2()).isPresent()) { @@ -1563,6 +1575,21 @@ && isAwaitingAnotherDefendantResponse(caseData)) { .build(); } + private static Party applyRespondent2Address(CaseData caseData, CaseData.CaseDataBuilder updatedData) { + Party updatedRespondent2; + + if (NO.equals(caseData.getTempCorrespondenceAddress2Required())) { + updatedRespondent2 = caseData.getRespondent2().toBuilder() + .primaryAddress(caseData.getTempCorrespondenceAddress2()).build(); + } else { + updatedRespondent2 = caseData.getRespondent2().toBuilder() + .primaryAddress(caseData.getRespondent2Copy().getPrimaryAddress()).build(); + } + + updatedData.respondent2(updatedRespondent2).respondent2Copy(null); + return updatedRespondent2; + } + private boolean ifResponseTypeIsPartOrFullAdmission(CaseData caseData) { return (RespondentResponseTypeSpec.PART_ADMISSION.equals(caseData.getRespondent1ClaimResponseTypeForSpec()) || RespondentResponseTypeSpec.PART_ADMISSION.equals( @@ -1577,19 +1604,19 @@ private void updateCorrespondenceAddress(CallbackParams callbackParams, CaseData.CaseDataBuilder updatedCaseData, CaseData caseData) { if (solicitorHasCaseRole(callbackParams, RESPONDENTSOLICITORONE) - && caseData.getSpecAoSRespondentCorrespondenceAddressRequired() == YesOrNo.NO) { - Address newAddress = caseData.getSpecAoSRespondentCorrespondenceAddressdetails(); + && caseData.getRespondentSolicitor1ServiceAddressRequired() == YesOrNo.NO) { + Address newAddress = caseData.getRespondentSolicitor1ServiceAddress(); updatedCaseData.specRespondentCorrespondenceAddressdetails(newAddress) - .specAoSRespondentCorrespondenceAddressdetails(Address.builder().build()); + .respondentSolicitor1ServiceAddress(Address.builder().build()); if (getMultiPartyScenario(caseData) == ONE_V_TWO_ONE_LEGAL_REP) { // to keep with heading tab updatedCaseData.specRespondent2CorrespondenceAddressdetails(newAddress); } } else if (solicitorHasCaseRole(callbackParams, RESPONDENTSOLICITORTWO) - && caseData.getSpecAoSRespondent2CorrespondenceAddressRequired() == YesOrNo.NO) { + && caseData.getRespondentSolicitor2ServiceAddressRequired() == YesOrNo.NO) { updatedCaseData.specRespondent2CorrespondenceAddressdetails( - caseData.getSpecAoSRespondent2CorrespondenceAddressdetails()) - .specAoSRespondent2CorrespondenceAddressdetails(Address.builder().build()); + caseData.getRespondentSolicitor2ServiceAddress()) + .respondentSolicitor2ServiceAddress(Address.builder().build()); } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceCallbackHandler.java index add98412f45..7b1599b7eb8 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceCallbackHandler.java @@ -14,12 +14,10 @@ import uk.gov.hmcts.reform.civil.config.ToggleConfiguration; import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType; -import uk.gov.hmcts.reform.civil.enums.AllocatedTrack; import uk.gov.hmcts.reform.civil.enums.CaseCategory; import uk.gov.hmcts.reform.civil.enums.CaseState; import uk.gov.hmcts.reform.civil.enums.DocCategory; import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; -import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.helpers.LocationHelper; import uk.gov.hmcts.reform.civil.model.BusinessProcess; import uk.gov.hmcts.reform.civil.model.CaseData; @@ -36,6 +34,7 @@ import uk.gov.hmcts.reform.civil.service.Time; import uk.gov.hmcts.reform.civil.utils.AssignCategoryId; import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser; +import uk.gov.hmcts.reform.civil.utils.JudicialReferralUtils; import uk.gov.hmcts.reform.civil.utils.LocationRefDataUtil; import uk.gov.hmcts.reform.civil.utils.UnavailabilityDatesUtils; import uk.gov.hmcts.reform.civil.validation.UnavailableDateValidator; @@ -56,7 +55,6 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.MID; import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CLAIMANT_RESPONSE; -import static uk.gov.hmcts.reform.civil.enums.AllocatedTrack.getAllocatedTrack; import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.ONE_V_TWO_ONE_LEGAL_REP; import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.ONE_V_TWO_TWO_LEGAL_REP; import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.TWO_V_ONE; @@ -288,57 +286,12 @@ private CallbackResponse aboutToSubmit(CallbackParams callbackParams) { return AboutToStartOrSubmitCallbackResponse.builder() .data(builder.build().toMap(objectMapper)) - .state((shouldMoveToJudicialReferral(caseData) + .state((JudicialReferralUtils.shouldMoveToJudicialReferral(caseData) ? CaseState.JUDICIAL_REFERRAL : CaseState.PROCEEDS_IN_HERITAGE_SYSTEM).name()) .build(); } - /** - * Computes whether the case data should move to judicial referral or not. - * - * @param caseData a case data such that defendants rejected the claim, and claimant(s) wants to proceed - * vs all the defendants - * @return true if and only if the case should move to judicial referral - */ - public static boolean shouldMoveToJudicialReferral(CaseData caseData) { - CaseCategory caseCategory = caseData.getCaseAccessCategory(); - - if (CaseCategory.SPEC_CLAIM.equals(caseCategory)) { - MultiPartyScenario multiPartyScenario = getMultiPartyScenario(caseData); - boolean addRespondent2 = YES.equals(caseData.getAddRespondent2()); - - return switch (multiPartyScenario) { - case ONE_V_ONE -> caseData.getApplicant1ProceedWithClaim() == YesOrNo.YES; - case TWO_V_ONE -> caseData.getApplicant1ProceedWithClaimSpec2v1() == YesOrNo.YES; - case ONE_V_TWO_ONE_LEGAL_REP -> addRespondent2 - && YES.equals(caseData.getRespondentResponseIsSame()); - case ONE_V_TWO_TWO_LEGAL_REP -> addRespondent2 - && caseData.getRespondentResponseIsSame() == null; - }; - } else { - AllocatedTrack allocatedTrack = - getAllocatedTrack( - CaseCategory.UNSPEC_CLAIM.equals(caseCategory) - ? caseData.getClaimValue().toPounds() - : caseData.getTotalClaimAmount(), - caseData.getClaimType() - ); - if (AllocatedTrack.MULTI_CLAIM.equals(allocatedTrack)) { - return false; - } - MultiPartyScenario multiPartyScenario = getMultiPartyScenario(caseData); - return switch (multiPartyScenario) { - case ONE_V_ONE -> caseData.getApplicant1ProceedWithClaim() == YesOrNo.YES; - case TWO_V_ONE -> caseData.getApplicant1ProceedWithClaimMultiParty2v1() == YES - && caseData.getApplicant2ProceedWithClaimMultiParty2v1() == YES; - case ONE_V_TWO_ONE_LEGAL_REP, ONE_V_TWO_TWO_LEGAL_REP -> - caseData.getApplicant1ProceedWithClaimAgainstRespondent1MultiParty1v2() == YES - && caseData.getApplicant1ProceedWithClaimAgainstRespondent2MultiParty1v2() == YES; - }; - } - } - private void updateApplicants(CaseData caseData, CaseData.CaseDataBuilder builder, StatementOfTruth statementOfTruth) { if (caseData.getApplicant1DQ() != null && caseData.getApplicant1DQ().getApplicant1DQFileDirectionsQuestionnaire() != null) { diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandler.java index 121a605dc71..ecbac578256 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandler.java @@ -16,13 +16,13 @@ import uk.gov.hmcts.reform.civil.enums.AllocatedTrack; import uk.gov.hmcts.reform.civil.enums.CaseCategory; import uk.gov.hmcts.reform.civil.enums.CaseState; +import uk.gov.hmcts.reform.civil.enums.RespondentResponsePartAdmissionPaymentTimeLRspec; import uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec; import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.handler.callback.user.spec.CaseDataToTextGenerator; import uk.gov.hmcts.reform.civil.handler.callback.user.spec.RespondToResponseConfirmationHeaderGenerator; import uk.gov.hmcts.reform.civil.handler.callback.user.spec.RespondToResponseConfirmationTextGenerator; import uk.gov.hmcts.reform.civil.handler.callback.user.spec.show.DefendantResponseShowTag; -import uk.gov.hmcts.reform.civil.handler.callback.user.spec.show.ResponseOneVOneShowTag; import uk.gov.hmcts.reform.civil.helpers.LocationHelper; import uk.gov.hmcts.reform.civil.model.BusinessProcess; import uk.gov.hmcts.reform.civil.model.CaseData; @@ -41,8 +41,11 @@ import uk.gov.hmcts.reform.civil.service.PaymentDateService; import uk.gov.hmcts.reform.civil.service.Time; import uk.gov.hmcts.reform.civil.service.citizenui.RespondentMediationService; +import uk.gov.hmcts.reform.civil.service.citizenui.ResponseOneVOneShowTagService; +import uk.gov.hmcts.reform.civil.service.citizenui.responsedeadline.DeadlineExtensionCalculatorService; import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser; import uk.gov.hmcts.reform.civil.utils.CourtLocationUtils; +import uk.gov.hmcts.reform.civil.utils.JudicialReferralUtils; import uk.gov.hmcts.reform.civil.utils.MonetaryConversions; import uk.gov.hmcts.reform.civil.utils.UnavailabilityDatesUtils; import uk.gov.hmcts.reform.civil.validation.UnavailableDateValidator; @@ -71,7 +74,6 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackVersion.V_1; import static uk.gov.hmcts.reform.civil.callback.CallbackVersion.V_2; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CLAIMANT_RESPONSE_SPEC; -import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.ONE_V_ONE; import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.TWO_V_ONE; import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.getMultiPartyScenario; import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.isOneVOne; @@ -109,6 +111,8 @@ public class RespondToDefenceSpecCallbackHandler extends CallbackHandler private static final String datePattern = "dd MMMM yyyy"; private final RespondentMediationService respondentMediationService; private final PaymentDateService paymentDateService; + private final ResponseOneVOneShowTagService responseOneVOneShowTagService; + private final DeadlineExtensionCalculatorService deadlineCalculatorService; @Override public List handledEvents() { @@ -384,7 +388,7 @@ private void updateDQCourtLocations(CallbackParams callbackParams, CaseData case private void putCaseStateInJudicialReferral(CaseData caseData, AboutToStartOrSubmitCallbackResponse.AboutToStartOrSubmitCallbackResponseBuilder response) { if (caseData.isRespondentResponseFullDefence() - && RespondToDefenceCallbackHandler.shouldMoveToJudicialReferral(caseData)) { + && JudicialReferralUtils.shouldMoveToJudicialReferral(caseData)) { response.state(CaseState.JUDICIAL_REFERRAL.name()); } } @@ -415,7 +419,7 @@ private CallbackResponse populateCaseData(CallbackParams callbackParams) { if (isDefendantFullAdmitPayImmediately(caseData)) { LocalDate whenBePaid = paymentDateService.getPaymentDateAdmittedClaim(caseData); - updatedCaseData.showResponseOneVOneFlag(setUpOneVOneFlow(caseData)); + updatedCaseData.showResponseOneVOneFlag(responseOneVOneShowTagService.setUpOneVOneFlow(caseData)); updatedCaseData.whenToBePaidText(formatLocalDate(whenBePaid, DATE)); } @@ -431,7 +435,7 @@ private CallbackResponse populateCaseData(CallbackParams callbackParams) { ).build()); if (V_2.equals(callbackParams.getVersion()) && featureToggleService.isPinInPostEnabled()) { - updatedCaseData.showResponseOneVOneFlag(setUpOneVOneFlow(caseData)); + updatedCaseData.showResponseOneVOneFlag(responseOneVOneShowTagService.setUpOneVOneFlow(caseData)); updatedCaseData.respondent1PaymentDateToStringSpec(setUpPayDateToString(caseData)); Optional howMuchWasPaid = Optional.ofNullable(caseData.getRespondToAdmittedClaim()) @@ -553,27 +557,6 @@ private String getDefaultConfirmationHeader(CaseData caseData) { } } - private ResponseOneVOneShowTag setUpOneVOneFlow(CaseData caseData) { - if (ONE_V_ONE.equals(getMultiPartyScenario(caseData))) { - if (caseData.getRespondent1ClaimResponseTypeForSpec() == null) { - return null; - } - switch (caseData.getRespondent1ClaimResponseTypeForSpec()) { - case FULL_DEFENCE: - return ResponseOneVOneShowTag.ONE_V_ONE_FULL_DEFENCE; - case FULL_ADMISSION: - return setUpOneVOneFlowForFullAdmit(caseData); - case PART_ADMISSION: - return setUpOneVOneFlowForPartAdmit(caseData); - case COUNTER_CLAIM: - return ResponseOneVOneShowTag.ONE_V_ONE_COUNTER_CLAIM; - default: - return null; - } - } - return null; - } - private String setUpPayDateToString(CaseData caseData) { if (caseData.getRespondToClaimAdmitPartLRspec() != null && caseData.getRespondToClaimAdmitPartLRspec().getWhenWillThisAmountBePaid() != null) { @@ -586,44 +569,14 @@ private String setUpPayDateToString(CaseData caseData) { .format(DateTimeFormatter.ofPattern(datePattern, Locale.ENGLISH)); } if (caseData.getRespondent1ResponseDate() != null) { - return caseData.getRespondent1ResponseDate().plusDays(5) + return deadlineCalculatorService.calculateExtendedDeadline( + caseData.getRespondent1ResponseDate().toLocalDate(), + RespondentResponsePartAdmissionPaymentTimeLRspec.DAYS_TO_PAY_IMMEDIATELY) .format(DateTimeFormatter.ofPattern(datePattern, Locale.ENGLISH)); } return null; } - private ResponseOneVOneShowTag setUpOneVOneFlowForPartAdmit(CaseData caseData) { - if (YES.equals(caseData.getSpecDefenceAdmittedRequired())) { - return ResponseOneVOneShowTag.ONE_V_ONE_PART_ADMIT_HAS_PAID; - } - switch (caseData.getDefenceAdmitPartPaymentTimeRouteRequired()) { - case IMMEDIATELY: - return ResponseOneVOneShowTag.ONE_V_ONE_PART_ADMIT_PAY_IMMEDIATELY; - case BY_SET_DATE: - return ResponseOneVOneShowTag.ONE_V_ONE_PART_ADMIT_PAY_BY_SET_DATE; - case SUGGESTION_OF_REPAYMENT_PLAN: - return ResponseOneVOneShowTag.ONE_V_ONE_PART_ADMIT_PAY_INSTALMENT; - default: - return ResponseOneVOneShowTag.ONE_V_ONE_PART_ADMIT; - } - } - - private ResponseOneVOneShowTag setUpOneVOneFlowForFullAdmit(CaseData caseData) { - if (YES.equals(caseData.getSpecDefenceFullAdmittedRequired())) { - return ResponseOneVOneShowTag.ONE_V_ONE_FULL_ADMIT_HAS_PAID; - } - switch (caseData.getDefenceAdmitPartPaymentTimeRouteRequired()) { - case IMMEDIATELY: - return ResponseOneVOneShowTag.ONE_V_ONE_FULL_ADMIT_PAY_IMMEDIATELY; - case BY_SET_DATE: - return ResponseOneVOneShowTag.ONE_V_ONE_FULL_ADMIT_PAY_BY_SET_DATE; - case SUGGESTION_OF_REPAYMENT_PLAN: - return ResponseOneVOneShowTag.ONE_V_ONE_FULL_ADMIT_PAY_INSTALMENT; - default: - return ResponseOneVOneShowTag.ONE_V_ONE_FULL_ADMIT; - } - } - private CallbackResponse validatePaymentDate(CallbackParams callbackParams) { CaseData caseData = callbackParams.getCaseData(); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/StandardDirectionOrderDJ.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/StandardDirectionOrderDJ.java index e5202ab4def..70020cfb326 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/StandardDirectionOrderDJ.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/StandardDirectionOrderDJ.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; @@ -17,6 +18,7 @@ import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; import uk.gov.hmcts.reform.civil.enums.CaseCategory; import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.enums.dj.DisposalAndTrialHearingDJToggle; import uk.gov.hmcts.reform.civil.enums.dj.DisposalHearingMethodDJ; import uk.gov.hmcts.reform.civil.enums.sdo.DateToShowToggle; @@ -57,6 +59,7 @@ import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; import uk.gov.hmcts.reform.civil.service.CategoryService; import uk.gov.hmcts.reform.civil.service.DeadlinesCalculator; +import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.service.docmosis.dj.DefaultJudgmentOrderFormGenerator; import uk.gov.hmcts.reform.civil.utils.AssignCategoryId; import uk.gov.hmcts.reform.civil.utils.HearingMethodUtils; @@ -88,6 +91,7 @@ import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element; import static uk.gov.hmcts.reform.civil.utils.HearingUtils.getHearingNotes; +@Slf4j @Service @RequiredArgsConstructor public class StandardDirectionOrderDJ extends CallbackHandler { @@ -99,6 +103,7 @@ public class StandardDirectionOrderDJ extends CallbackHandler { private final ObjectMapper objectMapper; private final DefaultJudgmentOrderFormGenerator defaultJudgmentOrderFormGenerator; private final LocationRefDataService locationRefDataService; + private final FeatureToggleService featureToggleService; String participantString; public static final String DISPOSAL_HEARING = "DISPOSAL_HEARING"; public static final String ORDER_1_CLAI = "The directions order has been sent to: " @@ -628,9 +633,22 @@ private DynamicList getLocationList(CallbackParams callbackParams, ); Optional matchingLocation = Optional.ofNullable(preferredCourt) .flatMap(requestedCourt -> locationHelper.getMatching(locations, preferredCourt)); - return DynamicList.fromList(locations, LocationRefDataService::getDisplayEntry, - matchingLocation.orElse(null), true - ); + + DynamicList locationsList; + if (matchingLocation.isPresent()) { + locationsList = DynamicList.fromList(locations, this::getLocationEpimms, LocationRefDataService::getDisplayEntry, + matchingLocation.get(), true + ); + } else { + locationsList = DynamicList.fromList(locations, this::getLocationEpimms, LocationRefDataService::getDisplayEntry, + null, true + ); + } + return locationsList; + } + + private String getLocationEpimms(LocationRefData location) { + return location.getEpimmsId(); } private CallbackResponse generateSDONotifications(CallbackParams callbackParams) { @@ -643,7 +661,6 @@ private CallbackResponse generateSDONotifications(CallbackParams callbackParams) caseDataBuilder.orderSDODocumentDJ(null); assignCategoryId.assignCategoryIdToCollection(caseData.getOrderSDODocumentDJCollection(), document -> document.getValue().getDocumentLink(), "sdo"); caseDataBuilder.businessProcess(BusinessProcess.ready(STANDARD_DIRECTION_ORDER_DJ)); - var state = "CASE_PROGRESSION"; String authToken = callbackParams.getParams().get(BEARER_TOKEN).toString(); List locations = (locationRefDataService .getCourtLocationsForDefaultJudgments(authToken)); @@ -655,15 +672,35 @@ private CallbackResponse generateSDONotifications(CallbackParams callbackParams) .ifPresent(caseDataBuilder::locationName); } - + var state = "CASE_PROGRESSION"; caseDataBuilder.hearingNotes(getHearingNotes(caseData)); + if (featureToggleService.isEarlyAdoptersEnabled()) { + if (featureToggleService.isLocationWhiteListedForCaseProgression( + getEpimmsId(caseData))) { + log.info("Case {} is whitelisted for case progression.", caseData.getCcdCaseReference()); + caseDataBuilder.eaCourtLocation(YesOrNo.YES); + } else { + log.info("Case {} is NOT whitelisted for case progression.", caseData.getCcdCaseReference()); + caseDataBuilder.eaCourtLocation(YesOrNo.NO); + } + } + return AboutToStartOrSubmitCallbackResponse.builder() .data(caseDataBuilder.build().toMap(objectMapper)) .state(state) .build(); } + private String getEpimmsId(CaseData caseData) { + if (caseData.getTrialHearingMethodInPersonDJ() != null) { + return caseData.getTrialHearingMethodInPersonDJ().getValue().getCode(); + } else if (caseData.getDisposalHearingMethodInPersonDJ() != null) { + return caseData.getDisposalHearingMethodInPersonDJ().getValue().getCode(); + } + throw new IllegalArgumentException("Epimms Id is not provided"); + } + private SubmittedCallbackResponse buildConfirmation(CallbackParams callbackParams) { var caseData = callbackParams.getCaseData(); return SubmittedCallbackResponse.builder() diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/event/EvidenceUploadNotificationEventHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/event/EvidenceUploadNotificationEventHandler.java index ed52e4d8582..84adb0d19a8 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/event/EvidenceUploadNotificationEventHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/event/EvidenceUploadNotificationEventHandler.java @@ -4,7 +4,10 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Service; +import uk.gov.hmcts.reform.ccd.client.model.CaseDataContent; import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; +import uk.gov.hmcts.reform.ccd.client.model.Event; +import uk.gov.hmcts.reform.ccd.client.model.StartEventResponse; import uk.gov.hmcts.reform.civil.event.EvidenceUploadNotificationEvent; import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.CaseData; @@ -12,6 +15,10 @@ import uk.gov.hmcts.reform.civil.notification.EvidenceUploadRespondentNotificationHandler; import uk.gov.hmcts.reform.civil.service.CoreCaseDataService; +import java.util.Map; + +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.EVIDENCE_UPLOAD_CHECK; + @Slf4j @Service @RequiredArgsConstructor @@ -50,5 +57,19 @@ public void sendEvidenceUploadNotification(EvidenceUploadNotificationEvent event } catch (Exception e) { log.warn("Failed to send email notification to respondent solicitor2 for case '{}'", event.getCaseId()); } + // null notificationText so it cleared each day, for any future evidence uploads + StartEventResponse startEventResponse = coreCaseDataService.startUpdate(event.getCaseId().toString(), EVIDENCE_UPLOAD_CHECK); + CaseDataContent caseContent = getCaseContent(startEventResponse); + coreCaseDataService.submitUpdate(event.getCaseId().toString(), caseContent); + } + + private CaseDataContent getCaseContent(StartEventResponse startEventResponse) { + Map data = startEventResponse.getCaseDetails().getData(); + data.put("notificationText", "NULLED"); + return CaseDataContent.builder() + .eventToken(startEventResponse.getToken()) + .event(Event.builder().id(startEventResponse.getEventId()).build()) + .data(data) + .build(); } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/helpers/bundle/BundleRequestMapper.java b/src/main/java/uk/gov/hmcts/reform/civil/helpers/bundle/BundleRequestMapper.java index 549965f3176..8267d327903 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/helpers/bundle/BundleRequestMapper.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/helpers/bundle/BundleRequestMapper.java @@ -35,6 +35,7 @@ import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.TreeMap; @@ -43,6 +44,7 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; +import static uk.gov.hmcts.reform.civil.enums.CaseCategory.SPEC_CLAIM; import static uk.gov.hmcts.reform.civil.helpers.bundle.BundleFileNameHelper.getEvidenceUploadDocsByPartyAndDocType; import static uk.gov.hmcts.reform.civil.helpers.bundle.BundleFileNameHelper.getExpertDocsByPartyAndDocType; import static uk.gov.hmcts.reform.civil.helpers.bundle.BundleFileNameHelper.getWitnessDocsByPartyAndDocType; @@ -116,6 +118,32 @@ private BundlingCaseData mapCaseData(CaseData caseData, String bundleConfigFileN return bundlingCaseData; } + private List mapParticularsOfClaimDocs(CaseData caseData) { + List bundlingRequestDocuments = new ArrayList<>(); + if (Objects.nonNull(caseData.getServedDocumentFiles()) + && Objects.nonNull((caseData.getServedDocumentFiles().getParticularsOfClaimDocument()))) { + caseData.getServedDocumentFiles() + .getParticularsOfClaimDocument() + .forEach(poc -> bundlingRequestDocuments.add( + buildBundlingRequestDoc(getParticularsOfClaimName(caseData), + poc.getValue(), ""))); + } + return bundlingRequestDocuments; + } + + private String getParticularsOfClaimName(CaseData caseData) { + LocalDate pocDate; + if (SPEC_CLAIM.equals(caseData.getCaseAccessCategory())) { + pocDate = caseData.getIssueDate(); + } else if (Objects.nonNull(caseData.getClaimDetailsNotificationDate())) { + pocDate = caseData.getClaimDetailsNotificationDate().toLocalDate(); + } else { + pocDate = caseData.getSubmittedDate().toLocalDate(); + } + return generateDocName(BundleFileNameList.PARTICULARS_OF_CLAIM.getDisplayName(), + null, null, pocDate); + } + private List> mapJointStatementOfExperts(CaseData caseData) { List bundlingRequestDocuments = new ArrayList<>(); Arrays.stream(PartyType.values()).toList().forEach(partyType -> { @@ -503,9 +531,7 @@ private List> mapOrdersDocument(CaseData caseDa bundlingRequestDocuments.addAll(mapSystemGeneratedCaseDocument(caseData.getDirectionOrderDocStaff(), BundleFileNameList.ORDER.getDisplayName())); } - if (caseData.getFinalOrderDocument() != null) { - bundlingRequestDocuments.add(buildBundlingRequestDoc(caseData.getFinalOrderDocument().getDocumentFileName(), caseData.getFinalOrderDocument(), "")); - } + return ElementUtils.wrapElements(bundlingRequestDocuments); } @@ -518,6 +544,7 @@ private List> mapStatementOfcaseDocs(CaseData c && caseDocumentElement.getValue().getDocumentLink().getCategoryID().equals("detailsOfClaim")) .collect(Collectors.toList()), BundleFileNameList.CLAIM_FORM.getDisplayName())); + bundlingRequestDocuments.addAll(mapParticularsOfClaimDocs(caseData)); List> clAndDfDocList = caseData.getDefendantResponseDocuments(); clAndDfDocList.addAll(caseData.getClaimantResponseDocuments()); List> sortedDefendantDefenceAndClaimantReply = diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java b/src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java index c8b8a40bc85..953b02321d3 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java @@ -572,7 +572,9 @@ public boolean hasNoOngoingBusinessProcess() { //case progression private final List> documentAndName; + private final List> documentAndNameToAdd; private final List> documentAndNote; + private final List> documentAndNoteToAdd; private final CaseNoteType caseNoteType; private final String caseNoteTA; private final List> caseNotesTA; @@ -605,8 +607,10 @@ public boolean hasNoOngoingBusinessProcess() { private final FreeFormOrderValues orderOnCourtInitiative; private final FreeFormOrderValues orderWithoutNotice; private final OrderOnCourtsList orderOnCourtsList; + private final String freeFormHearingNotes; + + private CaseDocument finalOrderDocument; - private Document finalOrderDocument; @Builder.Default private final List> finalOrderDocumentCollection = new ArrayList<>(); @@ -870,16 +874,15 @@ && isApplicant1NotRepresented() @JsonIgnore public boolean isJudgementDateNotPermitted() { - return nonNull(getRespondent1ResponseDate()) - && getRespondent1ResponseDate() - .toLocalDate().plusDays(5).atTime(DeadlinesCalculator.END_OF_BUSINESS_DAY).isAfter(LocalDateTime.now()); + return nonNull(getRespondToClaimAdmitPartLRspec().getWhenWillThisAmountBePaid()) + && getRespondToClaimAdmitPartLRspec().getWhenWillThisAmountBePaid() + .atTime(DeadlinesCalculator.END_OF_BUSINESS_DAY).isAfter(LocalDateTime.now()); } @JsonIgnore - public String setUpJudgementFormattedPermittedDate() { + public String setUpJudgementFormattedPermittedDate(LocalDate extendedRespondent1ResponseDate) { if (isJudgementDateNotPermitted()) { - return formatLocalDateTime(getRespondent1ResponseDate() - .toLocalDate().plusDays(5).atTime(DeadlinesCalculator.END_OF_BUSINESS_DAY), DATE_TIME_AT); + return formatLocalDateTime(extendedRespondent1ResponseDate.atTime(DeadlinesCalculator.END_OF_BUSINESS_DAY), DATE_TIME_AT); } return null; } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/CaseDataParent.java b/src/main/java/uk/gov/hmcts/reform/civil/model/CaseDataParent.java index 4c06a057441..5db7728550f 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/CaseDataParent.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/CaseDataParent.java @@ -311,6 +311,8 @@ public class CaseDataParent implements MappableObject { private CaseDocument sdoOrderDocument; + private final YesOrNo eaCourtLocation; + // sdo ui flags private final YesOrNo setSmallClaimsFlag; private final YesOrNo setFastTrackFlag; @@ -441,6 +443,7 @@ public boolean isApplicantNotRepresented() { private final CertificateOfService cosNotifyClaimDefendant1; private final CertificateOfService cosNotifyClaimDefendant2; + private final String notificationText; private final List disclosureSelectionEvidence; private final List disclosureSelectionEvidenceRes; private final List witnessSelectionEvidence; @@ -531,9 +534,13 @@ public boolean isApplicantNotRepresented() { private final List> applicantWitnesses; private final List> respondent1Witnesses; private final List> respondent2Witnesses; - private final List> applicantSolOrgIndividuals; - private final List> respondent1SolOrgIndividuals; - private final List> applicant1SolOrgIndividuals; + private final List> applicant1LRIndividuals; + private final List> respondent1LRIndividuals; + private final List> respondent2LRIndividuals; + private final List> applicant1OrgIndividuals; + private final List> applicant2OrgIndividuals; + private final List> respondent1OrgIndividuals; + private final List> respondent2OrgIndividuals; private List disposalHearingDisclosureOfDocumentsDJToggle; private List disposalHearingWitnessOfFactDJToggle; @@ -716,6 +723,23 @@ public boolean isApplicantNotRepresented() { private FastTrackAllocation fastTrackAllocation; + /** + * used to temporary hold addresses. + */ + private final Address tempCorrespondenceAddress1; + /** + * used with tempCorrespondenceAddress1. + */ + private final YesOrNo tempCorrespondenceAddress1Required; + /** + * used to temporary hold addresses. + */ + private final Address tempCorrespondenceAddress2; + /** + * used with tempCorrespondenceAddress2. + */ + private final YesOrNo tempCorrespondenceAddress2Required; + @JsonIgnore public boolean isResponseAcceptedByClaimant() { return applicant1AcceptAdmitAmountPaidSpec == YesOrNo.YES diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/Party.java b/src/main/java/uk/gov/hmcts/reform/civil/model/Party.java index 48edc3146ae..32382122fad 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/Party.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/Party.java @@ -103,6 +103,11 @@ public boolean isOrganisation() { return ORGANISATION.equals(getType()); } + @JsonIgnore + public boolean isCompanyOROrganisation() { + return this.isCompany() || this.isOrganisation(); + } + @JsonIgnore public LocalDate getDateOfBirth() { return Optional.ofNullable(individualDateOfBirth).orElse(soleTraderDateOfBirth); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/UpdateDetailsForm.java b/src/main/java/uk/gov/hmcts/reform/civil/model/UpdateDetailsForm.java index 82f48651bb7..33b489f1fec 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/UpdateDetailsForm.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/UpdateDetailsForm.java @@ -1,6 +1,5 @@ package uk.gov.hmcts.reform.civil.model; -import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -11,17 +10,18 @@ import java.util.List; @Data -@Builder +@Builder(toBuilder = true) @NoArgsConstructor @AllArgsConstructor public class UpdateDetailsForm { - @JsonProperty("partyChosen") private DynamicList partyChosen; - - @JsonProperty("additionalUnavailableDates") - private List> additionalUnavailableDates; - - @JsonProperty("hidePartyChoice") + private String partyChosenId; + private String partyChosenType; private YesOrNo hidePartyChoice; + private List> additionalUnavailableDates; + private List> updateExpertsDetailsForm; + private List> updateWitnessesDetailsForm; + private YesOrNo manageContactDetailsEventUsed; } + diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/UpdatePartyDetailsForm.java b/src/main/java/uk/gov/hmcts/reform/civil/model/UpdatePartyDetailsForm.java new file mode 100644 index 00000000000..5955d276a92 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/UpdatePartyDetailsForm.java @@ -0,0 +1,16 @@ +package uk.gov.hmcts.reform.civil.model; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder(toBuilder = true) +public class UpdatePartyDetailsForm { + + private String firstName; + private String lastName; + private String phoneNumber; + private String emailAddress; + private String partyId; + private String fieldOfExpertise; +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/bundle/BundlingCaseData.java b/src/main/java/uk/gov/hmcts/reform/civil/model/bundle/BundlingCaseData.java index 80340c02507..f37439ded9c 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/bundle/BundlingCaseData.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/bundle/BundlingCaseData.java @@ -22,6 +22,8 @@ public class BundlingCaseData { private final List> trialDocuments; @JsonProperty("statementsOfCaseDocuments") private final List> statementsOfCaseDocuments; + @JsonProperty("particularsOfClaim") + private final List> particularsOfClaim; @JsonProperty("ordersDocuments") private final List> ordersDocuments; @JsonProperty("claimant1WitnessStatements") diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/citizenui/dto/ExtendedDeadlineDto.java b/src/main/java/uk/gov/hmcts/reform/civil/model/citizenui/dto/ExtendedDeadlineDto.java new file mode 100644 index 00000000000..58c4a1182de --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/citizenui/dto/ExtendedDeadlineDto.java @@ -0,0 +1,18 @@ +package uk.gov.hmcts.reform.civil.model.citizenui.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ExtendedDeadlineDto { + + private LocalDate responseDate; + private Integer plusDays; +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/common/DynamicList.java b/src/main/java/uk/gov/hmcts/reform/civil/model/common/DynamicList.java index 1fe3e01a3f6..075db0e94a5 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/common/DynamicList.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/common/DynamicList.java @@ -16,7 +16,7 @@ */ @Data @Jacksonized -@Builder +@Builder(toBuilder = true) public class DynamicList { /** @@ -39,18 +39,20 @@ public static DynamicList fromList(List list) { } /** - * Sometimes a dynamic list can be prepopulated with a value. + * A dynamic list can be pre-populated with a code and value. * * @param list the original list of items + * @param toCode (optional) how to populate the DynamicListElement code, defaults to random UUID * @param toLabel how to create the label * @param value (optional) value to be selected * @param type of element * @return dynamic list, possibly with value set */ - public static DynamicList fromList(List list, Function toLabel, T value, boolean sort) { + public static DynamicList fromList(List list, Function toCode, Function toLabel, T value, boolean sort) { List items = list.stream() - .map(toLabel) - .map(DynamicListElement::dynamicElement) + .map(item -> toCode != null + ? DynamicListElement.dynamicElementFromCode(toCode.apply(item), toLabel.apply(item)) + : DynamicListElement.dynamicElement(toLabel.apply(item))) .collect(toList()); int index = value != null ? list.indexOf(value) : -1; @@ -68,6 +70,19 @@ public static DynamicList fromList(List list, Function toLabel return DynamicList.builder().listItems(items).value(chosen).build(); } + /** + * Sometimes a dynamic list can be pre-populated with a value. + * + * @param list the original list of items + * @param toLabel how to create the label + * @param value (optional) value to be selected + * @param type of element + * @return dynamic list, possibly with value set + */ + public static DynamicList fromList(List list, Function toLabel, T value, boolean sort) { + return fromList(list, null, toLabel, value, sort); + } + public static DynamicList fromDynamicListElementList(List list) { return DynamicList.builder().listItems(list).value(DynamicListElement.EMPTY).build(); } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/sealedclaim/ResponseRepaymentDetailsForm.java b/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/sealedclaim/ResponseRepaymentDetailsForm.java index d5ef37d76de..ae474fb8326 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/sealedclaim/ResponseRepaymentDetailsForm.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/sealedclaim/ResponseRepaymentDetailsForm.java @@ -27,7 +27,7 @@ import static uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec.COUNTER_CLAIM; @Getter -@Builder +@Builder(toBuilder = true) @AllArgsConstructor @EqualsAndHashCode public class ResponseRepaymentDetailsForm { @@ -78,9 +78,9 @@ public static ResponseRepaymentDetailsForm toSealedClaimResponseCommonContent(Ca .build(); } - private static void addRepaymentMethod(CaseData caseData, ResponseRepaymentDetailsForm.ResponseRepaymentDetailsFormBuilder builder, BigDecimal totalAmount) { + private static void addRepaymentMethod(CaseData caseData, ResponseRepaymentDetailsFormBuilder builder, BigDecimal totalAmount) { if (caseData.isPayImmediately()) { - addPayByDatePayImmediately(builder, totalAmount); + addPayByDatePayImmediately(builder, totalAmount, caseData.getRespondToClaimAdmitPartLRspec().getWhenWillThisAmountBePaid()); } else if (caseData.isPayByInstallment()) { addRepaymentPlan(caseData, builder, totalAmount); } else if (caseData.isPayBySetDate()) { @@ -94,10 +94,8 @@ private static void addPayBySetDate(CaseData caseData, ResponseRepaymentDetailsF .whyNotPayImmediately(caseData.getResponseToClaimAdmitPartWhyNotPayLRspec()); } - private static void addPayByDatePayImmediately(ResponseRepaymentDetailsForm.ResponseRepaymentDetailsFormBuilder builder, BigDecimal totalClaimAmount) { - builder.payBy(LocalDate.now() - .plusDays(RespondentResponsePartAdmissionPaymentTimeLRspec.DAYS_TO_PAY_IMMEDIATELY)) - .amountToPay(totalClaimAmount + ""); + private static void addPayByDatePayImmediately(ResponseRepaymentDetailsFormBuilder builder, BigDecimal totalClaimAmount, LocalDate responseDate) { + builder.payBy(responseDate).amountToPay(totalClaimAmount + ""); } private static void addRepaymentPlan(CaseData caseData, ResponseRepaymentDetailsForm.ResponseRepaymentDetailsFormBuilder builder, BigDecimal totalClaimAmount) { @@ -142,7 +140,7 @@ private static void fullDefenceData(CaseData caseData, ResponseRepaymentDetailsF } } - private static void partAdmissionData(CaseData caseData, ResponseRepaymentDetailsForm.ResponseRepaymentDetailsFormBuilder builder) { + private static void partAdmissionData(CaseData caseData, ResponseRepaymentDetailsFormBuilder builder) { addDetailsOnWhyClaimIsRejected(caseData, builder); if (caseData.getSpecDefenceAdmittedRequired() == YesOrNo.YES) { alreadyPaid(caseData, builder); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/sealedclaim/SealedClaimLipResponseForm.java b/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/sealedclaim/SealedClaimLipResponseForm.java index ad5b44ed543..91c0bfdda51 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/sealedclaim/SealedClaimLipResponseForm.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/sealedclaim/SealedClaimLipResponseForm.java @@ -37,7 +37,7 @@ import java.util.stream.Stream; @Getter -@Builder +@Builder(toBuilder = true) @AllArgsConstructor @EqualsAndHashCode public class SealedClaimLipResponseForm implements MappableObject { diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/documents/DocumentAndNote.java b/src/main/java/uk/gov/hmcts/reform/civil/model/documents/DocumentAndNote.java index 33cb4c343cf..fee4c6e850a 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/documents/DocumentAndNote.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/documents/DocumentAndNote.java @@ -7,6 +7,7 @@ import uk.gov.hmcts.reform.civil.documentmanagement.model.Document; import java.time.LocalDateTime; +import java.time.ZoneId; @Data @Builder(toBuilder = true) @@ -18,6 +19,6 @@ public class DocumentAndNote { private Document document; private String documentNote; @Builder.Default - private LocalDateTime createdDateTime = LocalDateTime.now(); + private LocalDateTime createdDateTime = LocalDateTime.now(ZoneId.of("Europe/London")); } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/documents/DocumentWithName.java b/src/main/java/uk/gov/hmcts/reform/civil/model/documents/DocumentWithName.java index 3538f61d331..9aabf622994 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/documents/DocumentWithName.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/documents/DocumentWithName.java @@ -7,6 +7,7 @@ import uk.gov.hmcts.reform.civil.documentmanagement.model.Document; import java.time.LocalDateTime; +import java.time.ZoneId; @Data @Builder(toBuilder = true) @@ -17,5 +18,5 @@ public class DocumentWithName { private Document document; private String documentName; @Builder.Default - private LocalDateTime createdDateTime = LocalDateTime.now(); + private LocalDateTime createdDateTime = LocalDateTime.now(ZoneId.of("Europe/London")); } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/genapplication/CaseLocationCivil.java b/src/main/java/uk/gov/hmcts/reform/civil/model/genapplication/CaseLocationCivil.java index edc224ba820..20bc4d13f5a 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/genapplication/CaseLocationCivil.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/genapplication/CaseLocationCivil.java @@ -14,4 +14,6 @@ public class CaseLocationCivil { private String region; private String siteName; private String baseLocation; + private String address; + private String postcode; } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/notification/EvidenceUploadApplicantNotificationHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/notification/EvidenceUploadApplicantNotificationHandler.java index 5a5c2c8e67d..06d1bcbee18 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/notification/EvidenceUploadApplicantNotificationHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/notification/EvidenceUploadApplicantNotificationHandler.java @@ -11,6 +11,8 @@ import java.util.Map; +import static java.util.Objects.nonNull; + @Service @RequiredArgsConstructor public class EvidenceUploadApplicantNotificationHandler implements NotificationData { @@ -24,12 +26,14 @@ public void notifyApplicantEvidenceUpload(CaseData caseData) throws Notification boolean isApplicantLip = isApplicantLip(caseData); //Send email to Applicant - notificationService.sendMail( - getEmail(caseData, isApplicantLip), - getTemplate(caseData, isApplicantLip), - addProperties(caseData), - getReference(caseData) - ); + if (nonNull(caseData.getNotificationText()) && !caseData.getNotificationText().equals("NULLED")) { + notificationService.sendMail( + getEmail(caseData, isApplicantLip), + getTemplate(caseData, isApplicantLip), + addProperties(caseData), + getReference(caseData) + ); + } } private static String getReference(CaseData caseData) { @@ -53,7 +57,8 @@ private boolean isApplicantLip(CaseData caseData) { @Override public Map addProperties(CaseData caseData) { return Map.of( - CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference() + CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(), + UPLOADED_DOCUMENTS, caseData.getNotificationText() ); } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/notification/EvidenceUploadRespondentNotificationHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/notification/EvidenceUploadRespondentNotificationHandler.java index eb6758fa47c..a8a7dc43178 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/notification/EvidenceUploadRespondentNotificationHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/notification/EvidenceUploadRespondentNotificationHandler.java @@ -11,6 +11,7 @@ import java.util.Map; +import static java.util.Objects.nonNull; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO; @Service @@ -41,7 +42,7 @@ public void notifyRespondentEvidenceUpload(CaseData caseData, boolean isForRespo isRespondentLip = true; } - if (null != email) { + if (null != email && nonNull(caseData.getNotificationText()) && !caseData.getNotificationText().equals("NULLED")) { notificationService.sendMail( email, getTemplate(isRespondentLip), @@ -62,7 +63,8 @@ public String getTemplate(boolean isRespondentLip) { @Override public Map addProperties(CaseData caseData) { return Map.of( - CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference() - ); + CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(), + UPLOADED_DOCUMENTS, caseData.getNotificationText() + ); } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/GenAppStateHelperService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/GenAppStateHelperService.java index 2569a7ad87b..f0d0abaf206 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/GenAppStateHelperService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/GenAppStateHelperService.java @@ -14,6 +14,7 @@ import uk.gov.hmcts.reform.civil.model.genapplication.GADetailsRespondentSol; import uk.gov.hmcts.reform.civil.model.genapplication.GeneralApplication; import uk.gov.hmcts.reform.civil.model.genapplication.GeneralApplicationsDetails; +import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData; import java.util.ArrayList; import java.util.HashMap; @@ -31,6 +32,7 @@ public class GenAppStateHelperService { private final CoreCaseDataService coreCaseDataService; private final CaseDetailsConverter caseDetailsConverter; + private final InitiateGeneralApplicationService genAppService; private final ObjectMapper objectMapper; @@ -69,16 +71,19 @@ public boolean triggerEvent(CaseData caseData, CaseEvent event) { return true; } - public CaseData updateApplicationLocationDetailsInClaim(CaseData caseData) { + public CaseData updateApplicationLocationDetailsInClaim(CaseData caseData, String authToken) { if (!Collections.isEmpty(caseData.getGeneralApplications())) { List genApps = new ArrayList<>(); CaseData finalCaseData = caseData; + LocationRefData locationDetails = genAppService.getWorkAllocationLocationDetails(finalCaseData.getCaseManagementLocation().getBaseLocation(), authToken); caseData.getGeneralApplications().forEach(generalApplicationElement -> { GeneralApplication generalApplication = generalApplicationElement.getValue(); generalApplication.getCaseManagementLocation().setBaseLocation(finalCaseData.getCaseManagementLocation().getBaseLocation()); generalApplication.getCaseManagementLocation().setRegion(finalCaseData.getCaseManagementLocation().getRegion()); - generalApplication.getCaseManagementLocation().setSiteName(finalCaseData.getLocationName()); + generalApplication.getCaseManagementLocation().setSiteName(locationDetails.getSiteName()); + generalApplication.getCaseManagementLocation().setAddress(locationDetails.getCourtAddress()); + generalApplication.getCaseManagementLocation().setPostcode(locationDetails.getPostcode()); Map genAppMap = generalApplication.toMap(objectMapper); genAppMap.put("isCcmccLocation", YesOrNo.NO); generalApplication = objectMapper.convertValue(genAppMap, GeneralApplication.class); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationService.java index a6191151527..f70a80f9ad5 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationService.java @@ -179,6 +179,13 @@ private GeneralApplication buildApplication(CaseData.CaseDataBuilder dataBuilder Pair caseLocation = getWorkAllocationLocation(caseData, authToken); //Setting Work Allocation location and location name + if (Objects.isNull(caseLocation.getLeft().getSiteName()) + && Objects.nonNull(caseLocation.getLeft().getBaseLocation())) { + LocationRefData locationDetails = getWorkAllocationLocationDetails(caseLocation.getLeft().getBaseLocation(), authToken); + caseLocation.getLeft().setSiteName(locationDetails.getSiteName()); + caseLocation.getLeft().setAddress(locationDetails.getCourtAddress()); + caseLocation.getLeft().setPostcode(locationDetails.getPostcode()); + } applicationBuilder.caseManagementLocation(caseLocation.getLeft()); applicationBuilder.isCcmccLocation(caseLocation.getRight() ? YES : NO); applicationBuilder.locationName(hasSDOBeenMade(caseData.getCcdState()) @@ -343,6 +350,8 @@ public Pair getWorkAllocationLocation(CaseData caseD .region(ccmccLocation.getRegionId()) .baseLocation(ccmccLocation.getEpimmsId()) .siteName(ccmccLocation.getSiteName()) + .address(ccmccLocation.getCourtAddress()) + .postcode(ccmccLocation.getPostcode()) .build(); return Pair.of(courtLocation, true); } @@ -369,6 +378,15 @@ private CaseLocationCivil getClaimant1PreferredLocation(CaseData caseData) { .build(); } + public LocationRefData getWorkAllocationLocationDetails(String baseLocation, String authToken) { + List locationDetails = locationRefDataService.getCourtLocationsByEpimmsId(authToken, baseLocation); + if (locationDetails != null && !locationDetails.isEmpty()) { + return locationDetails.get(0); + } else { + return LocationRefData.builder().build(); + } + } + private boolean isDefendant1RespondedFirst(CaseData caseData) { return caseData.getRespondent2ResponseDate() == null || (caseData.getRespondent1ResponseDate() != null diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/citizen/UpdateCaseManagementDetailsService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/citizen/UpdateCaseManagementDetailsService.java new file mode 100644 index 00000000000..b37adcba484 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/citizen/UpdateCaseManagementDetailsService.java @@ -0,0 +1,118 @@ +package uk.gov.hmcts.reform.civil.service.citizen; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.reform.civil.callback.CallbackParams; +import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; +import uk.gov.hmcts.reform.civil.helpers.LocationHelper; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.CaseManagementCategory; +import uk.gov.hmcts.reform.civil.model.CaseManagementCategoryElement; +import uk.gov.hmcts.reform.civil.model.common.Element; +import uk.gov.hmcts.reform.civil.model.dq.RequestedCourt; +import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; +import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData; +import uk.gov.hmcts.reform.civil.utils.CourtLocationUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN; +import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.getMultiPartyScenario; +import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element; + +@Slf4j +@Service +@RequiredArgsConstructor +public class UpdateCaseManagementDetailsService { + + private final LocationHelper locationHelper; + private final LocationRefDataService locationRefDataService; + private final CourtLocationUtils courtLocationUtils; + + public void updateCaseManagementDetails(CaseData.CaseDataBuilder builder, CallbackParams callbackParams) { + CaseData caseData = callbackParams.getCaseData(); + final List availableLocations = fetchLocationData(callbackParams); + + updateApplicant1RequestedCourtDetails(caseData, builder, availableLocations); + updateRespondent1RequestedCourtDetails(caseData, builder, availableLocations); + + caseData = builder.build(); + locationHelper.getCaseManagementLocation(caseData) + .ifPresent(requestedCourt -> locationHelper.updateCaseManagementLocation( + builder, + requestedCourt, + () -> locationRefDataService.getCourtLocationsForDefaultJudgments(callbackParams.getParams().get( + CallbackParams.Params.BEARER_TOKEN).toString()) + )); + + builder.caseNameHmctsInternal(caseParticipants(caseData).toString()); + + CaseManagementCategoryElement civil = + CaseManagementCategoryElement.builder().code("Civil").label("Civil").build(); + List> itemList = new ArrayList<>(); + itemList.add(element(civil)); + builder.caseManagementCategory( + CaseManagementCategory.builder().value(civil).list_items(itemList).build()); + + } + + private void updateApplicant1RequestedCourtDetails(CaseData caseData, CaseData.CaseDataBuilder builder, List availableLocations) { + Optional.ofNullable(caseData.getApplicant1DQ()) + .ifPresent(dq -> Optional.ofNullable(dq.getApplicant1DQRequestedCourt()) + .ifPresent(requestedCourt -> builder.applicant1DQ( + dq.toBuilder().applicant1DQRequestedCourt(correctCaseLocation(requestedCourt, availableLocations)) + .build()))); + } + + private void updateRespondent1RequestedCourtDetails(CaseData caseData, CaseData.CaseDataBuilder builder, List availableLocations) { + Optional.ofNullable(caseData.getRespondent1DQ()) + .ifPresent(dq -> Optional.ofNullable(dq.getRespondent1DQRequestedCourt()) + .ifPresent(requestedCourt -> builder.respondent1DQ( + dq.toBuilder().respondent1DQRequestedCourt(correctCaseLocation(requestedCourt, availableLocations)) + .build()))); + } + + private RequestedCourt correctCaseLocation(RequestedCourt requestedCourt, List locations) { + String locationLabel = requestedCourt.getCaseLocation().getBaseLocation(); + LocationRefData preferredLocation = locations.stream() + .filter(locationRefData -> courtLocationUtils.checkLocation(locationRefData, locationLabel)) + .findFirst().orElseThrow(RuntimeException::new); + return requestedCourt.toBuilder() + .responseCourtCode(preferredLocation.getCourtLocationCode()) + .caseLocation(LocationHelper.buildCaseLocation(preferredLocation)) + .build(); + } + + private List fetchLocationData(CallbackParams callbackParams) { + String authToken = callbackParams.getParams().get(BEARER_TOKEN).toString(); + return locationRefDataService.getCourtLocationsForDefaultJudgments(authToken); + } + + private StringBuilder caseParticipants(CaseData caseData) { + StringBuilder participantString = new StringBuilder(); + MultiPartyScenario multiPartyScenario = getMultiPartyScenario(caseData); + if (multiPartyScenario.equals(MultiPartyScenario.ONE_V_TWO_ONE_LEGAL_REP) + || multiPartyScenario.equals(MultiPartyScenario.ONE_V_TWO_TWO_LEGAL_REP)) { + participantString.append(caseData.getApplicant1().getPartyName()) + .append(" v ").append(caseData.getRespondent1().getPartyName()) + .append(" and ").append(caseData.getRespondent2().getPartyName()); + + } else if (multiPartyScenario.equals(MultiPartyScenario.TWO_V_ONE)) { + participantString.append(caseData.getApplicant1().getPartyName()) + .append(" and ").append(caseData.getApplicant2().getPartyName()) + .append(" v ") + .append(caseData.getRespondent1().getPartyName()); + + } else { + participantString.append(caseData.getApplicant1().getPartyName()) + .append(" v ") + .append(caseData.getRespondent1().getPartyName()); + } + return participantString; + + } + +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/citizenui/ResponseOneVOneShowTagService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/citizenui/ResponseOneVOneShowTagService.java new file mode 100644 index 00000000000..f639722d4b1 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/citizenui/ResponseOneVOneShowTagService.java @@ -0,0 +1,55 @@ +package uk.gov.hmcts.reform.civil.service.citizenui; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import uk.gov.hmcts.reform.civil.handler.callback.user.spec.show.ResponseOneVOneShowTag; +import uk.gov.hmcts.reform.civil.model.CaseData; + +import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.ONE_V_ONE; +import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.getMultiPartyScenario; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; + +@Service +@RequiredArgsConstructor +public class ResponseOneVOneShowTagService { + + public ResponseOneVOneShowTag setUpOneVOneFlow(CaseData caseData) { + if (ONE_V_ONE.equals(getMultiPartyScenario(caseData))) { + if (caseData.getRespondent1ClaimResponseTypeForSpec() == null) { + return null; + } + return switch (caseData.getRespondent1ClaimResponseTypeForSpec()) { + case FULL_DEFENCE -> ResponseOneVOneShowTag.ONE_V_ONE_FULL_DEFENCE; + case FULL_ADMISSION -> setUpOneVOneFlowForFullAdmit(caseData); + case PART_ADMISSION -> setUpOneVOneFlowForPartAdmit(caseData); + case COUNTER_CLAIM -> ResponseOneVOneShowTag.ONE_V_ONE_COUNTER_CLAIM; + default -> null; + }; + } + return null; + } + + private ResponseOneVOneShowTag setUpOneVOneFlowForPartAdmit(CaseData caseData) { + if (YES.equals(caseData.getSpecDefenceAdmittedRequired())) { + return ResponseOneVOneShowTag.ONE_V_ONE_PART_ADMIT_HAS_PAID; + } + return switch (caseData.getDefenceAdmitPartPaymentTimeRouteRequired()) { + case IMMEDIATELY -> ResponseOneVOneShowTag.ONE_V_ONE_PART_ADMIT_PAY_IMMEDIATELY; + case BY_SET_DATE -> ResponseOneVOneShowTag.ONE_V_ONE_PART_ADMIT_PAY_BY_SET_DATE; + case SUGGESTION_OF_REPAYMENT_PLAN -> ResponseOneVOneShowTag.ONE_V_ONE_PART_ADMIT_PAY_INSTALMENT; + default -> ResponseOneVOneShowTag.ONE_V_ONE_PART_ADMIT; + }; + } + + private ResponseOneVOneShowTag setUpOneVOneFlowForFullAdmit(CaseData caseData) { + if (YES.equals(caseData.getSpecDefenceFullAdmittedRequired())) { + return ResponseOneVOneShowTag.ONE_V_ONE_FULL_ADMIT_HAS_PAID; + } + return switch (caseData.getDefenceAdmitPartPaymentTimeRouteRequired()) { + case IMMEDIATELY -> ResponseOneVOneShowTag.ONE_V_ONE_FULL_ADMIT_PAY_IMMEDIATELY; + case BY_SET_DATE -> ResponseOneVOneShowTag.ONE_V_ONE_FULL_ADMIT_PAY_BY_SET_DATE; + case SUGGESTION_OF_REPAYMENT_PLAN -> ResponseOneVOneShowTag.ONE_V_ONE_FULL_ADMIT_PAY_INSTALMENT; + default -> ResponseOneVOneShowTag.ONE_V_ONE_FULL_ADMIT; + }; + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/citizenui/responsedeadline/DeadlineExtensionCalculatorService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/citizenui/responsedeadline/DeadlineExtensionCalculatorService.java index 0e6e5479803..71bf64f61c1 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/citizenui/responsedeadline/DeadlineExtensionCalculatorService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/citizenui/responsedeadline/DeadlineExtensionCalculatorService.java @@ -6,16 +6,28 @@ import java.time.LocalDate; +import static java.util.Objects.requireNonNull; + @Service @RequiredArgsConstructor public class DeadlineExtensionCalculatorService { private final WorkingDayIndicator workingDayIndicator; + int workingDaysCounter; - public LocalDate calculateExtendedDeadline(LocalDate dateProposed) { - return workingDayIndicator.isWorkingDay(dateProposed) - ? dateProposed - : workingDayIndicator.getNextWorkingDay(dateProposed); + public LocalDate calculateExtendedDeadline(LocalDate responseDate, int plusDays) { + workingDaysCounter = 0; + requireNonNull(responseDate); + if (plusDays == 0) { + return workingDayIndicator.getNextWorkingDay(responseDate); + } + return calculateWorkingDays(responseDate.plusDays(1), plusDays); } + public LocalDate calculateWorkingDays(LocalDate responseDate, int plusDays) { + if (workingDayIndicator.isWorkingDay(responseDate)) { + workingDaysCounter++; + } + return workingDaysCounter == plusDays ? responseDate : calculateWorkingDays(responseDate.plusDays(1), plusDays); + } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/sealedclaim/SealedClaimLipResponseFormGenerator.java b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/sealedclaim/SealedClaimLipResponseFormGenerator.java index 754d9ef596a..bc971235285 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/sealedclaim/SealedClaimLipResponseFormGenerator.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/sealedclaim/SealedClaimLipResponseFormGenerator.java @@ -1,7 +1,6 @@ package uk.gov.hmcts.reform.civil.service.docmosis.sealedclaim; import lombok.RequiredArgsConstructor; - import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.civil.documentmanagement.DocumentManagementService; import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/flowstate/FlowStateAllowedEventService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/flowstate/FlowStateAllowedEventService.java index f38fd3c46ce..85c31fb7330 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/flowstate/FlowStateAllowedEventService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/flowstate/FlowStateAllowedEventService.java @@ -6,7 +6,6 @@ import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.CaseData; -import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.stateflow.StateFlow; import java.util.List; @@ -29,68 +28,69 @@ import static uk.gov.hmcts.reform.civil.callback.CaseEvent.APPLICATION_OFFLINE_UPDATE_CLAIM; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.APPLY_NOC_DECISION; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.BUNDLE_CREATION_NOTIFICATION; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.LIP_CLAIM_SETTLED; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CLAIMANT_RESPONSE_CUI; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_CLAIM_SPEC_AFTER_PAYMENT; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_CLAIM_AFTER_PAYMENT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CASE_PROCEEDS_IN_CASEMAN; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CHANGE_SOLICITOR_EMAIL; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CLAIMANT_RESPONSE; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CLAIMANT_RESPONSE_CUI; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CLAIMANT_RESPONSE_SPEC; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_CLAIM; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_CLAIM_AFTER_PAYMENT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_CLAIM_SPEC; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_CLAIM_SPEC_AFTER_PAYMENT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_LIP_CLAIM; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_SDO; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.DEFAULT_JUDGEMENT; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.MANAGE_CONTACT_INFORMATION; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_HEARING_PARTIES; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.REQUEST_JUDGEMENT_ADMISSION_SPEC; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.DEFAULT_JUDGEMENT_SPEC; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.DEFENDANT_RESPONSE; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.DEFENDANT_RESPONSE_CUI; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.DEFENDANT_RESPONSE_SPEC; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.DISCONTINUE_CLAIM; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.DISMISS_CLAIM; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.ENTER_BREATHING_SPACE_SPEC; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.ENTER_BREATHING_SPACE_LIP; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.ENTER_BREATHING_SPACE_SPEC; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.EVIDENCE_UPLOAD_APPLICANT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.EVIDENCE_UPLOAD_JUDGE; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.EVIDENCE_UPLOAD_RESPONDENT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.EXTEND_RESPONSE_DEADLINE; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.HEARING_FEE_UNPAID; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_DIRECTIONS_ORDER; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.HEARING_FEE_PAID; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.HEARING_FEE_UNPAID; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.HEARING_SCHEDULED; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.INFORM_AGREED_EXTENSION_DATE; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.INFORM_AGREED_EXTENSION_DATE_SPEC; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.INITIATE_GENERAL_APPLICATION; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.JUDGMENT_PAID_IN_FULL; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.LIFT_BREATHING_SPACE_SPEC; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.LIP_CLAIM_SETTLED; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.MANAGE_CONTACT_INFORMATION; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.MEDIATION_SUCCESSFUL; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.MEDIATION_UNSUCCESSFUL; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.RESET_PIN; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRIAL_READINESS; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.UPLOAD_TRANSLATED_DOCUMENT; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.migrateCase; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.MOVE_TO_DECISION_OUTCOME; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOC_REQUEST; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_DEFENDANT_CUI_FOR_DEADLINE_EXTENSION; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_CLAIMANT_CUI_FOR_DEADLINE_EXTENSION; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_DEFENDANT_CUI_FOR_DEADLINE_EXTENSION; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_DEFENDANT_OF_CLAIM; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_DEFENDANT_OF_CLAIM_DETAILS; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_HEARING_PARTIES; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NotSuitable_SDO; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.RECORD_JUDGMENT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.REFER_TO_JUDGE; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.REQUEST_JUDGEMENT_ADMISSION_SPEC; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.RESET_PIN; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.RESUBMIT_CLAIM; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.SERVICE_REQUEST_RECEIVED; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.SET_ASIDE_JUDGMENT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.STANDARD_DIRECTION_ORDER_DJ; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TAKE_CASE_OFFLINE; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRIAL_READY_NOTIFICATION; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRANSFER_ONLINE_CASE; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRIAL_READINESS; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRIAL_READY_CHECK; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GENERATE_DIRECTIONS_ORDER; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRIAL_READY_NOTIFICATION; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.UPLOAD_TRANSLATED_DOCUMENT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.WITHDRAW_CLAIM; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.SET_ASIDE_JUDGMENT; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.JUDGMENT_PAID_IN_FULL; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.RECORD_JUDGMENT; -import static uk.gov.hmcts.reform.civil.callback.CaseEvent.TRANSFER_ONLINE_CASE; -import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PREPARE_FOR_HEARING_CONDUCT_HEARING; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.asyncStitchingComplete; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.migrateCase; +import static uk.gov.hmcts.reform.civil.enums.CaseCategory.SPEC_CLAIM; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.AWAITING_RESPONSES_FULL_DEFENCE_RECEIVED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.AWAITING_RESPONSES_NOT_FULL_DEFENCE_RECEIVED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.CLAIM_DETAILS_NOTIFIED; @@ -123,17 +123,18 @@ import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PAST_CLAIM_DISMISSED_DEADLINE_AWAITING_CAMUNDA; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PAST_CLAIM_NOTIFICATION_DEADLINE_AWAITING_CAMUNDA; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PENDING_CLAIM_ISSUED_UNREPRESENTED_DEFENDANT; +import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PREPARE_FOR_HEARING_CONDUCT_HEARING; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.RESPONDENT_RESPONSE_LANGUAGE_IS_BILINGUAL; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.SPEC_DRAFT; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.TAKEN_OFFLINE_AFTER_CLAIM_DETAILS_NOTIFIED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.TAKEN_OFFLINE_AFTER_CLAIM_NOTIFIED; +import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.TAKEN_OFFLINE_AFTER_SDO; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.TAKEN_OFFLINE_BY_STAFF; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.TAKEN_OFFLINE_PAST_APPLICANT_RESPONSE_DEADLINE; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.TAKEN_OFFLINE_SDO_NOT_DRAWN; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.TAKEN_OFFLINE_UNREGISTERED_DEFENDANT; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.TAKEN_OFFLINE_UNREPRESENTED_DEFENDANT; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.TAKEN_OFFLINE_UNREPRESENTED_UNREGISTERED_DEFENDANT; -import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.TAKEN_OFFLINE_AFTER_SDO; @Service @RequiredArgsConstructor @@ -141,7 +142,6 @@ public class FlowStateAllowedEventService { private final StateFlowEngine stateFlowEngine; private final CaseDetailsConverter caseDetailsConverter; - private final FeatureToggleService toggleService; private static final Map> ALLOWED_EVENTS_ON_FLOW_STATE = Map.ofEntries( entry( @@ -282,7 +282,8 @@ public class FlowStateAllowedEventService { GENERATE_DIRECTIONS_ORDER, TRIAL_READINESS, BUNDLE_CREATION_NOTIFICATION, - TRANSFER_ONLINE_CASE + TRANSFER_ONLINE_CASE, + asyncStitchingComplete ) ), @@ -542,7 +543,8 @@ public class FlowStateAllowedEventService { SET_ASIDE_JUDGMENT, JUDGMENT_PAID_IN_FULL, RECORD_JUDGMENT, - TRANSFER_ONLINE_CASE + TRANSFER_ONLINE_CASE, + asyncStitchingComplete ) ), @@ -864,7 +866,8 @@ public class FlowStateAllowedEventService { EVIDENCE_UPLOAD_RESPONDENT, BUNDLE_CREATION_NOTIFICATION, CHANGE_SOLICITOR_EMAIL, - LIP_CLAIM_SETTLED + LIP_CLAIM_SETTLED, + asyncStitchingComplete ) ), entry( @@ -903,7 +906,8 @@ public class FlowStateAllowedEventService { EVIDENCE_UPLOAD_RESPONDENT, BUNDLE_CREATION_NOTIFICATION, CHANGE_SOLICITOR_EMAIL, - LIP_CLAIM_SETTLED + LIP_CLAIM_SETTLED, + asyncStitchingComplete ) ), entry( @@ -1100,7 +1104,8 @@ public class FlowStateAllowedEventService { JUDGMENT_PAID_IN_FULL, RECORD_JUDGMENT, LIP_CLAIM_SETTLED, - TRANSFER_ONLINE_CASE + TRANSFER_ONLINE_CASE, + asyncStitchingComplete ) ), @@ -1285,7 +1290,8 @@ public class FlowStateAllowedEventService { ADD_CASE_NOTE, CHANGE_SOLICITOR_EMAIL, ADD_UNAVAILABLE_DATES, - LIP_CLAIM_SETTLED + LIP_CLAIM_SETTLED, + asyncStitchingComplete ) ), entry( @@ -1327,7 +1333,8 @@ public class FlowStateAllowedEventService { TRIAL_READINESS, BUNDLE_CREATION_NOTIFICATION, CHANGE_SOLICITOR_EMAIL, - ADD_UNAVAILABLE_DATES + ADD_UNAVAILABLE_DATES, + asyncStitchingComplete ) ), entry( @@ -1335,6 +1342,76 @@ public class FlowStateAllowedEventService { List.of( asyncStitchingComplete ) + ), + entry( + TAKEN_OFFLINE_BY_STAFF.fullName(), + List.of( + ADD_CASE_NOTE, + APPLICATION_OFFLINE_UPDATE_CLAIM, + migrateCase + ) + ), + entry( + TAKEN_OFFLINE_UNREGISTERED_DEFENDANT.fullName(), + List.of( + ADD_CASE_NOTE, + APPLICATION_OFFLINE_UPDATE_CLAIM, + migrateCase + ) + ), + entry( + TAKEN_OFFLINE_UNREPRESENTED_DEFENDANT.fullName(), + List.of( + ADD_CASE_NOTE, + APPLICATION_OFFLINE_UPDATE_CLAIM, + migrateCase + ) + ), + entry( + TAKEN_OFFLINE_UNREPRESENTED_UNREGISTERED_DEFENDANT.fullName(), + List.of( + ADD_CASE_NOTE, + APPLICATION_OFFLINE_UPDATE_CLAIM, + migrateCase + ) + ), + entry( + TAKEN_OFFLINE_PAST_APPLICANT_RESPONSE_DEADLINE.fullName(), + List.of( + ADD_CASE_NOTE, + APPLICATION_OFFLINE_UPDATE_CLAIM, + migrateCase + ) + ), + entry( + TAKEN_OFFLINE_AFTER_CLAIM_DETAILS_NOTIFIED.fullName(), + List.of( + ADD_CASE_NOTE, + APPLICATION_OFFLINE_UPDATE_CLAIM, + migrateCase + ) + ), + entry( + TAKEN_OFFLINE_AFTER_CLAIM_NOTIFIED.fullName(), + List.of( + ADD_CASE_NOTE, + APPLICATION_OFFLINE_UPDATE_CLAIM, + migrateCase + ) + ), + entry( + TAKEN_OFFLINE_SDO_NOT_DRAWN.fullName(), + List.of( + ADD_CASE_NOTE, + migrateCase + ) + ), + entry( + TAKEN_OFFLINE_AFTER_SDO.fullName(), + List.of( + ADD_CASE_NOTE, + AMEND_PARTY_DETAILS + ) ) ); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/flowstate/StateFlowEngine.java b/src/main/java/uk/gov/hmcts/reform/civil/service/flowstate/StateFlowEngine.java index 03ad14f2cee..39f82bb7088 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/flowstate/StateFlowEngine.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/flowstate/StateFlowEngine.java @@ -3,13 +3,13 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; -import uk.gov.hmcts.reform.civil.handler.callback.user.RespondToDefenceCallbackHandler; import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.stateflow.StateFlow; import uk.gov.hmcts.reform.civil.stateflow.StateFlowBuilder; import uk.gov.hmcts.reform.civil.stateflow.model.State; +import uk.gov.hmcts.reform.civil.utils.JudicialReferralUtils; import java.util.Map; @@ -18,8 +18,8 @@ import static uk.gov.hmcts.reform.civil.service.flowstate.FlowFlag.BULK_CLAIM_ENABLED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowFlag.GENERAL_APPLICATION_ENABLED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowLipPredicate.agreedToMediation; -import static uk.gov.hmcts.reform.civil.service.flowstate.FlowLipPredicate.declinedMediation; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowLipPredicate.ccjRequestJudgmentByAdmission; +import static uk.gov.hmcts.reform.civil.service.flowstate.FlowLipPredicate.declinedMediation; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowLipPredicate.isLipCase; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowLipPredicate.isTranslatedDocumentUploaded; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowLipPredicate.partAdmitPayImmediately; @@ -40,9 +40,9 @@ import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.caseDismissedAfterDetailNotifiedExtension; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.caseDismissedPastHearingFeeDue; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.casemanMarksMediationUnsuccessful; -import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.claimDismissalOutOfTime; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.certificateOfServiceEnabled; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.claimDetailsNotified; +import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.claimDismissalOutOfTime; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.claimDismissedByCamunda; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.claimIssued; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.claimNotified; @@ -72,8 +72,8 @@ import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.fullDefenceSpec; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.isClaimantNotSettlePartAdmitClaim; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.isInHearingReadiness; -import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.isRespondentResponseLangIsBilingual; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.isPayImmediately; +import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.isRespondentResponseLangIsBilingual; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.multipartyCase; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.noticeOfChangeEnabled; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowPredicate.notificationAcknowledged; @@ -137,11 +137,11 @@ import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FLOW_NAME; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_ADMISSION; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_ADMIT_AGREE_REPAYMENT; +import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_ADMIT_JUDGMENT_ADMISSION; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_ADMIT_NOT_PROCEED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_ADMIT_PAY_IMMEDIATELY; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_ADMIT_PROCEED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_ADMIT_REJECT_REPAYMENT; -import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_ADMIT_JUDGMENT_ADMISSION; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_DEFENCE; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_DEFENCE_NOT_PROCEED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.FULL_DEFENCE_PROCEED; @@ -153,9 +153,9 @@ import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMISSION; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMIT_AGREE_REPAYMENT; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMIT_AGREE_SETTLE; -import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMIT_PAY_IMMEDIATELY; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMIT_NOT_PROCEED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMIT_NOT_SETTLED_NO_MEDIATION; +import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMIT_PAY_IMMEDIATELY; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMIT_PROCEED; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PART_ADMIT_REJECT_REPAYMENT; import static uk.gov.hmcts.reform.civil.service.flowstate.FlowState.Main.PAST_APPLICANT_RESPONSE_DEADLINE_AWAITING_CAMUNDA; @@ -507,20 +507,20 @@ public StateFlow build(FlowState.Main initialState) { .onlyIf(fullDefenceProceed.and(allAgreedToLrMediationSpec).and(agreedToMediation.negate()).and(declinedMediation.negate())) .set((c, flags) -> { flags.put(FlowFlag.AGREED_TO_MEDIATION.name(), true); - flags.put(FlowFlag.SDO_ENABLED.name(), RespondToDefenceCallbackHandler.shouldMoveToJudicialReferral(c)); + flags.put(FlowFlag.SDO_ENABLED.name(), JudicialReferralUtils.shouldMoveToJudicialReferral(c)); }) .transitionTo(FULL_DEFENCE_PROCEED) .onlyIf(fullDefenceProceed.and(allAgreedToLrMediationSpec.negate().and(agreedToMediation.negate())) .or(declinedMediation).and(applicantOutOfTime.negate()).and(demageMultiClaim)) .set((c, flags) -> { flags.put(FlowFlag.IS_MULTI_TRACK.name(), true); - flags.put(FlowFlag.SDO_ENABLED.name(), RespondToDefenceCallbackHandler.shouldMoveToJudicialReferral(c)); + flags.put(FlowFlag.SDO_ENABLED.name(), JudicialReferralUtils.shouldMoveToJudicialReferral(c)); }) .transitionTo(FULL_DEFENCE_PROCEED) .onlyIf(fullDefenceProceed.and(allAgreedToLrMediationSpec.negate().and(agreedToMediation.negate())) .or(declinedMediation).and(applicantOutOfTime.negate()).and(demageMultiClaim.negate())) .setDynamic(Map.of(FlowFlag.SDO_ENABLED.name(), - RespondToDefenceCallbackHandler::shouldMoveToJudicialReferral)) + JudicialReferralUtils::shouldMoveToJudicialReferral)) .transitionTo(FULL_DEFENCE_NOT_PROCEED).onlyIf(fullDefenceNotProceed) .transitionTo(TAKEN_OFFLINE_BY_STAFF).onlyIf(takenOfflineByStaffAfterDefendantResponse) .transitionTo(PAST_APPLICANT_RESPONSE_DEADLINE_AWAITING_CAMUNDA) @@ -554,7 +554,7 @@ public StateFlow build(FlowState.Main initialState) { .transitionTo(PART_ADMIT_NOT_SETTLED_NO_MEDIATION) .onlyIf(isClaimantNotSettlePartAdmitClaim.and(not(agreedToMediation))) .setDynamic(Map.of(FlowFlag.SDO_ENABLED.name(), - RespondToDefenceCallbackHandler::shouldMoveToJudicialReferral)) + JudicialReferralUtils::shouldMoveToJudicialReferral)) .transitionTo(PART_ADMIT_PROCEED).onlyIf(fullDefenceProceed) .transitionTo(PART_ADMIT_NOT_PROCEED).onlyIf(fullDefenceNotProceed) .transitionTo(PART_ADMIT_PAY_IMMEDIATELY).onlyIf(partAdmitPayImmediately) diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyCheckSearchService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyCheckSearchService.java index d23f38cf85b..b418a6a16fd 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyCheckSearchService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyCheckSearchService.java @@ -13,6 +13,7 @@ import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; import static org.elasticsearch.index.query.QueryBuilders.rangeQuery; +import static uk.gov.hmcts.reform.civil.enums.CaseState.HEARING_READINESS; import static uk.gov.hmcts.reform.civil.enums.CaseState.PREPARE_FOR_HEARING_CONDUCT_HEARING; @Service @@ -30,7 +31,10 @@ public Query query(int startIndex) { .must(rangeQuery("data.hearingDate").lt(LocalDate.now() .atTime(LocalTime.MIN).plusWeeks(3) .toString())) - .must(beState(PREPARE_FOR_HEARING_CONDUCT_HEARING)) + .must(boolQuery() + .minimumShouldMatch(1) + .should(beState(PREPARE_FOR_HEARING_CONDUCT_HEARING)) + .should(beState(HEARING_READINESS))) .mustNot(matchQuery("data.allocatedTrack", "SMALL_CLAIM")) .mustNot(matchQuery("data.trialReadyChecked", "Yes"))), List.of("reference"), diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyNotificationSearchService.java b/src/main/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyNotificationSearchService.java index 878b2f73638..53a26cd55e1 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyNotificationSearchService.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyNotificationSearchService.java @@ -15,6 +15,7 @@ import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; import static org.elasticsearch.index.query.QueryBuilders.rangeQuery; +import static uk.gov.hmcts.reform.civil.enums.CaseState.HEARING_READINESS; import static uk.gov.hmcts.reform.civil.enums.CaseState.PREPARE_FOR_HEARING_CONDUCT_HEARING; @Service @@ -32,10 +33,13 @@ public Query query(int startIndex) { .must(rangeQuery("data.hearingDate").lt(LocalDate.now() .atTime(LocalTime.MIN) .plusWeeks(6).toString())) - .must(beState(PREPARE_FOR_HEARING_CONDUCT_HEARING))) + .must(boolQuery() + .minimumShouldMatch(1) + .should(beState(PREPARE_FOR_HEARING_CONDUCT_HEARING)) + .should(beState(HEARING_READINESS))) .mustNot(matchQuery("data.allocatedTrack", "SMALL_CLAIM")) .mustNot(matchQuery("data.listingOrRelisting", ListingOrRelisting.RELISTING)) - .mustNot(matchQuery("data.trialReadyNotified", YesOrNo.YES)), + .mustNot(matchQuery("data.trialReadyNotified", YesOrNo.YES))), List.of("reference"), startIndex ); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/utils/CaseFlagUtils.java b/src/main/java/uk/gov/hmcts/reform/civil/utils/CaseFlagUtils.java index 62a60317e95..cfc0249f777 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/utils/CaseFlagUtils.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/utils/CaseFlagUtils.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.reform.civil.utils; +import uk.gov.hmcts.reform.ccd.model.OrganisationPolicy; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.PartyFlagStructure; import uk.gov.hmcts.reform.civil.model.caseflags.FlagDetail; @@ -22,18 +23,45 @@ import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.unwrapElements; +import static uk.gov.hmcts.reform.civil.utils.ElementUtils.wrapElements; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_LEGAL_REP_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_ORG_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_ORG_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_LEGAL_REP_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_ORG_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_LEGAL_REP_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_ORG_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.PartyUtils.appendWithNewPartyId; import uk.gov.hmcts.reform.civil.model.LitigationFriend; import uk.gov.hmcts.reform.civil.model.Party; +import uk.gov.hmcts.reform.civil.prd.model.Organisation; +import uk.gov.hmcts.reform.civil.service.OrganisationService; public class CaseFlagUtils { - public static String RESPONDENT_SOLICITOR_ONE_WITNESS = "Respondent solicitor 1 witness"; - public static String RESPONDENT_SOLICITOR_ONE_EXPERT = "Respondent solicitor 1 expert"; - public static String RESPONDENT_SOLICITOR_TWO_WITNESS = "Respondent solicitor 2 witness"; - public static String RESPONDENT_SOLICITOR_TWO_EXPERT = "Respondent solicitor 2 expert"; - public static String APPLICANT_SOLICITOR_WITNESS = "Applicant solicitor witness"; - public static String APPLICANT_SOLICITOR_EXPERT = "Applicant solicitor expert"; + public static final String RESPONDENT_SOLICITOR_ONE_WITNESS = "Respondent solicitor 1 witness"; + public static final String RESPONDENT_SOLICITOR_ONE_EXPERT = "Respondent solicitor 1 expert"; + public static final String RESPONDENT_SOLICITOR_TWO_WITNESS = "Respondent solicitor 2 witness"; + public static final String RESPONDENT_SOLICITOR_TWO_EXPERT = "Respondent solicitor 2 expert"; + public static final String APPLICANT_SOLICITOR_WITNESS = "Applicant solicitor witness"; + public static final String APPLICANT_SOLICITOR_EXPERT = "Applicant solicitor expert"; + public static final String APPLICANT_ONE = "Applicant 1"; + public static final String APPLICANT_TWO = "Applicant 2"; + public static final String APPLICANT_ONE_LITIGATION_FRIEND = "Applicant 1 Litigation Friend"; + public static final String APPLICANT_TWO_LITIGATION_FRIEND = "Applicant 2 Litigation Friend"; + public static final String RESPONDENT_ONE = "Respondent 1"; + public static final String RESPONDENT_TWO = "Respondent 2"; + public static final String RESPONDENT_ONE_LITIGATION_FRIEND = "Respondent 1 Litigation Friend"; + public static final String RESPONDENT_TWO_LITIGATION_FRIEND = "Respondent 2 Litigation Friend"; private CaseFlagUtils() { //NO-OP @@ -49,7 +77,7 @@ public static Flags createFlags(String flagsPartyName, String roleOnCase) { private static PartyFlagStructure createPartiesCaseFlagsField(String partyId, String firstName, String lastName, String email, String phone, String roleOnCase) { - String partyName = String.format("%s %s", firstName, lastName); + String partyName = formattedPartyNameForFlags(firstName, lastName); return PartyFlagStructure.builder() .partyID(partyId) .firstName(firstName) @@ -72,7 +100,7 @@ public static LitigationFriend updateLitFriend(String roleOnCase, LitigationFrie // ToDo: Remove the use of fullName after H&L changes are default ===================================== litFriendToUpdate.getFullName() != null ? litFriendToUpdate.getFullName() // ==================================================================================================== - : String.format("%s %s", litFriendToUpdate.getFirstName(), litFriendToUpdate.getLastName()), + : formattedPartyNameForFlags(litFriendToUpdate.getFirstName(), litFriendToUpdate.getLastName()), roleOnCase)).build() : null; } @@ -171,6 +199,129 @@ public static void addApplicantExpertAndWitnessFlagsStructure(CaseData.CaseDataB } } + public static void createOrUpdateFlags(CaseData.CaseDataBuilder builder, CaseData caseData, OrganisationService organisationService) { + String partyChosen = caseData.getUpdateDetailsForm().getPartyChosenId(); + // claimant/defendant + updatePartyFlags(builder, caseData, partyChosen); + // litigation friend + updateLitigationFriendFlags(builder, caseData, partyChosen); + // attending for org/company + updateOrgIndividualsFlags(builder, caseData, partyChosen); + // attending for legal rep + updateLRIndividualsFlags(builder, caseData, partyChosen, organisationService); + } + + private static void updateLRIndividualsFlags(CaseData.CaseDataBuilder builder, CaseData caseData, String partyChosen, OrganisationService organisationService) { + if ((CLAIMANT_ONE_LEGAL_REP_INDIVIDUALS_ID).equals(partyChosen)) { + String legalRepFirmName = getLegalRepFirmName( + caseData.getApplicant1OrganisationPolicy(), + organisationService, + APPLICANT_ONE); + builder.applicant1LRIndividuals(updatePartyNameForPartyFlagStructures(caseData.getApplicant1LRIndividuals(), legalRepFirmName)); + } + if ((DEFENDANT_ONE_LEGAL_REP_INDIVIDUALS_ID).equals(partyChosen)) { + String legalRepFirmName = getLegalRepFirmName( + caseData.getRespondent1OrganisationPolicy(), + organisationService, + RESPONDENT_ONE); + builder.respondent1LRIndividuals(updatePartyNameForPartyFlagStructures(caseData.getRespondent1LRIndividuals(), legalRepFirmName)); + } + if ((DEFENDANT_TWO_LEGAL_REP_INDIVIDUALS_ID).equals(partyChosen)) { + String legalRepFirmName = getLegalRepFirmName( + caseData.getRespondent2OrganisationPolicy(), + organisationService, + RESPONDENT_TWO); + builder.respondent2LRIndividuals(updatePartyNameForPartyFlagStructures(caseData.getRespondent2LRIndividuals(), legalRepFirmName)); + } + } + + private static void updateOrgIndividualsFlags(CaseData.CaseDataBuilder builder, CaseData caseData, String partyChosen) { + if ((CLAIMANT_ONE_ORG_INDIVIDUALS_ID).equals(partyChosen)) { + builder.applicant1OrgIndividuals(updatePartyNameForPartyFlagStructures(caseData.getApplicant1OrgIndividuals(), caseData.getApplicant1().getPartyName())); + } + if ((CLAIMANT_TWO_ORG_INDIVIDUALS_ID).equals(partyChosen)) { + builder.applicant2OrgIndividuals(updatePartyNameForPartyFlagStructures(caseData.getApplicant2OrgIndividuals(), caseData.getApplicant2().getPartyName())); + } + if ((DEFENDANT_ONE_ORG_INDIVIDUALS_ID).equals(partyChosen)) { + builder.respondent1OrgIndividuals(updatePartyNameForPartyFlagStructures(caseData.getRespondent1OrgIndividuals(), caseData.getRespondent1().getPartyName())); + } + if ((DEFENDANT_TWO_ORG_INDIVIDUALS_ID).equals(partyChosen)) { + builder.respondent2OrgIndividuals(updatePartyNameForPartyFlagStructures(caseData.getRespondent2OrgIndividuals(), caseData.getRespondent2().getPartyName())); + } + } + + private static void updateLitigationFriendFlags(CaseData.CaseDataBuilder builder, CaseData caseData, String partyChosen) { + if ((CLAIMANT_ONE_LITIGATION_FRIEND_ID).equals(partyChosen)) { + builder.applicant1LitigationFriend(updatePartyNameForLitigationFriendFlags(caseData.getApplicant1LitigationFriend())); + } + if ((CLAIMANT_TWO_LITIGATION_FRIEND_ID).equals(partyChosen)) { + builder.applicant2LitigationFriend(updatePartyNameForLitigationFriendFlags(caseData.getApplicant2LitigationFriend())); + } + if ((DEFENDANT_ONE_LITIGATION_FRIEND_ID).equals(partyChosen)) { + builder.respondent1LitigationFriend(updatePartyNameForLitigationFriendFlags(caseData.getRespondent1LitigationFriend())); + } + if ((DEFENDANT_TWO_LITIGATION_FRIEND_ID).equals(partyChosen)) { + builder.respondent2LitigationFriend(updatePartyNameForLitigationFriendFlags(caseData.getRespondent2LitigationFriend())); + } + } + + private static void updatePartyFlags(CaseData.CaseDataBuilder builder, CaseData caseData, String partyChosen) { + if ((CLAIMANT_ONE_ID).equals(partyChosen)) { + builder.applicant1(updatePartyNameForFlags(caseData.getApplicant1())); + } + if ((CLAIMANT_TWO_ID).equals(partyChosen)) { + builder.applicant2(updatePartyNameForFlags(caseData.getApplicant2())); + } + if ((DEFENDANT_ONE_ID).equals(partyChosen)) { + builder.respondent1(updatePartyNameForFlags(caseData.getRespondent1())); + } + if ((DEFENDANT_TWO_ID).equals(partyChosen)) { + builder.respondent2(updatePartyNameForFlags(caseData.getRespondent2())); + } + } + + private static List> updatePartyNameForPartyFlagStructures(List> individuals, + String roleOnCase) { + if (individuals != null && !individuals.isEmpty()) { + List partyFlagStructures = unwrapElements(individuals); + List updatedList = new ArrayList<>(); + for (PartyFlagStructure partyFlagStructure : partyFlagStructures) { + String formattedPartyNameForFlags = formattedPartyNameForFlags(partyFlagStructure.getFirstName(), partyFlagStructure.getLastName()); + if (partyFlagStructure.getFlags() == null) { + // new party so initialise flags and party ID + updatedList.add( + appendWithNewPartyId(partyFlagStructure + .toBuilder() + .flags(createFlags(formattedPartyNameForFlags, roleOnCase)).build())); + } else { + // existing party with flags so just update the name + updatedList.add( + partyFlagStructure + .toBuilder() + .flags(partyFlagStructure.getFlags().toBuilder() + .partyName(formattedPartyNameForFlags) + .build()).build()); + } + } + return wrapElements(updatedList); + } + return null; + } + + private static Party updatePartyNameForFlags(Party party) { + return party.toBuilder().flags(party.getFlags().toBuilder() + .partyName(party.getPartyName()) + .build()).build(); + } + + private static LitigationFriend updatePartyNameForLitigationFriendFlags(LitigationFriend litigationFriend) { + return litigationFriend.toBuilder() + .flags(litigationFriend.getFlags().toBuilder() + .partyName(litigationFriend.getFullName() != null ? litigationFriend.getFullName() + : formattedPartyNameForFlags(litigationFriend.getFirstName(), litigationFriend.getLastName())) + .build()).build(); + } + public static List getAllCaseFlags(CaseData caseData) { var flagCollection = new ArrayList(); flagCollection.addAll(getFlagDetails(caseData.getCaseFlags())); @@ -222,4 +373,17 @@ public static List filter(List flagDetails, Predicate true)) .collect(Collectors.toList()); } + + private static String formattedPartyNameForFlags(String firstName, String lastName) { + return String.format("%s %s", firstName, lastName); + } + + private static String getLegalRepFirmName(OrganisationPolicy organisationPolicy, + OrganisationService organisationService, + String party) { + String organisationID = organisationPolicy.getOrganisation().getOrganisationID(); + return organisationService.findOrganisationById(organisationID) + .map(Organisation::getName) + .orElse(String.format("legal representative for %s", party.toLowerCase())); + } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/utils/CaseFlagsInitialiser.java b/src/main/java/uk/gov/hmcts/reform/civil/utils/CaseFlagsInitialiser.java index 8955dff6ea4..708b197e462 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/utils/CaseFlagsInitialiser.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/utils/CaseFlagsInitialiser.java @@ -5,16 +5,27 @@ import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.service.OrganisationService; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.APPLICANT_ONE; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.APPLICANT_ONE_LITIGATION_FRIEND; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.APPLICANT_TWO; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.APPLICANT_TWO_LITIGATION_FRIEND; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.RESPONDENT_ONE; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.RESPONDENT_ONE_LITIGATION_FRIEND; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.RESPONDENT_TWO; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.RESPONDENT_TWO_LITIGATION_FRIEND; import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.addApplicantExpertAndWitnessFlagsStructure; import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.addRespondentDQPartiesFlagStructure; +import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.createOrUpdateFlags; @Component @AllArgsConstructor public class CaseFlagsInitialiser { private final FeatureToggleService featureToggleService; + private final OrganisationService organisationService; public void initialiseCaseFlags(CaseEvent caseEvent, CaseData.CaseDataBuilder dataBuilder) { if (!featureToggleService.isCaseFlagsEnabled()) { @@ -42,6 +53,10 @@ public void initialiseCaseFlags(CaseEvent caseEvent, CaseData.CaseDataBuilder da addApplicantExpertAndWitnessFlagsStructure(dataBuilder, caseData); break; } + case MANAGE_CONTACT_INFORMATION: { + createOrUpdateFlags(dataBuilder, caseData, organisationService); + break; + } default: } } @@ -62,26 +77,26 @@ private void initialiseRespondentLitigationFriendFlags(CaseData.CaseDataBuilder dataBuilder .respondent1LitigationFriend( CaseFlagUtils.updateLitFriend( - "Respondent 1 Litigation Friend", + RESPONDENT_ONE_LITIGATION_FRIEND, caseData.getRespondent1LitigationFriend() )) .respondent2LitigationFriend( CaseFlagUtils.updateLitFriend( - "Respondent 2 Litigation Friend", + RESPONDENT_TWO_LITIGATION_FRIEND, caseData.getRespondent2LitigationFriend() )); } private void initialiseApplicantAndRespondentFlags(CaseData.CaseDataBuilder dataBuilder, CaseData caseData) { dataBuilder - .applicant1(CaseFlagUtils.updateParty("Applicant 1", caseData.getApplicant1())) - .applicant2(CaseFlagUtils.updateParty("Applicant 2", caseData.getApplicant2())) - .respondent1(CaseFlagUtils.updateParty("Respondent 1", caseData.getRespondent1())) - .respondent2(CaseFlagUtils.updateParty("Respondent 2", caseData.getRespondent2())) + .applicant1(CaseFlagUtils.updateParty(APPLICANT_ONE, caseData.getApplicant1())) + .applicant2(CaseFlagUtils.updateParty(APPLICANT_TWO, caseData.getApplicant2())) + .respondent1(CaseFlagUtils.updateParty(RESPONDENT_ONE, caseData.getRespondent1())) + .respondent2(CaseFlagUtils.updateParty(RESPONDENT_TWO, caseData.getRespondent2())) .applicant1LitigationFriend(CaseFlagUtils.updateLitFriend( - "Applicant 1 Litigation Friend", caseData.getApplicant1LitigationFriend())) + APPLICANT_ONE_LITIGATION_FRIEND, caseData.getApplicant1LitigationFriend())) .applicant2LitigationFriend(CaseFlagUtils.updateLitFriend( - "Applicant 2 Litigation Friend", caseData.getApplicant2LitigationFriend())); + APPLICANT_TWO_LITIGATION_FRIEND, caseData.getApplicant2LitigationFriend())); } private boolean shouldReinitialiseRespondentDQFlags(CaseData caseData) { diff --git a/src/main/java/uk/gov/hmcts/reform/civil/utils/CourtLocationUtils.java b/src/main/java/uk/gov/hmcts/reform/civil/utils/CourtLocationUtils.java index ac70c9b2442..d1fae17737c 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/utils/CourtLocationUtils.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/utils/CourtLocationUtils.java @@ -35,7 +35,7 @@ public LocationRefData findPreferredLocationData(final List loc return preferredLocation.orElse(null); } - private Boolean checkLocation(final LocationRefData location, String locationTempLabel) { + public Boolean checkLocation(final LocationRefData location, String locationTempLabel) { String locationLabel = location.getSiteName() + " - " + location.getCourtAddress() + " - " + location.getPostcode(); diff --git a/src/main/java/uk/gov/hmcts/reform/civil/utils/JudicialReferralUtils.java b/src/main/java/uk/gov/hmcts/reform/civil/utils/JudicialReferralUtils.java new file mode 100644 index 00000000000..2df4c2c08f1 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/utils/JudicialReferralUtils.java @@ -0,0 +1,58 @@ +package uk.gov.hmcts.reform.civil.utils; + +import uk.gov.hmcts.reform.civil.enums.AllocatedTrack; +import uk.gov.hmcts.reform.civil.enums.CaseCategory; +import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; +import uk.gov.hmcts.reform.civil.model.CaseData; + +import static uk.gov.hmcts.reform.civil.enums.AllocatedTrack.getAllocatedTrack; +import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.getMultiPartyScenario; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; + +public class JudicialReferralUtils { + + private JudicialReferralUtils() { + //NO-OP + } + + /** + * Computes whether the case data should move to judicial referral or not. + * + * @param caseData a case data such that defendants rejected the claim, and claimant(s) wants to proceed + * vs all the defendants + * @return true if and only if the case should move to judicial referral + */ + public static boolean shouldMoveToJudicialReferral(CaseData caseData) { + CaseCategory caseCategory = caseData.getCaseAccessCategory(); + + if (CaseCategory.SPEC_CLAIM.equals(caseCategory)) { + MultiPartyScenario multiPartyScenario = getMultiPartyScenario(caseData); + + return switch (multiPartyScenario) { + case ONE_V_ONE, ONE_V_TWO_ONE_LEGAL_REP, ONE_V_TWO_TWO_LEGAL_REP -> caseData.getApplicant1ProceedWithClaim() == YesOrNo.YES; + case TWO_V_ONE -> caseData.getApplicant1ProceedWithClaimSpec2v1() == YesOrNo.YES; + }; + } else { + AllocatedTrack allocatedTrack = + getAllocatedTrack( + CaseCategory.UNSPEC_CLAIM.equals(caseCategory) + ? caseData.getClaimValue().toPounds() + : caseData.getTotalClaimAmount(), + caseData.getClaimType() + ); + if (AllocatedTrack.MULTI_CLAIM.equals(allocatedTrack)) { + return false; + } + MultiPartyScenario multiPartyScenario = getMultiPartyScenario(caseData); + return switch (multiPartyScenario) { + case ONE_V_ONE -> caseData.getApplicant1ProceedWithClaim() == YesOrNo.YES; + case TWO_V_ONE -> caseData.getApplicant1ProceedWithClaimMultiParty2v1() == YES + && caseData.getApplicant2ProceedWithClaimMultiParty2v1() == YES; + case ONE_V_TWO_ONE_LEGAL_REP, ONE_V_TWO_TWO_LEGAL_REP -> + caseData.getApplicant1ProceedWithClaimAgainstRespondent1MultiParty1v2() == YES + && caseData.getApplicant1ProceedWithClaimAgainstRespondent2MultiParty1v2() == YES; + }; + } + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/utils/ManageContactInformationUtils.java b/src/main/java/uk/gov/hmcts/reform/civil/utils/ManageContactInformationUtils.java index 5967810fb19..83ff6136dd6 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/utils/ManageContactInformationUtils.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/utils/ManageContactInformationUtils.java @@ -2,16 +2,22 @@ import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.Party; +import uk.gov.hmcts.reform.civil.model.UpdatePartyDetailsForm; import uk.gov.hmcts.reform.civil.model.common.DynamicListElement; +import uk.gov.hmcts.reform.civil.model.common.Element; +import uk.gov.hmcts.reform.civil.model.dq.Expert; import uk.gov.hmcts.reform.civil.model.dq.Experts; +import uk.gov.hmcts.reform.civil.model.dq.Witness; import uk.gov.hmcts.reform.civil.model.dq.Witnesses; - +import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; - import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; import static uk.gov.hmcts.reform.civil.model.Party.Type.COMPANY; import static uk.gov.hmcts.reform.civil.model.Party.Type.ORGANISATION; import static uk.gov.hmcts.reform.civil.model.common.DynamicListElement.dynamicElementFromCode; +import static uk.gov.hmcts.reform.civil.utils.ElementUtils.unwrapElements; +import static uk.gov.hmcts.reform.civil.utils.ElementUtils.wrapElements; public class ManageContactInformationUtils { @@ -34,30 +40,30 @@ private ManageContactInformationUtils() { private static final String ORG_INDIVIDUALS = "Individuals attending for the organisation"; private static final String LEGAL_REP_INDIVIDUALS = "Individuals attending for the legal representative"; - private static final String CLAIMANT_ONE_ID = "CLAIMANT_1"; - private static final String CLAIMANT_ONE_LITIGATION_FRIEND_ID = "CLAIMANT_1_LITIGATIONFRIEND"; - private static final String CLAIMANT_ONE_LEGAL_REP_INDIVIDUALS_ID = "CLAIMANT_1_INDIVIDUALSSOLICITORORG"; - private static final String CLAIMANT_ONE_ORG_INDIVIDUALS_ID = "CLAIMANT_1_INDIVIDUALSORG"; - private static final String CLAIMANT_ONE_WITNESSES_ID = "CLAIMANT_1_WITNESSES"; - private static final String CLAIMANT_ONE_EXPERTS_ID = "CLAIMANT_1_EXPERTS"; - - private static final String CLAIMANT_TWO_ID = "CLAIMANT_2"; - private static final String CLAIMANT_TWO_LITIGATION_FRIEND_ID = "CLAIMANT_2_LITIGATIONFRIEND"; - private static final String CLAIMANT_TWO_ORG_INDIVIDUALS_ID = "CLAIMANT_1_INDIVIDUALSORG"; - - private static final String DEFENDANT_ONE_ID = "DEFENDANT_1"; - private static final String DEFENDANT_ONE_LITIGATION_FRIEND_ID = "DEFENDANT_1_LITIGATIONFRIEND"; - private static final String DEFENDANT_ONE_LEGAL_REP_INDIVIDUALS_ID = "DEFENDANT_1_INDIVIDUALSSOLICITORORG"; - private static final String DEFENDANT_ONE_ORG_INDIVIDUALS_ID = "DEFENDANT_1_INDIVIDUALSORG"; - private static final String DEFENDANT_ONE_WITNESSES_ID = "DEFENDANT_1_WITNESSES"; - private static final String DEFENDANT_ONE_EXPERTS_ID = "DEFENDANT_1_EXPERTS"; - - private static final String DEFENDANT_TWO_ID = "DEFENDANT_2"; - private static final String DEFENDANT_TWO_LITIGATION_FRIEND_ID = "DEFENDANT_2_LITIGATIONFRIEND"; - private static final String DEFENDANT_TWO_LEGAL_REP_INDIVIDUALS_ID = "DEFENDANT_2_INDIVIDUALSSOLICITORORG"; - private static final String DEFENDANT_TWO_ORG_INDIVIDUALS_ID = "DEFENDANT_2_INDIVIDUALSORG"; - private static final String DEFENDANT_TWO_WITNESSES_ID = "DEFENDANT_2_WITNESSES"; - private static final String DEFENDANT_TWO_EXPERTS_ID = "DEFENDANT_2_EXPERTS"; + public static final String CLAIMANT_ONE_ID = "CLAIMANT_1"; + public static final String CLAIMANT_ONE_LITIGATION_FRIEND_ID = "CLAIMANT_1_LITIGATION_FRIEND"; + public static final String CLAIMANT_ONE_LEGAL_REP_INDIVIDUALS_ID = "CLAIMANT_1_LR_INDIVIDUALS"; + public static final String CLAIMANT_ONE_ORG_INDIVIDUALS_ID = "CLAIMANT_1_ORGANISATION_INDIVIDUALS"; + public static final String CLAIMANT_ONE_WITNESSES_ID = "CLAIMANT_1_WITNESSES"; + public static final String CLAIMANT_ONE_EXPERTS_ID = "CLAIMANT_1_EXPERTS"; + + public static final String CLAIMANT_TWO_ID = "CLAIMANT_2"; + public static final String CLAIMANT_TWO_LITIGATION_FRIEND_ID = "CLAIMANT_2_LITIGATION_FRIEND"; + public static final String CLAIMANT_TWO_ORG_INDIVIDUALS_ID = "CLAIMANT_2_ORGANISATION_INDIVIDUALS"; + + public static final String DEFENDANT_ONE_ID = "DEFENDANT_1"; + public static final String DEFENDANT_ONE_LITIGATION_FRIEND_ID = "DEFENDANT_1_LITIGATION_FRIEND"; + public static final String DEFENDANT_ONE_LEGAL_REP_INDIVIDUALS_ID = "DEFENDANT_1_LR_INDIVIDUALS"; + public static final String DEFENDANT_ONE_ORG_INDIVIDUALS_ID = "DEFENDANT_1_ORGANISATION_INDIVIDUALS"; + public static final String DEFENDANT_ONE_WITNESSES_ID = "DEFENDANT_1_WITNESSES"; + public static final String DEFENDANT_ONE_EXPERTS_ID = "DEFENDANT_1_EXPERTS"; + + public static final String DEFENDANT_TWO_ID = "DEFENDANT_2"; + public static final String DEFENDANT_TWO_LITIGATION_FRIEND_ID = "DEFENDANT_2_LITIGATION_FRIEND"; + public static final String DEFENDANT_TWO_LEGAL_REP_INDIVIDUALS_ID = "DEFENDANT_2_LR_INDIVIDUALS"; + public static final String DEFENDANT_TWO_ORG_INDIVIDUALS_ID = "DEFENDANT_2_ORGANISATION_INDIVIDUALS"; + public static final String DEFENDANT_TWO_WITNESSES_ID = "DEFENDANT_2_WITNESSES"; + public static final String DEFENDANT_TWO_EXPERTS_ID = "DEFENDANT_2_EXPERTS"; public static void addApplicant1Options(List list, CaseData caseData, boolean isAdmin) { addApplicant1PartyOptions(list, caseData); @@ -95,6 +101,178 @@ public static void addDefendant2Options(List list, CaseData addDefendant2ExpertsAndWitnesses(list, caseData, isAdmin); } + public static String appendUserAndType(String partyChosen, CaseData caseData, boolean isAdmin) { + String user = isAdmin ? "ADMIN" : "LR"; + + switch (partyChosen) { + case (CLAIMANT_ONE_ID): { + return formatId(partyChosen, user, caseData.getApplicant1()); + } + case(CLAIMANT_TWO_ID): { + return formatId(partyChosen, user, caseData.getApplicant2()); + } + case (DEFENDANT_ONE_ID): { + return formatId(partyChosen, user, caseData.getRespondent1()); + } + case(DEFENDANT_TWO_ID): { + return formatId(partyChosen, user, caseData.getRespondent2()); + } + case(CLAIMANT_ONE_LITIGATION_FRIEND_ID): + case(CLAIMANT_TWO_LITIGATION_FRIEND_ID): + case(DEFENDANT_ONE_LITIGATION_FRIEND_ID): + case(DEFENDANT_TWO_LITIGATION_FRIEND_ID): { + return formatId(partyChosen, user); + } + default: { + throw new IllegalArgumentException("Manage Contact Information party chosen ID does not exist"); + } + } + } + + public static List> mapExpertsToUpdatePartyDetailsForm(List> experts) { + List> newExperts = new ArrayList<>(); + + if (experts != null) { + for (Element party : experts) { + Expert expert = party.getValue(); + newExperts.addAll(wrapElements(UpdatePartyDetailsForm.builder() + .firstName(expert.getFirstName()) + .lastName(expert.getLastName()) + .emailAddress(expert.getEmailAddress()) + .phoneNumber(expert.getPhoneNumber()) + .fieldOfExpertise(expert.getFieldOfExpertise()) + .partyId(expert.getPartyID()) //this will need to be added in new ticket + .build())); + } + } + return newExperts; + } + + public static List> mapUpdatePartyDetailsFormToDQExperts(List> existingDQExperts, List> formExperts) { + List> newExperts = new ArrayList<>(); + List experts = unwrapElements(existingDQExperts); + + if (formExperts != null) { + for (Element form : formExperts) { + UpdatePartyDetailsForm formExpert = form.getValue(); + + Expert dqExpert = experts.stream() + .filter(e -> e.getPartyID().equals(formExpert.getPartyId())) + .findFirst() + .orElse(null); + + if (dqExpert != null && dqExpert.getPartyID() != null) { + // if id already exists in dq + newExperts.addAll(wrapElements(dqExpert.toBuilder() + .firstName(formExpert.getFirstName()) + .lastName(formExpert.getLastName()) + .emailAddress(formExpert.getEmailAddress()) + .phoneNumber(formExpert.getPhoneNumber()) + .fieldOfExpertise(formExpert.getFieldOfExpertise()) + .build())); + } else { + // if id doesn't exist in dq means it is a newly added expert + newExperts.addAll(wrapElements(Expert.builder() + .firstName(formExpert.getFirstName()) + .lastName(formExpert.getLastName()) + .emailAddress(formExpert.getEmailAddress()) + .phoneNumber(formExpert.getPhoneNumber()) + .fieldOfExpertise(formExpert.getFieldOfExpertise()) + .dateAdded(LocalDate.now()) + .eventAdded("Manage Contact Information Event") + .partyID(null) //CIV-10382 + .build())); + // Replace above to this in CIV-10382 + // newExperts.addAll(wrapElements(appendWithNewPartyIds(Expert.builder() + // .firstName(formExpert.getFirstName()) + // .lastName(formExpert.getLastName()) + // .emailAddress(formExpert.getEmailAddress()) + // .phoneNumber(formExpert.getPhoneNumber()) + // .fieldOfExpertise(formExpert.getFieldOfExpertise()) + // .dateAdded(LocalDate.now()) + // .eventAdded("Manage Contact Information Event") + // .build()))); + } + } + } + + return newExperts; + } + + public static List> mapWitnessesToUpdatePartyDetailsForm(List> witnesses) { + List> newWitnesses = new ArrayList<>(); + + if (witnesses != null) { + for (Element party : witnesses) { + Witness witness = party.getValue(); + newWitnesses.addAll(wrapElements(UpdatePartyDetailsForm.builder() + .firstName(witness.getFirstName()) + .lastName(witness.getLastName()) + .emailAddress(witness.getEmailAddress()) + .phoneNumber(witness.getPhoneNumber()) + .partyId(witness.getPartyID()) + .build())); + } + } + return newWitnesses; + } + + public static List> mapUpdatePartyDetailsFormToDQWitnesses(List> existingDQWitnesses, List> formWitnesses) { + List> newWitnesses = new ArrayList<>(); + List witnesses = unwrapElements(existingDQWitnesses); + + if (formWitnesses != null) { + for (Element form : formWitnesses) { + UpdatePartyDetailsForm formWitness = form.getValue(); + + Witness dqWitness = witnesses.stream() + .filter(w -> w.getPartyID().equals(formWitness.getPartyId())) + .findFirst() + .orElse(null); + + // if id already exists in dq + if (dqWitness != null && dqWitness.getPartyID() != null) { + newWitnesses.addAll(wrapElements(dqWitness.toBuilder() + .firstName(formWitness.getFirstName()) + .lastName(formWitness.getLastName()) + .emailAddress(formWitness.getEmailAddress()) + .phoneNumber(formWitness.getPhoneNumber()) + .build())); + } else { + // if id doesn't exist in dq means it is a newly added witness + newWitnesses.addAll(wrapElements(Witness.builder() + .firstName(formWitness.getFirstName()) + .lastName(formWitness.getLastName()) + .emailAddress(formWitness.getEmailAddress()) + .phoneNumber(formWitness.getPhoneNumber()) + .dateAdded(LocalDate.now()) + .eventAdded("Manage Contact Information Event") + .partyID(null) //CIV-10382 + .build())); + // Replace above to this in CIV-10382 + // newWitnesses.addAll(wrapElements(appendWithNewPartyIds(Witness.builder() + // .firstName(formWitness.getFirstName()) + // .lastName(formWitness.getLastName()) + // .emailAddress(formWitness.getEmailAddress()) + // .phoneNumber(formWitness.getPhoneNumber()) + // .dateAdded(LocalDate.now()) + // .eventAdded("Manage Contact Information Event") + // .build()))); + } + } + } + + return newWitnesses; + } + + private static String formatId(String partyChosen, String isAdmin, Party party) { + return String.format("%s_%s_%s", partyChosen, isAdmin, party.getType().toString()); + } + + private static String formatId(String partyChosen, String isAdmin) { + return String.format("%s_%s", partyChosen, isAdmin); + } + private static void addApplicant1PartyOptions(List list, CaseData caseData) { // applicant 1 party name list.add(dynamicElementFromCode(CLAIMANT_ONE_ID, diff --git a/src/main/java/uk/gov/hmcts/reform/civil/utils/UnavailabilityDatesUtils.java b/src/main/java/uk/gov/hmcts/reform/civil/utils/UnavailabilityDatesUtils.java index 5c394d09ee5..81a5e845f2e 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/utils/UnavailabilityDatesUtils.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/utils/UnavailabilityDatesUtils.java @@ -76,7 +76,7 @@ public static void rollUpUnavailabilityDatesForRespondent(CaseData.CaseDataBuild .getUnavailableDates(); List> updatedUnavailableDates = addEventAndDate( - caseData.getRespondent1ResponseDate().toLocalDate(), + caseData.getRespondent2ResponseDate().toLocalDate(), DEFENDANT_RESPONSE_EVENT, respondent2DQUnavailableDates ); diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 485b2ee98f1..187c0e2b2f9 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -215,6 +215,7 @@ notifications: claimantSolicitorDefendantResponseForSpec: "28ea1d53-93b1-4e48-a7e5-7a876f910f86" claimantSolicitorImmediatelyDefendantResponseForSpec: "263d7737-933d-4d0b-9f08-23847613f6a4" respondentSolicitorDefendantResponseForSpec: "9527f77e-b346-4527-b93c-c2affd39fa51" + respondentSolicitorDefResponseSpecWithClaimantAction: "efbd38e8-3fe7-4db6-ad55-b751b96477b1" respondentDefendantResponseForSpec: "94c71894-9590-4995-aae0-edea94fc4594" sdoOrdered: "90667080-6b20-48f2-b9ea-349fa8ec78e4" sdoOrderedSpec: "1c1a200c-b3c1-45eb-9768-aeea56857420" @@ -228,6 +229,8 @@ notifications: respondentSolicitorNotifyNotToProceedSpec: "4dc0b5bb-674f-401e-8a39-05686dc0302e" claimantSolicitorConfirmsToProceedSpec: "99786d26-ab90-43c7-aa20-9d450d8ce4eb" respondentSolicitorNotifyToProceedSpec: "ea6cb18e-ebba-4759-8df3-426e00f2f09c" + claimantSolicitorConfirmsToProceedSpecWithAction: "d454e5a9-8c56-4a1d-acce-53a1686376bc" + respondentSolicitorNotifyToProceedSpecWithAction: "c1bb435e-0300-4e51-89ec-56dd7f77ef27" applicantSolicitor1DefaultJudgmentReceived: "14a43ad4-e337-490a-bf8b-1288520dc9eb" claimantSolicitorCounterClaimForSpec: "256b6cf4-6201-48f0-bf1e-88a187712196" respondentSolicitorCounterClaimForSpec: "6cb3b3d5-f1aa-4236-ad03-685605a9235e" diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/TriggerGenAppLocationUpdateCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/TriggerGenAppLocationUpdateCallbackHandlerTest.java index e82e3a302b3..53cd99df257 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/TriggerGenAppLocationUpdateCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/caseevents/TriggerGenAppLocationUpdateCallbackHandlerTest.java @@ -46,6 +46,8 @@ class TriggerGenAppLocationUpdateCallbackHandlerTest extends BaseCallbackHandler @MockBean private GenAppStateHelperService helperService; + private static final String authToken = "Bearer TestAuthToken"; + @Test void handleEventsReturnsTheExpectedCallbackEvent() { assertThat(handler.handledEvents()).contains(TRIGGER_UPDATE_GA_LOCATION); @@ -60,12 +62,12 @@ void shouldTriggerGeneralApplicationEvent_whenCaseHasGeneralApplication() { true, true, getOriginalStatusOfGeneralApplication() ); - when(helperService.updateApplicationLocationDetailsInClaim(caseData)).thenReturn(caseData); + when(helperService.updateApplicationLocationDetailsInClaim(any(), any())).thenReturn(caseData); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); assertThat(response.getErrors()).isNull(); - verify(helperService, times(1)).updateApplicationLocationDetailsInClaim(caseData); + verify(helperService, times(1)).updateApplicationLocationDetailsInClaim(any(), any()); verify(helperService, times(1)).triggerEvent(caseData, TRIGGER_LOCATION_UPDATE); verify(helperService, times(1)).triggerEvent(caseData, TRIGGER_LOCATION_UPDATE); verifyNoMoreInteractions(helperService); @@ -93,7 +95,7 @@ void triggerGeneralApplicationEventThrowsException_HandleFailure() { ); String expectedErrorMessage = "Could not trigger event to update location on application under case: " + caseData.getCcdCaseReference(); - when(helperService.updateApplicationLocationDetailsInClaim(caseData)).thenReturn(caseData); + when(helperService.updateApplicationLocationDetailsInClaim(any(), any())).thenReturn(caseData); when(helperService.triggerEvent(any(CaseData.class), eq(TRIGGER_LOCATION_UPDATE))) .thenThrow(new RuntimeException()); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/ClaimantResponseConfirmsToProceedRespondentNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/ClaimantResponseConfirmsToProceedRespondentNotificationHandlerTest.java index c9cf92fd0e1..9f67e39cac1 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/ClaimantResponseConfirmsToProceedRespondentNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/ClaimantResponseConfirmsToProceedRespondentNotificationHandlerTest.java @@ -12,17 +12,17 @@ import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.enums.CaseCategory; -import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; +import uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec; import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; -import uk.gov.hmcts.reform.civil.sampledata.PartyBuilder; -import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.notify.NotificationService; +import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; +import uk.gov.hmcts.reform.civil.prd.model.Organisation; import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; -import uk.gov.hmcts.reform.civil.notify.NotificationService; +import uk.gov.hmcts.reform.civil.sampledata.PartyBuilder; import uk.gov.hmcts.reform.civil.service.OrganisationService; -import uk.gov.hmcts.reform.civil.prd.model.Organisation; import java.util.Map; import java.util.Optional; @@ -60,8 +60,6 @@ class ClaimantResponseConfirmsToProceedRespondentNotificationHandlerTest extends private NotificationsProperties notificationsProperties; @Autowired private ClaimantResponseConfirmsToProceedRespondentNotificationHandler handler; - @MockBean - private FeatureToggleService featureToggleService; @Nested class AboutToSubmitCallback { @@ -72,6 +70,8 @@ void setup() { when(notificationsProperties.getClaimantSolicitorConfirmsNotToProceed()).thenReturn("template-id"); when(notificationsProperties.getRespondentSolicitorNotifyToProceedSpec()).thenReturn("spec-template-id"); when(notificationsProperties.getClaimantSolicitorConfirmsToProceedSpec()).thenReturn("spec-template-id"); + when(notificationsProperties.getRespondentSolicitorNotifyToProceedSpecWithAction()).thenReturn("spec-template-no-mediation"); + when(notificationsProperties.getClaimantSolicitorConfirmsToProceedSpecWithAction()).thenReturn("spec-template-no-mediation"); when(notificationsProperties.getRespondent1LipClaimUpdatedTemplate()).thenReturn("spec-template-id"); } @@ -113,6 +113,30 @@ void shouldNotifyRespondentSolicitor_whenInvoked_spec() { ); } + @Test + void shouldNotifyRespondentSolicitor_whenSpecRejectAllNoMediation() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimDetailsNotified() + .setClaimTypeToSpecClaim() + .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) + .build().toBuilder() + .responseClaimMediationSpecRequired(YesOrNo.NO) + .build(); + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( + CallbackRequest.builder().eventId("NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIMANT_CONFIRMS_TO_PROCEED") + .build()).build(); + + handler.handle(params); + + verify(notificationService).sendMail( + "respondentsolicitor@example.com", + "spec-template-no-mediation", + getNotificationDataMapSpec(caseData, + CaseEvent.NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIMANT_CONFIRMS_TO_PROCEED), + "claimant-confirms-to-proceed-respondent-notification-000DC001" + ); + } + @Test void shouldNotifyRespondentSolicitor2_whenInvoked_spec() { CaseData caseData = CaseDataBuilder.builder() @@ -155,6 +179,30 @@ void shouldNotifyApplicantSolicitor_whenInvoked_spec() { ); } + @Test + void shouldNotifyApplicantSolicitor_whenSpecRejectAllNoMediation() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimDetailsNotified() + .setClaimTypeToSpecClaim() + .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) + .build().toBuilder() + .responseClaimMediationSpecRequired(YesOrNo.NO) + .build(); + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( + CallbackRequest.builder().eventId("NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIMANT_CONFIRMS_TO_PROCEED_CC") + .build()).build(); + + handler.handle(params); + + verify(notificationService).sendMail( + "applicantsolicitor@example.com", + "spec-template-no-mediation", + getNotificationDataMapSpec(caseData, + CaseEvent.NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIMANT_CONFIRMS_TO_PROCEED_CC), + "claimant-confirms-to-proceed-respondent-notification-000DC001" + ); + } + @Test void shouldNotifyRespondentSolicitor2withNoIntentionToProceed_whenInvoked() { CaseData caseData = CaseDataBuilder.builder() @@ -316,11 +364,11 @@ void shouldReturnCorrectCamundaActivityId_whenInvoked() { "NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIMANT_CONFIRMS_TO_PROCEED").build()).build())).isEqualTo(TASK_ID); assertThat(handler.camundaActivityId(CallbackParamsBuilder.builder().request(CallbackRequest.builder().eventId( - "NOTIFY_RESPONDENT_SOLICITOR2_FOR_CLAIMANT_CONFIRMS_TO_PROCEED").build()) + "NOTIFY_RESPONDENT_SOLICITOR2_FOR_CLAIMANT_CONFIRMS_TO_PROCEED").build()) .build())).isEqualTo(Task_ID_RESPONDENT_SOL2); assertThat(handler.camundaActivityId(CallbackParamsBuilder.builder().request(CallbackRequest.builder().eventId( "NOTIFY_RESPONDENT_SOLICITOR1_FOR_CLAIMANT_CONFIRMS_TO_PROCEED_CC").build()).build())).isEqualTo( - TASK_ID_CC); + TASK_ID_CC); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/DefendantResponseApplicantNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/DefendantResponseApplicantNotificationHandlerTest.java index b0f44a92d31..b9c5d6e3dee 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/DefendantResponseApplicantNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/DefendantResponseApplicantNotificationHandlerTest.java @@ -85,7 +85,7 @@ void setup() { when(organisationService.findOrganisationById(anyString())) .thenReturn(Optional.of(Organisation.builder().name("Signer Name").build())); when(notificationsProperties.getClaimantSolicitorImmediatelyDefendantResponseForSpec()).thenReturn("templateImm-id"); - + when(notificationsProperties.getRespondentSolicitorDefResponseSpecWithClaimantAction()).thenReturn("spec-respondent-template-id-action"); } @Nested @@ -168,17 +168,17 @@ void shouldNotifyApplicantSolicitorSpec_whenInvoked() { LocalDate whenWillPay = LocalDate.now().plusMonths(1); CaseData caseData = CaseDataBuilder.builder() - .atStateNotificationAcknowledged() - .build().toBuilder() - .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.PART_ADMISSION) + .atStateNotificationAcknowledged() + .build().toBuilder() + .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.PART_ADMISSION) .respondent2ClaimResponseTypeForSpec(RespondentResponseTypeSpec.PART_ADMISSION) .defenceAdmitPartPaymentTimeRouteRequired(RespondentResponsePartAdmissionPaymentTimeLRspec.BY_SET_DATE) - .respondToClaimAdmitPartLRspec( - RespondToClaimAdmitPartLRspec.builder() + .respondToClaimAdmitPartLRspec( + RespondToClaimAdmitPartLRspec.builder() .whenWillThisAmountBePaid(whenWillPay) .build() - ) - .build(); + ) + .build(); caseData = caseData.toBuilder().caseAccessCategory(SPEC_CLAIM).build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( CallbackRequest.builder().eventId("NOTIFY_APPLICANT_SOLICITOR1_FOR_DEFENDANT_RESPONSE").build()) @@ -341,6 +341,29 @@ void shouldNotifyRespondentSolicitorSpecDef1_whenInvokedWithCcEvent() { handler.handle(params); + verify(notificationService).sendMail( + "respondentsolicitor@example.com", + "spec-respondent-template-id", + getNotificationDataMapPartAdmissionSpec(caseData), + "defendant-response-applicant-notification-000DC001" + ); + } + + @Test + void sendNotificationToSolicitorSpec_shouldNotifyRespondentSolicitorSpecDef1v1() { + CaseData caseData = CaseDataBuilder.builder() + .atStateNotificationAcknowledged().build(); + caseData = caseData.toBuilder().caseAccessCategory(SPEC_CLAIM) + .respondent1DQ(Respondent1DQ.builder().build()) + .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) + .build(); + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( + CallbackRequest.builder().eventId("NOTIFY_APPLICANT_SOLICITOR1_FOR_DEFENDANT_RESPONSE_CC") + .build()) + .build(); + + handler.handle(params); + verify(notificationService).sendMail( "respondentsolicitor@example.com", "spec-respondent-template-id", @@ -349,6 +372,30 @@ void shouldNotifyRespondentSolicitorSpecDef1_whenInvokedWithCcEvent() { ); } + @Test + void sendNotificationToSolicitorSpecPart_shouldNotifyRespondentSolicitorSpecDef1v1() { + CaseData caseData = CaseDataBuilder.builder() + .atStateNotificationAcknowledged().build(); + caseData = caseData.toBuilder().caseAccessCategory(SPEC_CLAIM) + .respondent1DQ(Respondent1DQ.builder().build()) + .defenceAdmitPartPaymentTimeRouteRequired(RespondentResponsePartAdmissionPaymentTimeLRspec.IMMEDIATELY) + .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.PART_ADMISSION) + .build(); + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( + CallbackRequest.builder().eventId("NOTIFY_APPLICANT_SOLICITOR1_FOR_DEFENDANT_RESPONSE_CC") + .build()) + .build(); + + handler.handle(params); + + verify(notificationService).sendMail( + "respondentsolicitor@example.com", + "spec-respondent-template-id-action", + getNotificationDataMapSpec(caseData), + "defendant-response-applicant-notification-000DC001" + ); + } + @Test void shouldNotifyRespondentSolicitorSpecDef1SecondScenerio_whenInvokedWithCcEvent() { CaseData caseData = CaseDataBuilder.builder() @@ -546,6 +593,15 @@ private Map getNotificationDataMapImmediatelySpec(CaseData caseD ); } + + private Map getNotificationDataMapPartAdmissionSpec(CaseData caseData) { + return Map.of( + "defendantName", "Mr. Sole Trader", + CLAIM_LEGAL_ORG_NAME_SPEC, "Signer Name", + CLAIM_REFERENCE_NUMBER, LEGACY_CASE_REFERENCE + ); + } + } @Test diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ClaimantResponseCuiCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ClaimantResponseCuiCallbackHandlerTest.java index 787f6d63f1f..8c889304389 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ClaimantResponseCuiCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ClaimantResponseCuiCallbackHandlerTest.java @@ -1,42 +1,79 @@ package uk.gov.hmcts.reform.civil.handler.callback.user; import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.enums.CaseState; import uk.gov.hmcts.reform.civil.enums.MediationDecision; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; +import uk.gov.hmcts.reform.civil.helpers.LocationHelper; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.Party; import uk.gov.hmcts.reform.civil.model.citizenui.CaseDataLiP; import uk.gov.hmcts.reform.civil.model.citizenui.ClaimantMediationLip; +import uk.gov.hmcts.reform.civil.model.defaultjudgment.CaseLocationCivil; +import uk.gov.hmcts.reform.civil.model.dq.Applicant1DQ; +import uk.gov.hmcts.reform.civil.model.dq.RequestedCourt; +import uk.gov.hmcts.reform.civil.model.dq.Respondent1DQ; +import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; +import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; +import uk.gov.hmcts.reform.civil.service.citizen.UpdateCaseManagementDetailsService; +import uk.gov.hmcts.reform.civil.service.citizenui.ResponseOneVOneShowTagService; +import uk.gov.hmcts.reform.civil.utils.CourtLocationUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CLAIMANT_RESPONSE_CUI; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO; +import static uk.gov.hmcts.reform.civil.model.Party.Type.COMPANY; +import static uk.gov.hmcts.reform.civil.model.Party.Type.ORGANISATION; @ExtendWith(SpringExtension.class) @SpringBootTest(classes = { ClaimantResponseCuiCallbackHandler.class, - JacksonAutoConfiguration.class + JacksonAutoConfiguration.class, + ResponseOneVOneShowTagService.class, + JacksonAutoConfiguration.class, + CourtLocationUtils.class, + LocationRefDataService.class, + LocationHelper.class, + UpdateCaseManagementDetailsService.class }) class ClaimantResponseCuiCallbackHandlerTest extends BaseCallbackHandlerTest { + @Autowired + private CourtLocationUtils courtLocationUtility; + @MockBean + private LocationHelper locationHelper; + @MockBean + private LocationRefDataService locationRefDataService; @Autowired private ClaimantResponseCuiCallbackHandler handler; + private static final String courtLocation = "Site 1 - Adr 1 - AAA 111"; @Autowired private final ObjectMapper mapper = new ObjectMapper(); + @MockBean + private ResponseOneVOneShowTagService responseOneVOneShowTagService; + @Nested class AboutToStartCallback { @@ -54,9 +91,21 @@ void shouldReturnNoError_WhenAboutToStartIsInvoked() { @Nested class AboutToSubmitCallback { + @BeforeEach + void before() { + LocationRefData locationRefData = LocationRefData.builder().siteName("Site 1").courtAddress("Adr 1").postcode("AAA 111") + .courtName("Court Name").region("Region").regionId("1").courtVenueId("1") + .courtTypeId("10").courtLocationCode("court1") + .epimmsId("111").build(); + given(locationRefDataService.getCourtLocationsForDefaultJudgments(any())) + .willReturn(getSampleCourLocationsRefObject()); + given(locationHelper.updateCaseManagementLocation(any(), any(), any())).willReturn(Optional.ofNullable(locationRefData)); + } + @Test void shouldUpdateBusinessProcess() { CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued1v1LiP() .caseDataLip( CaseDataLiP.builder() .applicant1ClaimMediationSpecRequiredLip( @@ -81,10 +130,28 @@ void shouldUpdateBusinessProcess() { @Test void shouldOnlyUpdateClaimStatus_whenPartAdmitNotSettled_NoMediation() { + Applicant1DQ applicant1DQ = + Applicant1DQ.builder().applicant1DQRequestedCourt(RequestedCourt.builder() + .responseCourtCode("court1") + .caseLocation(CaseLocationCivil.builder() + .region(courtLocation) + .baseLocation(courtLocation) + .build()) + .build()).build(); + Respondent1DQ respondent1DQ = + Respondent1DQ.builder().respondent1DQRequestedCourt(RequestedCourt.builder() + .responseCourtCode("court2") + .caseLocation(CaseLocationCivil.builder() + .region(courtLocation) + .baseLocation(courtLocation) + .build()) + .build()).build(); CaseData caseData = CaseDataBuilder.builder() .atStateClaimIssued() .applicant1PartAdmitConfirmAmountPaidSpec(NO) .applicant1PartAdmitIntentionToSettleClaimSpec(NO) + .applicant1DQ(applicant1DQ) + .respondent1DQ(respondent1DQ) .applicant1AcceptAdmitAmountPaidSpec(NO) .caseDataLip(CaseDataLiP.builder().applicant1ClaimMediationSpecRequiredLip(ClaimantMediationLip.builder().hasAgreedFreeMediation( MediationDecision.No).build()) @@ -103,6 +170,10 @@ void shouldOnlyUpdateClaimStatus_whenPartAdmitNotSettled_NoMediation() { .extracting("status") .isEqualTo("READY"); + assertThat(response.getState()).isEqualTo(CaseState.JUDICIAL_REFERRAL.name()); + CaseData data = mapper.convertValue(response.getData(), CaseData.class); + assertThat(data.getApplicant1DQ().getApplicant1DQRequestedCourt().getResponseCourtCode()).isEqualTo("court1"); + assertThat(data.getCaseNameHmctsInternal()).isEqualTo(data.getApplicant1().getPartyName() + " v " + data.getRespondent1().getPartyName()); } @Test @@ -120,5 +191,59 @@ void shouldChangeCaseState_whenApplicantRejectClaimSettlementAndAgreeToMediation assertThat(response.getState()).isEqualTo(CaseState.IN_MEDIATION.name()); } + + protected List getSampleCourLocationsRefObject() { + return new ArrayList<>(List.of( + LocationRefData.builder() + .epimmsId("111").siteName("Site 1").courtAddress("Adr 1").postcode("AAA 111") + .courtLocationCode("court1").build(), + LocationRefData.builder() + .epimmsId("222").siteName("Site 2").courtAddress("Adr 2").postcode("BBB 222") + .courtLocationCode("court2").build(), + LocationRefData.builder() + .epimmsId("333").siteName("Site 3").courtAddress("Adr 3").postcode("CCC 333") + .courtLocationCode("court3").build() + )); + } + + @Test + void shouldChangeCaseState_whenApplicantRejectRepaymentPlanAndIsCompany_toAllFinalOrdersIssued() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .applicant1AcceptPartAdmitPaymentPlanSpec(NO) + .respondent1(Party.builder() + .type(COMPANY) + .companyName("Test Inc") + .build()) + .build(); + + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + assertThat(response.getState()).isEqualTo(CaseState.PROCEEDS_IN_HERITAGE_SYSTEM.name()); + } + + @Test + void shouldChangeCaseState_whenApplicantRejectRepaymentPlanAndIsOrganisation_toAllFinalOrdersIssued() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .applicant1AcceptPartAdmitPaymentPlanSpec(NO) + .respondent1(Party.builder() + .type(ORGANISATION) + .companyName("Test Inc") + .build()) + .build(); + + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + assertThat(response.getState()).isEqualTo(CaseState.PROCEEDS_IN_HERITAGE_SYSTEM.name()); + } } + + @Test + void handleEventsReturnsTheExpectedCallbackEvents() { + assertThat(handler.handledEvents()).containsOnly(CLAIMANT_RESPONSE_CUI); + } + } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateSDOCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateSDOCallbackHandlerTest.java index 208f29cbf58..505d72475f1 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateSDOCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateSDOCallbackHandlerTest.java @@ -1,9 +1,12 @@ package uk.gov.hmcts.reform.civil.handler.callback.user; import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.SneakyThrows; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; @@ -65,9 +68,11 @@ import java.util.stream.Collectors; import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START; @@ -76,6 +81,8 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_SDO; import static uk.gov.hmcts.reform.civil.enums.CaseCategory.SPEC_CLAIM; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; import static uk.gov.hmcts.reform.civil.handler.callback.user.CreateSDOCallbackHandler.CONFIRMATION_HEADER; import static uk.gov.hmcts.reform.civil.handler.callback.user.CreateSDOCallbackHandler.CONFIRMATION_SUMMARY_1v1; import static uk.gov.hmcts.reform.civil.handler.callback.user.CreateSDOCallbackHandler.CONFIRMATION_SUMMARY_1v2; @@ -142,6 +149,49 @@ void setup() { .thenReturn(LocalDate.now().plusDays(7)); } + @Test + void shouldPopulateLocationListsWithPreselectedCourt() { + Category category = Category.builder().categoryKey("HearingChannel").key("INTER").valueEn("In Person").activeFlag("Y").build(); + CategorySearchResult categorySearchResult = CategorySearchResult.builder().categories(List.of(category)).build(); + String preSelectedCourt = "214320"; + List locations = List.of( + LocationRefData.builder().epimmsId("00001").courtLocationCode("00001") + .siteName("court 1").courtAddress("1 address").postcode("Y01 7RB").build(), + LocationRefData.builder().epimmsId(preSelectedCourt).courtLocationCode(preSelectedCourt) + .siteName("court 2").courtAddress("2 address").postcode("Y02 7RB").build(), + LocationRefData.builder().epimmsId("00003").courtLocationCode("00003") + .siteName("court 3").courtAddress("3 address").postcode("Y03 7RB").build() + ); + when(locationRefDataService.getCourtLocationsForDefaultJudgments(anyString())).thenReturn(locations); + when(categoryService.findCategoryByCategoryIdAndServiceId(any(), any(), any())).thenReturn(Optional.of(categorySearchResult)); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft() + .atStateClaimIssuedDisposalHearingSDOInPersonHearing().build(); + + CallbackParams params = callbackParamsOf(CallbackVersion.V_1, caseData, ABOUT_TO_START); + CaseDocument order = CaseDocument.builder().documentLink( + Document.builder().documentUrl("url").build()) + .build(); + when(sdoGeneratorService.generate(any(), any())).thenReturn(order); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + CaseData responseCaseData = objectMapper.convertValue(response.getData(), CaseData.class); + + DynamicList expected = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code(preSelectedCourt).label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .value(DynamicListElement.builder().code(preSelectedCourt).label("court 2 - 2 address - Y02 7RB").build()) + .build(); + + assertThat(responseCaseData.getDisposalHearingMethodInPerson()).isEqualTo(expected); + assertThat(responseCaseData.getFastTrackMethodInPerson()).isEqualTo(expected); + assertThat(responseCaseData.getSmallClaimsMethodInPerson()).isEqualTo(expected); + } + @Test void shouldGenerateDynamicListsCorrectly() { Category category = Category.builder().categoryKey("HearingChannel").key("INTER").valueEn("In Person").activeFlag("Y").build(); @@ -194,8 +244,15 @@ class AboutToSubmitCallback { @BeforeEach void setup() { + List items = List.of("label 1", "label 2", "label 3"); + DynamicList options = DynamicList.fromList(items, Object::toString, items.get(0), false); caseData = CaseDataBuilder.builder().atStateClaimDraft() .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) + .build().toBuilder() + .disposalHearingMethodInPerson(options) + .fastTrackMethodInPerson(options) + .smallClaimsMethodInPerson(options) + .setFastTrackFlag(YES) .build(); params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); userId = UUID.randomUUID().toString(); @@ -206,11 +263,20 @@ void setup() { given(time.now()).willReturn(submittedDate); given(featureToggleService.isLocationWhiteListedForCaseProgression(anyString())).willReturn(true); + + given(featureToggleService.isEarlyAdoptersEnabled()).willReturn(true); } @Test void shouldUpdateBusinessProcess_whenInvoked() { - var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle( + params.toBuilder() + .caseData(params.getCaseData().toBuilder() + .claimsTrack(ClaimsTrack.smallClaimsTrack) + .drawDirectionsOrderRequired(NO) + .build()) + .build() + ); assertThat(response.getData()) .extracting("businessProcess") @@ -249,6 +315,8 @@ void shouldNotUpdateCaseLocation_whenDisposal() { .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) .disposalHearingMethod(DisposalHearingMethod.disposalHearingMethodInPerson) .disposalHearingMethodInPerson(options) + .fastTrackMethodInPerson(options) + .smallClaimsMethodInPerson(options) .disposalHearingMethodToggle(Collections.singletonList(OrderDetailsPagesSectionsToggle.SHOW)) .caseManagementLocation(previousManagementLocation) .build(); @@ -314,6 +382,8 @@ void shouldNotUpdateCaseLocation_whenSmallClaims() { CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) .smallClaimsMethod(SmallClaimsMethod.smallClaimsMethodInPerson) + .disposalHearingMethodInPerson(options) + .fastTrackMethodInPerson(options) .smallClaimsMethodInPerson(options) .claimsTrack(ClaimsTrack.smallClaimsTrack) .caseManagementLocation(previousManagementLocation) @@ -372,7 +442,7 @@ void shouldNotUpdateCaseLocation_whenFastTrackAndOrderRequired() { @Test void shouldNotUpdateCaseLocation_whenSmallClaimsAndOrderRequired() { List items = List.of("label 1", "label 2", "label 3"); - DynamicList options = DynamicList.fromList(items, Object::toString, items.get(0), false); + DynamicList options = DynamicList.fromList(items, Object::toString, Object::toString, items.get(0), false); CaseLocationCivil previousManagementLocation = CaseLocationCivil.builder() .region("previous region") .baseLocation("previous base location") @@ -380,6 +450,8 @@ void shouldNotUpdateCaseLocation_whenSmallClaimsAndOrderRequired() { CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) .smallClaimsMethod(SmallClaimsMethod.smallClaimsMethodInPerson) + .fastTrackMethodInPerson(options) + .disposalHearingMethodInPerson(options) .smallClaimsMethodInPerson(options) .drawDirectionsOrderRequired(YesOrNo.YES) .drawDirectionsOrderSmallClaims(YesOrNo.YES) @@ -404,8 +476,14 @@ void shouldNotUpdateCaseLocation_whenSmallClaimsAndOrderRequired() { @Test void shouldReturnNullDocument_whenInvokedAboutToSubmit() { + List items = List.of("label 1", "label 2", "label 3"); + DynamicList options = DynamicList.fromList(items, Object::toString, Object::toString, items.get(0), false); CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) + .build().toBuilder() + .fastTrackMethodInPerson(options) + .disposalHearingMethodInPerson(options) + .smallClaimsMethodInPerson(options) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -415,6 +493,212 @@ void shouldReturnNullDocument_whenInvokedAboutToSubmit() { } } + @ParameterizedTest + @CsvSource({"true", "false"}) + void shouldSetEarlyAdoptersFlag_whenDisposal(Boolean isLocationWhiteListed) { + DynamicList options = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .build(); + + DynamicListElement selectedCourt = DynamicListElement.builder() + .code("00002").label("court 2 - 2 address - Y02 7RB").build(); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() + .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) + .disposalHearingMethod(DisposalHearingMethod.disposalHearingMethodInPerson) + .disposalHearingMethodInPerson(options.toBuilder().value(selectedCourt).build()) + .fastTrackMethodInPerson(options) + .smallClaimsMethodInPerson(options) + .disposalHearingMethodInPerson(options.toBuilder().value(selectedCourt).build()) + .disposalHearingMethodToggle(Collections.singletonList(OrderDetailsPagesSectionsToggle.SHOW)) + .orderType(OrderType.DISPOSAL) + .build(); + + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(featureToggleService.isEarlyAdoptersEnabled()).thenReturn(true); + when(featureToggleService.isLocationWhiteListedForCaseProgression(eq(selectedCourt.getCode()))).thenReturn( + isLocationWhiteListed); + when(locationRefDataService.getLocationMatchingLabel(selectedCourt.getCode(), params.getParams().get( + CallbackParams.Params.BEARER_TOKEN).toString())) + .thenReturn(Optional.of(LocationRefData.builder() + .regionId("region id") + .epimmsId("epimms id") + .siteName("site name") + .build())); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData responseCaseData = objectMapper.convertValue(response.getData(), CaseData.class); + + assertThat(responseCaseData.getEaCourtLocation()).isEqualTo(isLocationWhiteListed ? YES : NO); + } + + @ParameterizedTest + @CsvSource({"true", "false"}) + void shouldSetEarlyAdoptersFlag_whenSmallClaims(Boolean isLocationWhiteListed) { + DynamicList options = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .build(); + + DynamicListElement selectedCourt = DynamicListElement.builder() + .code("00002").label("court 2 - 2 address - Y02 7RB").build(); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() + .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) + .smallClaimsMethod(SmallClaimsMethod.smallClaimsMethodInPerson) + .disposalHearingMethodInPerson(options) + .fastTrackMethodInPerson(options) + .smallClaimsMethodInPerson(options.toBuilder().value(selectedCourt).build()) + .claimsTrack(ClaimsTrack.smallClaimsTrack) + .setSmallClaimsFlag(YES) + .drawDirectionsOrderRequired(NO) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(featureToggleService.isEarlyAdoptersEnabled()).thenReturn(true); + when(featureToggleService.isLocationWhiteListedForCaseProgression(eq(selectedCourt.getCode()))).thenReturn( + isLocationWhiteListed); + when(locationRefDataService.getLocationMatchingLabel("label 1", params.getParams().get( + CallbackParams.Params.BEARER_TOKEN).toString())).thenReturn( + Optional.of(LocationRefData.builder() + .regionId("region id") + .epimmsId("epimms id") + .siteName("location name") + .build())); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData responseCaseData = objectMapper.convertValue(response.getData(), CaseData.class); + + assertThat(responseCaseData.getEaCourtLocation()).isEqualTo(isLocationWhiteListed ? YES : NO); + } + + @ParameterizedTest + @CsvSource({"true", "false"}) + void shouldSetEarlyAdoptersFlag_whenFastTrack(Boolean isLocationWhiteListed) { + DynamicList options = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .build(); + + DynamicListElement selectedCourt = DynamicListElement.builder() + .code("00002").label("court 2 - 2 address - Y02 7RB").build(); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() + .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) + .fastTrackMethod(FastTrackMethod.fastTrackMethodInPerson) + .smallClaimsMethodInPerson(options) + .fastTrackMethodInPerson(options.toBuilder().value(selectedCourt).build()) + .disposalHearingMethodInPerson(options) + .claimsTrack(ClaimsTrack.fastTrack) + .setFastTrackFlag(YES) + .drawDirectionsOrderRequired(NO) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(featureToggleService.isEarlyAdoptersEnabled()).thenReturn(true); + when(featureToggleService.isLocationWhiteListedForCaseProgression(eq(selectedCourt.getCode()))).thenReturn( + isLocationWhiteListed); + when(locationRefDataService.getLocationMatchingLabel("label 1", params.getParams().get( + CallbackParams.Params.BEARER_TOKEN).toString())).thenReturn( + Optional.of(LocationRefData.builder() + .regionId("region id") + .epimmsId("epimms id") + .siteName("location name") + .build())); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData responseCaseData = objectMapper.convertValue(response.getData(), CaseData.class); + + assertThat(responseCaseData.getEaCourtLocation()).isEqualTo(isLocationWhiteListed ? YES : NO); + } + + @Test + @SneakyThrows + void shouldThrowIllegalArgumentException_whenClaimTrackCannotDefined() { + DynamicList options = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .build(); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() + .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) + .fastTrackMethod(FastTrackMethod.fastTrackMethodInPerson) + .smallClaimsMethodInPerson(options) + .fastTrackMethodInPerson(options) + .disposalHearingMethodInPerson(options) + .claimsTrack(ClaimsTrack.fastTrack) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(featureToggleService.isEarlyAdoptersEnabled()).thenReturn(true); + when(locationRefDataService.getLocationMatchingLabel("label 1", params.getParams().get( + CallbackParams.Params.BEARER_TOKEN).toString())).thenReturn( + Optional.of(LocationRefData.builder() + .regionId("region id") + .epimmsId("epimms id") + .siteName("location name") + .build())); + + assertThrows(IllegalArgumentException.class, () -> handler.handle(params), + "Epimms Id is not provided" + ); + } + + @ParameterizedTest + @CsvSource({"true", "false"}) + void shouldNotSetEarlyAdoptersFlag_whenEarlyAdoptersToggleIsOff(Boolean isLocationWhiteListed) { + DynamicList options = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .build(); + + DynamicListElement selectedCourt = DynamicListElement.builder() + .code("00002").label("court 2 - 2 address - Y02 7RB").build(); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() + .caseManagementLocation(CaseLocationCivil.builder().baseLocation("00000").build()) + .fastTrackMethod(FastTrackMethod.fastTrackMethodInPerson) + .fastTrackMethodInPerson(options.toBuilder().value(selectedCourt).build()) + .smallClaimsMethodInPerson(options) + .disposalHearingMethodInPerson(options) + .claimsTrack(ClaimsTrack.fastTrack) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(featureToggleService.isEarlyAdoptersEnabled()).thenReturn(false); + when(featureToggleService.isLocationWhiteListedForCaseProgression(eq(selectedCourt.getCode()))).thenReturn( + isLocationWhiteListed); + when(locationRefDataService.getLocationMatchingLabel("label 1", params.getParams().get( + CallbackParams.Params.BEARER_TOKEN).toString())).thenReturn( + Optional.of(LocationRefData.builder() + .regionId("region id") + .epimmsId("epimms id") + .siteName("location name") + .build())); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData responseCaseData = objectMapper.convertValue(response.getData(), CaseData.class); + + assertThat(responseCaseData.getEaCourtLocation()).isNull(); + } + @Nested class MidEventDisposalHearingLocationRefDataCallback extends LocationRefSampleDataBuilder { diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadApplicantHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadApplicantHandlerTest.java index 5c0d9113902..3704297d425 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadApplicantHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadApplicantHandlerTest.java @@ -96,7 +96,32 @@ class EvidenceUploadApplicantHandlerTest extends BaseCallbackHandlerTest { private final UploadEvidenceExpert uploadEvidenceDate = new UploadEvidenceExpert(); private final UploadEvidenceWitness uploadEvidenceDate2 = new UploadEvidenceWitness(); private final UploadEvidenceDocumentType uploadEvidenceDate3 = new UploadEvidenceDocumentType(); - + private static final String NotificationWhenBothClaimant = "\n" + + "Both claimants - Disclosure list\n" + + "Both claimants - Documents for disclosure\n" + + "Both claimants - Documents referred to in the statement\n" + + "Both claimants - Expert's report\n" + + "Both claimants - Joint Statement of Experts / Single Joint Expert Report\n" + + "Both claimants - Questions for other party's expert or joint experts\n" + + "Both claimants - Answer to questions asked\n" + + "Both claimants - Case Summary\n" + + "Both claimants - Skeleton argument\n" + + "Both claimants - Authorities\n" + + "Both claimants - Costs\n" + + "Both claimants - Documentary evidence for trial"; + private static final String NotificationWhenClaimantTwo = "\n" + + "Claimant 2 - Disclosure list\n" + + "Claimant 2 - Documents for disclosure\n" + + "Claimant 2 - Documents referred to in the statement\n" + + "Claimant 2 - Expert's report\n" + + "Claimant 2 - Joint Statement of Experts / Single Joint Expert Report\n" + + "Claimant 2 - Questions for other party's expert or joint experts\n" + + "Claimant 2 - Answer to questions asked\n" + + "Claimant 2 - Case Summary\n" + + "Claimant 2 - Skeleton argument\n" + + "Claimant 2 - Authorities\n" + + "Claimant 2 - Costs\n" + + "Claimant 2 - Documentary evidence for trial"; private static final String PAGE_ID = "validateValuesApplicant"; @BeforeEach @@ -108,6 +133,7 @@ void setup() { void givenAboutToStart_assignCaseProgAllocatedTrackUnSpec() { // Given CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() + .notificationText(null) .claimType(ClaimType.CLINICAL_NEGLIGENCE) .claimValue(ClaimValue.builder() .statementOfValueInPennies(BigDecimal.valueOf(5000)) @@ -121,12 +147,14 @@ void givenAboutToStart_assignCaseProgAllocatedTrackUnSpec() { .handle(params); // Then assertThat(response.getData()).extracting("caseProgAllocatedTrack").isEqualTo("SMALL_CLAIM"); + assertThat(response.getData()).extracting("notificationText").isNull(); } @Test void givenAboutToStart_assignCaseProgAllocatedTrackSpec() { // Given CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() + .notificationText(null) .claimType(null) .totalClaimAmount(BigDecimal.valueOf(12500)) .build(); @@ -138,6 +166,7 @@ void givenAboutToStart_assignCaseProgAllocatedTrackSpec() { .handle(params); // Then assertThat(response.getData()).extracting("caseProgAllocatedTrack").isEqualTo("FAST_CLAIM"); + assertThat(response.getData()).extracting("notificationText").isNull(); } @Test @@ -496,6 +525,7 @@ void shouldAssignCategoryID_whenDocumentExists() { "hash", null); var documentUpload = UploadEvidenceWitness.builder() .witnessOptionUploadDate(LocalDate.of(2023, 2, 10)) + .createdDatetime(LocalDateTime.of(2022, 05, 10, 12, 13, 12)) .witnessOptionDocument(testDocument).build(); List> documentList = new ArrayList<>(); documentList.add(Element.builder().value(documentUpload).build()); @@ -676,7 +706,6 @@ void shouldBreakWhenThereIsAnyCaseBundlesWithNullCreatedDate() { @CsvSource({"0", "2"}) void should_do_naming_convention(String selected) { LocalDateTime createdDate = LocalDateTime.of(2022, 05, 10, 12, 13, 12); - String witnessName = "AppWitness"; LocalDate witnessDate = LocalDate.of(2023, 2, 10); List options = List.of(EvidenceUploadHandlerBase.OPTION_APP1, @@ -814,10 +843,137 @@ void should_do_naming_convention(String selected) { assertThat(updatedData.getDocumentCostsApp2().get(0).getValue() .getDocumentUpload().getDocumentFileName()).isEqualTo(TEST_FILE_NAME); assertThat(updatedData.getDocumentCostsApp2().get(0).getValue() - .getDocumentUpload().getCategoryID()).isEqualTo(EvidenceUploadHandlerBase.APPLICANT_TWO_ANY_PRECEDENT_H); + .getDocumentUpload().getCategoryID()).isEqualTo(EvidenceUploadHandlerBase.APPLICANT_TWO_SCHEDULE_OF_COSTS); + assertThat(updatedData.getNotificationText()).isEqualTo(NotificationWhenBothClaimant); } } + @Test + void should_do_naming_convention_app2() { + LocalDateTime createdDate = LocalDateTime.of(2022, 05, 10, 12, 13, 12); + List> witnessEvidenceDocs = new ArrayList<>(); + String witnessName = "appTwoWitness"; + List options = List.of(EvidenceUploadHandlerBase.OPTION_APP1, + EvidenceUploadHandlerBase.OPTION_APP2, + EvidenceUploadHandlerBase.OPTION_APP_BOTH); + LocalDate witnessDate = LocalDate.of(2023, 2, 10); + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .addApplicant2(YES) + .applicant1(PartyBuilder.builder().individual().build()) + .applicant2(PartyBuilder.builder().individual().build()) + .evidenceUploadOptions(DynamicList.fromList(options, Object::toString, options.get(1), false)) + .documentWitnessSummaryApp2(createWitnessDocs(witnessName, createdDate, witnessDate)) + .documentWitnessStatementApp2(createWitnessDocs(witnessName, createdDate, witnessDate)) + .documentHearsayNoticeApp2(createWitnessDocs(witnessName, createdDate, witnessDate)) + .documentExpertReportApp2(createExpertDocs("expertName", witnessDate, "expertise", null, null, null, null)) + .documentJointStatementApp2(createExpertDocs("expertsName", witnessDate, null, "expertises", null, null, null)) + .documentQuestionsApp2(createExpertDocs("expertName", witnessDate, null, null, "other", "question", null)) + .documentAnswersApp2(createExpertDocs("expertName", witnessDate, null, null, "other", null, "answer")) + .documentForDisclosureApp2(createEvidenceDocs("typeDisclosure", witnessDate)) + .documentReferredInStatementApp2(createEvidenceDocs("typeReferred", witnessDate)) + .documentEvidenceForTrialApp2(createEvidenceDocs("typeForTrial", witnessDate)) + .documentDisclosureListApp2(createEvidenceDocs(null, null)) + .documentCaseSummaryApp2(createEvidenceDocs(null, null)) + .documentSkeletonArgumentApp2(createEvidenceDocs(null, null)) + .documentAuthoritiesApp2(createEvidenceDocs(null, null)) + .documentCostsApp2(createEvidenceDocs(null, null)) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + given(userService.getUserInfo(anyString())).willReturn(UserInfo.builder().uid("uid").build()); + + given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).willReturn(false); + given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).willReturn(false); + + // When handle is called + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + + // Then applicant docs should have name changed + assertThat(updatedData.getDocumentWitnessSummaryApp2().get(0).getValue() + .getWitnessOptionDocument().getDocumentFileName()).isEqualTo("Witness Summary of appTwoWitness.pdf"); + assertThat(updatedData.getDocumentWitnessStatementApp2().get(0).getValue() + .getWitnessOptionDocument().getDocumentFileName()).isEqualTo("Witness Statement of appTwoWitness 10-02-2023.pdf"); + assertThat(updatedData.getDocumentHearsayNoticeApp2().get(0).getValue() + .getWitnessOptionDocument().getDocumentFileName()).isEqualTo("Hearsay evidence appTwoWitness 10-02-2023.pdf"); + assertThat(updatedData.getDocumentExpertReportApp2().get(0).getValue() + .getExpertDocument().getDocumentFileName()).isEqualTo("Experts report expertName expertise 10-02-2023.pdf"); + assertThat(updatedData.getDocumentJointStatementApp2().get(0).getValue() + .getExpertDocument().getDocumentFileName()).isEqualTo("Joint report expertsName expertises 10-02-2023.pdf"); + assertThat(updatedData.getDocumentQuestionsApp2().get(0).getValue() + .getExpertDocument().getDocumentFileName()).isEqualTo("expertName other question.pdf"); + assertThat(updatedData.getDocumentAnswersApp2().get(0).getValue() + .getExpertDocument().getDocumentFileName()).isEqualTo("expertName other answer.pdf"); + assertThat(updatedData.getDocumentForDisclosureApp2().get(0).getValue() + .getDocumentUpload().getDocumentFileName()).isEqualTo("Document for disclosure typeDisclosure 10-02-2023.pdf"); + assertThat(updatedData.getDocumentReferredInStatementApp2().get(0).getValue() + .getDocumentUpload().getDocumentFileName()).isEqualTo("Referred Document typeReferred 10-02-2023.pdf"); + assertThat(updatedData.getDocumentEvidenceForTrialApp2().get(0).getValue() + .getDocumentUpload().getDocumentFileName()).isEqualTo("Documentary Evidence typeForTrial 10-02-2023.pdf"); + assertThat(updatedData.getDocumentDisclosureListApp2().get(0).getValue() + .getDocumentUpload().getDocumentFileName()).isEqualTo(TEST_FILE_NAME); + assertThat(updatedData.getDocumentCaseSummaryApp2().get(0).getValue() + .getDocumentUpload().getDocumentFileName()).isEqualTo(TEST_FILE_NAME); + assertThat(updatedData.getDocumentSkeletonArgumentApp2().get(0).getValue() + .getDocumentUpload().getDocumentFileName()).isEqualTo(TEST_FILE_NAME); + assertThat(updatedData.getDocumentAuthoritiesApp2().get(0).getValue() + .getDocumentUpload().getDocumentFileName()).isEqualTo(TEST_FILE_NAME); + assertThat(updatedData.getDocumentCostsApp2().get(0).getValue() + .getDocumentUpload().getDocumentFileName()).isEqualTo(TEST_FILE_NAME); + assertThat(updatedData.getNotificationText()).isEqualTo(NotificationWhenClaimantTwo); + } + + @Test + void shouldNotAddSameNotificationIfAlreadyAdded_notificationText() { + // If we populate notification string with an entry, we do not want to duplicate that on further uploads of same type. + List options = List.of(EvidenceUploadHandlerBase.OPTION_APP1, + EvidenceUploadHandlerBase.OPTION_APP2, + EvidenceUploadHandlerBase.OPTION_APP_BOTH); + LocalDate witnessDate = LocalDate.of(2023, 2, 10); + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .notificationText("Documentation that has been uploaded: \n\n Claimant 1 - Joint Statement of Experts / Single Joint Expert Report \n") + .applicant1(PartyBuilder.builder().individual().build()) + .evidenceUploadOptions(DynamicList.fromList(options, Object::toString, options.get(0), false)) + .documentJointStatement(createExpertDocs("expertsName", witnessDate, null, "expertises", null, null, null)) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + given(userService.getUserInfo(anyString())).willReturn(UserInfo.builder().uid("uid").build()); + given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).willReturn(false); + given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).willReturn(false); + given(coreCaseDataService.getCase(anyLong())).willReturn(CaseDetails.builder().build()); + // When handle is called + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + // Then Notificcation should not have a duplicate entry + assertThat(updatedData.getNotificationText()) + .isEqualTo("Documentation that has been uploaded: \n\n Claimant 1 - Joint Statement of Experts / Single Joint Expert Report \n"); + } + + @Test + void shouldNotPopulateNotificationWithOldDocument_whenNewDocumentUploadAdded() { + // When evidence upload is retriggered we do not send a notification for old content i.e uploaded before midnight of current day + List options = List.of(EvidenceUploadHandlerBase.OPTION_APP1, + EvidenceUploadHandlerBase.OPTION_APP2, + EvidenceUploadHandlerBase.OPTION_APP_BOTH); + LocalDate witnessDate = LocalDate.of(2023, 2, 10); + String witnessName = "Witness"; + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .notificationText(null) + .evidenceUploadOptions(DynamicList.fromList(options, Object::toString, options.get(0), false)) + .documentWitnessStatement(createWitnessDocs(witnessName, LocalDateTime.now().minusDays(2), witnessDate)) + .documentWitnessSummary(createWitnessDocs(witnessName, LocalDateTime.now(), witnessDate)) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + given(userService.getUserInfo(anyString())).willReturn(UserInfo.builder().uid("uid").build()); + given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).willReturn(false); + given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).willReturn(false); + given(coreCaseDataService.getCase(anyLong())).willReturn(CaseDetails.builder().build()); + // When handle is called + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + // Then Notification should not have old entry (witness statement) + assertThat(updatedData.getNotificationText()).isEqualTo("\nClaimant 1 - Witness summary"); + } + private List> createEvidenceDocs(String type, LocalDate issuedDate) { Document document = Document.builder().documentBinaryUrl( TEST_URL) diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadJudgeHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadJudgeHandlerTest.java index ddc7d79823c..d37c56db259 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadJudgeHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadJudgeHandlerTest.java @@ -97,20 +97,115 @@ void shouldPopulateNoteDateTime_whenNoteIsAddedToCase() { assertThat(response.getData()).extracting("caseNotesTA") .isEqualTo(objectMapper.convertValue(updatedCaseNotes, new TypeReference<>() {})); + assertThat(response.getData()).extracting("documentAndName").isNull(); + assertThat(response.getData()).extracting("documentAndNote").isNull(); + } + + @Test + void shouldCopyDocumentAndNameToAdd_whenDocumentWithNameIsNull() { + Document document = Document.builder().documentFileName("fileName").build(); + DocumentWithName testDocument = DocumentWithName.builder() + .documentName("testDocument") + .document(document) + .build(); + List> documentWithNameToAdd = wrapElements(testDocument); + + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .caseNoteType(CaseNoteType.DOCUMENT_ONLY) + .documentAndNameToAdd(documentWithNameToAdd) + .caseNoteTA(null) + .build(); + + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + assertThat(response.getData()).extracting("documentAndName") + .isEqualTo(objectMapper.convertValue(documentWithNameToAdd, new TypeReference<>() {})); + assertThat(response.getData()).extracting("caseNotesTA").isNull(); + assertThat(response.getData()).extracting("documentAndNote").isNull(); } @Test - void shouldNotPopulateNoteDateTime_whenNoteIsAddedToCase() { + void shouldAddDocument_whenDocumentWithNameIsNotNull() { + Document document = Document.builder().documentFileName("fileName").build(); + DocumentWithName testDocument = DocumentWithName.builder() + .documentName("testDocument") + .document(document) + .build(); + List> documentWithNameToAdd = wrapElements(testDocument); + List> documentWithNameStart = wrapElements(testDocument); + List> documentWithNameEnd = wrapElements(testDocument, testDocument); + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() .caseNoteType(CaseNoteType.DOCUMENT_ONLY) + .documentAndNameToAdd(documentWithNameToAdd) + .documentAndName(documentWithNameStart) .caseNoteTA(null) .build(); + + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + assertThat(response.getData()).extracting("documentAndName") + .isEqualTo(objectMapper.convertValue(documentWithNameEnd, new TypeReference<>() {})); + assertThat(response.getData()).extracting("caseNotesTA").isNull(); + assertThat(response.getData()).extracting("documentAndNote").isNull(); + + } + + @Test + void shouldAddNote_whenDocumentWithNoteIsNotNull() { + Document document = Document.builder().documentFileName("fileName").build(); + DocumentAndNote testDocument = DocumentAndNote.builder() + .documentName("testDocument") + .document(document) + .documentNote("Note") + .build(); + List> documentAndNoteToAdd = wrapElements(testDocument); + List> documentAndNoteStart = wrapElements(testDocument); + List> documentAndNoteEnd = wrapElements(testDocument, testDocument); + + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .caseNoteType(CaseNoteType.DOCUMENT_AND_NOTE) + .documentAndNoteToAdd(documentAndNoteToAdd) + .documentAndNote(documentAndNoteStart) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + assertThat(response.getData()).extracting("documentAndNote") + .isEqualTo(objectMapper.convertValue(documentAndNoteEnd, new TypeReference<>() {})); + assertThat(response.getData()).extracting("caseNotesTA").isNull(); + assertThat(response.getData()).extracting("documentAndName").isNull(); + + } + + @Test + void shouldCopyDocumentAndNoteToAdd_whenDocumentWithNoteIsNull() { + Document document = Document.builder().documentFileName("fileName").build(); + DocumentAndNote testDocument = DocumentAndNote.builder() + .documentName("testDocument") + .document(document) + .documentNote("Note") + .build(); + List> documentAndNoteToAdd = wrapElements(testDocument); + + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .caseNoteType(CaseNoteType.DOCUMENT_AND_NOTE) + .documentAndNoteToAdd(documentAndNoteToAdd) + .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + assertThat(response.getData()).extracting("documentAndNote") + .isEqualTo(objectMapper.convertValue(documentAndNoteToAdd, new TypeReference<>() {})); assertThat(response.getData()).extracting("caseNotesTA").isNull(); + assertThat(response.getData()).extracting("documentAndName").isNull(); } } @@ -133,7 +228,7 @@ void shouldPopulateConfirmation_DocumentAndNote() { documentList.add(Element.builder().value(documentAndNote).build()); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() - .documentAndNote(documentList) + .documentAndNoteToAdd(documentList) .caseNoteType(CaseNoteType.DOCUMENT_AND_NOTE) .build(); CallbackParams params = callbackParamsOf(caseData, CallbackType.SUBMITTED); @@ -162,7 +257,7 @@ void submittedCallback_documentOnly() { documentList.add(Element.builder().value(documentAndNote).build()); CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() - .documentAndName(documentList) + .documentAndNameToAdd(documentList) .caseNoteType(CaseNoteType.DOCUMENT_ONLY) .build(); CallbackParams params = callbackParamsOf(caseData, CallbackType.SUBMITTED); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadRespondentHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadRespondentHandlerTest.java index 82478e5d0af..d5c32eeac09 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadRespondentHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/EvidenceUploadRespondentHandlerTest.java @@ -111,7 +111,32 @@ class EvidenceUploadRespondentHandlerTest extends BaseCallbackHandlerTest { private final UploadEvidenceExpert uploadEvidenceDate = new UploadEvidenceExpert(); private final UploadEvidenceWitness uploadEvidenceDate2 = new UploadEvidenceWitness(); private final UploadEvidenceDocumentType uploadEvidenceDate3 = new UploadEvidenceDocumentType(); - + private static final String NotificationWhenBothDefendant = "\n" + + "Both defendants - Disclosure list\n" + + "Both defendants - Documents for disclosure\n" + + "Both defendants - Documents referred to in the statement\n" + + "Both defendants - Expert's report\n" + + "Both defendants - Joint Statement of Experts / Single Joint Expert Report\n" + + "Both defendants - Questions for other party's expert or joint experts\n" + + "Both defendants - Answer to questions asked\n" + + "Both defendants - Case Summary\n" + + "Both defendants - Skeleton argument\n" + + "Both defendants - Authorities\n" + + "Both defendants - Costs\n" + + "Both defendants - Documentary evidence for trial"; + private static final String NotificationWhenDefendantTwo = "\n" + + "Defendant 2 - Disclosure list\n" + + "Defendant 2 - Documents for disclosure\n" + + "Defendant 2 - Documents referred to in the statement\n" + + "Defendant 2 - Expert's report\n" + + "Defendant 2 - Joint Statement of Experts / Single Joint Expert Report\n" + + "Defendant 2 - Questions for other party's expert or joint experts\n" + + "Defendant 2 - Answer to questions asked\n" + + "Defendant 2 - Case Summary\n" + + "Defendant 2 - Skeleton argument\n" + + "Defendant 2 - Authorities\n" + + "Defendant 2 - Costs\n" + + "Defendant 2 - Documentary evidence for trial"; private static final String PAGE_ID = "validateValuesRespondent"; @BeforeEach @@ -123,6 +148,7 @@ void setup() { void givenAboutToStart_assignCaseProgAllocatedTrackUnSpec() { // Given CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() + .notificationText("NULLED") .claimType(ClaimType.CLINICAL_NEGLIGENCE) .claimValue(ClaimValue.builder() .statementOfValueInPennies(BigDecimal.valueOf(5000)) @@ -136,12 +162,14 @@ void givenAboutToStart_assignCaseProgAllocatedTrackUnSpec() { .handle(params); // Then assertThat(response.getData()).extracting("caseProgAllocatedTrack").isEqualTo("SMALL_CLAIM"); + assertThat(response.getData()).extracting("notificationText").isNull(); } @Test void givenAboutToStart_assignCaseProgAllocatedTrackSpec() { // Given CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() + .notificationText(null) .claimType(null) .totalClaimAmount(BigDecimal.valueOf(12500)) .build(); @@ -153,12 +181,14 @@ void givenAboutToStart_assignCaseProgAllocatedTrackSpec() { .handle(params); // Then assertThat(response.getData()).extracting("caseProgAllocatedTrack").isEqualTo("FAST_CLAIM"); + assertThat(response.getData()).extracting("notificationText").isNull(); } @Test void givenAboutToStart_1v2SameSolicitor_shouldShowOptions() { // Given CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() + .notificationText("existing notification") .claimType(null) .totalClaimAmount(BigDecimal.valueOf(12500)) .addRespondent2(YES) @@ -172,6 +202,7 @@ void givenAboutToStart_1v2SameSolicitor_shouldShowOptions() { .handle(params); // Then assertThat(response.getData()).extracting("evidenceUploadOptions").isNotNull(); + assertThat(response.getData()).extracting("notificationText").isEqualTo("existing notification"); } @ParameterizedTest @@ -997,7 +1028,8 @@ void shouldAssignCategoryID_whenDocumentExistsTwoRespondentSpec() { "testBinUrl", "A Fancy Name", "hash", null); var documentUpload = UploadEvidenceDocumentType.builder() - .documentIssuedDate(LocalDate.of(2023, 2, 10)) + .documentIssuedDate(LocalDate.of(2022, 2, 10)) + .createdDatetime(LocalDateTime.of(2022, 05, 10, 12, 13, 12)) .documentUpload(testDocument).build(); List> documentList = new ArrayList<>(); documentList.add(Element.builder().value(documentUpload).build()); @@ -1023,7 +1055,8 @@ void shouldAssignCategoryID_whenDocumentExistsTwoRespondentUnSpec() { "testBinUrl", "A Fancy Name", "hash", null); var documentUpload = UploadEvidenceDocumentType.builder() - .documentIssuedDate(LocalDate.of(2023, 2, 10)) + .documentIssuedDate(LocalDate.of(2022, 2, 10)) + .createdDatetime(LocalDateTime.of(2022, 05, 10, 12, 13, 12)) .documentUpload(testDocument).build(); List> documentList = new ArrayList<>(); documentList.add(Element.builder().value(documentUpload).build()); @@ -1048,7 +1081,10 @@ void shouldAssignCategoryID_whenDocumentExistsOneRespondentSpec() { Document testDocument = new Document("testurl", "testBinUrl", "A Fancy Name", "hash", null); - var documentUpload = UploadEvidenceExpert.builder().expertDocument(testDocument).build(); + var documentUpload = UploadEvidenceExpert.builder() + .expertDocument(testDocument) + .createdDatetime(LocalDateTime.of(2022, 05, 10, 12, 13, 12)) + .build(); List> documentList = new ArrayList<>(); documentList.add(Element.builder().value(documentUpload).build()); // Given @@ -1073,7 +1109,10 @@ void shouldAssignCategoryID_whenDocumentExistsOneRespondentUnSpec() { Document testDocument = new Document("testurl", "testBinUrl", "A Fancy Name", "hash", null); - var documentUpload = UploadEvidenceExpert.builder().expertDocument(testDocument).build(); + var documentUpload = UploadEvidenceExpert.builder() + .expertDocument(testDocument) + .createdDatetime(LocalDateTime.of(2022, 05, 10, 12, 13, 12)) + .build(); List> documentList = new ArrayList<>(); documentList.add(Element.builder().value(documentUpload).build()); // Given @@ -1273,7 +1312,6 @@ void shouldBreakWhenThereIsAnyCaseBundlesWithNullCreatedDate() { @CsvSource({"0", "2"}) void should_do_naming_convention_resp1(String selected) { LocalDateTime createdDate = LocalDateTime.of(2022, 05, 10, 12, 13, 12); - List> witnessEvidenceDocs = new ArrayList<>(); String witnessName = "ResOneWitness"; List options = List.of(EvidenceUploadHandlerBase.OPTION_DEF1, @@ -1413,7 +1451,8 @@ void should_do_naming_convention_resp1(String selected) { assertThat(updatedData.getDocumentCostsRes2().get(0).getValue() .getDocumentUpload().getDocumentFileName()).isEqualTo(TEST_FILE_NAME); assertThat(updatedData.getDocumentCostsRes2().get(0).getValue() - .getDocumentUpload().getCategoryID()).isEqualTo(EvidenceUploadHandlerBase.RESPONDENT_TWO_ANY_PRECEDENT_H); + .getDocumentUpload().getCategoryID()).isEqualTo(EvidenceUploadHandlerBase.RESPONDENT_TWO_SCHEDULE_OF_COSTS); + assertThat(updatedData.getNotificationText()).contains(NotificationWhenBothDefendant); } } @@ -1484,6 +1523,59 @@ void should_do_naming_convention_resp2() { .getDocumentUpload().getDocumentFileName()).isEqualTo(TEST_FILE_NAME); assertThat(updatedData.getDocumentCostsRes2().get(0).getValue() .getDocumentUpload().getDocumentFileName()).isEqualTo(TEST_FILE_NAME); + assertThat(updatedData.getNotificationText()).isEqualTo(NotificationWhenDefendantTwo); + } + + @Test + void shouldNotAddSameNotificationIfAlreadyAdded_notificationText() { + // If we populate notification string with an entry, we do not want to duplicate that on further uploads of same type. + List options = List.of(EvidenceUploadHandlerBase.OPTION_DEF1, + EvidenceUploadHandlerBase.OPTION_DEF2, + EvidenceUploadHandlerBase.OPTION_DEF_BOTH); + LocalDate witnessDate = LocalDate.of(2023, 2, 10); + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .notificationText("Documentation that has been uploaded: \n\n Defendant 1 - Joint Statement of Experts / Single Joint Expert Report \n") + .applicant1(PartyBuilder.builder().individual().build()) + .evidenceUploadOptions(DynamicList.fromList(options, Object::toString, options.get(0), false)) + .documentJointStatementRes(createExpertDocs("expertsName", witnessDate, null, "expertises", null, null, null)) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + given(userService.getUserInfo(anyString())).willReturn(UserInfo.builder().uid("uid").build()); + given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).willReturn(true); + given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).willReturn(false); + given(coreCaseDataService.getCase(anyLong())).willReturn(CaseDetails.builder().build()); + // When handle is called + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + // Then Notificcation should not have a duplicate entry + assertThat(updatedData.getNotificationText()) + .isEqualTo("Documentation that has been uploaded: \n\n Defendant 1 - Joint Statement of Experts / Single Joint Expert Report \n"); + } + + @Test + void shouldNotPopulateNotificationWithOldDocument_whenNewDocumentUploadAdded() { + // When evidence upload is retriggered we do not send a notification for old content i.e uploaded before midnight of current day + List options = List.of(EvidenceUploadHandlerBase.OPTION_DEF1, + EvidenceUploadHandlerBase.OPTION_DEF2, + EvidenceUploadHandlerBase.OPTION_DEF_BOTH); + LocalDate witnessDate = LocalDate.of(2023, 2, 10); + String witnessName = "Witness"; + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .notificationText(null) + .evidenceUploadOptions(DynamicList.fromList(options, Object::toString, options.get(0), false)) + .documentWitnessStatementRes(createWitnessDocs(witnessName, LocalDateTime.now().minusDays(2), witnessDate)) + .documentWitnessSummaryRes(createWitnessDocs(witnessName, LocalDateTime.now(), witnessDate)) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + given(userService.getUserInfo(anyString())).willReturn(UserInfo.builder().uid("uid").build()); + given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).willReturn(true); + given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).willReturn(false); + given(coreCaseDataService.getCase(anyLong())).willReturn(CaseDetails.builder().build()); + // When handle is called + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + // Then Notification should not have old entry (witness statement) + assertThat(updatedData.getNotificationText()).isEqualTo("\nDefendant 1 - Witness summary"); } @Test diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/GenerateDirectionOrderCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/GenerateDirectionOrderCallbackHandlerTest.java index f4405df2cfd..9891b5f8586 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/GenerateDirectionOrderCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/GenerateDirectionOrderCallbackHandlerTest.java @@ -275,6 +275,18 @@ void shouldPopulateFields_whenIsCalledAfterSdo() { assertThat(response.getData()).extracting("assistedOrderMakeAnOrderForCosts") .extracting("makeAnOrderForCostsQOCSYesOrNo") .isEqualTo("No"); + assertThat(response.getData()).extracting("assistedOrderMakeAnOrderForCosts") + .extracting("makeAnOrderForCostsList") + .isEqualTo("CLAIMANT"); + assertThat(response.getData()).extracting("assistedOrderMakeAnOrderForCosts") + .extracting("assistedOrderClaimantDefendantFirstDropdown") + .isEqualTo("SUBJECT_DETAILED_ASSESSMENT"); + assertThat(response.getData()).extracting("assistedOrderMakeAnOrderForCosts") + .extracting("assistedOrderAssessmentSecondDropdownList1") + .isEqualTo("STANDARD_BASIS"); + assertThat(response.getData()).extracting("assistedOrderMakeAnOrderForCosts") + .extracting("assistedOrderAssessmentSecondDropdownList2") + .isEqualTo("NO"); assertThat(response.getData()).extracting("publicFundingCostsProtection") .isEqualTo("No"); assertThat(response.getData()).extracting("finalOrderAppealComplex") @@ -334,7 +346,7 @@ void shouldPopulateFields_whenIsCalledAfterSdoDiffSol() { } } - + @Nested class MidEventValidateAndGenerateOrderDocumentPreview { private static final String PAGE_ID = "validate-and-generate-document"; @@ -421,6 +433,14 @@ static Stream validAssistedOrderDates() { .datesToAvoidDates(LocalDate.now().plusDays(2)) .build()).build()).build() ), + Arguments.of( + CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .finalOrderSelection(FinalOrderSelection.ASSISTED_ORDER) + .finalOrderFurtherHearingComplex(FinalOrderFurtherHearing.builder() + .dateToDate(LocalDate.now().minusDays(4)) + .listFromDate(LocalDate.now().minusDays(5)) + .build()).build() + ), Arguments.of( CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() .finalOrderSelection(FinalOrderSelection.ASSISTED_ORDER) @@ -532,7 +552,16 @@ static Stream invalidAssistedOrderDates() { "The date in Further hearing may not be before the established date" ), Arguments.of( - CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .finalOrderSelection(FinalOrderSelection.ASSISTED_ORDER) + .finalOrderFurtherHearingComplex(FinalOrderFurtherHearing.builder() + .dateToDate(LocalDate.now().minusDays(5)) + .listFromDate(LocalDate.now().minusDays(4)) + .build()).build(), + "The date range in Further hearing may not have a 'from date', that is after the 'date to'" + ), + Arguments.of( + CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() .finalOrderSelection(FinalOrderSelection.ASSISTED_ORDER) .assistedOrderMakeAnOrderForCosts(AssistedOrderCostDetails.builder() .assistedOrderCostsFirstDropdownDate(LocalDate.now().minusDays(2)) @@ -760,10 +789,10 @@ void shouldAddDocumentToCollection_onAboutToSubmit() { CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() .finalOrderSelection(FinalOrderSelection.ASSISTED_ORDER) .finalOrderDocumentCollection(finalCaseDocuments) + .finalOrderDocument(finalOrder) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); // When - when(judgeFinalOrderGenerator.generate(any(), any())).thenReturn(finalOrder); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); // Then @@ -780,10 +809,10 @@ void shouldChangeStateToFinalOrder_onAboutToSubmitAndFreeFormOrder() { CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() .finalOrderSelection(FinalOrderSelection.FREE_FORM_ORDER) .finalOrderDocumentCollection(finalCaseDocuments) + .finalOrderDocument(finalOrder) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); // When - when(judgeFinalOrderGenerator.generate(any(), any())).thenReturn(finalOrder); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); // Then assertThat(response.getState()).isEqualTo("All_FINAL_ORDERS_ISSUED"); @@ -798,10 +827,10 @@ void shouldChangeStateToFinalOrder_onAboutToSubmitAndAssistedOrderAndNoFurtherHe .finalOrderSelection(FinalOrderSelection.ASSISTED_ORDER) .finalOrderFurtherHearingToggle(null) .finalOrderDocumentCollection(finalCaseDocuments) + .finalOrderDocument(finalOrder) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); // When - when(judgeFinalOrderGenerator.generate(any(), any())).thenReturn(finalOrder); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); // Then assertThat(response.getState()).isEqualTo("All_FINAL_ORDERS_ISSUED"); @@ -818,10 +847,10 @@ void shouldChangeStateToCaseProgression_onAboutToSubmitAndAssistedOrderWithFurth .finalOrderSelection(FinalOrderSelection.ASSISTED_ORDER) .finalOrderFurtherHearingToggle(toggle) .finalOrderDocumentCollection(finalCaseDocuments) + .finalOrderDocument(finalOrder) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); // When - when(judgeFinalOrderGenerator.generate(any(), any())).thenReturn(finalOrder); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); // Then assertThat(response.getState()).isEqualTo("CASE_PROGRESSION"); @@ -835,17 +864,34 @@ void shouldRePopulateHearingNotes_whenAssistedHearingNotesExist() { CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() .finalOrderSelection(FinalOrderSelection.ASSISTED_ORDER) .finalOrderFurtherHearingToggle(toggle) + .finalOrderDocument(finalOrder) .finalOrderFurtherHearingComplex(FinalOrderFurtherHearing.builder() .hearingNotesText("test text hearing notes assisted order").build()) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); // When - when(judgeFinalOrderGenerator.generate(any(), any())).thenReturn(finalOrder); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); // Then assertThat(response.getData()).extracting("hearingNotes").extracting("notes").isEqualTo("test text hearing notes assisted order"); } + @Test + void shouldRePopulateHearingNotes_whenFreeFormHearingNotesExist() { + // Given + List toggle = new ArrayList<>(); + toggle.add(FinalOrderToggle.SHOW); + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .finalOrderSelection(FinalOrderSelection.FREE_FORM_ORDER) + .freeFormHearingNotes("test text hearing notes free form order") + .finalOrderDocument(finalOrder) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + // When + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + // Then + assertThat(response.getData()).extracting("hearingNotes").extracting("notes").isEqualTo("test text hearing notes free form order"); + } + @Test void shouldNotRePopulateHearingNotes_whenAssistedHearingNotesDoNotExist() { // Given @@ -854,11 +900,29 @@ void shouldNotRePopulateHearingNotes_whenAssistedHearingNotesDoNotExist() { CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() .finalOrderSelection(FinalOrderSelection.ASSISTED_ORDER) .finalOrderFurtherHearingToggle(toggle) + .finalOrderDocument(finalOrder) .hearingNotes(HearingNotes.builder().notes("preexisting hearing notes").build()) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); // When - when(judgeFinalOrderGenerator.generate(any(), any())).thenReturn(finalOrder); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + // Then + assertThat(response.getData()).extracting("hearingNotes").extracting("notes").isEqualTo("preexisting hearing notes"); + } + + @Test + void shouldNotRePopulateHearingNotes_whenFreeFormHearingNotesDoNotExist() { + // Given + List toggle = new ArrayList<>(); + toggle.add(FinalOrderToggle.SHOW); + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .finalOrderSelection(FinalOrderSelection.FREE_FORM_ORDER) + .finalOrderFurtherHearingToggle(toggle) + .hearingNotes(HearingNotes.builder().notes("preexisting hearing notes").build()) + .finalOrderDocument(finalOrder) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + // When var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); // Then assertThat(response.getData()).extracting("hearingNotes").extracting("notes").isEqualTo("preexisting hearing notes"); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandlerTest.java index 832084cce8f..8ff9b667be7 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ManageContactInformationCallbackHandlerTest.java @@ -4,40 +4,80 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; +import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CallbackType; +import uk.gov.hmcts.reform.civil.enums.CaseCategory; import uk.gov.hmcts.reform.civil.enums.CaseState; import uk.gov.hmcts.reform.civil.enums.RespondentResponseType; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; +import uk.gov.hmcts.reform.civil.model.Address; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.Party; +import uk.gov.hmcts.reform.civil.model.UpdateDetailsForm; +import uk.gov.hmcts.reform.civil.model.UpdatePartyDetailsForm; +import uk.gov.hmcts.reform.civil.model.common.DynamicList; +import uk.gov.hmcts.reform.civil.model.common.DynamicListElement; +import uk.gov.hmcts.reform.civil.model.common.Element; +import uk.gov.hmcts.reform.civil.model.dq.Applicant1DQ; +import uk.gov.hmcts.reform.civil.model.dq.Expert; +import uk.gov.hmcts.reform.civil.model.dq.Experts; +import uk.gov.hmcts.reform.civil.model.dq.Respondent1DQ; +import uk.gov.hmcts.reform.civil.model.dq.Respondent2DQ; +import uk.gov.hmcts.reform.civil.model.dq.Witness; +import uk.gov.hmcts.reform.civil.model.dq.Witnesses; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.service.CoreCaseUserService; +import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser; +import uk.gov.hmcts.reform.civil.validation.PostcodeValidator; import uk.gov.hmcts.reform.idam.client.models.UserInfo; - +import java.time.LocalDate; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; -import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED; +import static uk.gov.hmcts.reform.civil.callback.CallbackType.MID; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; import static uk.gov.hmcts.reform.civil.model.Party.Type.COMPANY; +import static uk.gov.hmcts.reform.civil.model.Party.Type.INDIVIDUAL; import static uk.gov.hmcts.reform.civil.utils.DynamicListUtils.listFromDynamicList; +import static uk.gov.hmcts.reform.civil.utils.ElementUtils.unwrapElements; +import static uk.gov.hmcts.reform.civil.utils.ElementUtils.wrapElements; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_EXPERTS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_WITNESSES_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_EXPERTS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_WITNESSES_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_EXPERTS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_WITNESSES_ID; @SpringBootTest(classes = { ManageContactInformationCallbackHandler.class, JacksonAutoConfiguration.class, - CaseDetailsConverter.class + CaseDetailsConverter.class, + PostcodeValidator.class }) class ManageContactInformationCallbackHandlerTest extends BaseCallbackHandlerTest { @@ -47,9 +87,18 @@ class ManageContactInformationCallbackHandlerTest extends BaseCallbackHandlerTes @Autowired private ObjectMapper mapper; + @MockBean + private CaseFlagsInitialiser caseFlagInitialiser; + @MockBean private CoreCaseUserService coreCaseUserService; + @MockBean + private CaseDetailsConverter caseDetailsConverter; + + @MockBean + private PostcodeValidator postcodeValidator; + private static final UserInfo ADMIN_USER = UserInfo.builder() .roles(List.of("caseworker-civil-admin")) .uid("uid") @@ -664,31 +713,537 @@ void shouldReturnExpectedList_WhenInvokedFor1v2DifferentSolicitorAsRespondentSol @Nested class AboutToSubmit { + UpdatePartyDetailsForm party; + Expert dqExpert; + Expert expectedExpert1; + Witness dqWitness; + Witness expectedWitness1; + + @BeforeEach + void setup() { + party = UpdatePartyDetailsForm.builder().firstName("First").lastName("Name").build(); + dqExpert = Expert.builder().partyID("id").firstName("dq").lastName("dq").build(); + expectedExpert1 = dqExpert.builder().firstName("First").lastName("Name") + .eventAdded("Manage Contact Information Event").dateAdded(LocalDate.now()) + .partyID(null) //change this for CIV-10382 + .build(); + dqWitness = Witness.builder().firstName("dq").lastName("dq").partyID("id").build(); + expectedWitness1 = Witness.builder().firstName("First").lastName("Name") + .eventAdded("Manage Contact Information Event").dateAdded(LocalDate.now()) + .partyID(null).build(); // CIV-10382 + } @Test - void shouldReturnExpectedResponse_WhenAboutToSubmitIsInvoked() { - CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build(); + void shouldUpdateApplicantOneExperts() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(CLAIMANT_ONE_EXPERTS_ID) + .build()) + .build()) + .partyChosenId(CLAIMANT_ONE_EXPERTS_ID) + .updateExpertsDetailsForm(wrapElements(party)) + .build()) + .applicant1DQ(Applicant1DQ.builder() + .applicant1DQExperts(Experts.builder().details(wrapElements(dqExpert)).build()) + .build()) + .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler .handle(params); - assertEquals(AboutToStartOrSubmitCallbackResponse.builder().build(), response); + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(unwrapElements(updatedData.getApplicant1DQ().getApplicant1DQExperts().getDetails()).get(0)).isEqualTo(expectedExpert1); } - } - @Nested - class Submitted { + @Test + void shouldUpdateDefendantOneExperts() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(DEFENDANT_ONE_EXPERTS_ID) + .build()) + .build()) + .partyChosenId(DEFENDANT_ONE_EXPERTS_ID) + .updateExpertsDetailsForm(wrapElements(party)) + .build()) + .respondent1DQ(Respondent1DQ.builder() + .respondent1DQExperts(Experts.builder().details(wrapElements(dqExpert)).build()) + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(unwrapElements(updatedData.getRespondent1DQ().getRespondent1DQExperts().getDetails()).get(0)).isEqualTo(expectedExpert1); + } + + @Test + void shouldUpdateDefendantTwoExperts() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(DEFENDANT_TWO_EXPERTS_ID) + .build()) + .build()) + .partyChosenId(DEFENDANT_TWO_EXPERTS_ID) + .updateExpertsDetailsForm(wrapElements(party)) + .build()) + .respondent2DQ(Respondent2DQ.builder() + .respondent2DQExperts(Experts.builder().details(wrapElements(dqExpert)).build()) + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(unwrapElements(updatedData.getRespondent2DQ().getRespondent2DQExperts().getDetails()).get(0)).isEqualTo(expectedExpert1); + } + + @Test + void shouldUpdateApplicantOneWitnesses() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(CLAIMANT_ONE_WITNESSES_ID) + .build()) + .build()) + .partyChosenId(CLAIMANT_ONE_WITNESSES_ID) + .updateWitnessesDetailsForm(wrapElements(party)) + .build()) + .applicant1DQ(Applicant1DQ.builder() + .applicant1DQWitnesses(Witnesses.builder().details(wrapElements(dqWitness)).build()) + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(unwrapElements(updatedData.getApplicant1DQ().getApplicant1DQWitnesses().getDetails()).get(0)).isEqualTo(expectedWitness1); + } + + @Test + void shouldUpdateDefendantOneWitnesses() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(DEFENDANT_ONE_WITNESSES_ID) + .build()) + .build()) + .partyChosenId(DEFENDANT_ONE_WITNESSES_ID) + .updateWitnessesDetailsForm(wrapElements(party)) + .build()) + .respondent1DQ(Respondent1DQ.builder() + .respondent1DQWitnesses(Witnesses.builder().details(wrapElements(dqWitness)).build()) + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(unwrapElements(updatedData.getRespondent1DQ().getRespondent1DQWitnesses().getDetails()).get(0)).isEqualTo(expectedWitness1); + } @Test - void shouldReturnExpectedResponse_WhenSubmittedIsInvoked() { - CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build(); - CallbackParams params = callbackParamsOf(caseData, SUBMITTED); + void shouldUpdateDefendantTwoWitnesses() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(DEFENDANT_TWO_WITNESSES_ID) + .build()) + .build()) + .partyChosenId(DEFENDANT_TWO_WITNESSES_ID) + .updateWitnessesDetailsForm(wrapElements(party)) + .build()) + .respondent2DQ(Respondent2DQ.builder() + .respondent2DQWitnesses(Witnesses.builder().details(wrapElements(dqWitness)).build()) + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler .handle(params); - assertEquals(AboutToStartOrSubmitCallbackResponse.builder().build(), response); + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(unwrapElements(updatedData.getRespondent2DQ().getRespondent2DQWitnesses().getDetails()).get(0)).isEqualTo(expectedWitness1); + } + + @Test + void addingExpertWhenNoneExisted() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(CLAIMANT_ONE_EXPERTS_ID) + .build()) + .build()) + .partyChosenId(CLAIMANT_ONE_EXPERTS_ID) + .updateExpertsDetailsForm(wrapElements(party)) + .build()) + .applicant1DQ(Applicant1DQ.builder() + .applicant1DQExperts(Experts.builder() + .expertRequired(NO) + .build()) + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(unwrapElements(updatedData.getApplicant1DQ().getApplicant1DQExperts().getDetails()).get(0)).isEqualTo(expectedExpert1); + assertThat(updatedData.getApplicant1DQ().getApplicant1DQExperts().getExpertRequired()).isEqualTo(YES); + } + + @Test + void removingAllExperts() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(CLAIMANT_ONE_EXPERTS_ID) + .build()) + .build()) + .partyChosenId(CLAIMANT_ONE_EXPERTS_ID) + .updateExpertsDetailsForm(null) + .build()) + .applicant1DQ(Applicant1DQ.builder() + .applicant1DQExperts(Experts.builder() + .expertRequired(YES) + .details(wrapElements(dqExpert)).build()) + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(unwrapElements(updatedData.getApplicant1DQ().getApplicant1DQExperts().getDetails())).isEmpty(); + assertThat(updatedData.getApplicant1DQ().getApplicant1DQExperts().getExpertRequired()).isEqualTo(NO); + } + + @Test + void addingWitnessWhenNoneExisted() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(DEFENDANT_ONE_WITNESSES_ID) + .build()) + .build()) + .partyChosenId(DEFENDANT_ONE_WITNESSES_ID) + .updateWitnessesDetailsForm(wrapElements(party)) + .build()) + .respondent1DQ(Respondent1DQ.builder() + .respondent1DQWitnesses(Witnesses.builder().witnessesToAppear(NO).build()) + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(unwrapElements(updatedData.getRespondent1DQ().getRespondent1DQWitnesses().getDetails()).get(0)).isEqualTo(expectedWitness1); + assertThat(updatedData.getRespondent1DQ().getRespondent1DQWitnesses().getWitnessesToAppear()).isEqualTo(YES); + } + + @Test + void removingAllWitnesses() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(DEFENDANT_ONE_WITNESSES_ID) + .build()) + .build()) + .partyChosenId(DEFENDANT_ONE_WITNESSES_ID) + .updateWitnessesDetailsForm(null) + .build()) + .respondent1DQ(Respondent1DQ.builder() + .respondent1DQWitnesses(Witnesses.builder() + .details(wrapElements(dqWitness)) + .witnessesToAppear(YES).build()) + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(unwrapElements(updatedData.getRespondent1DQ().getRespondent1DQWitnesses().getDetails())).isEmpty(); + assertThat(updatedData.getRespondent1DQ().getRespondent1DQWitnesses().getWitnessesToAppear()).isEqualTo(NO); + } + } + + @Nested + class MidShowWarning { + private static final String PAGE_ID = "show-warning"; + + @ParameterizedTest + @ValueSource(strings = {CLAIMANT_ONE_ID, CLAIMANT_TWO_ID, DEFENDANT_ONE_ID, DEFENDANT_TWO_ID}) + void shouldReturnWarning(String partyChosenId) { + String errorTitle = "Check the litigation friend's details"; + String errorMessage = "After making these changes, please ensure that the " + + "litigation friend's contact information is also up to date."; + + CaseData caseData = CaseDataBuilder.builder() + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(partyChosenId) + .build()) + .build()) + .build()) + .addApplicant1LitigationFriend() + .addApplicant2LitigationFriend() + .addRespondent1LitigationFriend() + .addRespondent2LitigationFriend() + .build(); + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); + + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + assertThat(response.getWarnings()).contains(errorTitle); + assertThat(response.getWarnings()).contains(errorMessage); + } + + @ParameterizedTest + @ValueSource(strings = {CLAIMANT_ONE_ID, CLAIMANT_TWO_ID, DEFENDANT_ONE_ID, DEFENDANT_TWO_ID, DEFENDANT_ONE_LITIGATION_FRIEND_ID}) + void shouldNotReturnWarning(String partyChosenId) { + CaseData caseData = CaseDataBuilder.builder() + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(partyChosenId) + .build()) + .build()) + .build()) + .build(); + + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); + + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + assertThat(response.getWarnings()).isEmpty(); + } + + @Test + void shouldReturnPostcodeError() { + given(postcodeValidator.validate(any())).willReturn(List.of("Please enter Postcode")); + + CaseData caseData = CaseDataBuilder.builder() + .caseAccessCategory(CaseCategory.SPEC_CLAIM) + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(CLAIMANT_ONE_ID) + .build()) + .build()) + .build()) + .applicant1(Party.builder() + .type(INDIVIDUAL) + .primaryAddress(Address.builder() + .postCode(null) + .build()) + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); + + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + assertThat(response.getErrors()).isNotNull(); + assertEquals(1, response.getErrors().size()); + assertEquals("Please enter Postcode", response.getErrors().get(0)); + } + } + + @Nested + class MidShowPartyField { + private static final String PAGE_ID = "show-party-field"; + + @Test + void shouldPopulatePartyChosenId() { + CaseData caseData = CaseDataBuilder.builder() + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code("CODE") + .build()) + .build()) + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(updatedData.getUpdateDetailsForm().getPartyChosenId()).isEqualTo("CODE"); + assertThat(updatedData.getUpdateDetailsForm().getPartyChosenType()).isEqualTo(null); + assertThat(updatedData.getUpdateDetailsForm().getUpdateExpertsDetailsForm()).isEmpty(); + assertThat(updatedData.getUpdateDetailsForm().getUpdateWitnessesDetailsForm()).isEmpty(); + } + + @ParameterizedTest + @ValueSource(strings = {CLAIMANT_ONE_ID, CLAIMANT_TWO_ID, DEFENDANT_ONE_ID, DEFENDANT_TWO_ID}) + void shouldPopulatePartyType(String partyChosenId) { + when(userService.getUserInfo(anyString())).thenReturn(ADMIN_USER); + CaseData caseDataBefore = CaseDataBuilder.builder() + .applicant1(Party.builder().type(INDIVIDUAL).build()) + .applicant2(Party.builder().type(INDIVIDUAL).build()) + .respondent1(Party.builder().type(INDIVIDUAL).build()) + .respondent2(Party.builder().type(INDIVIDUAL).build()) + .buildClaimIssuedPaymentCaseData(); + given(caseDetailsConverter.toCaseData(any(CaseDetails.class))).willReturn(caseDataBefore); + + CaseData caseData = CaseDataBuilder.builder() + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(partyChosenId) + .build()) + .build()) + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(updatedData.getUpdateDetailsForm().getPartyChosenId()).isEqualTo(partyChosenId); + assertThat(updatedData.getUpdateDetailsForm().getPartyChosenType()).isEqualTo(partyChosenId + "_ADMIN_INDIVIDUAL"); + assertThat(updatedData.getUpdateDetailsForm().getUpdateExpertsDetailsForm()).isEmpty(); + assertThat(updatedData.getUpdateDetailsForm().getUpdateWitnessesDetailsForm()).isEmpty(); + } + + @ParameterizedTest + @ValueSource(strings = {CLAIMANT_ONE_LITIGATION_FRIEND_ID, CLAIMANT_TWO_LITIGATION_FRIEND_ID, DEFENDANT_ONE_LITIGATION_FRIEND_ID, DEFENDANT_TWO_LITIGATION_FRIEND_ID}) + void shouldPopulatePartyTypeForLitigationFriend(String partyChosenId) { + when(userService.getUserInfo(anyString())).thenReturn(LEGAL_REP_USER); + CaseData caseDataBefore = CaseDataBuilder.builder() + .applicant1(Party.builder().type(INDIVIDUAL).build()) + .applicant2(Party.builder().type(INDIVIDUAL).build()) + .respondent1(Party.builder().type(INDIVIDUAL).build()) + .respondent2(Party.builder().type(INDIVIDUAL).build()) + .buildClaimIssuedPaymentCaseData(); + given(caseDetailsConverter.toCaseData(any(CaseDetails.class))).willReturn(caseDataBefore); + + CaseData caseData = CaseDataBuilder.builder() + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(partyChosenId) + .build()) + .build()) + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(updatedData.getUpdateDetailsForm().getPartyChosenId()).isEqualTo(partyChosenId); + assertThat(updatedData.getUpdateDetailsForm().getPartyChosenType()).isEqualTo(partyChosenId + "_LR"); + assertThat(updatedData.getUpdateDetailsForm().getUpdateExpertsDetailsForm()).isEmpty(); + assertThat(updatedData.getUpdateDetailsForm().getUpdateWitnessesDetailsForm()).isEmpty(); + } + + @ParameterizedTest + @ValueSource(strings = {CLAIMANT_ONE_EXPERTS_ID, DEFENDANT_ONE_EXPERTS_ID, DEFENDANT_TWO_EXPERTS_ID}) + void shouldPopulateExperts(String partyChosenId) { + when(userService.getUserInfo(anyString())).thenReturn(ADMIN_USER); + Expert expert = Expert.builder().firstName("First").lastName("Name").partyID("id").build(); + UpdatePartyDetailsForm party = UpdatePartyDetailsForm.builder().firstName("First").lastName("Name") + .partyId("id").build(); + List> form = wrapElements(party); + + CaseData caseData = CaseDataBuilder.builder() + .applicant1DQ(Applicant1DQ.builder() + .applicant1DQExperts(Experts.builder().details(wrapElements(expert)).build()) + .build()) + .respondent1DQ(Respondent1DQ.builder() + .respondent1DQExperts(Experts.builder().details(wrapElements(expert)).build()) + .build()) + .respondent2DQ(Respondent2DQ.builder() + .respondent2DQExperts(Experts.builder().details(wrapElements(expert)).build()) + .build()) + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(partyChosenId) + .build()) + .build()) + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(updatedData.getUpdateDetailsForm().getPartyChosenId()).isEqualTo(partyChosenId); + assertThat(updatedData.getUpdateDetailsForm().getPartyChosenType()).isEqualTo(null); + assertThat(updatedData.getUpdateDetailsForm().getUpdateExpertsDetailsForm()).isEqualTo(form); + assertThat(updatedData.getUpdateDetailsForm().getUpdateWitnessesDetailsForm()).isEmpty(); + + } + + @ParameterizedTest + @ValueSource(strings = {CLAIMANT_ONE_WITNESSES_ID, DEFENDANT_ONE_WITNESSES_ID, DEFENDANT_TWO_WITNESSES_ID}) + void shouldPopulateWitnesses(String partyChosenId) { + Witness witness = Witness.builder().firstName("First").lastName("Name").partyID("id").build(); + UpdatePartyDetailsForm party = UpdatePartyDetailsForm.builder().firstName("First").lastName("Name") + .partyId("id").build(); + List> form = wrapElements(party); + + CaseData caseData = CaseDataBuilder.builder() + .applicant1DQ(Applicant1DQ.builder() + .applicant1DQWitnesses(Witnesses.builder().details(wrapElements(witness)).build()) + .build()) + .respondent1DQ(Respondent1DQ.builder() + .respondent1DQWitnesses(Witnesses.builder().details(wrapElements(witness)).build()) + .build()) + .respondent2DQ(Respondent2DQ.builder() + .respondent2DQWitnesses(Witnesses.builder().details(wrapElements(witness)).build()) + .build()) + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosen(DynamicList.builder() + .value(DynamicListElement.builder() + .code(partyChosenId) + .build()) + .build()) + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(updatedData.getUpdateDetailsForm().getPartyChosenId()).isEqualTo(partyChosenId); + assertThat(updatedData.getUpdateDetailsForm().getPartyChosenType()).isEqualTo(null); + assertThat(updatedData.getUpdateDetailsForm().getUpdateExpertsDetailsForm()).isEmpty(); + assertThat(updatedData.getUpdateDetailsForm().getUpdateWitnessesDetailsForm()).isEqualTo(form); + } } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestJudgementByAdmissionForSpecCuiCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestJudgementByAdmissionForSpecCuiCallbackHandlerTest.java index c113efe39a6..4587d7afc7a 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestJudgementByAdmissionForSpecCuiCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RequestJudgementByAdmissionForSpecCuiCallbackHandlerTest.java @@ -20,6 +20,7 @@ import uk.gov.hmcts.reform.civil.model.CCJPaymentDetails; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.Fee; +import uk.gov.hmcts.reform.civil.model.RespondToClaimAdmitPartLRspec; import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.service.FeatureToggleService; @@ -27,6 +28,7 @@ import uk.gov.hmcts.reform.civil.utils.MonetaryConversions; import java.math.BigDecimal; +import java.time.LocalDate; import java.time.LocalDateTime; import static java.lang.String.format; @@ -34,8 +36,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START; -import static uk.gov.hmcts.reform.civil.callback.CallbackType.MID; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; +import static uk.gov.hmcts.reform.civil.callback.CallbackType.MID; import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.REQUEST_JUDGEMENT_ADMISSION_SPEC; import static uk.gov.hmcts.reform.civil.enums.CaseState.AWAITING_APPLICANT_INTENTION; @@ -70,10 +72,12 @@ public class RequestJudgementByAdmissionForSpecCuiCallbackHandlerTest extends Ba class AboutToStartCallback { @Test void shouldReturnError_WhenAboutToStartIsInvoked() { + LocalDate whenWillPay = LocalDate.now().plusDays(5); CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() .respondent1ResponseDate(LocalDateTime.now()) .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_ADMISSION) .ccdState(AWAITING_APPLICANT_INTENTION) + .respondToClaimAdmitPartLRspec(RespondToClaimAdmitPartLRspec.builder().whenWillThisAmountBePaid(whenWillPay).build()) .build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_START, caseData).build(); AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler @@ -83,10 +87,12 @@ void shouldReturnError_WhenAboutToStartIsInvoked() { @Test void shouldNotReturnError_WhenAboutToStartIsInvokedOneDefendant() { + LocalDate whenWillPay = LocalDate.of(2023, 10, 11); CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() .respondent1ResponseDate(LocalDateTime.now().minusDays(15)) .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_ADMISSION) .ccdState(AWAITING_APPLICANT_INTENTION) + .respondToClaimAdmitPartLRspec(RespondToClaimAdmitPartLRspec.builder().whenWillThisAmountBePaid(whenWillPay).build()) .build(); CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_START, caseData).build(); AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandlerTest.java index ac9d11481ef..73040deeb42 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToClaimSpecCallbackHandlerTest.java @@ -19,6 +19,7 @@ import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest; import uk.gov.hmcts.reform.ccd.client.model.CallbackResponse; import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse; +import uk.gov.hmcts.reform.civil.callback.CallbackException; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CallbackType; import uk.gov.hmcts.reform.civil.constants.SpecJourneyConstantLRSpec; @@ -55,31 +56,35 @@ import uk.gov.hmcts.reform.civil.model.UnavailableDate; import uk.gov.hmcts.reform.civil.model.common.DynamicList; import uk.gov.hmcts.reform.civil.model.common.Element; -import uk.gov.hmcts.reform.civil.model.dq.RequestedCourt; import uk.gov.hmcts.reform.civil.model.dq.Respondent1DQ; import uk.gov.hmcts.reform.civil.model.dq.Respondent2DQ; -import uk.gov.hmcts.reform.civil.model.dq.SmallClaimHearing; import uk.gov.hmcts.reform.civil.model.dq.Witness; import uk.gov.hmcts.reform.civil.model.dq.Witnesses; +import uk.gov.hmcts.reform.civil.model.dq.RequestedCourt; +import uk.gov.hmcts.reform.civil.model.dq.Expert; +import uk.gov.hmcts.reform.civil.model.dq.Experts; +import uk.gov.hmcts.reform.civil.model.dq.ExpertDetails; +import uk.gov.hmcts.reform.civil.model.dq.SmallClaimHearing; import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData; import uk.gov.hmcts.reform.civil.sampledata.AddressBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.sampledata.PartyBuilder; -import uk.gov.hmcts.reform.civil.service.CoreCaseUserService; import uk.gov.hmcts.reform.civil.service.DeadlinesCalculator; import uk.gov.hmcts.reform.civil.service.ExitSurveyContentService; import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.service.Time; import uk.gov.hmcts.reform.civil.service.UserService; +import uk.gov.hmcts.reform.civil.service.CoreCaseUserService; +import uk.gov.hmcts.reform.civil.service.citizenui.responsedeadline.DeadlineExtensionCalculatorService; import uk.gov.hmcts.reform.civil.service.flowstate.FlowFlag; import uk.gov.hmcts.reform.civil.service.flowstate.StateFlowEngine; import uk.gov.hmcts.reform.civil.stateflow.StateFlow; import uk.gov.hmcts.reform.civil.utils.AssignCategoryId; import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser; import uk.gov.hmcts.reform.civil.utils.CourtLocationUtils; -import uk.gov.hmcts.reform.civil.utils.ElementUtils; import uk.gov.hmcts.reform.civil.utils.MonetaryConversions; +import uk.gov.hmcts.reform.civil.utils.ElementUtils; import uk.gov.hmcts.reform.civil.validation.DateOfBirthValidator; import uk.gov.hmcts.reform.civil.validation.PaymentDateValidator; import uk.gov.hmcts.reform.civil.validation.PostcodeValidator; @@ -98,8 +103,11 @@ import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; @@ -117,6 +125,7 @@ import static uk.gov.hmcts.reform.civil.enums.CaseRole.RESPONDENTSOLICITORTWO; import static uk.gov.hmcts.reform.civil.enums.RespondentResponsePartAdmissionPaymentTimeLRspec.IMMEDIATELY; import static uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec.FULL_ADMISSION; +import static uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec.FULL_DEFENCE; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; import static uk.gov.hmcts.reform.civil.helpers.DateFormatHelper.DATE; @@ -162,6 +171,8 @@ class RespondToClaimSpecCallbackHandlerTest extends BaseCallbackHandlerTest { private CourtLocationUtils courtLocationUtils; @Mock private CaseFlagsInitialiser caseFlagsInitialiser; + @Mock + private DeadlineExtensionCalculatorService deadlineExtensionCalculatorService; @Spy private List confirmationTextGenerators = List.of( @@ -194,15 +205,82 @@ public void setup() { ); } + @Test + void whenCallBackEventNotImplementedOrEventInvalid() { + // Given + String postCode = "postCode"; + CaseData caseData = CaseData.builder() + .build().toBuilder() + .respondentSolicitor1ServiceAddressRequired(NO) + .respondentSolicitor1ServiceAddress(Address.builder().postCode(postCode).build()) + .isRespondent1(YES) + .build(); + CallbackParams callbackParams = callbackParamsOf(caseData, CallbackType.MID, " ").toBuilder() + .request(CallbackRequest.builder().eventId(SpecJourneyConstantLRSpec.DEFENDANT_RESPONSE_SPEC) + .build()).build(); + + //When + CallbackException ex = assertThrows(CallbackException.class, () -> handler.handle(callbackParams), + + "A CallbackException was expected to be thrown but wasn't."); + // Then + assertThat(ex.getMessage()).contains("Callback for event"); + } + + @Test + void resetStatementOfTruth() { + CaseData caseData = CaseDataBuilder.builder().build(); + CallbackParams params = callbackParamsOf(caseData, CallbackType.MID, "statement-of-truth"); + CallbackRequest request = CallbackRequest.builder() + .eventId(SpecJourneyConstantLRSpec.DEFENDANT_RESPONSE_SPEC) + .build(); + params = params.toBuilder().request(request).build(); + + // When + CallbackResponse response = handler.handle(params); + + // Then + assertNotNull(response); + } + @Test void midSpecCorrespondenceAddress_checkAddressIfWasIncorrect() { // Given String postCode = "postCode"; CaseData caseData = CaseData.builder() - .specAoSApplicantCorrespondenceAddressRequired(YesOrNo.NO) - .specAoSApplicantCorrespondenceAddressdetails(Address.builder() - .postCode(postCode) - .build()) + .build().toBuilder() + .respondentSolicitor1ServiceAddressRequired(NO) + .respondentSolicitor1ServiceAddress(Address.builder().postCode(postCode).build()) + .isRespondent1(YES) + .build(); + CallbackParams params = callbackParamsOf(caseData, CallbackType.MID, "specCorrespondenceAddress"); + CallbackRequest request = CallbackRequest.builder() + .eventId(SpecJourneyConstantLRSpec.DEFENDANT_RESPONSE_SPEC) + .build(); + params = params.toBuilder().request(request).build(); + + List errors = Collections.singletonList("error 1"); + Mockito.when(postcodeValidator.validate(postCode)).thenReturn(errors); + + // When + CallbackResponse response = handler.handle(params); + + // Then + assertEquals(errors, ((AboutToStartOrSubmitCallbackResponse) response).getErrors()); + } + + @Test + void midSpecCorrespondenceAddress_checkAddressIfWasIncorrectForSol2() { + // Given + String postCode = "postCode"; + CaseData caseData = CaseData.builder() + .build().toBuilder() + .respondentSolicitor1ServiceAddressRequired(YES) + .respondentSolicitor1ServiceAddress(Address.builder().postCode(postCode).build()) + .isRespondent1(YES) + .isRespondent2(YES) + .respondentSolicitor2ServiceAddressRequired(NO) + .respondentSolicitor2ServiceAddress(Address.builder().postCode(postCode).build()) .build(); CallbackParams params = callbackParamsOf(caseData, CallbackType.MID, "specCorrespondenceAddress"); CallbackRequest request = CallbackRequest.builder() @@ -310,10 +388,8 @@ void testSpecDefendantResponseFastTrackOneVTwoLegalRep() { assertThat(response.getData()).isNotNull(); assertThat(response.getData()).containsEntry("responseClaimTrack", AllocatedTrack.FAST_CLAIM.name()); assertThat(response.getData()).containsEntry("specDisputesOrPartAdmission", "No"); - assertThat(response.getData()).containsEntry( - "specPaidLessAmountOrDisputesOrPartAdmission", - "No" - ); + assertThat(response.getData()).containsEntry("specPaidLessAmountOrDisputesOrPartAdmission", + "No"); } @Test @@ -343,10 +419,8 @@ void testSpecDefendantResponseFastTrackOneVTwoSameLegalRep() { assertThat(response.getData()).isNotNull(); assertThat(response.getData()).containsEntry("responseClaimTrack", AllocatedTrack.FAST_CLAIM.name()); assertThat(response.getData()).containsEntry("specDisputesOrPartAdmission", "No"); - assertThat(response.getData()).containsEntry( - "specPaidLessAmountOrDisputesOrPartAdmission", - "No" - ); + assertThat(response.getData()).containsEntry("specPaidLessAmountOrDisputesOrPartAdmission", + "No"); } @Test @@ -372,10 +446,8 @@ void testSpecDefendantResponseFastTrackTwoVOne() { assertThat(response.getData()).isNotNull(); assertThat(response.getData()).containsEntry("responseClaimTrack", AllocatedTrack.FAST_CLAIM.name()); assertThat(response.getData()).containsEntry("specDisputesOrPartAdmission", "No"); - assertThat(response.getData()).containsEntry( - "specPaidLessAmountOrDisputesOrPartAdmission", - "No" - ); + assertThat(response.getData()).containsEntry("specPaidLessAmountOrDisputesOrPartAdmission", + "No"); } @Test @@ -658,9 +730,6 @@ public void testValidateRespondentPaymentDate() { AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler .handle(params); - List expectedErrorArray = new ArrayList<>(); - expectedErrorArray.add("Date for when will the amount be paid must be today or in the future."); - // Then assertThat(response).isNotNull(); /* @@ -719,8 +788,9 @@ void updateRespondent1AddressWhenUpdated() { CaseData caseData = CaseDataBuilder.builder() .respondent1(PartyBuilder.builder().individual().build()) .atStateApplicantRespondToDefenceAndProceed() - .atSpecAoSApplicantCorrespondenceAddressRequired(NO) - .atSpecAoSApplicantCorrespondenceAddressDetails(AddressBuilder.maximal().build()) + .build().toBuilder() + .tempCorrespondenceAddress1Required(NO) + .tempCorrespondenceAddress1(AddressBuilder.maximal().build()) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -751,17 +821,21 @@ void updateRespondent2AddressWhenUpdated() { when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); - Address changedAddress = AddressBuilder.maximal().build(); - + Address newAddress2 = AddressBuilder.defaults().build(); CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed() .respondent2DQ() .respondent1Copy(PartyBuilder.builder().individual().build()) - .atSpecAoSApplicantCorrespondenceAddressRequired(YES) .addRespondent2(YES) .respondent2(PartyBuilder.builder().individual().build()) .respondent2Copy(PartyBuilder.builder().individual().build()) - .atSpecAoSRespondent2HomeAddressRequired(NO) - .atSpecAoSRespondent2HomeAddressDetails(AddressBuilder.maximal().build()) + .build().toBuilder() + .tempCorrespondenceAddress1Required(YES) + .tempCorrespondenceAddress1(Address.builder().build()) + .build().toBuilder() + .tempCorrespondenceAddress2Required(NO) + .tempCorrespondenceAddress2(newAddress2) + .respondentSolicitor2ServiceAddressRequired(NO) + .respondentSolicitor2ServiceAddress(newAddress2) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -775,28 +849,52 @@ void updateRespondent2AddressWhenUpdated() { // Then assertThat(response.getData()) .extracting("respondent2").extracting("primaryAddress") - .extracting("AddressLine1").isEqualTo("address line 1"); + .extracting("AddressLine1").isEqualTo(newAddress2.getAddressLine1()); assertThat(response.getData()) .extracting("respondent2").extracting("primaryAddress") - .extracting("AddressLine2").isEqualTo("address line 2"); + .extracting("AddressLine2").isEqualTo(newAddress2.getAddressLine2()); assertThat(response.getData()) .extracting("respondent2").extracting("primaryAddress") - .extracting("AddressLine3").isEqualTo("address line 3"); + .extracting("AddressLine3").isEqualTo(newAddress2.getAddressLine3()); } @Test - void updateRespondent2AddressWhenSpecAoSRespondent2HomeAddressRequiredIsNO() { + void defendantResponsePopulatesWitnessesData() { // Given + LocalDateTime dateTime = LocalDateTime.of(2023, 6, 6, 6, 6, 6); + LocalDate date = dateTime.toLocalDate(); when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(time.now()).thenReturn(dateTime); when(mockedStateFlow.isFlagSet(any())).thenReturn(true); when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); - - Party partyWithPrimaryAddress = PartyBuilder.builder().individual().build(); - partyWithPrimaryAddress.setPrimaryAddress(AddressBuilder.maximal() - .addressLine1("address line 1") - .addressLine2("address line 2") - .addressLine3("address line 3") - .build()); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); + when(toggleService.isHmcEnabled()).thenReturn(true); + + Witnesses res1witnesses = Witnesses.builder().details( + wrapElements( + Witness.builder() + .firstName("Witness") + .lastName("One") + .emailAddress("test-witness-one@example.com") + .phoneNumber("07865456789") + .reasonForWitness("great reasons") + .eventAdded("Defendant Response Event") + .dateAdded(date) + .build()) + ).build(); + + Witnesses res2witnesses = Witnesses.builder().details( + wrapElements( + Witness.builder() + .firstName("Witness") + .lastName("Two") + .emailAddress("test-witness-two@example.com") + .phoneNumber("07532628263") + .reasonForWitness("good reasons") + .eventAdded("Defendant Response Event") + .dateAdded(date) + .build()) + ).build(); CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed() .respondent2DQ() @@ -804,420 +902,693 @@ void updateRespondent2AddressWhenSpecAoSRespondent2HomeAddressRequiredIsNO() { .addRespondent2(YES) .respondent2(PartyBuilder.builder().individual().build()) .respondent2Copy(PartyBuilder.builder().individual().build()) - .atSpecAoSRespondent2HomeAddressRequired(NO) - .atSpecAoSRespondent2HomeAddressDetails(AddressBuilder.maximal() - .addressLine1("new address line 1") - .build()) + .build().toBuilder() + .respondent1DQWitnessesSmallClaim(res1witnesses) + .respondent2DQWitnessesSmallClaim(res2witnesses) + .build().toBuilder() + .tempCorrespondenceAddress1Required(YES) + .tempCorrespondenceAddress1(Address.builder().build()) + .respondent2ResponseDate(dateTime) + .respondent1ResponseDate(dateTime).build().toBuilder() + .tempCorrespondenceAddress2Required(NO) + .tempCorrespondenceAddress2(AddressBuilder.maximal().build()) .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(deadlinesCalculator.calculateApplicantResponseDeadlineSpec(any(), any())) + .thenReturn(LocalDateTime.now()); + // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle( - callbackParamsOf(caseData, ABOUT_TO_SUBMIT)); + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + var objectMapper = new ObjectMapper(); + objectMapper.findAndRegisterModules(); + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); // Then - assertThat(response.getData()) - .extracting("respondent2") - .extracting("primaryAddress") - .extracting("AddressLine1") - .isEqualTo("new address line 1"); + + Witnesses actualRespondent1DQWitnesses = objectMapper.convertValue(response.getData().get("respondent1DQWitnesses"), new TypeReference<>() {}); + Witness actualRespondent1Witness = unwrapElements(actualRespondent1DQWitnesses.getDetails()).get(0); + assertThat(actualRespondent1Witness.getPartyID()).isNotNull(); + assertThat(actualRespondent1Witness.getFirstName()).isEqualTo("Witness"); + assertThat(actualRespondent1Witness.getLastName()).isEqualTo("One"); + assertThat(actualRespondent1Witness.getEmailAddress()).isEqualTo("test-witness-one@example.com"); + assertThat(actualRespondent1Witness.getPhoneNumber()).isEqualTo("07865456789"); + assertThat(actualRespondent1Witness.getReasonForWitness()).isEqualTo("great reasons"); + assertThat(actualRespondent1Witness.getEventAdded()).isEqualTo("Defendant Response Event"); + assertThat(actualRespondent1Witness.getDateAdded()).isEqualTo(date); + + Witnesses actualRespondent2DQWitnesses = objectMapper.convertValue(response.getData().get("respondent2DQWitnesses"), new TypeReference<>() {}); + Witness respondent2Witness = unwrapElements(actualRespondent2DQWitnesses.getDetails()).get(0); + assertThat(respondent2Witness.getPartyID()).isNotNull(); + assertThat(respondent2Witness.getFirstName()).isEqualTo("Witness"); + assertThat(respondent2Witness.getLastName()).isEqualTo("Two"); + assertThat(respondent2Witness.getEmailAddress()).isEqualTo("test-witness-two@example.com"); + assertThat(respondent2Witness.getPhoneNumber()).isEqualTo("07532628263"); + assertThat(respondent2Witness.getReasonForWitness()).isEqualTo("good reasons"); + assertThat(respondent2Witness.getEventAdded()).isEqualTo("Defendant Response Event"); + assertThat(respondent2Witness.getDateAdded()).isEqualTo(date); + } - @Test - void updateRespondent2AddressWhenSpecAoSRespondent2HomeAddressRequiredIsNotNO() { - // Given - when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); - when(mockedStateFlow.isFlagSet(any())).thenReturn(true); - when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); + @Nested + class HandleLocations { + + @Test + void oneVOne() { + // Given + DynamicList locationValues = DynamicList.fromList(List.of("Value 1")); + DynamicList preferredCourt = DynamicList.builder() + .listItems(locationValues.getListItems()) + .value(locationValues.getListItems().get(0)) + .build(); + Party defendant1 = Party.builder() + .type(Party.Type.COMPANY) + .companyName("company") + .build(); + CaseData caseData = CaseData.builder() + .caseAccessCategory(SPEC_CLAIM) + .ccdCaseReference(354L) + .respondent1(defendant1) + .respondent1Copy(defendant1) + .respondent1DQ( + Respondent1DQ.builder() + .respondToCourtLocation( + RequestedCourt.builder() + .responseCourtLocations(preferredCourt) + .reasonForHearingAtSpecificCourt("Reason") + .build() + ) + .build() + ) + .showConditionFlags(EnumSet.of( + DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_1 + )) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + List locations = List.of(LocationRefData.builder().build()); + when(locationRefDataService.getCourtLocationsForDefaultJudgments(any())) + .thenReturn(locations); + LocationRefData completePreferredLocation = LocationRefData.builder() + .regionId("regionId") + .epimmsId("epimms") + .courtLocationCode("code") + .build(); + when(courtLocationUtils.findPreferredLocationData( + locations, preferredCourt + )).thenReturn(completePreferredLocation); + StateFlow flow = mock(StateFlow.class); + when(flow.isFlagSet(FlowFlag.TWO_RESPONDENT_REPRESENTATIVES)).thenReturn(false); + when(stateFlowEngine.evaluate(caseData)) + .thenReturn(flow); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), any(CaseRole.class))) + .thenReturn(true); + UserInfo userInfo = UserInfo.builder().uid("798").build(); + when(userService.getUserInfo(anyString())).thenReturn(userInfo); + + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + // Then + AbstractObjectAssert sent1 = assertThat(response.getData()) + .extracting("respondent1DQRequestedCourt"); + sent1.extracting("caseLocation") + .extracting("region") + .isEqualTo(completePreferredLocation.getRegionId()); + sent1.extracting("caseLocation") + .extracting("baseLocation") + .isEqualTo(completePreferredLocation.getEpimmsId()); + sent1.extracting("responseCourtCode") + .isEqualTo(completePreferredLocation.getCourtLocationCode()); + sent1.extracting("reasonForHearingAtSpecificCourt") + .isEqualTo("Reason"); + } + + @Test + void oneVTwo_SecondDefendantRepliesSameLegalRep() { + // Given + DynamicList locationValues = DynamicList.fromList(List.of("Value 1")); + DynamicList preferredCourt = DynamicList.builder() + .listItems(locationValues.getListItems()) + .value(locationValues.getListItems().get(0)) + .build(); + Party defendant1 = Party.builder() + .type(Party.Type.COMPANY) + .companyName("company") + .build(); + Party defendant2 = Party.builder() + .type(Party.Type.COMPANY) + .companyName("company2") + .build(); + CaseData caseData = CaseData.builder() + .respondent2SameLegalRepresentative(YES) + .caseAccessCategory(SPEC_CLAIM) + .ccdCaseReference(354L) + .defenceAdmitPartPaymentTimeRouteRequired(IMMEDIATELY) + .respondent2ClaimResponseTypeForSpec(FULL_ADMISSION) + .respondent1(defendant1) + .respondent1Copy(defendant1) + .respondent2(defendant2) + .respondent2Copy(defendant2) + .respondent1DQ( + Respondent1DQ.builder() + .respondToCourtLocation( + RequestedCourt.builder() + .responseCourtLocations(preferredCourt) + .reasonForHearingAtSpecificCourt("Reason") + .build() + ) + .build() + ) + .respondent2DQ( + Respondent2DQ.builder() + .respondToCourtLocation2( + RequestedCourt.builder() + .responseCourtLocations(preferredCourt) + .reasonForHearingAtSpecificCourt("Reason123") + .build() + ) + .build() + ) + .showConditionFlags(EnumSet.of( + DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_1, + DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_2 + )) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + List locations = List.of(LocationRefData.builder().build()); + when(locationRefDataService.getCourtLocationsForDefaultJudgments(any())) + .thenReturn(locations); + LocationRefData completePreferredLocation = LocationRefData.builder() + .regionId("regionId") + .epimmsId("epimms") + .courtLocationCode("code") + .build(); + when(courtLocationUtils.findPreferredLocationData( + locations, preferredCourt + )).thenReturn(completePreferredLocation); + StateFlow flow = mock(StateFlow.class); + when(flow.isFlagSet(FlowFlag.TWO_RESPONDENT_REPRESENTATIVES)).thenReturn(true); + when(stateFlowEngine.evaluate(caseData)).thenReturn(flow); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), any(CaseRole.class))) + .thenReturn(true); + UserInfo userInfo = UserInfo.builder().uid("798").build(); + when(userService.getUserInfo(anyString())).thenReturn(userInfo); + LocalDate whenWillPay = LocalDate.now().plusDays(5); + given(deadlineExtensionCalculatorService.calculateExtendedDeadline(any(), anyInt())).willReturn(whenWillPay); + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + // Then + AbstractObjectAssert sent2 = assertThat(response.getData()) + .extracting("respondent2DQRequestedCourt"); + sent2.extracting("caseLocation") + .extracting("region") + .isEqualTo(completePreferredLocation.getRegionId()); + sent2.extracting("caseLocation") + .extracting("baseLocation") + .isEqualTo(completePreferredLocation.getEpimmsId()); + sent2.extracting("responseCourtCode") + .isEqualTo(completePreferredLocation.getCourtLocationCode()); + sent2.extracting("reasonForHearingAtSpecificCourt") + .isEqualTo("Reason123"); + } + + @Test + void oneVTwo_SecondDefendantReplies() { + // Given + DynamicList locationValues = DynamicList.fromList(List.of("Value 1")); + DynamicList preferredCourt = DynamicList.builder() + .listItems(locationValues.getListItems()) + .value(locationValues.getListItems().get(0)) + .build(); + Party defendant1 = Party.builder() + .type(Party.Type.COMPANY) + .companyName("company") + .build(); + Party defendant2 = Party.builder() + .type(Party.Type.COMPANY) + .companyName("company 2") + .build(); + CaseData caseData = CaseData.builder() + .caseAccessCategory(SPEC_CLAIM) + .ccdCaseReference(354L) + .respondent1(defendant1) + .respondent1Copy(defendant1) + .respondent2(defendant2) + .respondent2Copy(defendant2) + .respondent1DQ( + Respondent1DQ.builder() + .respondToCourtLocation( + RequestedCourt.builder() + .responseCourtLocations(preferredCourt) + .reasonForHearingAtSpecificCourt("Reason") + .build() + ) + .build() + ) + .respondent2DQ( + Respondent2DQ.builder() + .respondToCourtLocation2( + RequestedCourt.builder() + .responseCourtLocations(preferredCourt) + .reasonForHearingAtSpecificCourt("Reason123") + .build() + ) + .build() + ) + .showConditionFlags(EnumSet.of( + DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_1, + DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_2 + )) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + List locations = List.of(LocationRefData.builder().build()); + when(locationRefDataService.getCourtLocationsForDefaultJudgments(any())) + .thenReturn(locations); + LocationRefData completePreferredLocation = LocationRefData.builder() + .regionId("regionId") + .epimmsId("epimms") + .courtLocationCode("code") + .build(); + when(courtLocationUtils.findPreferredLocationData( + locations, preferredCourt + )).thenReturn(completePreferredLocation); + StateFlow flow = mock(StateFlow.class); + when(flow.isFlagSet(FlowFlag.TWO_RESPONDENT_REPRESENTATIVES)).thenReturn(true); + when(stateFlowEngine.evaluate(caseData)).thenReturn(flow); + when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), any(CaseRole.class))) + .thenReturn(true); + UserInfo userInfo = UserInfo.builder().uid("798").build(); + when(userService.getUserInfo(anyString())).thenReturn(userInfo); + + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + // Then + AbstractObjectAssert sent2 = assertThat(response.getData()) + .extracting("respondent2DQRequestedCourt"); + sent2.extracting("caseLocation") + .extracting("region") + .isEqualTo(completePreferredLocation.getRegionId()); + sent2.extracting("caseLocation") + .extracting("baseLocation") + .isEqualTo(completePreferredLocation.getEpimmsId()); + sent2.extracting("responseCourtCode") + .isEqualTo(completePreferredLocation.getCourtLocationCode()); + sent2.extracting("reasonForHearingAtSpecificCourt") + .isEqualTo("Reason123"); + } + } - Party partyWithPrimaryAddress = PartyBuilder.builder().individual().build(); - partyWithPrimaryAddress.setPrimaryAddress(AddressBuilder.maximal() - .addressLine1("address line 1") - .addressLine2("address line 2") - .addressLine3("address line 3") - .build()); + } - CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed() - .respondent2DQ() - .respondent1Copy(PartyBuilder.builder().individual().build()) - .addRespondent2(YES) - .respondent2(PartyBuilder.builder().individual().build()) - .respondent2Copy(PartyBuilder.builder().individual().build()) - .atSpecAoSRespondent2HomeAddressRequired(YES) - .build(); + @Test + void shouldNullDocuments_whenInvokedAndCaseFileEnabled() { + // Given + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(mockedStateFlow.isFlagSet(any())).thenReturn(true); + when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); + when(toggleService.isCaseFileViewEnabled()).thenReturn(true); + var testDocument = ResponseDocument.builder() + .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle( - callbackParamsOf(caseData, ABOUT_TO_SUBMIT)); + CaseData caseData = CaseData.builder() + .respondent1(PartyBuilder.builder().individual().build()) + .respondent1Copy(PartyBuilder.builder().individual().build()) + .respondent1DQ(Respondent1DQ.builder().build()) + .respondent2(PartyBuilder.builder().individual().build()) + .respondent2Copy(PartyBuilder.builder().individual().build()) + .respondent2DQ(Respondent2DQ.builder().build()) + .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) + .respondent2ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) + .ccdCaseReference(354L) + .respondent1SpecDefenceResponseDocument(testDocument) + .respondent2SpecDefenceResponseDocument(testDocument) + .build(); - // Then - assertThat(response.getData()) - .extracting("respondent2") - .extracting("primaryAddress") - .extracting("AddressLine1") - .isEqualTo("address line 1"); - assertThat(response.getData()) - .extracting("respondent2") - .extracting("primaryAddress") - .extracting("AddressLine2") - .isEqualTo("address line 2"); - assertThat(response.getData()) - .extracting("respondent2") - .extracting("primaryAddress") - .extracting("AddressLine3") - .isEqualTo("address line 3"); - } + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + // Then + assertThat(response.getData().get("respondent1SpecDefenceResponseDocument")).isNull(); + assertThat(response.getData().get("respondent2SpecDefenceResponseDocument")).isNull(); } @Test - void defendantResponsePopulatesWitnessesData() { + void shouldUpdateExpertEvents_whenInvokedAndUpdateContactDetailsEnabled_For2DivergeResponse() { // Given LocalDateTime dateTime = LocalDateTime.of(2023, 6, 6, 6, 6, 6); - LocalDate date = dateTime.toLocalDate(); when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); - when(time.now()).thenReturn(dateTime); when(mockedStateFlow.isFlagSet(any())).thenReturn(true); when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); - when(toggleService.isHmcEnabled()).thenReturn(true); - - Witnesses res1witnesses = Witnesses.builder().details( - wrapElements( - Witness.builder() - .firstName("Witness") - .lastName("One") - .emailAddress("test-witness-one@example.com") - .phoneNumber("07865456789") - .reasonForWitness("great reasons") - .eventAdded("Defendant Response Event") - .dateAdded(date) - .build()) - ).build(); - - Witnesses res2witnesses = Witnesses.builder().details( - wrapElements( - Witness.builder() - .firstName("Witness") - .lastName("Two") - .emailAddress("test-witness-two@example.com") - .phoneNumber("07532628263") - .reasonForWitness("good reasons") - .eventAdded("Defendant Response Event") - .dateAdded(date) - .build()) - ).build(); - - CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed() - .respondent2DQ() + when(toggleService.isUpdateContactDetailsEnabled()).thenReturn(true); + + CaseData caseData = CaseData.builder() + .respondent1(PartyBuilder.builder().individual().build()) .respondent1Copy(PartyBuilder.builder().individual().build()) - .atSpecAoSApplicantCorrespondenceAddressRequired(YES) - .addRespondent2(YES) + .respondent1DQ(Respondent1DQ.builder() + .respondent1DQExperts(Experts.builder() + .details(wrapElements(Expert.builder().build())).build()) + .build()) .respondent2(PartyBuilder.builder().individual().build()) .respondent2Copy(PartyBuilder.builder().individual().build()) - .atSpecAoSRespondent2HomeAddressRequired(NO) - .atSpecAoSRespondent2HomeAddressDetails(AddressBuilder.maximal().build()) - .build().toBuilder() - .respondent1DQWitnessesSmallClaim(res1witnesses) - .respondent2DQWitnessesSmallClaim(res2witnesses) - .build().toBuilder() - .respondent2ResponseDate(dateTime) - .respondent1ResponseDate(dateTime).build(); + .respondent2DQ(Respondent2DQ.builder().build()) + .claimant1ClaimResponseTypeForSpec(FULL_DEFENCE) + .claimant2ClaimResponseTypeForSpec(FULL_ADMISSION) + .ccdCaseReference(354L) + .respondent1ResponseDate(dateTime).build().toBuilder() + .respondent2SameLegalRepresentative(YES) + .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - when(deadlinesCalculator.calculateApplicantResponseDeadlineSpec(any(), any())) - .thenReturn(LocalDateTime.now()); // When AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler .handle(params); - var objectMapper = new ObjectMapper(); - objectMapper.findAndRegisterModules(); - objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + // Then + assertThat(response.getData().get("respondent1DQExperts")).isNotNull(); + assertThat(response.getData().get("respondent2DQExperts")).isNull(); + + } + + @Test + void shouldUpdateExpertEvents_whenInvokedAndUpdateContactDetailsEnabled_CanAddApplicant2() { + // Given + LocalDateTime dateTime = LocalDateTime.of(2023, 6, 6, 6, 6, 6); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(mockedStateFlow.isFlagSet(any())).thenReturn(true); + when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); + when(toggleService.isUpdateContactDetailsEnabled()).thenReturn(true); + + CaseData caseData = CaseData.builder() + .respondent1(PartyBuilder.builder().individual().build()) + .respondent1Copy(PartyBuilder.builder().individual().build()) + .respondent1DQ(Respondent1DQ.builder() + .respondent1DQExperts(Experts.builder() + .details(wrapElements(Expert.builder().build())).build()) + .build()) + .respondent2(PartyBuilder.builder().individual().build()) + .respondent2Copy(PartyBuilder.builder().individual().build()) + .respondent2DQ(Respondent2DQ.builder().build()) + .claimant1ClaimResponseTypeForSpec(FULL_DEFENCE) + .claimant2ClaimResponseTypeForSpec(FULL_ADMISSION) + .ccdCaseReference(354L) + .respondent1ResponseDate(dateTime).build().toBuilder() + .addApplicant2(YES) + .build(); + + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); // Then + assertThat(response.getData().get("respondent1DQExperts")).isNotNull(); + assertThat(response.getData().get("respondent2DQExperts")).isNull(); + + } + + @Test + void shouldUpdateExpertEvents_whenInvokedAndUpdateContactDetailsEnabled_FullAdmission() { + // Given + LocalDateTime dateTime = LocalDateTime.of(2023, 6, 6, 6, 6, 6); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(mockedStateFlow.isFlagSet(any())).thenReturn(true); + when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); + when(toggleService.isUpdateContactDetailsEnabled()).thenReturn(true); + + CaseData caseData = CaseData.builder() + .respondent1(PartyBuilder.builder().individual().build()) + .respondent1Copy(PartyBuilder.builder().individual().build()) + .respondent1DQ(Respondent1DQ.builder() + .respondent1DQExperts(Experts.builder() + .details(wrapElements(Expert.builder().build())).build()) + .build()) + .respondent2(PartyBuilder.builder().individual().build()) + .respondent2Copy(PartyBuilder.builder().individual().build()) + .respondent2DQ(Respondent2DQ.builder().build()) + .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_ADMISSION) + .respondent2ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_ADMISSION) + .ccdCaseReference(354L) + .respondent1ResponseDate(dateTime).build().toBuilder() + .build(); - Witnesses actualRespondent1DQWitnesses = objectMapper.convertValue(response.getData().get( - "respondent1DQWitnesses"), new TypeReference<>() { - }); - Witness actualRespondent1Witness = unwrapElements(actualRespondent1DQWitnesses.getDetails()).get(0); - assertThat(actualRespondent1Witness.getPartyID()).isNotNull(); - assertThat(actualRespondent1Witness.getFirstName()).isEqualTo("Witness"); - assertThat(actualRespondent1Witness.getLastName()).isEqualTo("One"); - assertThat(actualRespondent1Witness.getEmailAddress()).isEqualTo("test-witness-one@example.com"); - assertThat(actualRespondent1Witness.getPhoneNumber()).isEqualTo("07865456789"); - assertThat(actualRespondent1Witness.getReasonForWitness()).isEqualTo("great reasons"); - assertThat(actualRespondent1Witness.getEventAdded()).isEqualTo("Defendant Response Event"); - assertThat(actualRespondent1Witness.getDateAdded()).isEqualTo(date); - - Witnesses actualRespondent2DQWitnesses = objectMapper.convertValue(response.getData().get( - "respondent2DQWitnesses"), new TypeReference<>() { - }); - Witness respondent2Witness = unwrapElements(actualRespondent2DQWitnesses.getDetails()).get(0); - assertThat(respondent2Witness.getPartyID()).isNotNull(); - assertThat(respondent2Witness.getFirstName()).isEqualTo("Witness"); - assertThat(respondent2Witness.getLastName()).isEqualTo("Two"); - assertThat(respondent2Witness.getEmailAddress()).isEqualTo("test-witness-two@example.com"); - assertThat(respondent2Witness.getPhoneNumber()).isEqualTo("07532628263"); - assertThat(respondent2Witness.getReasonForWitness()).isEqualTo("good reasons"); - assertThat(respondent2Witness.getEventAdded()).isEqualTo("Defendant Response Event"); - assertThat(respondent2Witness.getDateAdded()).isEqualTo(date); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + // Then + assertThat(response.getData().get("respondent1DQExperts")).isNotNull(); + assertThat(response.getData().get("respondent2DQExperts")).isNull(); } - @Nested - class HandleLocations { + @Test + void shouldUpdateExpertEvents_whenInvokedAndUpdateContactDetailsEnabled() { + // Given + LocalDateTime dateTime = LocalDateTime.of(2023, 6, 6, 6, 6, 6); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(mockedStateFlow.isFlagSet(any())).thenReturn(true); + when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); + when(toggleService.isUpdateContactDetailsEnabled()).thenReturn(true); - @Test - void oneVOne() { - // Given - DynamicList locationValues = DynamicList.fromList(List.of("Value 1")); - DynamicList preferredCourt = DynamicList.builder() - .listItems(locationValues.getListItems()) - .value(locationValues.getListItems().get(0)) - .build(); - Party defendant1 = Party.builder() - .type(Party.Type.COMPANY) - .companyName("company") - .build(); - CaseData caseData = CaseData.builder() - .caseAccessCategory(SPEC_CLAIM) - .ccdCaseReference(354L) - .respondent1(defendant1) - .respondent1Copy(defendant1) - .respondent1DQ( - Respondent1DQ.builder() - .respondToCourtLocation( - RequestedCourt.builder() - .responseCourtLocations(preferredCourt) - .reasonForHearingAtSpecificCourt("Reason") - .build() - ) - .build() - ) - .showConditionFlags(EnumSet.of( - DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_1 - )) - .build(); - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + CaseData caseData = CaseData.builder() + .respondent1(PartyBuilder.builder().individual().build()) + .respondent1Copy(PartyBuilder.builder().individual().build()) + .respondent1DQ(Respondent1DQ.builder() + .respondent1DQExperts(Experts.builder() + .details(wrapElements(Expert.builder().build())).build()) + .build()) + .respondent2(PartyBuilder.builder().individual().build()) + .respondent2Copy(PartyBuilder.builder().individual().build()) + .respondent2DQ(Respondent2DQ.builder().build()) + .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) + .respondent2ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) + .ccdCaseReference(354L) + .respondent1ResponseDate(dateTime).build().toBuilder() + .build(); - List locations = List.of(LocationRefData.builder().build()); - when(locationRefDataService.getCourtLocationsForDefaultJudgments(any())) - .thenReturn(locations); - LocationRefData completePreferredLocation = LocationRefData.builder() - .regionId("regionId") - .epimmsId("epimms") - .courtLocationCode("code") - .build(); - when(courtLocationUtils.findPreferredLocationData( - locations, preferredCourt - )).thenReturn(completePreferredLocation); - StateFlow flow = mock(StateFlow.class); - when(flow.isFlagSet(FlowFlag.TWO_RESPONDENT_REPRESENTATIVES)).thenReturn(false); - when(stateFlowEngine.evaluate(caseData)) - .thenReturn(flow); - when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), any(CaseRole.class))) - .thenReturn(true); - UserInfo userInfo = UserInfo.builder().uid("798").build(); - when(userService.getUserInfo(anyString())).thenReturn(userInfo); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); - // Then - AbstractObjectAssert sent1 = assertThat(response.getData()) - .extracting("respondent1DQRequestedCourt"); - sent1.extracting("caseLocation") - .extracting("region") - .isEqualTo(completePreferredLocation.getRegionId()); - sent1.extracting("caseLocation") - .extracting("baseLocation") - .isEqualTo(completePreferredLocation.getEpimmsId()); - sent1.extracting("responseCourtCode") - .isEqualTo(completePreferredLocation.getCourtLocationCode()); - sent1.extracting("reasonForHearingAtSpecificCourt") - .isEqualTo("Reason"); - } + // Then + assertThat(response.getData().get("respondent1DQExperts")).isNotNull(); + assertThat(response.getData().get("respondent2DQExperts")).isNull(); - @Test - void oneVTwo_SecondDefendantRepliesSameLegalRep() { - // Given - DynamicList locationValues = DynamicList.fromList(List.of("Value 1")); - DynamicList preferredCourt = DynamicList.builder() - .listItems(locationValues.getListItems()) - .value(locationValues.getListItems().get(0)) - .build(); - Party defendant1 = Party.builder() - .type(Party.Type.COMPANY) - .companyName("company") - .build(); - CaseData caseData = CaseData.builder() - .respondent2SameLegalRepresentative(YES) - .caseAccessCategory(SPEC_CLAIM) - .ccdCaseReference(354L) - .defenceAdmitPartPaymentTimeRouteRequired(IMMEDIATELY) - .respondent2ClaimResponseTypeForSpec(FULL_ADMISSION) - .respondent1(defendant1) - .respondent1Copy(defendant1) - .respondent1DQ( - Respondent1DQ.builder() - .respondToCourtLocation( - RequestedCourt.builder() - .responseCourtLocations(preferredCourt) - .reasonForHearingAtSpecificCourt("Reason") - .build() - ) - .build() - ) - .respondent2DQ( - Respondent2DQ.builder() - .respondToCourtLocation2( - RequestedCourt.builder() - .responseCourtLocations(preferredCourt) - .reasonForHearingAtSpecificCourt("Reason123") - .build() - ) - .build() - ) - .showConditionFlags(EnumSet.of( - DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_1, - DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_2 - )) - .build(); - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + } + + @Test + void shouldUpdateExpertEvents_whenInvokedAndUpdateContactDetailsEnabled_V2DraftDirections() { + // Given + LocalDateTime dateTime = LocalDateTime.of(2023, 6, 6, 6, 6, 6); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(mockedStateFlow.isFlagSet(any())).thenReturn(true); + when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); + when(toggleService.isUpdateContactDetailsEnabled()).thenReturn(true); + + CaseData caseData = CaseData.builder() + .respondent1(PartyBuilder.builder().individual().build()) + .respondent1Copy(PartyBuilder.builder().individual().build()) + .respondent1DQ(Respondent1DQ.builder() + .respondent1DQExperts(Experts.builder() + .details(wrapElements(Expert.builder().build())).build()) + .build()) + .respondent2(PartyBuilder.builder().individual().build()) + .respondent2Copy(PartyBuilder.builder().individual().build()) + .respondent2DQ(Respondent2DQ.builder() + .respondent2DQDraftDirections(Document.builder().build()).build()) + .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) + .respondent2ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) + .ccdCaseReference(354L) + .respondent1ResponseDate(dateTime).build().toBuilder() + .build(); + + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + // Then + assertThat(response.getData().get("respondent1DQExperts")).isNotNull(); + assertThat(response.getData().get("respondent2DQExperts")).isNull(); + + } + + @Test + void shouldUpdateWitnessEvents_whenInvokedAndUpdateContactDetailsEnabled() { + // Given + LocalDateTime dateTime = LocalDateTime.of(2023, 6, 6, 6, 6, 6); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(mockedStateFlow.isFlagSet(any())).thenReturn(true); + when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); + when(toggleService.isUpdateContactDetailsEnabled()).thenReturn(true); + + CaseData caseData = CaseData.builder() + .respondent1(PartyBuilder.builder().individual().build()) + .respondent1Copy(PartyBuilder.builder().individual().build()) + .respondent1DQ(Respondent1DQ.builder() + .respondent1DQWitnesses(Witnesses.builder() + .details(wrapElements(Witness.builder().build())).build()) + .build()) + + .respondent2(PartyBuilder.builder().individual().build()) + .respondent2Copy(PartyBuilder.builder().individual().build()) + .respondent2DQ(Respondent2DQ.builder().build()) + .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) + .respondent2ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_DEFENCE) + .ccdCaseReference(354L) + .respondent1ResponseDate(dateTime).build().toBuilder() + .build(); + + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + // Then + assertThat(response.getData().get("respondent1DQWitnesses")).isNotNull(); + assertThat(response.getData().get("respondent2DQWitnesses")).isNull(); + + } + + @Test + void shouldUpdateCorrespondence1_whenProvided() { + // Given + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(mockedStateFlow.isFlagSet(any())).thenReturn(true); + when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).thenReturn(true); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(false); + when(toggleService.isCaseFileViewEnabled()).thenReturn(true); + var testDocument = ResponseDocument.builder() + .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); + + CaseData caseData = CaseData.builder() + .respondent1(PartyBuilder.builder().individual().build()) + .respondent1Copy(PartyBuilder.builder().individual().build()) + .respondent1DQ(Respondent1DQ.builder().build()) + .respondent2DQ(Respondent2DQ.builder().build()) + .ccdCaseReference(354L) + .respondent1SpecDefenceResponseDocument(testDocument) + .respondent2SpecDefenceResponseDocument(testDocument) + .isRespondent1(YesOrNo.YES) + .respondentSolicitor1ServiceAddressRequired(YesOrNo.NO) + .respondentSolicitor1ServiceAddress( + Address.builder() + .postCode("new postcode") + .build() + ) + .build(); - List locations = List.of(LocationRefData.builder().build()); - when(locationRefDataService.getCourtLocationsForDefaultJudgments(any())) - .thenReturn(locations); - LocationRefData completePreferredLocation = LocationRefData.builder() - .regionId("regionId") - .epimmsId("epimms") - .courtLocationCode("code") - .build(); - when(courtLocationUtils.findPreferredLocationData( - locations, preferredCourt - )).thenReturn(completePreferredLocation); - StateFlow flow = mock(StateFlow.class); - when(flow.isFlagSet(FlowFlag.TWO_RESPONDENT_REPRESENTATIVES)).thenReturn(true); - when(stateFlowEngine.evaluate(caseData)).thenReturn(flow); - when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), any(CaseRole.class))) - .thenReturn(true); - UserInfo userInfo = UserInfo.builder().uid("798").build(); - when(userService.getUserInfo(anyString())).thenReturn(userInfo); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); - // Then - AbstractObjectAssert sent2 = assertThat(response.getData()) - .extracting("respondent2DQRequestedCourt"); - sent2.extracting("caseLocation") - .extracting("region") - .isEqualTo(completePreferredLocation.getRegionId()); - sent2.extracting("caseLocation") - .extracting("baseLocation") - .isEqualTo(completePreferredLocation.getEpimmsId()); - sent2.extracting("responseCourtCode") - .isEqualTo(completePreferredLocation.getCourtLocationCode()); - sent2.extracting("reasonForHearingAtSpecificCourt") - .isEqualTo("Reason123"); - } + // Then + assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) + .extracting("PostCode") + .isEqualTo("new postcode"); + assertThat(response.getData().get("respondentSolicitor1ServiceAddress")) + .extracting("PostCode") + .isNull(); + } - @Test - void oneVTwo_SecondDefendantReplies() { - // Given - DynamicList locationValues = DynamicList.fromList(List.of("Value 1")); - DynamicList preferredCourt = DynamicList.builder() - .listItems(locationValues.getListItems()) - .value(locationValues.getListItems().get(0)) - .build(); - Party defendant1 = Party.builder() - .type(Party.Type.COMPANY) - .companyName("company") - .build(); - CaseData caseData = CaseData.builder() - .caseAccessCategory(SPEC_CLAIM) - .ccdCaseReference(354L) - .respondent1(defendant1) - .respondent1Copy(defendant1) - .respondent1DQ( - Respondent1DQ.builder() - .respondToCourtLocation( - RequestedCourt.builder() - .responseCourtLocations(preferredCourt) - .reasonForHearingAtSpecificCourt("Reason") - .build() - ) - .build() - ) - .respondent2DQ( - Respondent2DQ.builder() - .respondToCourtLocation2( - RequestedCourt.builder() - .responseCourtLocations(preferredCourt) - .reasonForHearingAtSpecificCourt("Reason123") - .build() - ) - .build() - ) - .showConditionFlags(EnumSet.of( - DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_1, - DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_2 - )) - .build(); - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + @Test + void shouldUpdateCorrespondence1_whenProvided1v2ss() { + // Given + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(mockedStateFlow.isFlagSet(any())).thenReturn(true); + when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).thenReturn(true); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(false); + when(toggleService.isCaseFileViewEnabled()).thenReturn(true); + var testDocument = ResponseDocument.builder() + .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); - List locations = List.of(LocationRefData.builder().build()); - when(locationRefDataService.getCourtLocationsForDefaultJudgments(any())) - .thenReturn(locations); - LocationRefData completePreferredLocation = LocationRefData.builder() - .regionId("regionId") - .epimmsId("epimms") - .courtLocationCode("code") - .build(); - when(courtLocationUtils.findPreferredLocationData( - locations, preferredCourt - )).thenReturn(completePreferredLocation); - StateFlow flow = mock(StateFlow.class); - when(flow.isFlagSet(FlowFlag.TWO_RESPONDENT_REPRESENTATIVES)).thenReturn(true); - when(stateFlowEngine.evaluate(caseData)).thenReturn(flow); - when(coreCaseUserService.userHasCaseRole(anyString(), anyString(), any(CaseRole.class))) - .thenReturn(true); - UserInfo userInfo = UserInfo.builder().uid("798").build(); - when(userService.getUserInfo(anyString())).thenReturn(userInfo); + CaseData caseData = CaseData.builder() + .respondent1(PartyBuilder.builder().individual().build()) + .respondent1Copy(PartyBuilder.builder().individual().build()) + .respondent1DQ(Respondent1DQ.builder().build()) + .respondent2DQ(Respondent2DQ.builder().build()) + .ccdCaseReference(354L) + .respondent1SpecDefenceResponseDocument(testDocument) + .respondent2SpecDefenceResponseDocument(testDocument) + .isRespondent1(YesOrNo.YES) + .respondentSolicitor1ServiceAddressRequired(YesOrNo.NO) + .respondentSolicitor1ServiceAddress( + Address.builder() + .postCode("new postcode") + .build() + ) + .respondent2(Party.builder() + .type(Party.Type.COMPANY) + .companyName("Company 3") + .build()) + .respondent2SameLegalRepresentative(YES) + .build(); - // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); - // Then - AbstractObjectAssert sent2 = assertThat(response.getData()) - .extracting("respondent2DQRequestedCourt"); - sent2.extracting("caseLocation") - .extracting("region") - .isEqualTo(completePreferredLocation.getRegionId()); - sent2.extracting("caseLocation") - .extracting("baseLocation") - .isEqualTo(completePreferredLocation.getEpimmsId()); - sent2.extracting("responseCourtCode") - .isEqualTo(completePreferredLocation.getCourtLocationCode()); - sent2.extracting("reasonForHearingAtSpecificCourt") - .isEqualTo("Reason123"); - } + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + // Then + assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) + .extracting("PostCode") + .isEqualTo("new postcode"); + assertThat(response.getData().get("respondentSolicitor1ServiceAddress")) + .extracting("PostCode") + .isNull(); + assertEquals( + response.getData().get("specRespondentCorrespondenceAddressdetails"), + response.getData().get("specRespondent2CorrespondenceAddressdetails") + ); + assertEquals( + response.getData().get("specRespondentCorrespondenceAddressRequired"), + response.getData().get("specRespondent2CorrespondenceAddressRequired") + ); } @Test - void shouldNullDocuments_whenInvokedAndCaseFileEnabled() { + void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse() { // Given when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); when(mockedStateFlow.isFlagSet(any())).thenReturn(true); when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); - when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).thenReturn(true); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(false); when(toggleService.isCaseFileViewEnabled()).thenReturn(true); var testDocument = ResponseDocument.builder() - .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl( - "binary-url").build()).build(); + .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); CaseData caseData = CaseData.builder() .respondent1(PartyBuilder.builder().individual().build()) @@ -1227,6 +1598,19 @@ void shouldNullDocuments_whenInvokedAndCaseFileEnabled() { .ccdCaseReference(354L) .respondent1SpecDefenceResponseDocument(testDocument) .respondent2SpecDefenceResponseDocument(testDocument) + .isRespondent1(YesOrNo.YES) + .respondentResponseIsSame(YES) + .respondentSolicitor1ServiceAddressRequired(YesOrNo.NO) + .respondentSolicitor1ServiceAddress( + Address.builder() + .postCode("new postcode") + .build() + ) + .respondent2(Party.builder() + .type(Party.Type.COMPANY) + .companyName("Company 3") + .build()) + .respondent2SameLegalRepresentative(YES) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -1236,12 +1620,24 @@ void shouldNullDocuments_whenInvokedAndCaseFileEnabled() { .handle(params); // Then - assertThat(response.getData().get("respondent1SpecDefenceResponseDocument")).isNull(); - assertThat(response.getData().get("respondent2SpecDefenceResponseDocument")).isNull(); + assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) + .extracting("PostCode") + .isEqualTo("new postcode"); + assertThat(response.getData().get("respondentSolicitor1ServiceAddress")) + .extracting("PostCode") + .isNull(); + assertEquals( + response.getData().get("specRespondentCorrespondenceAddressdetails"), + response.getData().get("specRespondent2CorrespondenceAddressdetails") + ); + assertEquals( + response.getData().get("specRespondentCorrespondenceAddressRequired"), + response.getData().get("specRespondent2CorrespondenceAddressRequired") + ); } @Test - void shouldUpdateCorrespondence1_whenProvided() { + void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse_withv2copy() { // Given when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); when(mockedStateFlow.isFlagSet(any())).thenReturn(true); @@ -1250,8 +1646,7 @@ void shouldUpdateCorrespondence1_whenProvided() { when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(false); when(toggleService.isCaseFileViewEnabled()).thenReturn(true); var testDocument = ResponseDocument.builder() - .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl( - "binary-url").build()).build(); + .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); CaseData caseData = CaseData.builder() .respondent1(PartyBuilder.builder().individual().build()) @@ -1262,12 +1657,19 @@ void shouldUpdateCorrespondence1_whenProvided() { .respondent1SpecDefenceResponseDocument(testDocument) .respondent2SpecDefenceResponseDocument(testDocument) .isRespondent1(YesOrNo.YES) - .specAoSRespondentCorrespondenceAddressRequired(YesOrNo.NO) - .specAoSRespondentCorrespondenceAddressdetails( + .respondentResponseIsSame(YES) + .respondentSolicitor1ServiceAddressRequired(YesOrNo.NO) + .respondentSolicitor1ServiceAddress( Address.builder() .postCode("new postcode") .build() ) + .respondent2(Party.builder() + .type(Party.Type.COMPANY) + .companyName("Company 3") + .build()) + .respondent2Copy(PartyBuilder.builder().individual().build()) + .respondent2SameLegalRepresentative(YES) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -1280,13 +1682,21 @@ void shouldUpdateCorrespondence1_whenProvided() { assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) .extracting("PostCode") .isEqualTo("new postcode"); - assertThat(response.getData().get("specAoSRespondentCorrespondenceAddressdetails")) + assertThat(response.getData().get("respondentSolicitor1ServiceAddress")) .extracting("PostCode") .isNull(); + assertEquals( + response.getData().get("specRespondentCorrespondenceAddressdetails"), + response.getData().get("specRespondent2CorrespondenceAddressdetails") + ); + assertEquals( + response.getData().get("specRespondentCorrespondenceAddressRequired"), + response.getData().get("specRespondent2CorrespondenceAddressRequired") + ); } @Test - void shouldUpdateCorrespondence1_whenProvided1v2ss() { + void shouldUpdateCorrespondence1_whenProvided1v2ss_withSameResponse_withv2copyAndNoTempAdr() { // Given when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); when(mockedStateFlow.isFlagSet(any())).thenReturn(true); @@ -1295,8 +1705,7 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss() { when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(false); when(toggleService.isCaseFileViewEnabled()).thenReturn(true); var testDocument = ResponseDocument.builder() - .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl( - "binary-url").build()).build(); + .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); CaseData caseData = CaseData.builder() .respondent1(PartyBuilder.builder().individual().build()) @@ -1307,8 +1716,9 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss() { .respondent1SpecDefenceResponseDocument(testDocument) .respondent2SpecDefenceResponseDocument(testDocument) .isRespondent1(YesOrNo.YES) - .specAoSRespondentCorrespondenceAddressRequired(YesOrNo.NO) - .specAoSRespondentCorrespondenceAddressdetails( + .respondentResponseIsSame(YES) + .respondentSolicitor1ServiceAddressRequired(YesOrNo.NO) + .respondentSolicitor1ServiceAddress( Address.builder() .postCode("new postcode") .build() @@ -1317,7 +1727,9 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss() { .type(Party.Type.COMPANY) .companyName("Company 3") .build()) + .respondent2Copy(PartyBuilder.builder().individual().build()) .respondent2SameLegalRepresentative(YES) + .tempCorrespondenceAddress2Required(NO) .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); @@ -1330,7 +1742,7 @@ void shouldUpdateCorrespondence1_whenProvided1v2ss() { assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) .extracting("PostCode") .isEqualTo("new postcode"); - assertThat(response.getData().get("specAoSRespondentCorrespondenceAddressdetails")) + assertThat(response.getData().get("respondentSolicitor1ServiceAddress")) .extracting("PostCode") .isNull(); assertEquals( @@ -1352,20 +1764,21 @@ void shouldUpdateCorrespondence2_whenProvided() { when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); when(toggleService.isCaseFileViewEnabled()).thenReturn(true); var testDocument = ResponseDocument.builder() - .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl( - "binary-url").build()).build(); + .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); CaseData caseData = CaseData.builder() .respondent1(PartyBuilder.builder().individual().build()) .respondent1Copy(PartyBuilder.builder().individual().build()) .respondent1DQ(Respondent1DQ.builder().build()) + .respondent2(PartyBuilder.builder().individual().build()) + .respondent2Copy(PartyBuilder.builder().individual().build()) .respondent2DQ(Respondent2DQ.builder().build()) .ccdCaseReference(354L) .respondent1SpecDefenceResponseDocument(testDocument) .respondent2SpecDefenceResponseDocument(testDocument) .isRespondent2(YesOrNo.YES) - .specAoSRespondent2CorrespondenceAddressRequired(YesOrNo.NO) - .specAoSRespondent2CorrespondenceAddressdetails( + .respondentSolicitor2ServiceAddressRequired(YesOrNo.NO) + .respondentSolicitor2ServiceAddress( Address.builder() .postCode("new postcode") .build() @@ -1382,7 +1795,7 @@ void shouldUpdateCorrespondence2_whenProvided() { assertThat(response.getData().get("specRespondent2CorrespondenceAddressdetails")) .extracting("PostCode") .isEqualTo("new postcode"); - assertThat(response.getData().get("specAoSRespondent2CorrespondenceAddressdetails")) + assertThat(response.getData().get("respondentSolicitor2ServiceAddress")) .extracting("PostCode") .isNull(); } @@ -1412,6 +1825,58 @@ void shouldPopulateRespondent2Flag_WhenInvoked() { assertThat(response.getData().get("respondent2DocumentGeneration")).isEqualTo("userRespondent2"); } + @Test + void shouldPopulateRespondent2Flag_WhenInvokedWithSmallClaimExperts_1DQ() { + // Given + when(toggleService.isCaseFileViewEnabled()).thenReturn(true); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); + given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).willReturn(true); + given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).willReturn(false); + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimDetailsNotified() + .respondent2(PartyBuilder.builder().individual().build()) + .addRespondent2(YES) + .respondent1(PartyBuilder.builder().individual().build()) + .respondent1Copy(PartyBuilder.builder().individual().build()) + .respondent1DQ(Respondent1DQ.builder() + .respondToClaimExperts(ExpertDetails.builder().build()).build()) + .respondent2DQ(Respondent2DQ.builder().build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + // Given + assertThat(response.getData().get("respondent2DocumentGeneration")).isEqualTo("userRespondent2"); + } + + @Test + void shouldPopulateRespondent2Flag_WhenInvokedWithSmallClaimExperts_2DQ() { + // Given + when(toggleService.isCaseFileViewEnabled()).thenReturn(true); + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); + given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).willReturn(true); + given(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).willReturn(false); + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimDetailsNotified() + .respondent2(PartyBuilder.builder().individual().build()) + .addRespondent2(YES) + .respondent1(PartyBuilder.builder().individual().build()) + .respondent1Copy(PartyBuilder.builder().individual().build()) + .respondent2DQ(Respondent2DQ.builder() + .respondToClaimExperts2(ExpertDetails.builder().build()).build()) + .respondent1DQ(Respondent1DQ.builder().build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + // Given + assertThat(response.getData().get("respondent2DocumentGeneration")).isEqualTo("userRespondent2"); + } + @Test void shouldNotPopulateRespondent2Flag_WhenInvoked() { // Given @@ -1474,6 +1939,26 @@ void shouldSetMultiPartyResponseTypeFlags_Counter_Admit_OR_Admit_Part_combinatio .isEqualTo("COUNTER_ADMIT_OR_ADMIT_PART"); } + @Test + void shouldSetMultiPartyResponseTypeFlags_Counter_Admit_OR_Admit_Part_combination2_CanAddApplicant2() { + // Given + CaseData caseData = CaseDataBuilder.builder().atStateRespondent2v1BothNotFullDefence_CounterClaimX2() + .addApplicant2(YES) + .respondent1ClaimResponseTypeForSpec(FULL_ADMISSION) + .respondent1ClaimResponseTypeForSpec(FULL_ADMISSION) + .build(); + + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); + + // When + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + // Then + assertThat(response.getData()).extracting("multiPartyResponseTypeFlags") + .isEqualTo("COUNTER_ADMIT_OR_ADMIT_PART"); + } + + /** * if solicitor says that each defendant gets their response but then chooses the same * option from full defence/part admit/full admit/counterclaim, then it is not different response. @@ -1564,7 +2049,6 @@ void shouldReturnError_whenWitnessRequiredAndNullDetails() { void shouldReturnNoError_whenWitnessRequiredAndDetailsProvided() { // Given List> testWitness = wrapElements(Witness.builder().name("test witness").build()); - Witnesses witnesses = Witnesses.builder().witnessesToAppear(YES).details(testWitness).build(); CaseData caseData = CaseDataBuilder.builder() .respondent1DQ(Respondent1DQ.builder().build()) .respondent1DQWitnessesRequiredSpec(YES) @@ -1653,9 +2137,6 @@ void specificSummary_whenPartialAdmitNotPay() { // When SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); - LocalDateTime responseDeadline = caseData.getApplicant1ResponseDeadline(); - String claimNumber = caseData.getLegacyCaseReference(); - // Then assertThat(response.getConfirmationBody()) .contains(caseData.getApplicant1().getPartyName()) @@ -2063,12 +2544,12 @@ void whenProvided_thenValidateCorrespondence1() { CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build() .toBuilder() .isRespondent1(YES) - .specAoSRespondentCorrespondenceAddressRequired(YesOrNo.NO) - .specAoSRespondentCorrespondenceAddressdetails(Address.builder() + .respondentSolicitor1ServiceAddressRequired(YesOrNo.NO) + .respondentSolicitor1ServiceAddress(Address.builder() .postCode("postal code") .build()) .build(); - CallbackParams params = callbackParamsOf(caseData, MID, "confirm-details"); + CallbackParams params = callbackParamsOf(caseData, MID, "specCorrespondenceAddress"); when(postcodeValidator.validate("postal code")).thenReturn(Collections.emptyList()); // When @@ -2085,12 +2566,12 @@ void whenProvided_thenValidateCorrespondence2() { CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build() .toBuilder() .isRespondent2(YES) - .specAoSRespondent2CorrespondenceAddressRequired(YesOrNo.NO) - .specAoSRespondent2CorrespondenceAddressdetails(Address.builder() - .postCode("postal code") - .build()) + .respondentSolicitor2ServiceAddressRequired(YesOrNo.NO) + .respondentSolicitor2ServiceAddress(Address.builder() + .postCode("postal code") + .build()) .build(); - CallbackParams params = callbackParamsOf(caseData, MID, "confirm-details"); + CallbackParams params = callbackParamsOf(caseData, MID, "specCorrespondenceAddress"); when(postcodeValidator.validate("postal code")).thenReturn(Collections.emptyList()); // When @@ -2320,10 +2801,55 @@ public void shouldThrowError_whenValidateRespondentExpertsMultipartyWithNoUnavai // Then assertThat(response.getErrors()).isNotEmpty(); } + + @Test + public void shouldThrowError_whenValidateRespondentExpertsMultipartyWithNoUnavailableDates_DisputesTheClaim() { + // Given + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified() + .responseClaimTrack(SpecJourneyConstantLRSpec.DISPUTES_THE_CLAIM) + .respondent1DQ(Respondent1DQ.builder() + .respondent1DQHearingSmallClaim(SmallClaimHearing.builder().unavailableDatesRequired( + YES).build()).build()) + .build(); + List errors = Collections.singletonList("error 1"); + Mockito.when(dateValidator.validateFastClaimHearing(any())).thenReturn(errors); + CallbackParams params = callbackParamsOf(caseData, MID, "validate-unavailable-dates"); + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + // Then + assertThat(response.getErrors()).isNotEmpty(); + } + + @Test + public void shouldThrowError_whenValidateRespondentExpertsMultipartyWithNoUnavailableDates_V2() { + // Given + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified() + .responseClaimTrack(SpecJourneyConstantLRSpec.SMALL_CLAIM) + .respondent1DQ(Respondent1DQ.builder() + .respondent1DQHearingSmallClaim(SmallClaimHearing.builder().unavailableDatesRequired( + YES).build()).build()) + .respondent2DQ(Respondent2DQ.builder() + .respondent2DQHearingSmallClaim(SmallClaimHearing.builder().unavailableDatesRequired( + YES).build()).build()) + .isRespondent2(YES) + .build(); + List errors = Collections.singletonList("error 1"); + Mockito.when(dateValidator.validateSmallClaimsHearing(any())).thenReturn(errors); + CallbackParams params = callbackParamsOf(caseData, MID, "validate-unavailable-dates"); + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + // Then + assertThat(response.getErrors()).isNotEmpty(); + } } @Test void handleEventsReturnsTheExpectedCallbackEvents() { assertThat(handler.handledEvents()).containsOnly(DEFENDANT_RESPONSE_SPEC); } + } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandlerTest.java index 22ab7c93da4..9b5371b1f9f 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/RespondToDefenceSpecCallbackHandlerTest.java @@ -18,6 +18,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse; +import uk.gov.hmcts.reform.civil.bankholidays.WorkingDayIndicator; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CallbackVersion; import uk.gov.hmcts.reform.civil.config.ExitSurveyConfiguration; @@ -68,6 +69,8 @@ import uk.gov.hmcts.reform.civil.service.PaymentDateService; import uk.gov.hmcts.reform.civil.service.Time; import uk.gov.hmcts.reform.civil.service.citizenui.RespondentMediationService; +import uk.gov.hmcts.reform.civil.service.citizenui.ResponseOneVOneShowTagService; +import uk.gov.hmcts.reform.civil.service.citizenui.responsedeadline.DeadlineExtensionCalculatorService; import uk.gov.hmcts.reform.civil.service.flowstate.FlowState; import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser; import uk.gov.hmcts.reform.civil.utils.CourtLocationUtils; @@ -91,6 +94,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START; @@ -128,7 +132,8 @@ LocationHelper.class, LocationRefDataService.class, JudgementService.class, - PaymentDateService.class + PaymentDateService.class, + ResponseOneVOneShowTagService.class }) class RespondToDefenceSpecCallbackHandlerTest extends BaseCallbackHandlerTest { @@ -144,6 +149,9 @@ class RespondToDefenceSpecCallbackHandlerTest extends BaseCallbackHandlerTest { @Autowired private PaymentDateService paymentDateService; + @Autowired + private ResponseOneVOneShowTagService responseOneVOneShowTagService; + @MockBean private UnavailableDateValidator unavailableDateValidator; @@ -165,6 +173,10 @@ class RespondToDefenceSpecCallbackHandlerTest extends BaseCallbackHandlerTest { private RespondentMediationService respondentMediationService; @MockBean private DeadlinesCalculator deadlinesCalculator; + @MockBean + private WorkingDayIndicator workingDayIndicator; + @MockBean + private DeadlineExtensionCalculatorService deadlineCalculatorService; @Nested class AboutToStart { @@ -1079,6 +1091,7 @@ void shouldChangeCaseStateToJudicialReferral_ONE_V_TWO_ONE_REP() { .addRespondent2(YES) .respondentResponseIsSame(YES) .responseClaimTrack(FAST_CLAIM.name()) + .applicant1ProceedWithClaim(YES) .applicant1DQ(Applicant1DQ.builder().applicant1RespondToClaimExperts( ExpertDetails.builder().build()).build()) .respondent1(Party.builder().type(Party.Type.INDIVIDUAL).build()).build(); @@ -1099,6 +1112,7 @@ void shouldChangeCaseStateToJudicialReferral_ONE_V_TWO_TWO_REP() { .respondent2SameLegalRepresentative(NO) .addRespondent2(YES) .responseClaimTrack(FAST_CLAIM.name()) + .applicant1ProceedWithClaim(YES) .applicant1DQ(Applicant1DQ.builder().applicant1RespondToClaimExperts( ExpertDetails.builder().build()).build()) .respondent1(Party.builder().type(Party.Type.INDIVIDUAL).build()).build(); @@ -1355,7 +1369,9 @@ class SetUpPaymentDateToStringField { void shouldSetUpPaymentDateToString() { when(featureToggleService.isPinInPostEnabled()).thenReturn(true); - LocalDate whenWillPay = LocalDate.now().plusDays(5); + given(workingDayIndicator.isWorkingDay(any())).willReturn(true); + LocalDate whenWillPay = LocalDate.now(); + given(deadlineCalculatorService.calculateExtendedDeadline(any(), anyInt())).willReturn(whenWillPay); RespondToClaimAdmitPartLRspec respondToClaimAdmitPartLRspec = RespondToClaimAdmitPartLRspec.builder() @@ -1383,6 +1399,7 @@ void shouldSetUpPaymentDateToStringForPartAdmitPaid() { when(featureToggleService.isPinInPostEnabled()).thenReturn(true); LocalDate whenWillPay = LocalDate.now().plusDays(5); + given(deadlineCalculatorService.calculateExtendedDeadline(any(), anyInt())).willReturn(whenWillPay); RespondToClaim respondToAdmittedClaim = RespondToClaim.builder() @@ -1410,7 +1427,9 @@ void shouldSetUpPaymentDateToStringForPartAdmitPaid() { void shouldSetUpPaymentDateForResponseDateToString() { when(featureToggleService.isPinInPostEnabled()).thenReturn(true); - LocalDate whenWillPay = LocalDate.now().plusDays(5); + given(workingDayIndicator.isWorkingDay(any())).willReturn(true); + LocalDate whenWillPay = LocalDate.now(); + given(deadlineCalculatorService.calculateExtendedDeadline(any(), anyInt())).willReturn(whenWillPay); CaseData caseData = CaseData.builder() .respondent1ResponseDate(LocalDateTime.now()) diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/StandardDirectionOrderDJTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/StandardDirectionOrderDJTest.java index 4f94e09294f..3fea6f64824 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/StandardDirectionOrderDJTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/StandardDirectionOrderDJTest.java @@ -5,6 +5,8 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; @@ -49,6 +51,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START; @@ -57,6 +61,7 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.SUBMITTED; import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.ACKNOWLEDGEMENT_OF_CLAIM; import static uk.gov.hmcts.reform.civil.enums.CaseCategory.UNSPEC_CLAIM; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element; @@ -544,6 +549,44 @@ void shouldPrePopulateDJTrialHearingToggle() { var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); assertThat(response.getData()).extracting("trialHearingVariationsDirectionsDJToggle").isNotNull(); + assertThat(response.getData()).extracting("trialHearingVariationsDirectionsDJToggle").isNotNull(); + } + + @Test + void shouldPopulateLocationListsWithPreselectedCourt() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimDraft() + .atStateClaimIssuedTrialHearing() + .build(); + + String preSelectedCourt = "214320"; + + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); + List locations = List.of( + LocationRefData.builder().epimmsId("00001").courtLocationCode("00001") + .siteName("court 1").courtAddress("1 address").postcode("Y01 7RB").build(), + LocationRefData.builder().epimmsId(preSelectedCourt).courtLocationCode(preSelectedCourt) + .siteName("court 2").courtAddress("2 address").postcode("Y02 7RB").build(), + LocationRefData.builder().epimmsId("00003").courtLocationCode("00003") + .siteName("court 3").courtAddress("3 address").postcode("Y03 7RB").build() + ); + + when(locationRefDataService.getCourtLocationsForDefaultJudgments(anyString())).thenReturn(locations); + + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData responseCaseData = mapper.convertValue(response.getData(), CaseData.class); + DynamicList expected = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code(preSelectedCourt).label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .value(DynamicListElement.builder().code(preSelectedCourt).label("court 2 - 2 address - Y02 7RB").build()) + .build(); + + assertThat(responseCaseData.getTrialHearingMethodInPersonDJ()).isEqualTo(expected); + assertThat(responseCaseData.getDisposalHearingMethodInPersonDJ()).isEqualTo(expected); } @Test @@ -693,9 +736,21 @@ void shouldCreateAndSaveSDOOrder_whenStateClaimIssuedDisposalSDOVideoCall() { @Nested class AboutToSubmitCallback { + + @BeforeEach + void setup() { + given(featureToggleService.isEarlyAdoptersEnabled()).willReturn(true); + } + @Test void shouldFinishBusinessProcess() { - CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build(); + List items = List.of("label 1", "label 2", "label 3"); + DynamicList options = DynamicList.fromList(items, Object::toString, Object::toString, items.get(0), false); + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build() + .toBuilder() + .disposalHearingMethodInPersonDJ(options) + .trialHearingMethodInPersonDJ(options) + .build(); CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); assertThat(response.getData()).extracting("businessProcess").isNotNull(); @@ -717,9 +772,13 @@ void shouldAssignCategoryId_whenInvoked() { .build(); List> documentList = new ArrayList<>(); documentList.add(element(testDocument)); + List items = List.of("label 1", "label 2", "label 3"); + DynamicList options = DynamicList.fromList(items, Object::toString, items.get(0), false); //Given when(featureToggleService.isCaseFileViewEnabled()).thenReturn(true); CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build().toBuilder() + .trialHearingMethodInPersonDJ(options) + .disposalHearingMethodInPersonDJ(options) .orderSDODocumentDJCollection(documentList) .build(); @@ -730,6 +789,88 @@ void shouldAssignCategoryId_whenInvoked() { //Then assertThat(updatedData.getOrderSDODocumentDJCollection().get(0).getValue().getDocumentLink().getCategoryID()).isEqualTo("sdo"); } + + @ParameterizedTest + @CsvSource({"true", "false"}) + void shouldPopulateEarlyAdoptersFlag_whenDisposalHearingMethodInPersonDJIsSet(Boolean isLocationWhiteListed) { + DynamicList options = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .value(DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build()) + .build(); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build() + .toBuilder() + .disposalHearingMethodInPersonDJ(options) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(featureToggleService.isLocationWhiteListedForCaseProgression(eq(options.getValue().getCode()))).thenReturn( + isLocationWhiteListed); + + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData responseCaseData = mapper.convertValue(response.getData(), CaseData.class); + + assertThat(responseCaseData.getEaCourtLocation()).isEqualTo(isLocationWhiteListed ? YES : NO); + } + + @Test + void shouldNotPopulateEarlyAdoptersFlag_whenEarlyAdoptersToggleIsOff() { + DynamicList options = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .value(DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build()) + .build(); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build() + .toBuilder() + .disposalHearingMethodInPersonDJ(options) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(featureToggleService.isEarlyAdoptersEnabled()).thenReturn(false); + when(featureToggleService.isLocationWhiteListedForCaseProgression(eq(options.getValue().getCode()))) + .thenReturn(true); + + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData responseCaseData = mapper.convertValue(response.getData(), CaseData.class); + + assertThat(responseCaseData.getEaCourtLocation()).isNull(); + } + } + + @ParameterizedTest + @CsvSource({"true", "false"}) + void shouldPopulateEarlyAdoptersFlag_whenTrialHearingMethodInPersonDJIsSet(Boolean isLocationWhiteListed) { + DynamicList options = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("00001").label("court 1 - 1 address - Y01 7RB").build(), + DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build(), + DynamicListElement.builder().code("00003").label("court 3 - 3 address - Y03 7RB").build() + ) + ) + .value(DynamicListElement.builder().code("00002").label("court 2 - 2 address - Y02 7RB").build()) + .build(); + + CaseData caseData = CaseDataBuilder.builder().atStateClaimDraft().build() + .toBuilder() + .trialHearingMethodInPersonDJ(options) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + when(featureToggleService.isEarlyAdoptersEnabled()).thenReturn(true); + when(featureToggleService.isLocationWhiteListedForCaseProgression(eq(options.getValue().getCode()))).thenReturn( + isLocationWhiteListed); + + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + CaseData responseCaseData = mapper.convertValue(response.getData(), CaseData.class); + + assertThat(responseCaseData.getEaCourtLocation()).isEqualTo(isLocationWhiteListed ? YES : NO); } @Nested diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/event/EvidenceUploadNotificationEventHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/event/EvidenceUploadNotificationEventHandlerTest.java index e03aa29680d..7d8eccce7bc 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/event/EvidenceUploadNotificationEventHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/event/EvidenceUploadNotificationEventHandlerTest.java @@ -6,6 +6,7 @@ import org.mockito.Mock; import org.springframework.test.context.junit.jupiter.SpringExtension; import uk.gov.hmcts.reform.ccd.client.model.CaseDetails; +import uk.gov.hmcts.reform.ccd.client.model.StartEventResponse; import uk.gov.hmcts.reform.civil.event.EvidenceUploadNotificationEvent; import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.CaseData; @@ -18,6 +19,7 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.EVIDENCE_UPLOAD_CHECK; @ExtendWith(SpringExtension.class) class EvidenceUploadNotificationEventHandlerTest { @@ -43,6 +45,8 @@ void shouldNotifyAllSolicitors() { CaseDetails caseDetails = CaseDetailsBuilder.builder().data(caseData).build(); when(coreCaseDataService.getCase(caseId)).thenReturn(caseDetails); when(caseDetailsConverter.toCaseData(caseDetails)).thenReturn(caseData); + when(coreCaseDataService.startUpdate(caseId.toString(), EVIDENCE_UPLOAD_CHECK)) + .thenReturn(StartEventResponse.builder().caseDetails(caseDetails).build()); EvidenceUploadNotificationEvent event = new EvidenceUploadNotificationEvent(caseId); //when: Evidence upload Notification handler is called handler.sendEvidenceUploadNotification(event); @@ -62,6 +66,8 @@ void shouldContinueRespondentNotificationIfApplicantFailed() { //when: Exception is thrown from applicant notification handler when(coreCaseDataService.getCase(caseId)).thenReturn(caseDetails); when(caseDetailsConverter.toCaseData(caseDetails)).thenReturn(caseData); + when(coreCaseDataService.startUpdate(caseId.toString(), EVIDENCE_UPLOAD_CHECK)) + .thenReturn(StartEventResponse.builder().caseDetails(caseDetails).build()); doThrow(new RuntimeException()).when(applicantNotificationHandler).notifyApplicantEvidenceUpload(caseData); EvidenceUploadNotificationEvent event = new EvidenceUploadNotificationEvent(caseId); handler.sendEvidenceUploadNotification(event); @@ -80,6 +86,8 @@ void shouldContinueRespondent2IfRespondent1Failed() { //when: Exception is thrown for repondent1 notification handler when(coreCaseDataService.getCase(caseId)).thenReturn(caseDetails); when(caseDetailsConverter.toCaseData(caseDetails)).thenReturn(caseData); + when(coreCaseDataService.startUpdate(caseId.toString(), EVIDENCE_UPLOAD_CHECK)) + .thenReturn(StartEventResponse.builder().caseDetails(caseDetails).build()); doThrow(new RuntimeException()).when(respondentNotificationHandler).notifyRespondentEvidenceUpload(caseData, true); EvidenceUploadNotificationEvent event = new EvidenceUploadNotificationEvent(caseId); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/helpers/bundle/BundleRequestMapperTest.java b/src/test/java/uk/gov/hmcts/reform/civil/helpers/bundle/BundleRequestMapperTest.java index bc6d8bfe685..1e4665f1f00 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/helpers/bundle/BundleRequestMapperTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/helpers/bundle/BundleRequestMapperTest.java @@ -8,6 +8,7 @@ import uk.gov.hmcts.reform.civil.enums.caseprogression.TypeOfDocDocumentaryEvidenceOfTrial; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.Party; +import uk.gov.hmcts.reform.civil.model.ServedDocumentFiles; import uk.gov.hmcts.reform.civil.model.bundle.BundleCreateRequest; import uk.gov.hmcts.reform.civil.model.caseprogression.UploadEvidenceDocumentType; import uk.gov.hmcts.reform.civil.model.caseprogression.UploadEvidenceExpert; @@ -76,20 +77,22 @@ void testBundleRequestMapperWithAllDocs() { bundleCreateRequest.getCaseDetails().getCaseData().getTrialDocuments().get(11).getValue().getDocumentFileName()); assertEquals("Claim Form 10/02/2023", bundleCreateRequest.getCaseDetails().getCaseData().getStatementsOfCaseDocuments().get(0).getValue().getDocumentFileName()); - assertEquals("DF 1 Defence 10/02/2023", + assertEquals("Particulars Of Claim 10/02/2023", bundleCreateRequest.getCaseDetails().getCaseData().getStatementsOfCaseDocuments().get(1).getValue().getDocumentFileName()); - assertEquals("CL's reply 10/02/2023", + assertEquals("DF 1 Defence 10/02/2023", bundleCreateRequest.getCaseDetails().getCaseData().getStatementsOfCaseDocuments().get(2).getValue().getDocumentFileName()); - assertEquals("CL 1 reply to part 18 request 12/01/2023", + assertEquals("CL's reply 10/02/2023", bundleCreateRequest.getCaseDetails().getCaseData().getStatementsOfCaseDocuments().get(3).getValue().getDocumentFileName()); - assertEquals("CL 2 reply to part 18 request 12/01/2023", + assertEquals("CL 1 reply to part 18 request 12/01/2023", bundleCreateRequest.getCaseDetails().getCaseData().getStatementsOfCaseDocuments().get(4).getValue().getDocumentFileName()); - assertEquals("DF 1 reply to part 18 request 12/01/2023", + assertEquals("CL 2 reply to part 18 request 12/01/2023", bundleCreateRequest.getCaseDetails().getCaseData().getStatementsOfCaseDocuments().get(5).getValue().getDocumentFileName()); - assertEquals("DF 2 reply to part 18 request 12/01/2023", + assertEquals("DF 1 reply to part 18 request 12/01/2023", bundleCreateRequest.getCaseDetails().getCaseData().getStatementsOfCaseDocuments().get(6).getValue().getDocumentFileName()); - assertEquals("Directions Questionnaire 10/02/2023", + assertEquals("DF 2 reply to part 18 request 12/01/2023", bundleCreateRequest.getCaseDetails().getCaseData().getStatementsOfCaseDocuments().get(7).getValue().getDocumentFileName()); + assertEquals("Directions Questionnaire 10/02/2023", + bundleCreateRequest.getCaseDetails().getCaseData().getStatementsOfCaseDocuments().get(8).getValue().getDocumentFileName()); assertEquals("Directions Order 10/02/2023", bundleCreateRequest.getCaseDetails().getCaseData().getOrdersDocuments().get(0).getValue().getDocumentFileName()); assertEquals("Order 10/02/2023", @@ -148,6 +151,7 @@ void testBundleRequestMapperWithAllDocs() { bundleCreateRequest.getCaseDetails().getCaseData().getDefendant1CostsBudgets().get(0).getValue().getDocumentFileName()); assertEquals("testFileName 12/12/2023", bundleCreateRequest.getCaseDetails().getCaseData().getDefendant2CostsBudgets().get(0).getValue().getDocumentFileName()); + } private CaseData getCaseData() { @@ -213,9 +217,19 @@ private CaseData getCaseData() { .respondent2(Party.builder().individualLastName("lastname").individualFirstName("df2Fname").partyName( "respondent2").type(Party.Type.INDIVIDUAL).build()) .hearingDate(LocalDate.now()) + .submittedDate(LocalDateTime.of(2023, 2, 10, 2, + 2, 2)) + .servedDocumentFiles(setupParticularsOfClaimDocs()) .build(); } + private ServedDocumentFiles setupParticularsOfClaimDocs() { + List> particularsOfClaim = new ArrayList<>(); + Document document = Document.builder().documentFileName(TEST_FILE_NAME).documentUrl(TEST_URL).build(); + particularsOfClaim.add(ElementUtils.element(document)); + return ServedDocumentFiles.builder().particularsOfClaimDocument(particularsOfClaim).build(); + } + private List> getExpertOtherPartyQuestionDocs(String partyName) { String expertName = ""; String otherParty = ""; diff --git a/src/test/java/uk/gov/hmcts/reform/civil/model/PartyTest.java b/src/test/java/uk/gov/hmcts/reform/civil/model/PartyTest.java index 87ee19e09cc..177d6930853 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/model/PartyTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/model/PartyTest.java @@ -61,4 +61,28 @@ void shouldGetSoulTraderPartyNameExcludingTitle_whenInstantiated() { assertThat(party.getPartyName(true)).isEqualTo("James Carver"); } + @Test + void shouldReturnTrueWhenPartyIsCompany() { + Party party = Party.builder().type(Party.Type.COMPANY) + .build(); + + assertThat(party.isCompanyOROrganisation()).isTrue(); + } + + @Test + void shouldReturnTrueWhenPartyIsOrganisation() { + Party party = Party.builder().type(Party.Type.ORGANISATION) + .build(); + + assertThat(party.isCompanyOROrganisation()).isTrue(); + } + + @Test + void shouldReturnTrueWhenPartyIsNOTOrganisationOrCompany() { + Party party = Party.builder().type(Party.Type.INDIVIDUAL) + .build(); + + assertThat(party.isCompanyOROrganisation()).isFalse(); + } + } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/model/common/DynamicListTest.java b/src/test/java/uk/gov/hmcts/reform/civil/model/common/DynamicListTest.java new file mode 100644 index 00000000000..1aef0b2539b --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/model/common/DynamicListTest.java @@ -0,0 +1,57 @@ +package uk.gov.hmcts.reform.civil.model.common; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import java.util.Arrays; +import java.util.List; +import java.util.function.Function; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class DynamicListTest { + + private List listItems; + + @BeforeEach + public void setUp() { + listItems = Arrays.asList("Item1", "Item2", "Item3"); + } + + @Test + public void shouldPopulateDynamicListFromList_whenCodeFunctionIsProvided() { + Function toCode = item -> item + "_code"; + Function toLabel = item -> item + "_label"; + String value = "Item2"; + + DynamicList actual = DynamicList.fromList(listItems, toCode, toLabel, value, true); + + DynamicList expected = DynamicList.builder() + .listItems(List.of( + DynamicListElement.builder().code("Item1_code").label("Item1_label").build(), + DynamicListElement.builder().code("Item2_code").label("Item2_label").build(), + DynamicListElement.builder().code("Item3_code").label("Item3_label").build() + )) + .value(DynamicListElement.builder().code("Item2_code").label("Item2_label").build()) + .build(); + + assertEquals(expected, actual); + } + + @Test + public void shouldPopulateDynamicListFromList_whenCodeFunctionIsNotProvided() { + Function toLabel = item -> item + "_label"; + String value = "Item2"; + + DynamicList actual = DynamicList.fromList(listItems, null, toLabel, value, true); + + assertNotNull(actual.getListItems().get(0).getCode()); + assertEquals("Item1_label", actual.getListItems().get(0).getLabel()); + assertNotNull(actual.getListItems().get(1).getCode()); + assertEquals("Item2_label", actual.getListItems().get(1).getLabel()); + assertNotNull(actual.getListItems().get(2).getCode()); + assertEquals("Item3_label", actual.getListItems().get(2).getLabel()); + assertNotNull(actual.getValue().getCode()); + assertEquals("Item2_label", actual.getValue().getLabel()); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/civil/notification/EvidenceUploadApplicantNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/notification/EvidenceUploadApplicantNotificationHandlerTest.java index f1ebab3128e..8a90e4fbfd0 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/notification/EvidenceUploadApplicantNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/notification/EvidenceUploadApplicantNotificationHandlerTest.java @@ -19,8 +19,10 @@ import java.util.Map; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.CLAIM_REFERENCE_NUMBER; +import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.UPLOADED_DOCUMENTS; @SpringBootTest(classes = { EvidenceUploadApplicantNotificationHandler.class, @@ -47,7 +49,9 @@ void setup() { @Test void shouldNotifyApplicantSolicitor_whenInvoked() { //given: case where applicant solicitor has email as applicantsolicitor@example.com - CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build(); + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() + .notificationText("example of uploaded documents") + .build(); //when: ApplicantNotificationhandler is called handler.notifyApplicantEvidenceUpload(caseData); //then: email should be sent to applicant solicitor @@ -62,7 +66,8 @@ void shouldNotifyApplicantSolicitor_whenInvoked() { @Test void shouldNotifyApplicantLip_whenInvoked() { //given: case where applicant litigant in person has email as applicant@example.com - CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified() + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() + .notificationText("example of uploaded documents") .applicant1Represented(YesOrNo.NO) .applicant1(Party.builder().partyName("Billy").partyEmail("applicant@example.com").build()) .build(); @@ -77,10 +82,41 @@ void shouldNotifyApplicantLip_whenInvoked() { ); } + @Test + void shouldNotNotifyApplicantLip_whenInvokedAndNoNotificationContent() { + //Once emails are sent, we want to null notificationText, so any future emails will not contain past content. + //unable to null directly in EvidenceUploadNotificationEventHandler, so assigned as NULLED. + //given: case where applicant litigant in person has email as applicant@example.com + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().builder() + .notificationText("NULLED") + .applicant1Represented(YesOrNo.NO) + .applicant1(Party.builder().partyName("Billy").partyEmail("applicant@example.com").build()) + .build(); + //when: ApplicantNotificationhandler is called + handler.notifyApplicantEvidenceUpload(caseData); + //then: email should be sent to applicant + verifyNoInteractions(notificationService); + } + + @Test + void shouldNotNotifyApplicantLip_whenInvokedAndNoNotificationContentNull() { + //given: case where applicant litigant in person has email as applicant@example.com + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() + .notificationText(null) + .applicant1Represented(YesOrNo.NO) + .applicant1(Party.builder().partyName("Billy").partyEmail("applicant@example.com").build()) + .build(); + //when: ApplicantNotificationhandler is called + handler.notifyApplicantEvidenceUpload(caseData); + //then: email should be sent to applicant + verifyNoInteractions(notificationService); + } + @NotNull private Map getNotificationDataMap(CaseData caseData) { return Map.of( - CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference() + CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(), + UPLOADED_DOCUMENTS, "example of uploaded documents" ); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/notification/EvidenceUploadRespondentNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/notification/EvidenceUploadRespondentNotificationHandlerTest.java index 85d39b3c4b4..db5d359d8d4 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/notification/EvidenceUploadRespondentNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/notification/EvidenceUploadRespondentNotificationHandlerTest.java @@ -19,8 +19,10 @@ import java.util.Map; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.CLAIM_REFERENCE_NUMBER; +import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.UPLOADED_DOCUMENTS; @SpringBootTest(classes = { EvidenceUploadRespondentNotificationHandler.class, @@ -47,7 +49,9 @@ void setup() { @Test void shouldNotifyRespondent1Solicitor_whenInvoked() { //given: case data has one respondent solicitor - CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build(); + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() + .notificationText("example of uploaded documents") + .build();; //when: RepondentNotificationhandler for solictior1 is called handler.notifyRespondentEvidenceUpload(caseData, true); //then: email should be sent to respondent solicitor1 @@ -62,7 +66,8 @@ void shouldNotifyRespondent1Solicitor_whenInvoked() { @Test void shouldNotifyRespondent1Lip_whenInvoked() { //given: case data has one respondent litigant in person - CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified() + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() + .notificationText("example of uploaded documents") .respondent1Represented(YesOrNo.NO) .respondent1(Party.builder().partyName("Billy").partyEmail("respondent@example.com").build()) .build(); @@ -81,8 +86,9 @@ void shouldNotifyRespondent1Lip_whenInvoked() { @Test void shouldNotifyRespondent2Solicitor_whenInvoked() { //given: case data has two respondent solicitor - CaseData caseData = CaseDataBuilder.builder() - .atStateClaimDetailsNotified().addRespondent2(YesOrNo.YES) + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() + .notificationText("example of uploaded documents") + .addRespondent2(YesOrNo.YES) .respondentSolicitor2EmailAddress("respondentsolicitor2@example.com") .build(); //when: RepondentNotificationhandler for solictior2 is called @@ -99,8 +105,9 @@ void shouldNotifyRespondent2Solicitor_whenInvoked() { @Test void shouldNotifyRespondent2Lip_whenInvoked() { //given: case data has two respondents, with second being litigant in person - CaseData caseData = CaseDataBuilder.builder() - .atStateClaimDetailsNotified().addRespondent2(YesOrNo.YES) + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() + .notificationText("example of uploaded documents") + .addRespondent2(YesOrNo.YES) .respondent2Represented(YesOrNo.NO) .respondent2(Party.builder().partyName("Billy").partyEmail("respondent@example.com").build()) .build(); @@ -115,10 +122,37 @@ void shouldNotifyRespondent2Lip_whenInvoked() { ); } + @Test + void shouldNotNotifyRespondent1Solicitor_whenInvokedAndNoNotificationContent() { + //Once emails are sent, we want to null notificationText, so any future emails will not contain past content. + //unable to null directly in EvidenceUploadNotificationEventHandler, so assigned as NULLED. + //given: case data has one respondent solicitor + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() + .notificationText("NULLED") + .build(); + //when: RepondentNotificationhandler for solictior1 is called + handler.notifyRespondentEvidenceUpload(caseData, true); + //then: email should be sent to respondent solicitor1 + verifyNoInteractions(notificationService); + } + + @Test + void shouldNotNotifyRespondent1Solicitor_whenInvokedAndNoContentNull() { + //given: case data has one respondent solicitor + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build().toBuilder() + .notificationText(null) + .build(); + //when: RepondentNotificationhandler for solictior1 is called + handler.notifyRespondentEvidenceUpload(caseData, true); + //then: email should be sent to respondent solicitor1 + verifyNoInteractions(notificationService); + } + @NotNull private Map getNotificationDataMap(CaseData caseData) { return Map.of( - CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference() + CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(), + UPLOADED_DOCUMENTS, "example of uploaded documents" ); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/sampledata/CaseDataBuilder.java b/src/test/java/uk/gov/hmcts/reform/civil/sampledata/CaseDataBuilder.java index f6b96b180f4..df35ed83ab4 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/sampledata/CaseDataBuilder.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/sampledata/CaseDataBuilder.java @@ -488,6 +488,15 @@ public class CaseDataBuilder { private NotSuitableSdoOptions notSuitableSdoOptions; + private List> applicant1LRIndividuals; + private List> respondent1LRIndividuals; + private List> respondent2LRIndividuals; + + private List> applicant1OrgIndividuals; + private List> applicant2OrgIndividuals; + private List> respondent1OrgIndividuals; + private List> respondent2OrgIndividuals; + protected String hearingReference; protected ListingOrRelisting listingOrRelisting; @@ -6076,8 +6085,8 @@ public CaseDataBuilder claimantUserDetails(IdamUserDetails claimantUserDetails) return this; } - public CaseDataBuilder updateDetailsForm(UpdateDetailsForm additionalDates) { - this.updateDetailsForm = additionalDates; + public CaseDataBuilder updateDetailsForm(UpdateDetailsForm form) { + this.updateDetailsForm = form; return this; } @@ -6131,6 +6140,125 @@ public CaseDataBuilder atTrialHearingWitnessOfFactWithNegativeInputs() { return this; } + public CaseDataBuilder addApplicantLRIndividual(String firstName, String lastName) { + List> individual = + wrapElements(PartyFlagStructure.builder() + .partyID("app-lr-ind-party-id") + .firstName(firstName) + .lastName(lastName) + .email("abc@def.ghi") + .phone("07777777777") + .build()); + if (this.applicant1LRIndividuals != null && !this.applicant1LRIndividuals.isEmpty()) { + this.applicant1LRIndividuals.addAll(individual); + } else { + this.applicant1LRIndividuals = individual; + } + return this; + } + + public CaseDataBuilder addRespondent1LRIndividual(String firstName, String lastName) { + List> individual = + wrapElements(PartyFlagStructure.builder() + .partyID("res-1-lr-ind-party-id") + .firstName(firstName) + .lastName(lastName) + .email("abc@def.ghi") + .phone("07777777777") + .build()); + if (this.respondent1LRIndividuals != null && !this.respondent1LRIndividuals.isEmpty()) { + this.respondent1LRIndividuals.addAll(individual); + } else { + this.respondent1LRIndividuals = individual; + } + return this; + } + + public CaseDataBuilder addRespondent2LRIndividual(String firstName, String lastName) { + List> individual = + wrapElements(PartyFlagStructure.builder() + .partyID("res-2-lr-ind-party-id") + .firstName(firstName) + .lastName(lastName) + .email("abc@def.ghi") + .phone("07777777777") + .build()); + if (this.respondent2LRIndividuals != null && !this.respondent2LRIndividuals.isEmpty()) { + this.respondent2LRIndividuals.addAll(individual); + } else { + this.respondent2LRIndividuals = individual; + } + return this; + } + + public CaseDataBuilder addApplicant1OrgIndividual(String firstName, String lastName) { + List> individual = + wrapElements(PartyFlagStructure.builder() + .partyID("app-1-org-ind-party-id") + .firstName(firstName) + .lastName(lastName) + .email("abc@def.ghi") + .phone("07777777777") + .build()); + if (this.applicant1OrgIndividuals != null && !this.applicant1OrgIndividuals.isEmpty()) { + this.applicant1OrgIndividuals.addAll(individual); + } else { + this.applicant1OrgIndividuals = individual; + } + return this; + } + + public CaseDataBuilder addApplicant2OrgIndividual(String firstName, String lastName) { + List> individual = + wrapElements(PartyFlagStructure.builder() + .partyID("app-2-org-ind-party-id") + .firstName(firstName) + .lastName(lastName) + .email("abc@def.ghi") + .phone("07777777777") + .build()); + if (this.applicant2OrgIndividuals != null && !this.applicant2OrgIndividuals.isEmpty()) { + this.applicant2OrgIndividuals.addAll(individual); + } else { + this.applicant2OrgIndividuals = individual; + } + return this; + } + + public CaseDataBuilder addRespondent1OrgIndividual(String firstName, String lastName) { + List> individual = + wrapElements(PartyFlagStructure.builder() + .partyID("res-1-org-ind-party-id") + .firstName(firstName) + .lastName(lastName) + .email("abc@def.ghi") + .phone("07777777777") + .build()); + if (this.respondent1OrgIndividuals != null && !this.respondent1OrgIndividuals.isEmpty()) { + this.respondent1OrgIndividuals.addAll(individual); + } else { + this.respondent1OrgIndividuals = individual; + } + return this; + } + + public CaseDataBuilder addRespondent2OrgIndividual(String firstName, String lastName) { + List> individual = + wrapElements(PartyFlagStructure.builder() + .partyID("res-2-org-ind-party-id") + .firstName(firstName) + .lastName(lastName) + .email("abc@def.ghi") + .phone("07777777777") + .build()); + if (this.respondent2OrgIndividuals != null && !this.respondent2OrgIndividuals.isEmpty()) { + this.respondent2OrgIndividuals.addAll(individual); + } else { + this.respondent2OrgIndividuals = individual; + } + return this; + } + public static CaseDataBuilder builder() { return new CaseDataBuilder(); } @@ -6416,6 +6544,13 @@ public CaseData build() { .drawDirectionsOrderRequired(drawDirectionsOrderRequired) .transferCourtLocationList(transferCourtLocationList) .reasonForTransfer(reasonForTransfer) + .applicant1LRIndividuals(applicant1LRIndividuals) + .respondent1LRIndividuals(respondent1LRIndividuals) + .respondent2LRIndividuals(respondent2LRIndividuals) + .applicant1OrgIndividuals(applicant1OrgIndividuals) + .applicant2OrgIndividuals(applicant2OrgIndividuals) + .respondent1OrgIndividuals(respondent1OrgIndividuals) + .respondent2OrgIndividuals(respondent2OrgIndividuals) .build(); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/GenAppStateHelperServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/GenAppStateHelperServiceTest.java index 6aa26270c72..f6626efde69 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/GenAppStateHelperServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/GenAppStateHelperServiceTest.java @@ -18,14 +18,19 @@ import uk.gov.hmcts.reform.civil.model.genapplication.CaseLocationCivil; import uk.gov.hmcts.reform.civil.model.genapplication.GADetailsRespondentSol; import uk.gov.hmcts.reform.civil.model.genapplication.GeneralApplicationsDetails; +import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; +import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.sampledata.GeneralApplicationDetailsBuilder; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; @@ -50,13 +55,19 @@ class GenAppStateHelperServiceTest { @MockBean private CoreCaseDataService coreCaseDataService; + @MockBean + private InitiateGeneralApplicationService genAppService; @Autowired private CaseDetailsConverter caseDetailsConverter; + @MockBean + private LocationRefDataService locationRefDataService; + private static final String APPLICATION_CLOSED_TEXT = "Application Closed"; private static final String APPLICATION_OFFLINE_TEXT = "Proceeds In Heritage"; private static final String SET_DATE = "2022-08-31T22:50:11.2509019"; + private static final String authToken = "Bearer TestAuthToken"; @Nested class StatusChangeInApplicationDetailsInClaim { @@ -393,6 +404,10 @@ private CaseDetails getCaseDetails( @Test void updateApplicationLocationDetailsLists() { + when(locationRefDataService.getCourtLocationsByEpimmsId(any(), any())) + .thenReturn(getSampleCourLocationsRefObject()); + when(genAppService.getWorkAllocationLocationDetails(any(), any())) + .thenReturn(getSampleCourLocationsRefObject1()); CaseData caseData = GeneralApplicationDetailsBuilder.builder() .getTestCaseDataWithDetails(CaseData.builder().build(), true, @@ -404,8 +419,10 @@ void updateApplicationLocationDetailsLists() { Pair caseLocation = Pair.of(CaseLocationCivil.builder() .region("2") .baseLocation("00000").siteName("locationOfRegion2") + .address("Prince William House, Peel Cross Road, Salford") + .postcode("M5 4RR") .build(), false); - CaseData updatedData = service.updateApplicationLocationDetailsInClaim(caseData); + CaseData updatedData = service.updateApplicationLocationDetailsInClaim(caseData, authToken); assertThat(getGADetailsFromUpdatedCaseData(updatedData, "1234")).isNotNull(); assertThat(updatedData.getGeneralApplications().get(0).getValue().getCaseManagementLocation()).isEqualTo(caseLocation.getLeft()); @@ -416,6 +433,23 @@ void updateApplicationLocationDetailsLists() { assertThat(updatedData.getGeneralApplications().get(2).getValue().getIsCcmccLocation()).isEqualTo(YesOrNo.NO); } + protected List getSampleCourLocationsRefObject() { + return new ArrayList<>(List.of( + LocationRefData.builder() + .epimmsId("00000").siteName("locationOfRegion2").courtAddress("Prince William House, Peel Cross Road, Salford") + .postcode("M5 4RR") + .courtLocationCode("court1").build() + )); + } + + protected LocationRefData getSampleCourLocationsRefObject1() { + return + LocationRefData.builder() + .epimmsId("00000").siteName("locationOfRegion2").courtAddress("Prince William House, Peel Cross Road, Salford") + .postcode("M5 4RR") + .courtLocationCode("court1").build(); + } + @Test void noLocationUpdatesToCaseDataIfThereAreNoGeneralApplications() { setupForApplicationOffline(); @@ -427,8 +461,7 @@ void noLocationUpdatesToCaseDataIfThereAreNoGeneralApplications() { Map.of() ); - CaseData response = service.updateApplicationLocationDetailsInClaim( - caseData); + CaseData response = service.updateApplicationLocationDetailsInClaim(caseData, authToken); CaseData updatedData = mapper.convertValue(response, CaseData.class); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationServiceTest.java index 3eabd89f790..c4e659ce307 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationServiceTest.java @@ -901,7 +901,8 @@ void shouldPopulateApplicantDetails() { CaseData caseData = GeneralApplicationDetailsBuilder.builder() .getTestCaseDataForConsentUnconsentCheck(GARespondentOrderAgreement.builder().hasAgreed(NO).build()); when(locationRefDataService.getCcmccLocation(any())) - .thenReturn(LocationRefData.builder().regionId("9").epimmsId("574546").siteName("CCMCC").build()); + .thenReturn(LocationRefData.builder().regionId("9").epimmsId("574546").siteName("CCMCC") + .courtAddress("Prince William House, Peel Cross Road, Salford").postcode("M5 4RR").build()); CaseData result = service.buildCaseData(caseData.toBuilder(), caseData, UserDetails.builder() .email(APPLICANT_EMAIL_ID_CONSTANT).id(STRING_NUM_CONSTANT).build(), CallbackParams.builder().toString()); @@ -914,11 +915,98 @@ void shouldPopulateApplicantDetails() { assertThat(result.getGeneralApplications().get(0).getValue().getLocationName()) .isEqualTo("CCMCC"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getAddress()) + .isEqualTo("Prince William House, Peel Cross Road, Salford"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getPostcode()) + .isEqualTo("M5 4RR"); assertThat(result.getGeneralApplications().get(0).getValue().getGeneralAppRespondentSolicitors() .stream().filter(e -> STRING_NUM_CONSTANT.equals(e.getValue().getId())).count()).isEqualTo(0); } + @Test + void shouldPopulateLocationDetailsForBaseLocation() { + when(locationRefDataService.getCourtLocationsByEpimmsId(any(), any())).thenReturn(getSampleCourLocationsRefObject()); + CaseData caseData = GeneralApplicationDetailsBuilder.builder() + .getCaseDataForWorkAllocation(null, null, INDIVIDUAL, applicant1DQ, respondent1DQ, + respondent2DQ); + CaseData result = service.buildCaseData(caseData.toBuilder(), caseData, UserDetails.builder() + .email(APPLICANT_EMAIL_ID_CONSTANT).build(), CallbackParams.builder().toString()); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getBaseLocation()) + .isEqualTo("11111"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getSiteName()) + .isEqualTo("locationOfRegion2"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getAddress()) + .isEqualTo("Prince William House, Peel Cross Road, Salford"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getPostcode()) + .isEqualTo("M5 4RR"); + } + + protected List getSampleCourLocationsRefObject() { + return new ArrayList<>(List.of( + LocationRefData.builder() + .epimmsId("11111").siteName("locationOfRegion2").courtAddress("Prince William House, Peel Cross Road, Salford") + .postcode("M5 4RR") + .courtLocationCode("court1").build() + )); + } + + protected List getEmptyCourLocationsRefObject() { + return new ArrayList<>(List.of( + LocationRefData.builder().build() + )); + } + + protected List getSampleCourtLocationsRefObjectMultipleValues() { + return new ArrayList<>(List.of( + LocationRefData.builder() + .epimmsId("11111").siteName("locationOfRegion2").courtAddress("Prince William House, Peel Cross Road, Salford") + .postcode("M5 4RR") + .courtLocationCode("court1").build(), + + LocationRefData.builder() + .epimmsId("11111").siteName("locationOfRegion2").courtAddress("Prince William House, Peel Cross Road, Salford") + .postcode("M5 4RR") + .courtLocationCode("court1").build() + )); + } + + @Test + void shouldPopulateLocationDetailsForBaseLocationWhereListIsEmpty() { + when(locationRefDataService.getCourtLocationsByEpimmsId(any(), any())).thenReturn(getEmptyCourLocationsRefObject()); + CaseData caseData = GeneralApplicationDetailsBuilder.builder() + .getCaseDataForWorkAllocation(null, null, INDIVIDUAL, applicant1DQ, respondent1DQ, + respondent2DQ); + CaseData result = service.buildCaseData(caseData.toBuilder(), caseData, UserDetails.builder() + .email(APPLICANT_EMAIL_ID_CONSTANT).build(), CallbackParams.builder().toString()); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getBaseLocation()) + .isEqualTo("11111"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getSiteName()) + .isNull(); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getAddress()) + .isNull(); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getPostcode()) + .isNull(); + } + + @Test + void shouldPopulateLocationDetailsForBaseLocationWithMultipleListValues() { + when(locationRefDataService.getCourtLocationsByEpimmsId(any(), any())).thenReturn(getSampleCourtLocationsRefObjectMultipleValues()); + CaseData caseData = GeneralApplicationDetailsBuilder.builder() + .getCaseDataForWorkAllocation(null, null, INDIVIDUAL, applicant1DQ, respondent1DQ, + respondent2DQ); + CaseData result = service.buildCaseData(caseData.toBuilder(), caseData, UserDetails.builder() + .email(APPLICANT_EMAIL_ID_CONSTANT).build(), CallbackParams.builder().toString()); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getBaseLocation()) + .isEqualTo("11111"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getSiteName()) + .isEqualTo("locationOfRegion2"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getAddress()) + .isEqualTo("Prince William House, Peel Cross Road, Salford"); + assertThat(result.getGeneralApplications().get(0).getValue().getCaseManagementLocation().getPostcode()) + .isEqualTo("M5 4RR"); + } + @Test void shouldPopulateWorkAllocationLocationOnAboutToSubmit_beforeSDOHasBeenMade() { when(locationRefDataService.getCcmccLocation(any())) diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/citizenui/responsedeadline/DeadlineExtensionCalculatorServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/citizenui/responsedeadline/DeadlineExtensionCalculatorServiceTest.java index 736974f4cce..dcc0e6f718c 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/citizenui/responsedeadline/DeadlineExtensionCalculatorServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/citizenui/responsedeadline/DeadlineExtensionCalculatorServiceTest.java @@ -26,30 +26,54 @@ public class DeadlineExtensionCalculatorServiceTest { @Test void shouldReturnTheSameGivenDateWhenDateIsWorkday() { - given(workingDayIndicator.isWorkingDay(any())).willReturn(true); + given(workingDayIndicator.getNextWorkingDay(any())).willReturn(LocalDate.now()); LocalDate proposedExtensionDeadline = LocalDate.now(); LocalDate calculatedDeadline = deadlineExtensionCalculatorService.calculateExtendedDeadline( - proposedExtensionDeadline); + proposedExtensionDeadline, 0); assertThat(calculatedDeadline).isEqualTo(proposedExtensionDeadline); - verify(workingDayIndicator).isWorkingDay(proposedExtensionDeadline); - verify(workingDayIndicator, never()).getNextWorkingDay(proposedExtensionDeadline); + verify(workingDayIndicator).getNextWorkingDay(proposedExtensionDeadline); + verify(workingDayIndicator, never()).isWorkingDay(proposedExtensionDeadline); } @Test void shouldReturnNextWorkingDayWhenDateIsHoliday() { - given(workingDayIndicator.isWorkingDay(any())).willReturn(false); + LocalDate proposedExtensionDeadline = LocalDate.of(2022, 6, 3); LocalDate calculatedNextWorkingDay = LocalDate.of(2022, 6, 4); + given(workingDayIndicator.getNextWorkingDay(any())).willReturn(calculatedNextWorkingDay); - LocalDate proposedExtensionDeadline = LocalDate.of(2022, 6, 3); LocalDate calculatedDeadline = deadlineExtensionCalculatorService.calculateExtendedDeadline( - proposedExtensionDeadline); + proposedExtensionDeadline, 0); assertThat(calculatedDeadline).isEqualTo(calculatedNextWorkingDay); - verify(workingDayIndicator).isWorkingDay(proposedExtensionDeadline); - verify(workingDayIndicator).getNextWorkingDay(proposedExtensionDeadline); + verify(workingDayIndicator, never()).isWorkingDay(calculatedNextWorkingDay); + } + + @Test + void shouldReturnFifthWorkingDayFromTheGivenDateWhen_NoHoliday_NoWeekend_InBetween() { + given(workingDayIndicator.isWorkingDay(any())).willReturn(true); + LocalDate proposedExtensionDeadline = LocalDate.of(2023, 11, 17); + LocalDate expectedExtensionDeadline = LocalDate.of(2023, 11, 22); + + LocalDate calculatedDeadline = deadlineExtensionCalculatorService.calculateExtendedDeadline( + proposedExtensionDeadline, 5); + + assertThat(calculatedDeadline).isEqualTo(expectedExtensionDeadline); + } + + @Test + void shouldReturnFifthWorkingDayFromTheGivenDateWhen_Holiday_InBetween() { + given(workingDayIndicator.isWorkingDay(any())).willReturn(true); + given(workingDayIndicator.isWorkingDay(LocalDate.of(2023, 11, 19))).willReturn(false); + LocalDate proposedExtensionDeadline = LocalDate.of(2023, 11, 17); + LocalDate expectedExtensionDeadline = LocalDate.of(2023, 11, 23); + + LocalDate calculatedDeadline = deadlineExtensionCalculatorService.calculateExtendedDeadline( + proposedExtensionDeadline, 5); + + assertThat(calculatedDeadline).isEqualTo(expectedExtensionDeadline); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/sealedclaim/SealedClaimLipResponseFormGeneratorTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/sealedclaim/SealedClaimLipResponseFormGeneratorTest.java index 7d56c033818..ab25f0fbe0e 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/sealedclaim/SealedClaimLipResponseFormGeneratorTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/sealedclaim/SealedClaimLipResponseFormGeneratorTest.java @@ -50,6 +50,7 @@ import uk.gov.hmcts.reform.civil.model.dq.RecurringExpenseLRspec; import uk.gov.hmcts.reform.civil.model.dq.RecurringIncomeLRspec; import uk.gov.hmcts.reform.civil.model.dq.Respondent1DQ; +import uk.gov.hmcts.reform.civil.service.citizenui.responsedeadline.DeadlineExtensionCalculatorService; import uk.gov.hmcts.reform.civil.service.docmosis.DocumentGeneratorService; import uk.gov.hmcts.reform.civil.utils.ElementUtils; @@ -81,6 +82,8 @@ class SealedClaimLipResponseFormGeneratorTest { private DocumentGeneratorService documentGeneratorService; @MockBean private DocumentManagementService documentManagementService; + @MockBean + private DeadlineExtensionCalculatorService deadlineCalculatorService; @Autowired private SealedClaimLipResponseFormGenerator generator; @Captor @@ -115,15 +118,20 @@ void shouldGenerateDocumentSuccessfully() { @Test void admitPayImmediate() { - CaseData caseData = commonData() + LocalDate whenWillPay = LocalDate.now().plusDays(5); + CaseData.CaseDataBuilder builder = commonData() .respondent1(company("B")) .respondent2(individual("C")) .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_ADMISSION) .defenceAdmitPartPaymentTimeRouteRequired(RespondentResponsePartAdmissionPaymentTimeLRspec.IMMEDIATELY) - .build(); + .respondToClaimAdmitPartLRspec( + RespondToClaimAdmitPartLRspec.builder() + .whenWillThisAmountBePaid(whenWillPay) + .build() + ); SealedClaimLipResponseForm templateData = generator - .getTemplateData(caseData); + .getTemplateData(builder.build()); Assertions.assertEquals(LocalDate.now(), templateData.getGenerationDate()); } @@ -171,6 +179,7 @@ void admitPayByDate() { @Test void partAdmitPayImmediate() { + LocalDate whenWillPay = LocalDate.now().plusDays(5); CaseData.CaseDataBuilder builder = commonData() .respondent1(company("B")) .respondent2(individual("C")) @@ -178,7 +187,12 @@ void partAdmitPayImmediate() { .specDefenceAdmittedRequired(YesOrNo.NO) .respondToAdmittedClaimOwingAmount(BigDecimal.valueOf(2000)) .detailsOfWhyDoesYouDisputeTheClaim("Reason to dispute the claim") - .defenceAdmitPartPaymentTimeRouteRequired(RespondentResponsePartAdmissionPaymentTimeLRspec.IMMEDIATELY); + .defenceAdmitPartPaymentTimeRouteRequired(RespondentResponsePartAdmissionPaymentTimeLRspec.IMMEDIATELY) + .respondToClaimAdmitPartLRspec( + RespondToClaimAdmitPartLRspec.builder() + .whenWillThisAmountBePaid(whenWillPay) + .build() + ); CaseData caseData = timeline(financialDetails(builder)) .build(); @@ -334,6 +348,70 @@ void counterClaim() { Assertions.assertEquals(LocalDate.now(), templateData.getGenerationDate()); } + @Test + void shouldGenerateDocumentSuccessfullyForFullAdmit() { + //Given + LocalDate whenWillPay = LocalDate.now().plusDays(5); + CaseData caseData = commonData() + .respondent1(company("B")) + .respondent2(individual("C")) + .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.FULL_ADMISSION) + .defenceAdmitPartPaymentTimeRouteRequired(RespondentResponsePartAdmissionPaymentTimeLRspec.IMMEDIATELY) + .respondToClaimAdmitPartLRspec( + RespondToClaimAdmitPartLRspec.builder() + .whenWillThisAmountBePaid(whenWillPay) + .build() + ) + .build(); + String fileName = "someName"; + DocmosisDocument docmosisDocument = mock(DocmosisDocument.class); + byte[] bytes = {}; + given(docmosisDocument.getBytes()).willReturn(bytes); + CaseDocument caseDocument = CaseDocument.builder().documentName(fileName).build(); + given(documentGeneratorService.generateDocmosisDocument(any(MappableObject.class), any())).willReturn( + docmosisDocument); + given(documentManagementService.uploadDocument(anyString(), any(PDF.class))).willReturn(caseDocument); + SealedClaimLipResponseForm templateData = generator + .getTemplateData(caseData); + //When + CaseDocument result = generator.generate(caseData, AUTHORIZATION); + //Then + assertThat(result).isEqualTo(caseDocument); + } + + @Test + void shouldGenerateDocumentSuccessfullyForPartAdmit() { + //Given + LocalDate whenWillPay = LocalDate.now().plusDays(5); + CaseData caseData = commonData() + .respondent1(company("B")) + .respondent2(individual("C")) + .respondent1ClaimResponseTypeForSpec(RespondentResponseTypeSpec.PART_ADMISSION) + .specDefenceAdmittedRequired(YesOrNo.NO) + .respondToAdmittedClaimOwingAmount(BigDecimal.valueOf(2000)) + .detailsOfWhyDoesYouDisputeTheClaim("Reason to dispute the claim") + .defenceAdmitPartPaymentTimeRouteRequired(RespondentResponsePartAdmissionPaymentTimeLRspec.IMMEDIATELY) + .respondToClaimAdmitPartLRspec( + RespondToClaimAdmitPartLRspec.builder() + .whenWillThisAmountBePaid(whenWillPay) + .build() + ).build(); + String fileName = "someName"; + DocmosisDocument docmosisDocument = mock(DocmosisDocument.class); + byte[] bytes = {}; + given(docmosisDocument.getBytes()).willReturn(bytes); + CaseDocument caseDocument = CaseDocument.builder().documentName(fileName).build(); + given(documentGeneratorService.generateDocmosisDocument(any(MappableObject.class), any())).willReturn( + docmosisDocument); + given(documentManagementService.uploadDocument(anyString(), any(PDF.class))).willReturn(caseDocument); + SealedClaimLipResponseForm templateData = generator + .getTemplateData(caseData); + //When + CaseDocument result = generator.generate(caseData, AUTHORIZATION); + //Then + assertThat(result).isEqualTo(caseDocument); + } + private static AccountSimple account(@NotNull AccountType type, @NotNull YesOrNo joint, @NotNull BigDecimal balance) { AccountSimple a = new AccountSimple(); a.setAccountType(type); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/flowstate/FlowStateAllowedEventServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/flowstate/FlowStateAllowedEventServiceTest.java index cae90e7ca58..f1dd6858eae 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/flowstate/FlowStateAllowedEventServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/flowstate/FlowStateAllowedEventServiceTest.java @@ -137,6 +137,8 @@ class FlowStateAllowedEventServiceTest { @Autowired FlowStateAllowedEventService flowStateAllowedEventService; + // used by StateFlowEngine bean + @SuppressWarnings("unused") @MockBean private FeatureToggleService toggleService; @@ -318,7 +320,8 @@ public Stream provideArguments(ExtensionContext context) { GENERATE_DIRECTIONS_ORDER, TRIAL_READINESS, BUNDLE_CREATION_NOTIFICATION, - TRANSFER_ONLINE_CASE + TRANSFER_ONLINE_CASE, + asyncStitchingComplete } ), of( @@ -567,7 +570,8 @@ public Stream provideArguments(ExtensionContext context) { SET_ASIDE_JUDGMENT, JUDGMENT_PAID_IN_FULL, RECORD_JUDGMENT, - TRANSFER_ONLINE_CASE + TRANSFER_ONLINE_CASE, + asyncStitchingComplete } ), of( diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyCheckSearchServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyCheckSearchServiceTest.java index 0aefcb6a5c2..24a6e6b3716 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyCheckSearchServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyCheckSearchServiceTest.java @@ -26,7 +26,10 @@ protected Query buildQuery(int fromValue) { .should(boolQuery() .must(rangeQuery("data.hearingDate").lt(LocalDate.now().atTime(LocalTime.MIN).plusWeeks(3) .toString())) - .must(boolQuery().must(matchQuery("state", "PREPARE_FOR_HEARING_CONDUCT_HEARING"))) + .must(boolQuery() + .minimumShouldMatch(1) + .should(boolQuery().must(matchQuery("state", "PREPARE_FOR_HEARING_CONDUCT_HEARING"))) + .should(boolQuery().must(matchQuery("state", "HEARING_READINESS")))) .mustNot(matchQuery("data.allocatedTrack", "SMALL_CLAIM")) .mustNot(matchQuery("data.trialReadyChecked", "Yes"))); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyNotificationSearchServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyNotificationSearchServiceTest.java index 961b2c67253..f94d49c3430 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyNotificationSearchServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/search/TrialReadyNotificationSearchServiceTest.java @@ -28,10 +28,13 @@ protected Query buildQuery(int fromValue) { .should(boolQuery() .must(rangeQuery("data.hearingDate").lt(LocalDate.now().atTime(LocalTime.MIN).plusWeeks(6) .toString())) - .must(boolQuery().must(matchQuery("state", "PREPARE_FOR_HEARING_CONDUCT_HEARING")))) + .must(boolQuery() + .minimumShouldMatch(1) + .should(boolQuery().must(matchQuery("state", "PREPARE_FOR_HEARING_CONDUCT_HEARING"))) + .should(boolQuery().must(matchQuery("state", "HEARING_READINESS")))) .mustNot(matchQuery("data.allocatedTrack", "SMALL_CLAIM")) .mustNot(matchQuery("data.listingOrRelisting", ListingOrRelisting.RELISTING)) - .mustNot(matchQuery("data.trialReadyNotified", YesOrNo.YES)); + .mustNot(matchQuery("data.trialReadyNotified", YesOrNo.YES))); return new Query(query, List.of("reference"), fromValue); } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/utils/CaseFlagUtilsTest.java b/src/test/java/uk/gov/hmcts/reform/civil/utils/CaseFlagUtilsTest.java index cca5bf3657e..aae666611d3 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/utils/CaseFlagUtilsTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/utils/CaseFlagUtilsTest.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.reform.civil.utils; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -7,6 +8,7 @@ import uk.gov.hmcts.reform.civil.model.PartyFlagStructure; import uk.gov.hmcts.reform.civil.model.LitigationFriend; import uk.gov.hmcts.reform.civil.model.Party; +import uk.gov.hmcts.reform.civil.model.UpdateDetailsForm; import uk.gov.hmcts.reform.civil.model.caseflags.FlagDetail; import uk.gov.hmcts.reform.civil.model.caseflags.Flags; import uk.gov.hmcts.reform.civil.model.common.Element; @@ -18,15 +20,21 @@ import uk.gov.hmcts.reform.civil.model.dq.Respondent2DQ; import uk.gov.hmcts.reform.civil.model.dq.Witness; import uk.gov.hmcts.reform.civil.model.dq.Witnesses; +import uk.gov.hmcts.reform.civil.prd.model.Organisation; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.sampledata.PartyBuilder; +import uk.gov.hmcts.reform.civil.service.OrganisationService; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.APPLICANT_SOLICITOR_EXPERT; @@ -39,10 +47,35 @@ import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.addRespondentDQPartiesFlagStructure; import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.filter; import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.getAllCaseFlags; +import static uk.gov.hmcts.reform.civil.utils.ElementUtils.unwrapElements; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.wrapElements; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_LEGAL_REP_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_ORG_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_ORG_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_LEGAL_REP_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_ORG_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_LEGAL_REP_INDIVIDUALS_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_ORG_INDIVIDUALS_ID; class CaseFlagUtilsTest { + private OrganisationService organisationService; + + @BeforeEach + void setUp() { + organisationService = mock(OrganisationService.class); + when(organisationService.findOrganisationById(anyString())) + .thenReturn(Optional.of(Organisation.builder().name("Civil - Organisation").build())); + } + @Nested class CreateFlags { @@ -648,4 +681,663 @@ private List hearingRelevantFlagDetails() { return List.of(details1, details2, details3); } } + + @Nested + class CreateAndUpdateFlagNamesAfterManageContactInformationEvent { + + @Nested + class Parties { + + @Test + void shouldUpdateFlagName_whenClaimant1NameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_ONE_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant1(caseData.getApplicant1().toBuilder() + .flags(Flags.builder() + .partyName("Mr. John Rambo") + .roleOnCase("applicant") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .individualFirstName("Johnny") + .individualLastName("Rambo new").build()); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + Flags actual = builder.build().getApplicant1().getFlags(); + Flags expected = Flags.builder().partyName("Mr. Johnny Rambo new") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("applicant").build(); + + assertThat(actual).isEqualTo(expected); + } + + @Test + void shouldUpdateFlagName_whenClaimant2NameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .multiPartyClaimTwoApplicants() + .atStateClaimIssued() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_TWO_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant2(caseData.getApplicant2().toBuilder() + .flags(Flags.builder() + .partyName("Mr. Jason Rambo") + .roleOnCase("applicant") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .individualFirstName("JJ") + .individualLastName("Rambo edited").build()); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + Flags actual = builder.build().getApplicant2().getFlags(); + Flags expected = Flags.builder().partyName("Mr. JJ Rambo edited") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("applicant").build(); + + assertThat(actual).isEqualTo(expected); + } + + @Test + void shouldUpdateFlagName_whenRespondent1NameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_ONE_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent1(caseData.getRespondent1().toBuilder() + .flags(Flags.builder() + .partyName("Mr. Sole Trader") + .roleOnCase("respondent") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .soleTraderFirstName("Solo") + .soleTraderLastName("New trader").build()); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + Flags actual = builder.build().getRespondent1().getFlags(); + Flags expected = Flags.builder().partyName("Mr. Solo New trader") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("respondent").build(); + + assertThat(actual).isEqualTo(expected); + } + + @Test + void shouldUpdateFlagName_whenRespondent2NameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .multiPartyClaimTwoDefendantSolicitors() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_TWO_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent2(caseData.getRespondent2().toBuilder() + .flags(Flags.builder() + .partyName("Mr. John Rambo") + .roleOnCase("respondent") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .individualTitle("Miss") + .individualFirstName("Jenny") + .individualLastName("Rombo").build()); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + Flags actual = builder.build().getRespondent2().getFlags(); + Flags expected = Flags.builder().partyName("Miss Jenny Rombo") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("respondent").build(); + + assertThat(actual).isEqualTo(expected); + } + } + + @Nested + class LitigationFriend { + + @Test + void shouldUpdateFlagName_whenClaimant1LitigationFriendNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .addApplicant1LitigationFriend() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_ONE_LITIGATION_FRIEND_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant1LitigationFriend(caseData.getApplicant1LitigationFriend().toBuilder() + .flags(Flags.builder() + .partyName("Mr. Applicant Litigation Friend") + .roleOnCase("litigation friend") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .fullName(null) + .firstName("Johnny").lastName("Rambo new") + .build()); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + Flags actual = builder.build().getApplicant1LitigationFriend().getFlags(); + Flags expected = Flags.builder().partyName("Johnny Rambo new") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("litigation friend").build(); + + assertThat(actual).isEqualTo(expected); + } + + @Test + void shouldUpdateFlagName_whenClaimant2LitigationFriendNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .addApplicant2LitigationFriend() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_TWO_LITIGATION_FRIEND_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant2LitigationFriend(caseData.getApplicant2LitigationFriend().toBuilder() + .flags(Flags.builder() + .partyName("Applicant Two Litigation Friend") + .roleOnCase("litigation friend") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .fullName(null) + .firstName("Johnny").lastName("Rambo new") + .build()); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + Flags actual = builder.build().getApplicant2LitigationFriend().getFlags(); + Flags expected = Flags.builder().partyName("Johnny Rambo new") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("litigation friend").build(); + + assertThat(actual).isEqualTo(expected); + } + + @Test + void shouldUpdateFlagName_whenRespondent1LitigationFriendNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .addRespondent1LitigationFriend() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_ONE_LITIGATION_FRIEND_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent1LitigationFriend(caseData.getRespondent1LitigationFriend().toBuilder() + .flags(Flags.builder() + .partyName("Litigation Friend") + .roleOnCase("litigation friend") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .fullName(null) + .firstName("Johnny").lastName("Rambo new") + .build()); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + Flags actual = builder.build().getRespondent1LitigationFriend().getFlags(); + Flags expected = Flags.builder().partyName("Johnny Rambo new") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("litigation friend").build(); + + assertThat(actual).isEqualTo(expected); + } + + @Test + void shouldUpdateFlagName_whenRespondent2LitigationFriendNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .multiPartyClaimTwoDefendantSolicitors() + .atStateApplicantRespondToDefenceAndProceed() + .addRespondent2LitigationFriend() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_TWO_LITIGATION_FRIEND_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent2LitigationFriend(caseData.getRespondent2LitigationFriend().toBuilder() + .flags(Flags.builder() + .partyName("Litigation Friend") + .roleOnCase("litigation friend") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .fullName(null) + .firstName("Johnny").lastName("Rambo new") + .build()); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + Flags actual = builder.build().getRespondent2LitigationFriend().getFlags(); + Flags expected = Flags.builder().partyName("Johnny Rambo new") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("litigation friend").build(); + + assertThat(actual).isEqualTo(expected); + } + } + + @Nested + class LegalRepIndividuals { + + @Test + void shouldCreateFlag_whenClaimantLRIndividualAdded() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_ONE_LEGAL_REP_INDIVIDUALS_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant1LRIndividuals(wrapElements(PartyFlagStructure.builder() + .firstName("Legally").lastName("Rep") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getApplicant1LRIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Legally Rep") + .details(List.of()) + .roleOnCase("Civil - Organisation").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isNotNull(); + } + + @Test + void shouldUpdateFlagName_whenClaimantLRIndividualNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .addApplicantLRIndividual("Legal", "Rep") + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_ONE_LEGAL_REP_INDIVIDUALS_ID).build()) + .build(); + + PartyFlagStructure lrIndividual = unwrapElements(caseData.getApplicant1LRIndividuals()).get(0); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant1LRIndividuals(wrapElements(lrIndividual.toBuilder() + .flags(Flags.builder() + .partyName("Legal Rep") + .roleOnCase("Civil - Organisation") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .firstName("Legally").lastName("Rep") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getApplicant1LRIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Legally Rep") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("Civil - Organisation").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isEqualTo("app-lr-ind-party-id"); + } + + @Test + void shouldCreateFlag_whenRespondent1LRIndividualAdded() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_ONE_LEGAL_REP_INDIVIDUALS_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent1LRIndividuals(wrapElements(PartyFlagStructure.builder() + .firstName("Legally").lastName("Rep") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getRespondent1LRIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Legally Rep") + .details(List.of()) + .roleOnCase("Civil - Organisation").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isNotNull(); + } + + @Test + void shouldUpdateFlagName_whenRespondent1LRIndividualNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .addRespondent1LRIndividual("Legal", "Rep") + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_ONE_LEGAL_REP_INDIVIDUALS_ID).build()) + .build(); + + PartyFlagStructure lrIndividual = unwrapElements(caseData.getRespondent1LRIndividuals()).get(0); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent1LRIndividuals(wrapElements(lrIndividual.toBuilder() + .flags(Flags.builder() + .partyName("Legal Rep") + .roleOnCase("Civil - Organisation") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .firstName("Legally").lastName("Rep") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getRespondent1LRIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Legally Rep") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("Civil - Organisation").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isEqualTo("res-1-lr-ind-party-id"); + } + + @Test + void shouldCreateFlag_whenRespondent2LRIndividualAdded() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_TWO_LEGAL_REP_INDIVIDUALS_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent2LRIndividuals(wrapElements(PartyFlagStructure.builder() + .firstName("Legally").lastName("Rep") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getRespondent2LRIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Legally Rep") + .details(List.of()) + .roleOnCase("Civil - Organisation").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isNotNull(); + } + + @Test + void shouldUpdateFlagName_whenRespondent2LRIndividualNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .addRespondent2LRIndividual("Legal", "Rep") + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_TWO_LEGAL_REP_INDIVIDUALS_ID).build()) + .build(); + + PartyFlagStructure lrIndividual = unwrapElements(caseData.getRespondent2LRIndividuals()).get(0); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent2LRIndividuals(wrapElements(lrIndividual.toBuilder() + .flags(Flags.builder() + .partyName("Legal Rep") + .roleOnCase("Civil - Organisation") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .firstName("Legally").lastName("Rep") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getRespondent2LRIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Legally Rep") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("Civil - Organisation").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isEqualTo("res-2-lr-ind-party-id"); + } + } + + @Nested + class OrgIndividuals { + + @Test + void shouldCreateFlag_whenClaimant1OrgIndividualAdded() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_ONE_ORG_INDIVIDUALS_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant1OrgIndividuals(wrapElements(PartyFlagStructure.builder() + .firstName("Org").lastName("Ind") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getApplicant1OrgIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Org Ind") + .details(List.of()) + .roleOnCase("Mr. John Rambo").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isNotNull(); + } + + @Test + void shouldUpdateFlagName_whenClaimant1OrgIndividualNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .addApplicant1OrgIndividual("Org", "Person") + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_ONE_ORG_INDIVIDUALS_ID).build()) + .build(); + + PartyFlagStructure orgIndividual = unwrapElements(caseData.getApplicant1OrgIndividuals()).get(0); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant1OrgIndividuals(wrapElements(orgIndividual.toBuilder() + .flags(Flags.builder() + .partyName("Org Person") + .roleOnCase("Mr. John Rambo") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .firstName("Org").lastName("Ind") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getApplicant1OrgIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Org Ind") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("Mr. John Rambo").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isEqualTo("app-1-org-ind-party-id"); + } + + @Test + void shouldCreateFlag_whenClaimant2OrgIndividualAdded() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .multiPartyClaimTwoApplicants() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_TWO_ORG_INDIVIDUALS_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant2OrgIndividuals(wrapElements(PartyFlagStructure.builder() + .firstName("Org").lastName("Ind") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getApplicant2OrgIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Org Ind") + .details(List.of()) + .roleOnCase("Mr. Jason Rambo").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isNotNull(); + } + + @Test + void shouldUpdateFlagName_whenClaimant2OrgIndividualNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .multiPartyClaimTwoApplicants() + .addApplicant2OrgIndividual("Org", "Person") + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(CLAIMANT_TWO_ORG_INDIVIDUALS_ID).build()) + .build(); + + PartyFlagStructure orgIndividual = unwrapElements(caseData.getApplicant2OrgIndividuals()).get(0); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .applicant2OrgIndividuals(wrapElements(orgIndividual.toBuilder() + .flags(Flags.builder() + .partyName("Org Person") + .roleOnCase("Mr. Jason Rambo") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .firstName("Org").lastName("Ind") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getApplicant2OrgIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Org Ind") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("Mr. Jason Rambo").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isEqualTo("app-2-org-ind-party-id"); + } + + @Test + void shouldCreateFlag_whenRespondent1OrgIndividualAdded() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_ONE_ORG_INDIVIDUALS_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent1OrgIndividuals(wrapElements(PartyFlagStructure.builder() + .firstName("Org").lastName("Ind") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getRespondent1OrgIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Org Ind") + .details(List.of()) + .roleOnCase("Mr. Sole Trader").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isNotNull(); + } + + @Test + void shouldUpdateFlagName_whenRespondent1OrgIndividualNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateApplicantRespondToDefenceAndProceed() + .addRespondent1OrgIndividual("Org", "Person") + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_ONE_ORG_INDIVIDUALS_ID).build()) + .build(); + + PartyFlagStructure orgIndividual = unwrapElements(caseData.getRespondent1OrgIndividuals()).get(0); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent1OrgIndividuals(wrapElements(orgIndividual.toBuilder() + .flags(Flags.builder() + .partyName("Org Person") + .roleOnCase("Mr. Sole Trader") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .firstName("Org").lastName("Ind") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getRespondent1OrgIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Org Ind") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("Mr. Sole Trader").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isEqualTo("res-1-org-ind-party-id"); + } + + @Test + void shouldCreateFlag_whenRespondent2OrgIndividualAdded() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .multiPartyClaimTwoDefendantSolicitors() + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_TWO_ORG_INDIVIDUALS_ID).build()) + .build(); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent2OrgIndividuals(wrapElements(PartyFlagStructure.builder() + .firstName("Org").lastName("Ind") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getRespondent2OrgIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Org Ind") + .details(List.of()) + .roleOnCase("Mr. John Rambo").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isNotNull(); + } + + @Test + void shouldUpdateFlagName_whenRespondent2OrgIndividualNameUpdated() { + CaseData caseData = CaseDataBuilder.builder() + .atStateClaimIssued() + .multiPartyClaimTwoDefendantSolicitors() + .addRespondent2OrgIndividual("Org", "Person") + .updateDetailsForm(UpdateDetailsForm.builder().partyChosenId(DEFENDANT_TWO_ORG_INDIVIDUALS_ID).build()) + .build(); + + PartyFlagStructure lrIndividual = unwrapElements(caseData.getRespondent2OrgIndividuals()).get(0); + + CaseData.CaseDataBuilder builder = caseData.toBuilder() + .respondent2OrgIndividuals(wrapElements(lrIndividual.toBuilder() + .flags(Flags.builder() + .partyName("Org Person") + .roleOnCase("Mr. John Rambo") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))).build()) + .firstName("Org").lastName("Ind") + .build())); + + CaseFlagUtils.createOrUpdateFlags(builder, builder.build(), organisationService); + + PartyFlagStructure individual = unwrapElements(builder.build().getRespondent2OrgIndividuals()).get(0); + Flags actualFlags = individual.getFlags(); + Flags expectedFlags = Flags.builder().partyName("Org Ind") + .details(wrapElements(List.of( + FlagDetail.builder().name("flag name").build()))) + .roleOnCase("Mr. John Rambo").build(); + + assertThat(actualFlags).isEqualTo(expectedFlags); + assertThat(individual.getPartyID()).isEqualTo("res-2-org-ind-party-id"); + } + } + } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/utils/CaseFlagsInitialiserTest.java b/src/test/java/uk/gov/hmcts/reform/civil/utils/CaseFlagsInitialiserTest.java index bb546a4f699..334bb719764 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/utils/CaseFlagsInitialiserTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/utils/CaseFlagsInitialiserTest.java @@ -2,6 +2,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.ccd.model.OrganisationPolicy; import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.model.Party; import uk.gov.hmcts.reform.civil.model.PartyFlagStructure; @@ -14,17 +15,23 @@ import uk.gov.hmcts.reform.civil.model.dq.Respondent2DQ; import uk.gov.hmcts.reform.civil.model.dq.Witness; import uk.gov.hmcts.reform.civil.model.dq.Witnesses; -import uk.gov.hmcts.reform.civil.service.FeatureToggleService; +import uk.gov.hmcts.reform.civil.model.UpdateDetailsForm; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.LitigationFriend; import uk.gov.hmcts.reform.civil.model.caseflags.Flags; +import uk.gov.hmcts.reform.civil.prd.model.Organisation; import uk.gov.hmcts.reform.civil.sampledata.PartyBuilder; +import uk.gov.hmcts.reform.civil.service.FeatureToggleService; +import uk.gov.hmcts.reform.civil.service.OrganisationService; import java.util.List; +import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.APPLICANT_SOLICITOR_EXPERT; @@ -35,6 +42,7 @@ import static uk.gov.hmcts.reform.civil.utils.CaseFlagUtils.RESPONDENT_SOLICITOR_TWO_WITNESS; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.unwrapElements; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.wrapElements; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_LEGAL_REP_INDIVIDUALS_ID; class CaseFlagsInitialiserTest { @@ -42,11 +50,16 @@ class CaseFlagsInitialiserTest { private FeatureToggleService featureToggleService; + private OrganisationService organisationService; + @BeforeEach void setup() { featureToggleService = mock(FeatureToggleService.class); - caseFlagsInitialiser = new CaseFlagsInitialiser(featureToggleService); + organisationService = mock(OrganisationService.class); + caseFlagsInitialiser = new CaseFlagsInitialiser(featureToggleService, organisationService); when(featureToggleService.isCaseFlagsEnabled()).thenReturn(true); + when(organisationService.findOrganisationById(anyString())) + .thenReturn(Optional.of(Organisation.builder().name("Civil - Organisation 1").build())); } @Test @@ -178,6 +191,24 @@ void shouldNotInitialiseCaseFlagsWhenCaseFlagsToggleIsOff() { assertEquals(expected, actual.build()); } + @Test + void shouldInitialiseCaseFlagsForManageContactInformationEvent() { + CaseData caseData = CaseData.builder() + .applicant1OrganisationPolicy(OrganisationPolicy.builder() + .organisation(uk.gov.hmcts.reform.ccd.model.Organisation.builder() + .organisationID("id") + .build()) + .build()) + .updateDetailsForm(UpdateDetailsForm.builder() + .partyChosenId(CLAIMANT_ONE_LEGAL_REP_INDIVIDUALS_ID) + .build()) + .build(); + + caseFlagsInitialiser.initialiseCaseFlags(CaseEvent.MANAGE_CONTACT_INFORMATION, caseData.toBuilder()); + + verify(organisationService).findOrganisationById("id"); + } + @Test void shouldReinitialiseMissingCaseFlags() { Party applicant1 = PartyBuilder.builder().individual().build(); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/utils/JudicialReferralUtilsTest.java b/src/test/java/uk/gov/hmcts/reform/civil/utils/JudicialReferralUtilsTest.java new file mode 100644 index 00000000000..72601e30b71 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/utils/JudicialReferralUtilsTest.java @@ -0,0 +1,53 @@ +package uk.gov.hmcts.reform.civil.utils; + +import org.junit.jupiter.api.Test; +import uk.gov.hmcts.reform.civil.enums.CaseCategory; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.ClaimValue; + +import java.math.BigDecimal; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; + +public class JudicialReferralUtilsTest { + + @Test + public void testShouldMoveToJudicialReferralForSpecClaim() { + CaseData caseData = CaseData.builder() + .caseAccessCategory(CaseCategory.SPEC_CLAIM) + .applicant1ProceedWithClaim(YesOrNo.YES) + .build(); + + boolean judicialReferralUtils = JudicialReferralUtils.shouldMoveToJudicialReferral(caseData); + assertTrue(judicialReferralUtils); + } + + @Test + public void testShouldNotMoveToJudicialReferralForSpecClaim() { + CaseData caseData = CaseData.builder() + .caseAccessCategory(CaseCategory.SPEC_CLAIM) + .applicant1ProceedWithClaim(YesOrNo.NO) + .build(); + + boolean judicialReferralUtils = JudicialReferralUtils.shouldMoveToJudicialReferral(caseData); + + assertFalse(judicialReferralUtils); + } + + @Test + public void testShouldMoveToJudicialReferralForUnspecClaim() { + CaseData caseData = CaseData.builder() + .caseAccessCategory(CaseCategory.UNSPEC_CLAIM) + .claimValue(ClaimValue.builder() + .statementOfValueInPennies(BigDecimal.valueOf(10000_00)) + .build()) + .applicant1ProceedWithClaim(YesOrNo.YES) + .build(); + + boolean judicialReferralUtils = JudicialReferralUtils.shouldMoveToJudicialReferral(caseData); + assertTrue(judicialReferralUtils); + } + +} diff --git a/src/test/java/uk/gov/hmcts/reform/civil/utils/ManageContactInformationUtilsTest.java b/src/test/java/uk/gov/hmcts/reform/civil/utils/ManageContactInformationUtilsTest.java index f8fc3f207cb..ac5effba420 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/utils/ManageContactInformationUtilsTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/utils/ManageContactInformationUtilsTest.java @@ -1,11 +1,16 @@ package uk.gov.hmcts.reform.civil.utils; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.Party; +import uk.gov.hmcts.reform.civil.model.UpdatePartyDetailsForm; import uk.gov.hmcts.reform.civil.model.common.DynamicListElement; +import uk.gov.hmcts.reform.civil.model.dq.Expert; +import uk.gov.hmcts.reform.civil.model.dq.Witness; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; - +import java.math.BigDecimal; +import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -14,13 +19,26 @@ import static uk.gov.hmcts.reform.civil.enums.RespondentResponseType.FULL_DEFENCE; import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; import static uk.gov.hmcts.reform.civil.model.Party.Type.COMPANY; +import static uk.gov.hmcts.reform.civil.model.Party.Type.INDIVIDUAL; import static uk.gov.hmcts.reform.civil.model.Party.Type.ORGANISATION; +import static uk.gov.hmcts.reform.civil.model.Party.Type.SOLE_TRADER; import static uk.gov.hmcts.reform.civil.model.common.DynamicListElement.dynamicElementFromCode; +import static uk.gov.hmcts.reform.civil.utils.ElementUtils.wrapElements; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_ONE_LITIGATION_FRIEND_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.CLAIMANT_TWO_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_ONE_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_ID; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.DEFENDANT_TWO_LITIGATION_FRIEND_ID; import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.addApplicant1Options; import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.addApplicantOptions2v1; import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.addDefendant1Options; import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.addDefendant2Options; import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.addDefendantOptions1v2SameSolicitor; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.appendUserAndType; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.mapExpertsToUpdatePartyDetailsForm; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.mapUpdatePartyDetailsFormToDQExperts; +import static uk.gov.hmcts.reform.civil.utils.ManageContactInformationUtils.mapUpdatePartyDetailsFormToDQWitnesses; class ManageContactInformationUtilsTest { @@ -246,11 +264,219 @@ void shouldAddCorrectOptions_forDefendant1v2SameSolicitorAsAdmin() { assertThat(options).isEqualTo(expectedDefendants1v2SameSolicitorOptions(true, true)); } + @Test + void shouldMapExpertsToUpdatePartyDetailsForm() { + Expert expert1 = Expert.builder().firstName("First").lastName("Name").partyID("id").eventAdded("event").build(); + Expert expert2 = Expert.builder().firstName("Second").lastName("expert").fieldOfExpertise("field") + .phoneNumber("1").emailAddress("email").partyID("id2").build(); + UpdatePartyDetailsForm party = UpdatePartyDetailsForm.builder().firstName("First").lastName("Name") + .partyId("id").build(); + UpdatePartyDetailsForm party2 = UpdatePartyDetailsForm.builder().firstName("Second").lastName("expert") + .fieldOfExpertise("field").phoneNumber("1").emailAddress("email").partyId("id2").build(); + + assertThat(mapExpertsToUpdatePartyDetailsForm(wrapElements(expert1, expert2))) + .isEqualTo(wrapElements(party, party2)); + } + + @Test + void shouldMapExpertsToUpdatePartyDetailsForm_ifEmpty() { + assertThat(mapExpertsToUpdatePartyDetailsForm(null)).isEqualTo(new ArrayList<>()); + } + + @Nested + class MapToDQExperts { + UpdatePartyDetailsForm party = UpdatePartyDetailsForm.builder().firstName("Lewis").lastName("John") + .partyId("id").build(); + UpdatePartyDetailsForm party2 = UpdatePartyDetailsForm.builder().firstName("Second").lastName("expert") + .fieldOfExpertise("field").phoneNumber("1").emailAddress("expertemail").partyId("id2").build(); + + LocalDate date = LocalDate.of(2020, 3, 20); + + Expert expert1 = Expert.builder().firstName("First").lastName("Name").partyID("id").eventAdded("event") + .dateAdded(date).estimatedCost(BigDecimal.valueOf(10000)).build(); + Expert expert2 = Expert.builder().firstName("Second").lastName("expert").fieldOfExpertise("field") + .eventAdded("event").dateAdded(date).phoneNumber("1").emailAddress("email").partyID("id2").build(); + + @Test + void shouldEditExperts() { + Expert expectedExpert1 = Expert.builder().firstName("Lewis").lastName("John").partyID("id") + .eventAdded("event").dateAdded(date).estimatedCost(BigDecimal.valueOf(10000)).build(); + Expert expectedExpert2 = Expert.builder().firstName("Second").lastName("expert").fieldOfExpertise("field") + .eventAdded("event").dateAdded(date).phoneNumber("1").emailAddress("expertemail").partyID("id2").build(); + + assertThat(mapUpdatePartyDetailsFormToDQExperts(wrapElements(expert1, expert2), wrapElements(party, party2))) + .isEqualTo(wrapElements(expectedExpert1, expectedExpert2)); + } + + @Test + void shouldAddExperts() { + Expert expectedExpert1 = Expert.builder().firstName("Lewis").lastName("John") + .eventAdded("Manage Contact Information Event").dateAdded(LocalDate.now()) + .partyID(null) //change this for CIV-10382 + .build(); + Expert expectedExpert2 = Expert.builder().firstName("Second").lastName("expert").fieldOfExpertise("field") + .eventAdded("Manage Contact Information Event").dateAdded(LocalDate.now()).phoneNumber("1") + .emailAddress("expertemail") + .partyID(null) //change this for CIV-10382 + .build(); + + assertThat(mapUpdatePartyDetailsFormToDQExperts(null, wrapElements(party, party2))) + .isEqualTo(wrapElements(expectedExpert1, expectedExpert2)); + } + + @Test + void shouldAddExpertsWithExistingExperts() { + Expert expectedExpert1 = Expert.builder().firstName("Lewis").lastName("John").partyID("id") + .eventAdded("event").dateAdded(date).estimatedCost(BigDecimal.valueOf(10000)).build(); + Expert expectedExpert2 = Expert.builder().firstName("Second").lastName("expert").fieldOfExpertise("field") + .eventAdded("Manage Contact Information Event").dateAdded(LocalDate.now()).phoneNumber("1") + .emailAddress("expertemail") + .partyID(null) //change this for CIV-10382 + .build(); + + assertThat(mapUpdatePartyDetailsFormToDQExperts(wrapElements(expert1), wrapElements(party, party2))) + .isEqualTo(wrapElements(expectedExpert1, expectedExpert2)); + } + } + + @Nested + class MapToDQWitnesses { + UpdatePartyDetailsForm party = UpdatePartyDetailsForm.builder().firstName("Lewis").lastName("John") + .partyId("id").build(); + UpdatePartyDetailsForm party2 = UpdatePartyDetailsForm.builder().firstName("Second").lastName("witness") + .phoneNumber("1").emailAddress("witnessemail").partyId("id2").build(); + + LocalDate date = LocalDate.of(2020, 3, 20); + + Witness witness1 = Witness.builder().firstName("First").lastName("Name").partyID("id").eventAdded("event") + .dateAdded(date).reasonForWitness("reason").build(); + Witness witness2 = Witness.builder().firstName("Second").lastName("expert").eventAdded("event") + .dateAdded(date).phoneNumber("1").emailAddress("email").partyID("id2").build(); + + @Test + void shouldEditWitnesses() { + Witness expectedWitness1 = Witness.builder().firstName("Lewis").lastName("John") + .eventAdded("event").dateAdded(date).reasonForWitness("reason").partyID("id").build(); + + Witness expectedWitness2 = Witness.builder().firstName("Second").lastName("witness") + .eventAdded("event").dateAdded(date).phoneNumber("1").emailAddress("witnessemail") + .partyID("id2").build(); + + assertThat(mapUpdatePartyDetailsFormToDQWitnesses(wrapElements(witness1, witness2), wrapElements(party, party2))) + .isEqualTo(wrapElements(expectedWitness1, expectedWitness2)); + } + + @Test + void shouldAddWitnesses() { + Witness expectedWitness1 = Witness.builder().firstName("Lewis").lastName("John") + .eventAdded("Manage Contact Information Event").dateAdded(LocalDate.now()) + .partyID(null).build(); // CIV-10382 + Witness expectedWitness2 = Witness.builder().firstName("Second").lastName("witness") + .eventAdded("Manage Contact Information Event").dateAdded(LocalDate.now()).phoneNumber("1") + .emailAddress("witnessemail") + .partyID(null).build(); // CIV-10382 + + assertThat(mapUpdatePartyDetailsFormToDQWitnesses(null, wrapElements(party, party2))) + .isEqualTo(wrapElements(expectedWitness1, expectedWitness2)); + } + + @Test + void shouldRemoveWitnesses() { + assertThat(mapUpdatePartyDetailsFormToDQWitnesses(wrapElements(witness1, witness2), null)) + .isEmpty(); + } + + @Test + void shouldAddWitnessesWithExistingWitnesses() { + Witness expectedWitness1 = Witness.builder().firstName("Lewis").lastName("John").partyID("id") + .reasonForWitness("reason").eventAdded("event").dateAdded(date).build(); + Witness expectedWitness2 = Witness.builder().firstName("Second").lastName("witness") + .eventAdded("Manage Contact Information Event").dateAdded(LocalDate.now()).phoneNumber("1") + .emailAddress("witnessemail") + .partyID(null) //change this for CIV-10382 + .build(); + + assertThat(mapUpdatePartyDetailsFormToDQWitnesses(wrapElements(witness1), wrapElements(party, party2))) + .isEqualTo(wrapElements(expectedWitness1, expectedWitness2)); + } + } + + @Nested + class AppendCorrectUserAndType { + @Test + void shouldHaveCorrectID_ClaimantOneAdminIndividual() { + CaseData caseData = CaseDataBuilder.builder() + .applicant1(Party.builder().type(INDIVIDUAL).build()).build(); + + String result = appendUserAndType(CLAIMANT_ONE_ID, caseData, true); + + assertThat(result).isEqualTo("CLAIMANT_1_ADMIN_INDIVIDUAL"); + } + + @Test + void shouldHaveCorrectID_ClaimantTwoAdminSoleTrader() { + CaseData caseData = CaseDataBuilder.builder() + .applicant2(Party.builder().type(SOLE_TRADER).build()).build(); + + String result = appendUserAndType(CLAIMANT_TWO_ID, caseData, true); + + assertThat(result).isEqualTo("CLAIMANT_2_ADMIN_SOLE_TRADER"); + } + + @Test + void shouldHaveCorrectID_DefendantOneAdminOrganisation() { + CaseData caseData = CaseDataBuilder.builder() + .respondent1(Party.builder().type(ORGANISATION).build()).build(); + + String result = appendUserAndType(DEFENDANT_ONE_ID, caseData, true); + + assertThat(result).isEqualTo("DEFENDANT_1_ADMIN_ORGANISATION"); + } + + @Test + void shouldHaveCorrectID_DefendantTwoAdminCompany() { + CaseData caseData = CaseDataBuilder.builder() + .respondent2(Party.builder().type(COMPANY).build()).build(); + + String result = appendUserAndType(DEFENDANT_TWO_ID, caseData, true); + + assertThat(result).isEqualTo("DEFENDANT_2_ADMIN_COMPANY"); + } + + @Test + void shouldHaveCorrectID_DefendantTwoLegalRepIndividual() { + CaseData caseData = CaseDataBuilder.builder() + .respondent2(Party.builder().type(INDIVIDUAL).build()).build(); + + String result = appendUserAndType(DEFENDANT_TWO_ID, caseData, false); + + assertThat(result).isEqualTo("DEFENDANT_2_LR_INDIVIDUAL"); + } + + @Test + void shouldHaveCorrectID_Applicant1LitigationFriendAdmin() { + CaseData caseData = CaseDataBuilder.builder().build(); + + String result = appendUserAndType(CLAIMANT_ONE_LITIGATION_FRIEND_ID, caseData, false); + + assertThat(result).isEqualTo("CLAIMANT_1_LITIGATION_FRIEND_LR"); + } + + @Test + void shouldHaveCorrectID_Defendant2LitigationFriendAdmin() { + CaseData caseData = CaseDataBuilder.builder().build(); + + String result = appendUserAndType(DEFENDANT_TWO_LITIGATION_FRIEND_ID, caseData, true); + + assertThat(result).isEqualTo("DEFENDANT_2_LITIGATION_FRIEND_ADMIN"); + } + } + private List expectedApplicant1Options(boolean withExpertsAndWitnesses, boolean isAdmin) { List list = new ArrayList<>(); list.add(dynamicElementFromCode("CLAIMANT_1", "CLAIMANT 1: Mr. John Rambo")); - list.add(dynamicElementFromCode("CLAIMANT_1_LITIGATIONFRIEND", "CLAIMANT 1: Litigation Friend: Applicant Litigation Friend")); - list.add(dynamicElementFromCode("CLAIMANT_1_INDIVIDUALSSOLICITORORG", "CLAIMANT 1: Individuals attending for the legal representative")); + list.add(dynamicElementFromCode("CLAIMANT_1_LITIGATION_FRIEND", "CLAIMANT 1: Litigation Friend: Applicant Litigation Friend")); + list.add(dynamicElementFromCode("CLAIMANT_1_LR_INDIVIDUALS", "CLAIMANT 1: Individuals attending for the legal representative")); if (withExpertsAndWitnesses || isAdmin) { list.add(dynamicElementFromCode("CLAIMANT_1_WITNESSES", "CLAIMANT 1: Witnesses")); list.add(dynamicElementFromCode("CLAIMANT_1_EXPERTS", "CLAIMANT 1: Experts")); @@ -261,8 +487,8 @@ private List expectedApplicant1Options(boolean withExpertsAn private List expectedApplicant1OrgOptions(boolean withExpertsAndWitnesses, boolean isAdmin) { List list = new ArrayList<>(); list.add(dynamicElementFromCode("CLAIMANT_1", "CLAIMANT 1: Test Inc")); - list.add(dynamicElementFromCode("CLAIMANT_1_INDIVIDUALSORG", "CLAIMANT 1: Individuals attending for the organisation")); - list.add(dynamicElementFromCode("CLAIMANT_1_INDIVIDUALSSOLICITORORG", "CLAIMANT 1: Individuals attending for the legal representative")); + list.add(dynamicElementFromCode("CLAIMANT_1_ORGANISATION_INDIVIDUALS", "CLAIMANT 1: Individuals attending for the organisation")); + list.add(dynamicElementFromCode("CLAIMANT_1_LR_INDIVIDUALS", "CLAIMANT 1: Individuals attending for the legal representative")); if (withExpertsAndWitnesses || isAdmin) { list.add(dynamicElementFromCode("CLAIMANT_1_WITNESSES", "CLAIMANT 1: Witnesses")); list.add(dynamicElementFromCode("CLAIMANT_1_EXPERTS", "CLAIMANT 1: Experts")); @@ -273,10 +499,10 @@ private List expectedApplicant1OrgOptions(boolean withExpert private List expectedApplicants2v1Options(boolean withExpertsAndWitnesses, boolean isAdmin) { List list = new ArrayList<>(); list.add(dynamicElementFromCode("CLAIMANT_1", "CLAIMANT 1: Mr. John Rambo")); - list.add(dynamicElementFromCode("CLAIMANT_1_LITIGATIONFRIEND", "CLAIMANT 1: Litigation Friend: Applicant Litigation Friend")); + list.add(dynamicElementFromCode("CLAIMANT_1_LITIGATION_FRIEND", "CLAIMANT 1: Litigation Friend: Applicant Litigation Friend")); list.add(dynamicElementFromCode("CLAIMANT_2", "CLAIMANT 2: Mr. Jason Rambo")); - list.add(dynamicElementFromCode("CLAIMANT_2_LITIGATIONFRIEND", "CLAIMANT 2: Litigation Friend: Applicant Two Litigation Friend")); - list.add(dynamicElementFromCode("CLAIMANT_1_INDIVIDUALSSOLICITORORG", "CLAIMANTS: Individuals attending for the legal representative")); + list.add(dynamicElementFromCode("CLAIMANT_2_LITIGATION_FRIEND", "CLAIMANT 2: Litigation Friend: Applicant Two Litigation Friend")); + list.add(dynamicElementFromCode("CLAIMANT_1_LR_INDIVIDUALS", "CLAIMANTS: Individuals attending for the legal representative")); if (withExpertsAndWitnesses || isAdmin) { list.add(dynamicElementFromCode("CLAIMANT_1_WITNESSES", "CLAIMANTS: Witnesses")); list.add(dynamicElementFromCode("CLAIMANT_1_EXPERTS", "CLAIMANTS: Experts")); @@ -287,8 +513,8 @@ private List expectedApplicants2v1Options(boolean withExpert private List expectedDefendant1Options(boolean withExpertsAndWitnesses, boolean isAdmin) { List list = new ArrayList<>(); list.add(dynamicElementFromCode("DEFENDANT_1", "DEFENDANT 1: Mr. Sole Trader")); - list.add(dynamicElementFromCode("DEFENDANT_1_LITIGATIONFRIEND", "DEFENDANT 1: Litigation Friend: Litigation Friend")); - list.add(dynamicElementFromCode("DEFENDANT_1_INDIVIDUALSSOLICITORORG", "DEFENDANT 1: Individuals attending for the legal representative")); + list.add(dynamicElementFromCode("DEFENDANT_1_LITIGATION_FRIEND", "DEFENDANT 1: Litigation Friend: Litigation Friend")); + list.add(dynamicElementFromCode("DEFENDANT_1_LR_INDIVIDUALS", "DEFENDANT 1: Individuals attending for the legal representative")); if (withExpertsAndWitnesses || isAdmin) { list.add(dynamicElementFromCode("DEFENDANT_1_WITNESSES", "DEFENDANT 1: Witnesses")); list.add(dynamicElementFromCode("DEFENDANT_1_EXPERTS", "DEFENDANT 1: Experts")); @@ -299,8 +525,8 @@ private List expectedDefendant1Options(boolean withExpertsAn private List expectedDefendant2Options(boolean withExpertsAndWitnesses, boolean isAdmin) { List list = new ArrayList<>(); list.add(dynamicElementFromCode("DEFENDANT_2", "DEFENDANT 2: Mr. John Rambo")); - list.add(dynamicElementFromCode("DEFENDANT_2_LITIGATIONFRIEND", "DEFENDANT 2: Litigation Friend: Litigation Friend")); - list.add(dynamicElementFromCode("DEFENDANT_2_INDIVIDUALSSOLICITORORG", "DEFENDANT 2: Individuals attending for the legal representative")); + list.add(dynamicElementFromCode("DEFENDANT_2_LITIGATION_FRIEND", "DEFENDANT 2: Litigation Friend: Litigation Friend")); + list.add(dynamicElementFromCode("DEFENDANT_2_LR_INDIVIDUALS", "DEFENDANT 2: Individuals attending for the legal representative")); if (withExpertsAndWitnesses || isAdmin) { list.add(dynamicElementFromCode("DEFENDANT_2_WITNESSES", "DEFENDANT 2: Witnesses")); list.add(dynamicElementFromCode("DEFENDANT_2_EXPERTS", "DEFENDANT 2: Experts")); @@ -311,10 +537,10 @@ private List expectedDefendant2Options(boolean withExpertsAn private List expectedDefendants1v2SameSolicitorOptions(boolean withExpertsAndWitnesses, boolean isAdmin) { List list = new ArrayList<>(); list.add(dynamicElementFromCode("DEFENDANT_1", "DEFENDANT 1: Mr. Sole Trader")); - list.add(dynamicElementFromCode("DEFENDANT_1_LITIGATIONFRIEND", "DEFENDANT 1: Litigation Friend: Litigation Friend")); + list.add(dynamicElementFromCode("DEFENDANT_1_LITIGATION_FRIEND", "DEFENDANT 1: Litigation Friend: Litigation Friend")); list.add(dynamicElementFromCode("DEFENDANT_2", "DEFENDANT 2: Mr. John Rambo")); - list.add(dynamicElementFromCode("DEFENDANT_2_LITIGATIONFRIEND", "DEFENDANT 2: Litigation Friend: Litigation Friend")); - list.add(dynamicElementFromCode("DEFENDANT_1_INDIVIDUALSSOLICITORORG", "DEFENDANTS: Individuals attending for the legal representative")); + list.add(dynamicElementFromCode("DEFENDANT_2_LITIGATION_FRIEND", "DEFENDANT 2: Litigation Friend: Litigation Friend")); + list.add(dynamicElementFromCode("DEFENDANT_1_LR_INDIVIDUALS", "DEFENDANTS: Individuals attending for the legal representative")); if (withExpertsAndWitnesses || isAdmin) { list.add(dynamicElementFromCode("DEFENDANT_1_WITNESSES", "DEFENDANTS: Witnesses")); list.add(dynamicElementFromCode("DEFENDANT_1_EXPERTS", "DEFENDANTS: Experts"));