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/docker/docmosis/templates/CV-UNS-GAP-ENG-01067.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01067.docx index 3709881c7dc..1016e0a18c4 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..ca775174502 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..fe1a842c34e 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..e44df45adc1 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..52a6f485c03 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..9d6e2d9cb1d 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..6ebdfc6bb62 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/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 e00acfdeb49..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 @@ -14,6 +14,7 @@ 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; @@ -35,6 +36,7 @@ public class ClaimantResponseCuiCallbackHandler extends CallbackHandler { private final ResponseOneVOneShowTagService responseOneVOneService; private final ObjectMapper objectMapper; + private final UpdateCaseManagementDetailsService updateCaseManagementLocationDetailsService; @Override protected Map callbacks() { @@ -62,14 +64,16 @@ private CallbackResponse populateCaseData(CallbackParams callbackParams) { 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); 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..5640b94350a 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() { @@ -1383,7 +1386,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()); } 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 bc39dbf86fe..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,6 +16,7 @@ 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; @@ -41,6 +42,7 @@ 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; @@ -110,6 +112,7 @@ public class RespondToDefenceSpecCallbackHandler extends CallbackHandler private final RespondentMediationService respondentMediationService; private final PaymentDateService paymentDateService; private final ResponseOneVOneShowTagService responseOneVOneShowTagService; + private final DeadlineExtensionCalculatorService deadlineCalculatorService; @Override public List handledEvents() { @@ -566,7 +569,9 @@ 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; 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 717887a0472..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 @@ -531,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); } 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 9e490085485..7d2a5546ce9 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 @@ -443,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; @@ -533,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; 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/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/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/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/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/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 2b39e00bdd3..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 @@ -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( 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/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/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 d2dfccfe6ee..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,6 +1,7 @@ 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; @@ -14,14 +15,29 @@ 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; @@ -33,12 +49,24 @@ @SpringBootTest(classes = { ClaimantResponseCuiCallbackHandler.class, JacksonAutoConfiguration.class, - ResponseOneVOneShowTagService.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(); @@ -63,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( @@ -90,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()) @@ -112,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 @@ -130,6 +192,20 @@ 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() @@ -164,4 +240,10 @@ void shouldChangeCaseState_whenApplicantRejectRepaymentPlanAndIsOrganisation_toA 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/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..6fbfc1fb527 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 @@ -72,6 +72,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.FlowFlag; import uk.gov.hmcts.reform.civil.service.flowstate.StateFlowEngine; import uk.gov.hmcts.reform.civil.stateflow.StateFlow; @@ -100,6 +101,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.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; @@ -162,6 +164,8 @@ class RespondToClaimSpecCallbackHandlerTest extends BaseCallbackHandlerTest { private CourtLocationUtils courtLocationUtils; @Mock private CaseFlagsInitialiser caseFlagsInitialiser; + @Mock + private DeadlineExtensionCalculatorService deadlineExtensionCalculatorService; @Spy private List confirmationTextGenerators = List.of( @@ -751,8 +755,6 @@ void updateRespondent2AddressWhenUpdated() { when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); - Address changedAddress = AddressBuilder.maximal().build(); - CaseData caseData = CaseDataBuilder.builder().atStateApplicantRespondToDefenceAndProceed() .respondent2DQ() .respondent1Copy(PartyBuilder.builder().individual().build()) @@ -1084,7 +1086,6 @@ void oneVTwo_SecondDefendantRepliesSameLegalRep() { DefendantResponseShowTag.CAN_ANSWER_RESPONDENT_2 )) .build(); - CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); List locations = List.of(LocationRefData.builder().build()); when(locationRefDataService.getCourtLocationsForDefaultJudgments(any())) @@ -1104,10 +1105,13 @@ void oneVTwo_SecondDefendantRepliesSameLegalRep() { .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); + + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); // When - AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler - .handle(params); + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); // Then AbstractObjectAssert sent2 = assertThat(response.getData()) 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 15c778c9771..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; @@ -69,6 +70,7 @@ 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; @@ -92,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; @@ -170,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 { @@ -1362,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() @@ -1390,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() @@ -1417,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/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/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/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 3046d377756..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 @@ -320,7 +320,8 @@ public Stream provideArguments(ExtensionContext context) { GENERATE_DIRECTIONS_ORDER, TRIAL_READINESS, BUNDLE_CREATION_NOTIFICATION, - TRANSFER_ONLINE_CASE + TRANSFER_ONLINE_CASE, + asyncStitchingComplete } ), of( @@ -569,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/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/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"));