diff --git a/Jenkinsfile_CNP b/Jenkinsfile_CNP index 68db84c20ae..d5a5a308605 100644 --- a/Jenkinsfile_CNP +++ b/Jenkinsfile_CNP @@ -61,7 +61,7 @@ def publishRpaContract() { } def checkForEnableHelmLabel(branch_name) { - return new GithubAPI(this).getLabelsbyPattern(branch_name, "pr-values: enableHelm").contains("pr-values: enableHelm") + return new GithubAPI(this).getLabelsbyPattern(branch_name, "pr-values: enableHelm").contains("pr-values: enableHelm") } withPipeline(type, product, component) { @@ -70,9 +70,6 @@ withPipeline(type, product, component) { env.ENVIRONMENT = "preview" env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; loadVaultSecrets(secrets) - if (!checkForEnableHelmLabel(env.BRANCH_NAME)) { - enableCleanupOfHelmReleaseAlways(); - } } onMaster { loadVaultSecrets(secrets) diff --git a/docker/docmosis/templates/CV-UNS-HNO-ENG-01200.docx b/docker/docmosis/templates/CV-UNS-HNO-ENG-01200.docx index c4a7e5ad3ee..56e1165f73d 100644 Binary files a/docker/docmosis/templates/CV-UNS-HNO-ENG-01200.docx and b/docker/docmosis/templates/CV-UNS-HNO-ENG-01200.docx differ diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/noticeofchange/UpdateCaseDetailsAfterNoCHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/noticeofchange/UpdateCaseDetailsAfterNoCHandler.java index 9557adc9b6b..f78d721a010 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/noticeofchange/UpdateCaseDetailsAfterNoCHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/noticeofchange/UpdateCaseDetailsAfterNoCHandler.java @@ -12,6 +12,7 @@ import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.enums.CaseRole; +import uk.gov.hmcts.reform.civil.model.Address; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.IdamUserDetails; import uk.gov.hmcts.reform.civil.model.SolicitorReferences; @@ -169,6 +170,8 @@ private void updateRespondentSolicitor2Details( .respondent2OrganisationIDCopy(addedOrganisation); } else { caseDataBuilder.specRespondent2Represented(YES) + .specRespondent2CorrespondenceAddressRequired(null) + .specRespondent2CorrespondenceAddressdetails(Address.builder().build()) .specAoSRespondentCorrespondenceAddressdetails(null); } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/AmendPartyDetailsCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/AmendPartyDetailsCallbackHandler.java index a78bd96e669..de55dbee722 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/AmendPartyDetailsCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/AmendPartyDetailsCallbackHandler.java @@ -88,7 +88,7 @@ private void setOrganisationPolicy(CaseData caseData, CaseData.CaseDataBuilder c private CallbackResponse buildConfirmation(CallbackParams callbackParams) { return SubmittedCallbackResponse.builder() - .confirmationHeader("# You have updated a legal representative's email address") + .confirmationHeader("# You have updated a legal representative's information") .confirmationBody("
") .build(); } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ChangeSolicitorEmailCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ChangeSolicitorEmailCallbackHandler.java index 9dd4c387c3b..84e15742259 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ChangeSolicitorEmailCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/ChangeSolicitorEmailCallbackHandler.java @@ -2,23 +2,36 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.Nullable; 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.ccd.model.OrganisationPolicy; import uk.gov.hmcts.reform.civil.callback.Callback; 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.CaseCategory; import uk.gov.hmcts.reform.civil.enums.CaseRole; +import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; +import uk.gov.hmcts.reform.civil.model.Address; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.SolicitorReferences; import uk.gov.hmcts.reform.civil.service.CoreCaseUserService; import uk.gov.hmcts.reform.civil.service.UserService; +import uk.gov.hmcts.reform.civil.validation.PostcodeValidator; import uk.gov.hmcts.reform.civil.validation.ValidateEmailService; import uk.gov.hmcts.reform.idam.client.models.UserInfo; +import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; +import java.util.function.Consumer; +import java.util.stream.Stream; import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_START; @@ -43,6 +56,8 @@ public class ChangeSolicitorEmailCallbackHandler extends CallbackHandler { private final ObjectMapper objectMapper; + private final PostcodeValidator postcodeValidator; + @Override protected Map callbacks() { return Map.of( @@ -63,26 +78,297 @@ public List handledEvents() { private CallbackResponse aboutToStart(CallbackParams callbackParams) { List userRoles = getUserRoles(callbackParams); CaseData caseData = callbackParams.getCaseData(); - CaseData.CaseDataBuilder caseDataBuilder = caseData.toBuilder(); + CaseData.CaseDataBuilder caseDataBuilder = caseData.toBuilder(); - buildPartyFlags(userRoles, caseDataBuilder); + boolean isApplicant1 = userRoles.contains(CaseRole.APPLICANTSOLICITORONE.getFormattedName()); + boolean isRespondent1 = userRoles.contains(CaseRole.RESPONDENTSOLICITORONE.getFormattedName()); + boolean isRespondent2 = userRoles.contains(CaseRole.RESPONDENTSOLICITORTWO.getFormattedName()); + caseDataBuilder.isApplicant1(isApplicant1 ? YES : NO) + .isRespondent1(isRespondent1 ? YES : NO) + .isRespondent2(isRespondent2 ? YES : NO); + + // depending on flags, keep the current reference so we know if it was changed + String applicantReference = getSolicitorReference( + caseData.getApplicant1OrganisationPolicy(), + Optional.ofNullable(caseData.getSolicitorReferences()) + .map(SolicitorReferences::getApplicantSolicitor1Reference) + .orElse(null) + ); + String respondent1Reference = getSolicitorReference( + caseData.getRespondent1OrganisationPolicy(), + Optional.ofNullable(caseData.getSolicitorReferences()) + .map(SolicitorReferences::getRespondentSolicitor1Reference) + .orElse(null) + ); + String respondent2Reference = getSolicitorReference( + caseData.getRespondent2OrganisationPolicy(), + Optional.ofNullable(caseData.getSolicitorReferences()) + .map(SolicitorReferences::getRespondentSolicitor2Reference) + .orElse(null) + ); + caseDataBuilder.solicitorReferencesCopy( + SolicitorReferences.builder() + .applicantSolicitor1Reference(applicantReference) + .respondentSolicitor1Reference(respondent1Reference) + .respondentSolicitor2Reference(respondent2Reference) + .build() + ); + Optional.ofNullable(caseData.getApplicant1OrganisationPolicy()) + .map(op -> op.toBuilder().orgPolicyReference(applicantReference).build()) + .ifPresent(caseDataBuilder::applicant1OrganisationPolicy); + Optional.ofNullable(caseData.getRespondent1OrganisationPolicy()) + .map(op -> op.toBuilder().orgPolicyReference(respondent1Reference).build()) + .ifPresent(caseDataBuilder::respondent1OrganisationPolicy); + Optional.ofNullable(caseData.getRespondent2OrganisationPolicy()) + .map(op -> op.toBuilder().orgPolicyReference(respondent2Reference).build()) + .ifPresent(caseDataBuilder::respondent2OrganisationPolicy); + + prepareCorrespondenceAddresses(caseData, caseDataBuilder); return AboutToStartOrSubmitCallbackResponse.builder() .data(caseDataBuilder.build().toMap(objectMapper)) .build(); } + /** + * We want to send only serviceAddress, but if user says "no" to correspondence address, instead of removing + * what we have, we have to keep it. However, in that case, serviceAddress come as null. So, in spec cases, + * we copy spec's addresses over to serviceAddress, and in unspec we use the spec fields as a backup holder. + * + * @param caseData original case data + * @param caseDataBuilder updated case data + */ + private static void prepareCorrespondenceAddresses(CaseData caseData, CaseData.CaseDataBuilder caseDataBuilder) { + if (caseData.getCaseAccessCategory() == CaseCategory.SPEC_CLAIM) { + caseDataBuilder + .applicantSolicitor1ServiceAddressRequired( + caseData.getSpecApplicantCorrespondenceAddressRequired() + ) + .applicantSolicitor1ServiceAddress( + caseData.getSpecApplicantCorrespondenceAddressdetails() + ) + .respondentSolicitor1ServiceAddressRequired( + caseData.getSpecRespondentCorrespondenceAddressRequired() + ) + .respondentSolicitor1ServiceAddress( + caseData.getSpecRespondentCorrespondenceAddressdetails() + ) + .respondentSolicitor2ServiceAddressRequired( + caseData.getSpecRespondent2CorrespondenceAddressRequired() + ) + .respondentSolicitor2ServiceAddress( + caseData.getSpecRespondent2CorrespondenceAddressdetails() + ); + } else { + caseDataBuilder + .specApplicantCorrespondenceAddressRequired( + caseData.getApplicantSolicitor1ServiceAddressRequired() + ) + .specApplicantCorrespondenceAddressdetails( + caseData.getApplicantSolicitor1ServiceAddress() + ) + .specRespondentCorrespondenceAddressRequired( + caseData.getRespondentSolicitor1ServiceAddressRequired() + ) + .specRespondentCorrespondenceAddressdetails( + caseData.getRespondentSolicitor1ServiceAddress() + ) + .specRespondent2CorrespondenceAddressRequired( + caseData.getRespondentSolicitor2ServiceAddressRequired() + ) + .specRespondent2CorrespondenceAddressdetails( + caseData.getRespondentSolicitor2ServiceAddress() + ); + } + } + + @Nullable + private static String getSolicitorReference(OrganisationPolicy policy, String fromForm) { + return Stream.of( + Optional.ofNullable(policy) + .map(OrganisationPolicy::getOrgPolicyReference) + .orElse(null), + fromForm + ).filter(StringUtils::isNotBlank).findFirst().orElse(null); + } + private CallbackResponse aboutToSubmit(CallbackParams callbackParams) { CaseData caseData = callbackParams.getCaseData(); - CaseData.CaseDataBuilder caseBuilder = caseData.toBuilder(); + CaseData.CaseDataBuilder caseBuilder = prepareForSubmit(caseData); + // because we'll use the fields above + caseData = caseBuilder.build(); - clearPartyFlags(caseBuilder); + updateSolicitorReferences(callbackParams, caseData, caseBuilder); + updateSpecCorrespondenceAddresses(callbackParams, caseData, caseBuilder); + clearTempInfo(caseBuilder, caseData); return AboutToStartOrSubmitCallbackResponse.builder() .data(caseBuilder.build().toMap(objectMapper)) .build(); } + private CaseData.CaseDataBuilder prepareForSubmit(CaseData caseData) { + CaseData.CaseDataBuilder caseBuilder = caseData.toBuilder(); + prepareAddress( + caseData.getApplicantSolicitor1ServiceAddressRequired(), + caseData.getSpecApplicantCorrespondenceAddressdetails(), + caseBuilder::applicantSolicitor1ServiceAddressRequired, + caseBuilder::applicantSolicitor1ServiceAddress + ); + prepareAddress( + caseData.getRespondentSolicitor1ServiceAddressRequired(), + caseData.getSpecRespondentCorrespondenceAddressdetails(), + caseBuilder::respondentSolicitor1ServiceAddressRequired, + caseBuilder::respondentSolicitor1ServiceAddress + ); + prepareAddress( + caseData.getRespondentSolicitor2ServiceAddressRequired(), + caseData.getSpecRespondent2CorrespondenceAddressdetails(), + caseBuilder::respondentSolicitor2ServiceAddressRequired, + caseBuilder::respondentSolicitor2ServiceAddress + ); + if (MultiPartyScenario.ONE_V_TWO_ONE_LEGAL_REP == MultiPartyScenario.getMultiPartyScenario(caseData)) { + // copy 1 into 2 + CaseData temp = caseBuilder.build(); + caseBuilder + .respondentSolicitor2ServiceAddressRequired(temp.getRespondentSolicitor1ServiceAddressRequired()) + .respondentSolicitor2ServiceAddress(temp.getRespondentSolicitor1ServiceAddress()) + .respondentSolicitor2EmailAddress(temp.getRespondentSolicitor1EmailAddress()) + .respondent2OrganisationPolicy(temp.getRespondent1OrganisationPolicy()); + } + return caseBuilder; + } + + private void prepareAddress(YesOrNo requiredFromForm, + Address oldAddress, + Consumer setterYesNo, + Consumer
setterAddress) { + // if requiredFromForm = Yes assume serviceAddress was populated in the form + if (requiredFromForm == NO) { + Optional.ofNullable(oldAddress) + .map(Address::getPostCode).filter(StringUtils::isNotBlank) + .ifPresent(a -> { + setterYesNo.accept(YES); + setterAddress.accept(oldAddress); + }); + } + } + + /** + * If spec, copy modified correspondence address info back to spec's fields. + * + * @param caseData original case data + * @param caseDataBuilder updated case data + */ + private void updateSpecCorrespondenceAddresses(CallbackParams callbackParams, + CaseData caseData, + CaseData.CaseDataBuilder caseDataBuilder) { + if (caseData.getCaseAccessCategory() == CaseCategory.SPEC_CLAIM) { + List userRoles = getUserRoles(callbackParams); + if (userRoles.contains(CaseRole.APPLICANTSOLICITORONE.getFormattedName())) { + caseDataBuilder + .specApplicantCorrespondenceAddressRequired( + caseData.getApplicantSolicitor1ServiceAddressRequired() + ) + .specApplicantCorrespondenceAddressdetails( + caseData.getApplicantSolicitor1ServiceAddress() + ); + } else if (userRoles.contains(CaseRole.RESPONDENTSOLICITORONE.getFormattedName())) { + caseDataBuilder.specRespondentCorrespondenceAddressRequired( + caseData.getRespondentSolicitor1ServiceAddressRequired() + ) + .specRespondentCorrespondenceAddressdetails( + caseData.getRespondentSolicitor1ServiceAddress() + ); + if (MultiPartyScenario.ONE_V_TWO_ONE_LEGAL_REP == MultiPartyScenario.getMultiPartyScenario(caseData)) { + caseDataBuilder + .specRespondent2CorrespondenceAddressdetails( + caseData.getRespondentSolicitor1ServiceAddress()) + .specRespondent2CorrespondenceAddressRequired( + caseData.getRespondentSolicitor1ServiceAddressRequired()); + } + } else if (userRoles.contains(CaseRole.RESPONDENTSOLICITORTWO.getFormattedName())) { + caseDataBuilder.specRespondent2CorrespondenceAddressRequired( + caseData.getRespondentSolicitor2ServiceAddressRequired() + ) + .specRespondent2CorrespondenceAddressdetails( + caseData.getRespondentSolicitor2ServiceAddress() + ); + } + + caseDataBuilder + .applicantSolicitor1ServiceAddress(Address.builder().build()) + .respondentSolicitor1ServiceAddress(Address.builder().build()) + .respondentSolicitor2ServiceAddress(Address.builder().build()); + } + } + + /** + * Solicitor references appear twice with two different names (solicitorReferences, + * XXXOrganisationPolicy_OrgPolicyReference, respondentSolicitor2Reference...). + * At least two of them (solicitorReferences and XXXOrganisationPolicy) appear in the same journey, with no + * guarantee that their values are going to match. To lessen the side effects of this event, we check if + * the field was actually changed before updating the other field(s). + * + * @param caseData original case data + * @param caseBuilder case data being updated + */ + private void updateSolicitorReferences(CallbackParams callbackParams, CaseData caseData, + CaseData.CaseDataBuilder caseBuilder) { + List userRoles = getUserRoles(callbackParams); + if (userRoles.contains(CaseRole.APPLICANTSOLICITORONE.getFormattedName())) { + updateReference( + Optional.ofNullable(caseData.getSolicitorReferencesCopy()) + .map(SolicitorReferences::getApplicantSolicitor1Reference) + .orElse(null), + caseData.getApplicant1OrganisationPolicy(), + newReference -> { + SolicitorReferences references = Optional.ofNullable(caseData.getSolicitorReferences()) + .orElse(SolicitorReferences.builder().build()); + references.setApplicantSolicitor1Reference(newReference); + caseBuilder.solicitorReferences(references); + } + ); + } else if (userRoles.contains(CaseRole.RESPONDENTSOLICITORONE.getFormattedName())) { + updateReference( + Optional.ofNullable(caseData.getSolicitorReferencesCopy()) + .map(SolicitorReferences::getRespondentSolicitor1Reference) + .orElse(null), + caseData.getRespondent1OrganisationPolicy(), + newReference -> { + SolicitorReferences references = Optional.ofNullable(caseData.getSolicitorReferences()) + .orElse(SolicitorReferences.builder().build()); + references.setRespondentSolicitor1Reference(newReference); + caseBuilder.solicitorReferences(references); + } + ); + } else if (userRoles.contains(CaseRole.RESPONDENTSOLICITORTWO.getFormattedName())) { + updateReference( + Optional.ofNullable(caseData.getSolicitorReferencesCopy()) + .map(SolicitorReferences::getRespondentSolicitor2Reference) + .orElse(null), + caseData.getRespondent2OrganisationPolicy(), + newReference -> { + SolicitorReferences references = Optional.ofNullable(caseData.getSolicitorReferences()) + .orElse(SolicitorReferences.builder().build()); + references.setRespondentSolicitor2Reference(newReference); + caseBuilder.solicitorReferences(references) + .respondentSolicitor2Reference(newReference); + } + ); + } + caseBuilder.solicitorReferencesCopy(SolicitorReferences.builder().build()); + } + + private static void updateReference(String oldReference, OrganisationPolicy policy, Consumer ifDifferent) { + String newReference = Optional.ofNullable(policy) + .map(OrganisationPolicy::getOrgPolicyReference) + .orElse(""); + if (!StringUtils.equals(newReference, oldReference)) { + ifDifferent.accept(newReference); + } + } + private CallbackResponse buildConfirmation(CallbackParams callbackParams) { String partyType = getUserRoles(callbackParams).stream() .anyMatch(r -> r.equals(CaseRole.RESPONDENTSOLICITORTWO.getFormattedName()) @@ -91,39 +377,58 @@ private CallbackResponse buildConfirmation(CallbackParams callbackParams) { return SubmittedCallbackResponse.builder() .confirmationHeader( - String.format("# You have updated a %s's legal representative's email address", partyType)) + String.format("# You have updated a %s's legal representative's information", partyType)) .confirmationBody("
") .build(); } + private List validateAddress(Address address) { + String postCode = Optional.ofNullable(address) + .map(Address::getPostCode) + .orElse(null); + return postcodeValidator.validate(postCode); + } + private CallbackResponse validateApplicant1SolicitorEmail(CallbackParams callbackParams) { + List errors = new ArrayList<>(validateEmailService.validate( + callbackParams.getCaseData().getApplicantSolicitor1UserDetails().getEmail())); + errors.addAll(validateAddress(callbackParams.getCaseData().getApplicantSolicitor1ServiceAddress())); + return AboutToStartOrSubmitCallbackResponse.builder() - .errors(validateEmailService.validate( - callbackParams.getCaseData().getApplicantSolicitor1UserDetails().getEmail())).build(); + .errors(errors).build(); } private CallbackResponse validateRespondent1SolicitorEmail(CallbackParams callbackParams) { + List errors = new ArrayList<>(validateEmailService.validate( + callbackParams.getCaseData().getRespondentSolicitor1EmailAddress())); + errors.addAll(validateAddress(callbackParams.getCaseData().getRespondentSolicitor1ServiceAddress())); + return AboutToStartOrSubmitCallbackResponse.builder() - .errors(validateEmailService.validate( - callbackParams.getCaseData().getRespondentSolicitor1EmailAddress())).build(); + .errors(errors).build(); } private CallbackResponse validateRespondent2SolicitorEmail(CallbackParams callbackParams) { - return AboutToStartOrSubmitCallbackResponse.builder() - .errors(validateEmailService.validate( - callbackParams.getCaseData().getRespondentSolicitor2EmailAddress())).build(); - } + List errors = new ArrayList<>(validateEmailService.validate( + callbackParams.getCaseData().getRespondentSolicitor2EmailAddress())); + errors.addAll(validateAddress(callbackParams.getCaseData().getRespondentSolicitor2ServiceAddress())); - private void buildPartyFlags(List userRoles, CaseData.CaseDataBuilder caseDataBuilder) { - caseDataBuilder.isApplicant1(userRoles.contains(CaseRole.APPLICANTSOLICITORONE.getFormattedName()) ? YES : NO) - .isRespondent1(userRoles.contains(CaseRole.RESPONDENTSOLICITORONE.getFormattedName()) ? YES : NO) - .isRespondent2(userRoles.contains(CaseRole.RESPONDENTSOLICITORTWO.getFormattedName()) ? YES : NO); + return AboutToStartOrSubmitCallbackResponse.builder() + .errors(errors).build(); } - private void clearPartyFlags(CaseData.CaseDataBuilder caseDataBuilder) { + private void clearTempInfo(CaseData.CaseDataBuilder caseDataBuilder, CaseData caseData) { caseDataBuilder.isApplicant1(null) .isRespondent1(null) .isRespondent2(null); + if (caseData.getCaseAccessCategory() != CaseCategory.SPEC_CLAIM) { + caseDataBuilder + .specApplicantCorrespondenceAddressRequired(NO) + .specApplicantCorrespondenceAddressdetails(Address.builder().build()) + .specRespondentCorrespondenceAddressRequired(NO) + .specRespondentCorrespondenceAddressdetails(Address.builder().build()) + .specRespondent2CorrespondenceAddressRequired(NO) + .specRespondent2CorrespondenceAddressdetails(Address.builder().build()); + } } private List getUserRoles(CallbackParams callbackParams) { diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimCallbackHandler.java index 152c085ed41..b796643e4cd 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimCallbackHandler.java @@ -20,7 +20,6 @@ import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.helpers.LocationHelper; -import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.model.BusinessProcess; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.CaseManagementCategory; @@ -35,14 +34,16 @@ import uk.gov.hmcts.reform.civil.model.common.DynamicList; import uk.gov.hmcts.reform.civil.model.common.Element; import uk.gov.hmcts.reform.civil.model.defaultjudgment.CaseLocationCivil; +import uk.gov.hmcts.reform.civil.prd.model.Organisation; +import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData; import uk.gov.hmcts.reform.civil.repositories.ReferenceNumberRepository; import uk.gov.hmcts.reform.civil.service.DeadlinesCalculator; import uk.gov.hmcts.reform.civil.service.ExitSurveyContentService; +import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.service.FeesService; import uk.gov.hmcts.reform.civil.service.OrganisationService; import uk.gov.hmcts.reform.civil.service.Time; -import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; import uk.gov.hmcts.reform.civil.utils.AssignCategoryId; import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser; import uk.gov.hmcts.reform.civil.utils.CaseNameUtils; @@ -54,7 +55,6 @@ import uk.gov.hmcts.reform.civil.validation.interfaces.ParticularsOfClaimValidator; import uk.gov.hmcts.reform.idam.client.IdamClient; import uk.gov.hmcts.reform.idam.client.models.UserDetails; -import uk.gov.hmcts.reform.civil.prd.model.Organisation; import java.util.ArrayList; import java.util.Collections; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandler.java index 69c522256aa..21fb140cca7 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandler.java @@ -18,6 +18,7 @@ import uk.gov.hmcts.reform.civil.enums.CaseCategory; import uk.gov.hmcts.reform.civil.enums.MultiPartyScenario; import uk.gov.hmcts.reform.civil.enums.YesOrNo; +import uk.gov.hmcts.reform.civil.model.Address; import uk.gov.hmcts.reform.civil.model.BusinessProcess; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.CaseManagementCategory; @@ -30,14 +31,15 @@ import uk.gov.hmcts.reform.civil.model.SolicitorReferences; import uk.gov.hmcts.reform.civil.model.StatementOfTruth; import uk.gov.hmcts.reform.civil.model.TimelineOfEvents; -import uk.gov.hmcts.reform.civil.model.common.DynamicListElement; -import uk.gov.hmcts.reform.civil.service.FeatureToggleService; 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.defaultjudgment.CaseLocationCivil; +import uk.gov.hmcts.reform.civil.prd.model.Organisation; import uk.gov.hmcts.reform.civil.repositories.ReferenceNumberRepository; import uk.gov.hmcts.reform.civil.repositories.SpecReferenceNumberRepository; import uk.gov.hmcts.reform.civil.service.ExitSurveyContentService; +import uk.gov.hmcts.reform.civil.service.FeatureToggleService; import uk.gov.hmcts.reform.civil.service.FeesService; import uk.gov.hmcts.reform.civil.service.OrganisationService; import uk.gov.hmcts.reform.civil.service.Time; @@ -56,7 +58,6 @@ import uk.gov.hmcts.reform.civil.validation.interfaces.ParticularsOfClaimValidator; import uk.gov.hmcts.reform.idam.client.IdamClient; import uk.gov.hmcts.reform.idam.client.models.UserDetails; -import uk.gov.hmcts.reform.civil.prd.model.Organisation; import java.math.BigDecimal; import java.time.LocalDate; @@ -79,6 +80,7 @@ import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_CLAIM_SPEC; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.CREATE_SERVICE_REQUEST_CLAIM; import static uk.gov.hmcts.reform.civil.enums.CaseRole.RESPONDENTSOLICITORTWO; +import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.ONE_V_TWO_ONE_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; @@ -210,7 +212,19 @@ protected Map callbacks() { .put(callbackKey(MID, "setRespondent2SameLegalRepresentativeToNo"), this::setRespondent2SameLegalRepToNo) .put( callbackKey(MID, "specRespondentCorrespondenceAddress"), - this::validateCorrespondenceRespondentAddress + params -> validateCorrespondenceRespondentAddress( + params, + CaseData::getSpecRespondentCorrespondenceAddressRequired, + CaseData::getSpecRespondentCorrespondenceAddressdetails + ) + ) + .put( + callbackKey(MID, "specRespondent2CorrespondenceAddress"), + params -> validateCorrespondenceRespondentAddress( + params, + CaseData::getSpecRespondent2CorrespondenceAddressRequired, + CaseData::getSpecRespondent2CorrespondenceAddressdetails + ) ) .put(callbackKey(MID, "validate-spec-defendant-legal-rep-email"), this::validateSpecRespondentRepEmail) .put(callbackKey(MID, "validate-spec-defendant2-legal-rep-email"), this::validateSpecRespondent2RepEmail) @@ -338,7 +352,7 @@ private CallbackResponse calculateFee(CallbackParams callbackParams) { List pbaNumbers = getPbaAccounts(callbackParams.getParams().get(BEARER_TOKEN).toString()); caseDataBuilder.claimFee(feesService - .getFeeDataByClaimValue(caseData.getClaimValue())) + .getFeeDataByClaimValue(caseData.getClaimValue())) .applicantSolicitor1PbaAccounts(DynamicList.fromList(pbaNumbers)) .applicantSolicitor1PbaAccountsIsEmpty(pbaNumbers.isEmpty() ? YES : NO); @@ -468,32 +482,32 @@ private CallbackResponse submitClaim(CallbackParams callbackParams) { Optional references = ofNullable(caseData.getSolicitorReferences()); references.ifPresent(ref -> { SolicitorReferences updatedSolicitorReferences = SolicitorReferences.builder() - .applicantSolicitor1Reference(ref.getApplicantSolicitor1Reference()) - .respondentSolicitor1Reference(ref.getRespondentSolicitor1Reference()) - .respondentSolicitor2Reference(ref.getRespondentSolicitor1Reference()) - .build(); + .applicantSolicitor1Reference(ref.getApplicantSolicitor1Reference()) + .respondentSolicitor1Reference(ref.getRespondentSolicitor1Reference()) + .respondentSolicitor2Reference(ref.getRespondentSolicitor1Reference()) + .build(); dataBuilder.solicitorReferences(updatedSolicitorReferences); }); dataBuilder .respondentSolicitor2ServiceAddressRequired(caseData.getRespondentSolicitor1ServiceAddressRequired()); dataBuilder.respondentSolicitor2ServiceAddress(caseData.getRespondentSolicitor1ServiceAddress()); } else if (temporaryCaseData.getRespondent1OrgRegistered() == NO - && temporaryCaseData.getRespondent1Represented() == YES - && temporaryCaseData.getRespondent2SameLegalRepresentative() == YES) { + && temporaryCaseData.getRespondent1Represented() == YES + && temporaryCaseData.getRespondent2SameLegalRepresentative() == YES) { dataBuilder - .respondent2OrgRegistered(NO) - .respondentSolicitor2EmailAddress(caseData.getRespondentSolicitor1EmailAddress()); + .respondent2OrgRegistered(NO) + .respondentSolicitor2EmailAddress(caseData.getRespondentSolicitor1EmailAddress()); Optional references = ofNullable(caseData.getSolicitorReferences()); references.ifPresent(ref -> { SolicitorReferences updatedSolicitorReferences = SolicitorReferences.builder() - .applicantSolicitor1Reference(ref.getApplicantSolicitor1Reference()) - .respondentSolicitor1Reference(ref.getRespondentSolicitor1Reference()) - .respondentSolicitor2Reference(ref.getRespondentSolicitor1Reference()) - .build(); + .applicantSolicitor1Reference(ref.getApplicantSolicitor1Reference()) + .respondentSolicitor1Reference(ref.getRespondentSolicitor1Reference()) + .respondentSolicitor2Reference(ref.getRespondentSolicitor1Reference()) + .build(); dataBuilder.solicitorReferences(updatedSolicitorReferences); }); dataBuilder - .respondentSolicitor2ServiceAddressRequired(caseData.getRespondentSolicitor1ServiceAddressRequired()); + .respondentSolicitor2ServiceAddressRequired(caseData.getRespondentSolicitor1ServiceAddressRequired()); dataBuilder.respondentSolicitor2ServiceAddress(caseData.getRespondentSolicitor1ServiceAddress()); dataBuilder.respondentSolicitor2OrganisationDetails(caseData.getRespondentSolicitor1OrganisationDetails()); } @@ -519,6 +533,16 @@ private CallbackResponse submitClaim(CallbackParams callbackParams) { .build()).build()); } + if (getMultiPartyScenario(caseData) == ONE_V_TWO_ONE_LEGAL_REP + && caseData.getSpecRespondentCorrespondenceAddressdetails() != null) { + // to keep with heading tab + dataBuilder + .specRespondent2CorrespondenceAddressRequired( + caseData.getSpecRespondentCorrespondenceAddressRequired()) + .specRespondent2CorrespondenceAddressdetails( + caseData.getSpecRespondentCorrespondenceAddressdetails()); + } + return AboutToStartOrSubmitCallbackResponse.builder() .errors(errors) .data(dataBuilder.build().toMap(objectMapper)) @@ -610,20 +634,27 @@ private String getBody(CaseData caseData) { ((areRespondentsRepresentedAndRegistered(caseData) || isPinInPostCaseMatched(caseData)) ? getConfirmationSummary(caseData) - : format(LIP_CONFIRMATION_BODY, format(caseDocLocation, - caseData.getCcdCaseReference()), + : format(LIP_CONFIRMATION_BODY, format( + caseDocLocation, + caseData.getCcdCaseReference() + ), claimUrlsConfiguration.getResponsePackLink(), - formattedServiceDeadline)) - + exitSurveyContentService.applicantSurvey(); + formattedServiceDeadline + )) + + exitSurveyContentService.applicantSurvey(); } private String getConfirmationSummary(CaseData caseData) { if (featureToggleService.isPbaV3Enabled()) { - return format(CONFIRMATION_SUMMARY_PBA_V3, - format("/cases/case-details/%s#Service%%20Request", caseData.getCcdCaseReference())); + return format( + CONFIRMATION_SUMMARY_PBA_V3, + format("/cases/case-details/%s#Service%%20Request", caseData.getCcdCaseReference()) + ); } else { - return format(CONFIRMATION_SUMMARY, - format(caseDocLocation, caseData.getCcdCaseReference())); + return format( + CONFIRMATION_SUMMARY, + format(caseDocLocation, caseData.getCcdCaseReference()) + ); } } @@ -658,10 +689,12 @@ private CallbackResponse validatePostCode(String postCode) { .build(); } - private CallbackResponse validateCorrespondenceRespondentAddress(CallbackParams callbackParams) { + private CallbackResponse validateCorrespondenceRespondentAddress(CallbackParams callbackParams, + Function required, + Function address) { CaseData caseData = callbackParams.getCaseData(); - if (caseData.getSpecRespondentCorrespondenceAddressRequired().equals(YES)) { - return validatePostCode(caseData.getSpecRespondentCorrespondenceAddressdetails().getPostCode()); + if (YES.equals(required.apply(caseData))) { + return validatePostCode(address.apply(caseData).getPostCode()); } else { return AboutToStartOrSubmitCallbackResponse.builder() .build(); @@ -810,31 +843,37 @@ private String getSpecBody(CaseData caseData) { ((areRespondentsRepresentedAndRegistered(caseData) || isPinInPostCaseMatched(caseData)) ? getSpecConfirmationSummary(caseData) - : toggleService.isPbaV3Enabled() ? format(SPEC_LIP_CONFIRMATION_BODY_PBAV3, - format("/cases/case-details/%s#Service%%20Request", caseData.getCcdCaseReference()), - format(caseDocLocation, caseData.getCcdCaseReference()), - claimUrlsConfiguration.getResponsePackLink(), - claimUrlsConfiguration.getN9aLink(), - claimUrlsConfiguration.getN9bLink(), - claimUrlsConfiguration.getN215Link(), - formattedServiceDeadline - ) : format(SPEC_LIP_CONFIRMATION_BODY, - format(caseDocLocation, caseData.getCcdCaseReference()), - claimUrlsConfiguration.getResponsePackLink(), - claimUrlsConfiguration.getN9aLink(), - claimUrlsConfiguration.getN9bLink(), - claimUrlsConfiguration.getN215Link(), - formattedServiceDeadline + : toggleService.isPbaV3Enabled() ? format( + SPEC_LIP_CONFIRMATION_BODY_PBAV3, + format("/cases/case-details/%s#Service%%20Request", caseData.getCcdCaseReference()), + format(caseDocLocation, caseData.getCcdCaseReference()), + claimUrlsConfiguration.getResponsePackLink(), + claimUrlsConfiguration.getN9aLink(), + claimUrlsConfiguration.getN9bLink(), + claimUrlsConfiguration.getN215Link(), + formattedServiceDeadline + ) : format( + SPEC_LIP_CONFIRMATION_BODY, + format(caseDocLocation, caseData.getCcdCaseReference()), + claimUrlsConfiguration.getResponsePackLink(), + claimUrlsConfiguration.getN9aLink(), + claimUrlsConfiguration.getN9bLink(), + claimUrlsConfiguration.getN215Link(), + formattedServiceDeadline )) + exitSurveyContentService.applicantSurvey(); } private String getSpecConfirmationSummary(CaseData caseData) { if (featureToggleService.isPbaV3Enabled()) { - return format(SPEC_CONFIRMATION_SUMMARY_PBA_V3, - format("/cases/case-details/%s#Service%%20Request", caseData.getCcdCaseReference())); + return format( + SPEC_CONFIRMATION_SUMMARY_PBA_V3, + format("/cases/case-details/%s#Service%%20Request", caseData.getCcdCaseReference()) + ); } else { - return format(SPEC_CONFIRMATION_SUMMARY, - format(caseDocLocation, caseData.getCcdCaseReference())); + return format( + SPEC_CONFIRMATION_SUMMARY, + format(caseDocLocation, caseData.getCcdCaseReference()) + ); } } @@ -883,7 +922,7 @@ private boolean areRespondentsRepresentedAndRegistered(CaseData caseData) { public StringBuilder caseParticipants(CaseData caseData) { StringBuilder participantString = new StringBuilder(); - MultiPartyScenario multiPartyScenario = getMultiPartyScenario(caseData); + 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()) 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 39fc22d9a85..48d02d93648 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 @@ -636,6 +636,22 @@ CallbackResponse documentUploadTime(CallbackParams callbackParams) { setCategoryIdAndRenameDoc(caseData.getDocumentEvidenceForTrialApp2(), document -> document.getValue().getDocumentUpload(), APPLICANT_TWO_TRIAL_DOC_CORRESPONDENCE); } + // null the values of the lists, so that on future retriggers of the event, they are blank + caseDataBuilder.disclosureSelectionEvidence(null); + caseDataBuilder.disclosureSelectionEvidenceRes(null); + caseDataBuilder.witnessSelectionEvidence(null); + caseDataBuilder.witnessSelectionEvidenceSmallClaim(null); + caseDataBuilder.witnessSelectionEvidenceRes(null); + caseDataBuilder.witnessSelectionEvidenceSmallClaimRes(null); + caseDataBuilder.expertSelectionEvidenceRes(null); + caseDataBuilder.expertSelectionEvidence(null); + caseDataBuilder.expertSelectionEvidenceSmallClaim(null); + caseDataBuilder.expertSelectionEvidenceSmallClaimRes(null); + caseDataBuilder.trialSelectionEvidence(null); + caseDataBuilder.trialSelectionEvidenceSmallClaim(null); + caseDataBuilder.trialSelectionEvidenceRes(null); + caseDataBuilder.trialSelectionEvidenceSmallClaimRes(null); + return AboutToStartOrSubmitCallbackResponse.builder() .data(caseDataBuilder.build().toMap(objectMapper)) .build(); 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 85826ceaa7d..e9d8d00a50a 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 @@ -12,6 +12,7 @@ import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; 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.model.BusinessProcess; @@ -22,9 +23,11 @@ import uk.gov.hmcts.reform.civil.model.finalorders.AppealChoiceSecondDropdown; import uk.gov.hmcts.reform.civil.model.finalorders.AppealGrantedRefused; import uk.gov.hmcts.reform.civil.model.finalorders.AssistedOrderCostDetails; +import uk.gov.hmcts.reform.civil.model.finalorders.ClaimantAndDefendantHeard; import uk.gov.hmcts.reform.civil.model.finalorders.DatesFinalOrders; import uk.gov.hmcts.reform.civil.model.finalorders.FinalOrderAppeal; import uk.gov.hmcts.reform.civil.model.finalorders.FinalOrderFurtherHearing; +import uk.gov.hmcts.reform.civil.model.finalorders.FinalOrderRepresentation; import uk.gov.hmcts.reform.civil.model.finalorders.OrderMade; import uk.gov.hmcts.reform.civil.model.finalorders.OrderMadeOnDetails; import uk.gov.hmcts.reform.civil.model.finalorders.OrderMadeOnDetailsOrderWithoutNotice; @@ -55,6 +58,9 @@ import static uk.gov.hmcts.reform.civil.enums.CaseState.All_FINAL_ORDERS_ISSUED; import static uk.gov.hmcts.reform.civil.enums.CaseState.CASE_PROGRESSION; import static uk.gov.hmcts.reform.civil.enums.CaseState.JUDICIAL_REFERRAL; +import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.ONE_V_TWO_ONE_LEGAL_REP; +import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.ONE_V_TWO_TWO_LEGAL_REP; +import static uk.gov.hmcts.reform.civil.enums.MultiPartyScenario.TWO_V_ONE; import static uk.gov.hmcts.reform.civil.enums.caseprogression.FinalOrderSelection.ASSISTED_ORDER; import static uk.gov.hmcts.reform.civil.model.common.DynamicList.fromList; import static uk.gov.hmcts.reform.civil.utils.ElementUtils.element; @@ -79,6 +85,8 @@ public class GenerateDirectionOrderCallbackHandler extends CallbackHandler { public static final String NOT_ALLOWED_DATE = "The date in %s may not be later than the established date"; public static final String NOT_ALLOWED_DATE_RANGE = "The date range in %s may not have a 'from date', that is after the 'date to'"; public static final String NOT_ALLOWED_DATE_PAST = "The date in %s may not be before the established date"; + public String defendantTwoPartyName; + public String claimantTwoPartyName; private final LocationRefDataService locationRefDataService; private final ObjectMapper objectMapper; private final JudgeFinalOrderGenerator judgeFinalOrderGenerator; @@ -184,9 +192,19 @@ private boolean hasSDOBeenMade(CaseState state) { private CaseData.CaseDataBuilder populateFields( CaseData.CaseDataBuilder builder, List locations, CaseData caseData, String authToken) { LocalDate advancedDate = LocalDate.now().plusDays(14); + + populateClaimant2Defendant2PartyNames(caseData); return builder.finalOrderDateHeardComplex(OrderMade.builder().singleDateSelection(DatesFinalOrders .builder().singleDate(LocalDate.now()) .build()).build()) + .finalOrderRepresentation(FinalOrderRepresentation.builder() + .typeRepresentationComplex(ClaimantAndDefendantHeard + .builder() + .typeRepresentationClaimantOneDynamic(caseData.getApplicant1().getPartyName()) + .typeRepresentationDefendantOneDynamic(caseData.getRespondent1().getPartyName()) + .typeRepresentationDefendantTwoDynamic(defendantTwoPartyName) + .typeRepresentationClaimantTwoDynamic(claimantTwoPartyName) + .build()).build()) .finalOrderFurtherHearingComplex( FinalOrderFurtherHearing.builder() .hearingLocationList(populateCurrentHearingLocation(caseData, authToken)) @@ -218,6 +236,18 @@ private boolean hasSDOBeenMade(CaseState state) { .build()).build()); } + private void populateClaimant2Defendant2PartyNames(CaseData caseData) { + claimantTwoPartyName = null; + defendantTwoPartyName = null; + MultiPartyScenario scenario = MultiPartyScenario.getMultiPartyScenario(caseData); + if (scenario == ONE_V_TWO_ONE_LEGAL_REP || scenario == ONE_V_TWO_TWO_LEGAL_REP) { + defendantTwoPartyName = caseData.getRespondent2().getPartyName(); + } + if (scenario == TWO_V_ONE) { + claimantTwoPartyName = caseData.getApplicant2().getPartyName(); + } + } + private void validateDate(LocalDate date, String dateDescription, String errorMessage, List errors, Boolean pastDate) { if (pastDate) { if (nonNull(date) && date.isBefore(LocalDate.now())) { 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 afc8a748271..cd427bee902 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 @@ -12,6 +12,8 @@ import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.callback.CaseEvent; import uk.gov.hmcts.reform.civil.constants.SpecJourneyConstantLRSpec; +import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; +import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType; import uk.gov.hmcts.reform.civil.enums.AllocatedTrack; import uk.gov.hmcts.reform.civil.enums.CaseRole; import uk.gov.hmcts.reform.civil.enums.CaseState; @@ -20,12 +22,13 @@ import uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec; import uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpecPaidStatus; import uk.gov.hmcts.reform.civil.enums.TimelineUploadTypeSpec; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.handler.callback.user.spec.CaseDataToTextGenerator; import uk.gov.hmcts.reform.civil.handler.callback.user.spec.RespondToClaimConfirmationHeaderSpecGenerator; import uk.gov.hmcts.reform.civil.handler.callback.user.spec.RespondToClaimConfirmationTextSpecGenerator; import uk.gov.hmcts.reform.civil.handler.callback.user.spec.show.DefendantResponseShowTag; import uk.gov.hmcts.reform.civil.helpers.LocationHelper; -import uk.gov.hmcts.reform.civil.service.FeatureToggleService; +import uk.gov.hmcts.reform.civil.model.Address; import uk.gov.hmcts.reform.civil.model.BusinessProcess; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.Party; @@ -36,8 +39,6 @@ import uk.gov.hmcts.reform.civil.model.StatementOfTruth; import uk.gov.hmcts.reform.civil.model.common.DynamicList; import uk.gov.hmcts.reform.civil.model.common.Element; -import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; -import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType; 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.Hearing; @@ -46,13 +47,14 @@ import uk.gov.hmcts.reform.civil.model.dq.Respondent2DQ; import uk.gov.hmcts.reform.civil.model.dq.SmallClaimHearing; import uk.gov.hmcts.reform.civil.model.dq.Witnesses; +import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData; import uk.gov.hmcts.reform.civil.service.CoreCaseUserService; import uk.gov.hmcts.reform.civil.service.DeadlinesCalculator; +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.flowstate.StateFlowEngine; -import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; import uk.gov.hmcts.reform.civil.utils.AssignCategoryId; import uk.gov.hmcts.reform.civil.utils.CaseFlagsInitialiser; import uk.gov.hmcts.reform.civil.utils.CourtLocationUtils; @@ -746,10 +748,10 @@ private CallbackResponse setUploadTimelineTypeFlag(CallbackParams callbackParams /** * The condition to show the right title for why does X disputes the claim is too complex for the current * abilities of front, so we have to take care of it in back. + * This method may add the flags only_respondent_1_disputes, only_respondent_2_disputes or both_respondent_dispute. * * @param caseData the current case data - * @return copy of caseData.showConditionFlag adding the needed among only_respondent_1_disputes, - * only_respondent_2_disputes or both_respondent_dispute + * @return updated copy of caseData.showConditionFlag */ private Set whoDisputesPartAdmission(CaseData caseData) { Set tags = new HashSet<>(caseData.getShowConditionFlags()); @@ -1263,6 +1265,7 @@ private CallbackResponse validateDateOfBirth(CallbackParams callbackParams) { List errors = dateOfBirthValidator.validate(respondent); CaseData caseData = callbackParams.getCaseData(); + errors.addAll(correspondenceAddressCorrect(caseData)); CaseData.CaseDataBuilder updatedData = caseData.toBuilder(); if (ONE_V_TWO_TWO_LEGAL_REP.equals(getMultiPartyScenario(caseData)) && YES.equals(caseData.getAddRespondent2())) { @@ -1288,6 +1291,32 @@ && solicitorRepresentsOnlyOneOfRespondents(callbackParams, RESPONDENTSOLICITORON .build(); } + /** + * Checks that the address of case data was ok when the applicant set it, or that its postcode is correct + * if the defendant has modified. + * + * @param caseData the case data + * @return errors of the correspondence address (if any) + */ + private List correspondenceAddressCorrect(CaseData caseData) { + if (caseData.getIsRespondent1() == YesOrNo.YES + && caseData.getSpecAoSRespondentCorrespondenceAddressRequired() == YesOrNo.NO) { + return postcodeValidator.validate( + Optional.ofNullable(caseData.getSpecAoSRespondentCorrespondenceAddressdetails()) + .map(Address::getPostCode) + .orElse(null) + ); + } else if (caseData.getIsRespondent2() == YesOrNo.YES + && caseData.getSpecAoSRespondent2CorrespondenceAddressRequired() == YesOrNo.NO) { + return postcodeValidator.validate( + Optional.ofNullable(caseData.getSpecAoSRespondent2CorrespondenceAddressdetails()) + .map(Address::getPostCode) + .orElse(null) + ); + } + return Collections.emptyList(); + } + private CallbackResponse resetStatementOfTruth(CallbackParams callbackParams) { CaseData caseData = callbackParams.getCaseData(); @@ -1481,6 +1510,8 @@ && ifResponseTypeIsPartOrFullAdmission(caseData)) { } + updateCorrespondenceAddress(callbackParams, updatedData, caseData); + if (getMultiPartyScenario(caseData) == ONE_V_TWO_TWO_LEGAL_REP && isAwaitingAnotherDefendantResponse(caseData)) { @@ -1525,6 +1556,26 @@ private boolean ifResponseTypeIsPartOrFullAdmission(CaseData caseData) { ); } + private void updateCorrespondenceAddress(CallbackParams callbackParams, + CaseData.CaseDataBuilder updatedCaseData, + CaseData caseData) { + if (solicitorHasCaseRole(callbackParams, RESPONDENTSOLICITORONE) + && caseData.getSpecAoSRespondentCorrespondenceAddressRequired() == YesOrNo.NO) { + Address newAddress = caseData.getSpecAoSRespondentCorrespondenceAddressdetails(); + updatedCaseData.specRespondentCorrespondenceAddressdetails(newAddress) + .specAoSRespondentCorrespondenceAddressdetails(Address.builder().build()); + if (getMultiPartyScenario(caseData) == ONE_V_TWO_ONE_LEGAL_REP) { + // to keep with heading tab + updatedCaseData.specRespondent2CorrespondenceAddressdetails(newAddress); + } + } else if (solicitorHasCaseRole(callbackParams, RESPONDENTSOLICITORTWO) + && caseData.getSpecAoSRespondent2CorrespondenceAddressRequired() == YesOrNo.NO) { + updatedCaseData.specRespondent2CorrespondenceAddressdetails( + caseData.getSpecAoSRespondent2CorrespondenceAddressdetails()) + .specAoSRespondent2CorrespondenceAddressdetails(Address.builder().build()); + } + } + private void assembleResponseDocumentsSpec(CaseData caseData, CaseData.CaseDataBuilder updatedCaseData) { List> defendantUploads = new ArrayList<>(); ResponseDocument respondent1SpecDefenceResponseDocument = caseData.getRespondent1SpecDefenceResponseDocument(); @@ -1536,8 +1587,10 @@ private void assembleResponseDocumentsSpec(CaseData caseData, CaseData.CaseDataB updatedCaseData.build().getRespondent1ResponseDate(), DocumentType.DEFENDANT_DEFENCE )); - assignCategoryId.assignCategoryIdToDocument(respondent1ClaimDocument, - "defendant1DefenseDirectionsQuestionnaire"); + assignCategoryId.assignCategoryIdToDocument( + respondent1ClaimDocument, + "defendant1DefenseDirectionsQuestionnaire" + ); } } Respondent1DQ respondent1DQ = caseData.getRespondent1DQ(); @@ -1551,8 +1604,10 @@ private void assembleResponseDocumentsSpec(CaseData caseData, CaseData.CaseDataB updatedCaseData.build().getRespondent1ResponseDate(), DocumentType.DEFENDANT_DRAFT_DIRECTIONS )); - assignCategoryId.assignCategoryIdToDocument(respondent1DQDraftDirections, - "defendant1DefenseDirectionsQuestionnaire"); + assignCategoryId.assignCategoryIdToDocument( + respondent1DQDraftDirections, + "defendant1DefenseDirectionsQuestionnaire" + ); } ResponseDocument respondent2SpecDefenceResponseDocument = caseData.getRespondent2SpecDefenceResponseDocument(); if (respondent2SpecDefenceResponseDocument != null) { @@ -1563,8 +1618,10 @@ private void assembleResponseDocumentsSpec(CaseData caseData, CaseData.CaseDataB updatedCaseData.build().getRespondent2ResponseDate(), DocumentType.DEFENDANT_DEFENCE )); - assignCategoryId.assignCategoryIdToDocument(respondent2ClaimDocument, - "defendant2DefenseDirectionsQuestionnaire"); + assignCategoryId.assignCategoryIdToDocument( + respondent2ClaimDocument, + "defendant2DefenseDirectionsQuestionnaire" + ); } } } else { @@ -1577,8 +1634,10 @@ private void assembleResponseDocumentsSpec(CaseData caseData, CaseData.CaseDataB updatedCaseData.build().getRespondent2ResponseDate(), DocumentType.DEFENDANT_DEFENCE )); - assignCategoryId.assignCategoryIdToDocument(respondent2ClaimDocument, - "defendant2DefenseDirectionsQuestionnaire"); + assignCategoryId.assignCategoryIdToDocument( + respondent2ClaimDocument, + "defendant2DefenseDirectionsQuestionnaire" + ); } } } @@ -1593,8 +1652,10 @@ private void assembleResponseDocumentsSpec(CaseData caseData, CaseData.CaseDataB updatedCaseData.build().getRespondent2ResponseDate(), DocumentType.DEFENDANT_DRAFT_DIRECTIONS )); - assignCategoryId.assignCategoryIdToDocument(respondent2DQDraftDirections, - "defendant2DefenseDirectionsQuestionnaire"); + assignCategoryId.assignCategoryIdToDocument( + respondent2DQDraftDirections, + "defendant2DefenseDirectionsQuestionnaire" + ); } } if (!defendantUploads.isEmpty()) { 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 a0a2d6ebf58..6db3eb1fbbe 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 @@ -13,8 +13,8 @@ import uk.gov.hmcts.reform.civil.enums.CaseCategory; import uk.gov.hmcts.reform.civil.enums.DJPaymentTypeSelection; import uk.gov.hmcts.reform.civil.enums.EmploymentTypeCheckboxFixedListLRspec; -import uk.gov.hmcts.reform.civil.enums.PaymentType; import uk.gov.hmcts.reform.civil.enums.PaymentFrequencyClaimantResponseLRspec; +import uk.gov.hmcts.reform.civil.enums.PaymentType; import uk.gov.hmcts.reform.civil.enums.RepaymentFrequencyDJ; import uk.gov.hmcts.reform.civil.enums.RespondentResponsePartAdmissionPaymentTimeLRspec; import uk.gov.hmcts.reform.civil.enums.RespondentResponseTypeSpec; @@ -39,6 +39,7 @@ import uk.gov.hmcts.reform.civil.enums.hearing.HearingNoticeList; import uk.gov.hmcts.reform.civil.enums.hearing.ListingOrRelisting; import uk.gov.hmcts.reform.civil.enums.sdo.ClaimsTrack; +import uk.gov.hmcts.reform.civil.enums.sdo.DateToShowToggle; import uk.gov.hmcts.reform.civil.enums.sdo.DisposalHearingMethod; import uk.gov.hmcts.reform.civil.enums.sdo.DisposalHearingMethodTelephoneHearing; import uk.gov.hmcts.reform.civil.enums.sdo.DisposalHearingMethodVideoConferenceHearing; @@ -52,7 +53,6 @@ import uk.gov.hmcts.reform.civil.enums.sdo.SmallClaimsMethodTelephoneHearing; import uk.gov.hmcts.reform.civil.enums.sdo.SmallClaimsMethodVideoConferenceHearing; import uk.gov.hmcts.reform.civil.enums.sdo.SmallTrack; -import uk.gov.hmcts.reform.civil.enums.sdo.DateToShowToggle; import uk.gov.hmcts.reform.civil.handler.callback.user.spec.show.DefendantResponseShowTag; import uk.gov.hmcts.reform.civil.handler.callback.user.spec.show.ResponseOneVOneShowTag; import uk.gov.hmcts.reform.civil.model.caseflags.Flags; @@ -109,11 +109,11 @@ import uk.gov.hmcts.reform.civil.model.sdo.DisposalHearingWitnessOfFact; import uk.gov.hmcts.reform.civil.model.sdo.DisposalOrderWithoutHearing; import uk.gov.hmcts.reform.civil.model.sdo.FastTrackAddNewDirections; +import uk.gov.hmcts.reform.civil.model.sdo.FastTrackAllocation; import uk.gov.hmcts.reform.civil.model.sdo.FastTrackBuildingDispute; import uk.gov.hmcts.reform.civil.model.sdo.FastTrackClinicalNegligence; import uk.gov.hmcts.reform.civil.model.sdo.FastTrackCreditHire; import uk.gov.hmcts.reform.civil.model.sdo.FastTrackDisclosureOfDocuments; -import uk.gov.hmcts.reform.civil.model.sdo.FastTrackAllocation; import uk.gov.hmcts.reform.civil.model.sdo.FastTrackHearingNotes; import uk.gov.hmcts.reform.civil.model.sdo.FastTrackHearingTime; import uk.gov.hmcts.reform.civil.model.sdo.FastTrackHousingDisrepair; @@ -691,6 +691,8 @@ public boolean isApplicantNotRepresented() { private DisposalHearingMethodDJ trialHearingMethodDJ; private HearingMethodTelephoneHearingDJ trialHearingMethodTelephoneHearingDJ; private HearingMethodVideoConferenceDJ trialHearingMethodVideoConferenceHearingDJ; + private final Address specRespondent2CorrespondenceAddressdetails; + private final YesOrNo specRespondent2CorrespondenceAddressRequired; private List> applicant1UnavailableDatesForTab; private List> applicant2UnavailableDatesForTab; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/finalorders/ClaimantAndDefendantHeard.java b/src/main/java/uk/gov/hmcts/reform/civil/model/finalorders/ClaimantAndDefendantHeard.java index dba402b9453..664a65d3282 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/finalorders/ClaimantAndDefendantHeard.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/finalorders/ClaimantAndDefendantHeard.java @@ -18,4 +18,8 @@ public class ClaimantAndDefendantHeard { private FinalOrdersDefendantRepresentationList typeRepresentationDefendantList; private TrialNoticeProcedure trialProcedureComplex; private String detailsRepresentationText; + private String typeRepresentationClaimantOneDynamic; + private String typeRepresentationClaimantTwoDynamic; + private String typeRepresentationDefendantOneDynamic; + private String typeRepresentationDefendantTwoDynamic; } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/hearing/HearingNoticeHmcGenerator.java b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/hearing/HearingNoticeHmcGenerator.java index be331391198..8d3646a2e13 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/hearing/HearingNoticeHmcGenerator.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/hearing/HearingNoticeHmcGenerator.java @@ -1,6 +1,7 @@ package uk.gov.hmcts.reform.civil.service.docmosis.hearing; import lombok.RequiredArgsConstructor; +import org.jetbrains.annotations.Nullable; import org.springframework.stereotype.Service; import uk.gov.hmcts.reform.civil.documentmanagement.DocumentManagementService; import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; @@ -63,10 +64,14 @@ public HearingNoticeHmc getHearingNoticeTemplateData(CaseData caseData, HearingG var hearingDueDate = paymentFailed ? HearingFeeUtils .calculateHearingDueDate(LocalDate.now(), HmcDataUtils.getHearingStartDay(hearing) .getHearingStartDateTime().toLocalDate()) : null; - var hearingLocation = getHearingLocation(HmcDataUtils.getHearingStartDay(hearing).getHearingVenueId(), bearerToken); + LocationRefData hearingLocation = getLocationRefData( + HmcDataUtils.getHearingStartDay(hearing).getHearingVenueId(), + bearerToken); + LocationRefData caseManagementLocation = + getLocationRefData(caseData.getCaseManagementLocation().getBaseLocation(), bearerToken); return HearingNoticeHmc.builder() - .hearingSiteName(nonNull(hearingLocation) ? hearingLocation.getSiteName() : null) + .hearingSiteName(nonNull(caseManagementLocation) ? caseManagementLocation.getSiteName() : null) .hearingLocation(LocationRefDataService.getDisplayEntry(hearingLocation)) .caseNumber(caseData.getCcdCaseReference()) .creationDate(LocalDate.now()) @@ -97,7 +102,8 @@ private DocmosisTemplates getTemplate(CaseData caseData) { return HEARING_NOTICE_HMC; } - private LocationRefData getHearingLocation(String venueId, String bearerToken) { + @Nullable + private LocationRefData getLocationRefData(String venueId, String bearerToken) { List locations = locationRefDataService.getCourtLocationsForDefaultJudgments(bearerToken); var matchedLocations = locations.stream().filter(loc -> loc.getEpimmsId().equals(venueId)).toList(); return matchedLocations.size() > 0 ? matchedLocations.get(0) : null; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/robotics/mapper/RoboticsDataMapper.java b/src/main/java/uk/gov/hmcts/reform/civil/service/robotics/mapper/RoboticsDataMapper.java index 57592e3ea3b..35a06bd365d 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/robotics/mapper/RoboticsDataMapper.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/robotics/mapper/RoboticsDataMapper.java @@ -146,6 +146,7 @@ private Solicitor buildRespondentSolicitor(CaseData caseData, String id) { .contactEmailAddress(caseData.getRespondentSolicitor1EmailAddress()) .reference(ofNullable(caseData.getSolicitorReferences()) .map(SolicitorReferences::getRespondentSolicitor1Reference) + .map(s -> s.substring(0, Math.min(s.length(), 24))) .orElse(null) ); @@ -216,6 +217,7 @@ private Solicitor buildApplicantSolicitor(CaseData caseData, String id) { .contactEmailAddress(caseData.getApplicantSolicitor1UserDetails().getEmail()) .reference(ofNullable(caseData.getSolicitorReferences()) .map(SolicitorReferences::getApplicantSolicitor1Reference) + .map(s -> s.substring(0, Math.min(s.length(), 24))) .orElse(null) ); @@ -333,7 +335,11 @@ private Solicitor buildRespondent2Solicitor(CaseData caseData, String id) { .isPayee(false) .organisationId(organisationId) .contactEmailAddress(caseData.getRespondentSolicitor2EmailAddress()) - .reference(caseData.getRespondentSolicitor2Reference()); + .reference(ofNullable(caseData.getSolicitorReferences()) + .map(SolicitorReferences::getRespondentSolicitor2Reference) + .map(s -> s.substring(0, Math.min(s.length(), 24))) + .orElse(null) + ); if (organisationId != null) { organisationService.findOrganisationById(organisationId) diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/robotics/mapper/RoboticsDataMapperForSpec.java b/src/main/java/uk/gov/hmcts/reform/civil/service/robotics/mapper/RoboticsDataMapperForSpec.java index 691ac089391..e97f1c852fb 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/robotics/mapper/RoboticsDataMapperForSpec.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/robotics/mapper/RoboticsDataMapperForSpec.java @@ -107,20 +107,20 @@ private CaseHeader buildCaseHeader(CaseData caseData) { private List buildSolicitors(CaseData caseData) { List solicitorsList = new ArrayList<>(); - solicitorsList.add(buildApplicantSolicitor(caseData, APPLICANT_SOLICITOR_ID)); - ofNullable(buildRespondentSolicitor(caseData, RESPONDENT_SOLICITOR_ID)) + solicitorsList.add(buildApplicantSolicitor(caseData)); + ofNullable(buildRespondentSolicitor(caseData)) .ifPresent(solicitorsList::add); if (YES == caseData.getSpecRespondent2Represented() && YES != caseData.getRespondent2SameLegalRepresentative()) { - ofNullable(buildRespondent2Solicitor(caseData, RESPONDENT2_SOLICITOR_ID)) + ofNullable(buildRespondent2Solicitor(caseData)) .ifPresent(solicitorsList::add); } return solicitorsList; } - private Solicitor buildRespondentSolicitor(CaseData caseData, String id) { - Solicitor.SolicitorBuilder solicitorBuilder = Solicitor.builder(); + private Solicitor buildRespondentSolicitor(CaseData caseData) { + Solicitor.SolicitorBuilder solicitorBuilder = Solicitor.builder(); Optional organisationId = getOrganisationId(caseData.getRespondent1OrganisationPolicy()); var organisationDetails = ofNullable( caseData.getRespondentSolicitor1OrganisationDetails() @@ -132,25 +132,27 @@ private Solicitor buildRespondentSolicitor(CaseData caseData, String id) { caseData.getRespondentSolicitor1EmailAddress() ); solicitorBuilder - .id(id) + .id(RoboticsDataUtil.RESPONDENT_SOLICITOR_ID) .isPayee(false) .organisationId(organisationId.orElse(null)) .contactEmailAddress(solicitorEmail.orElse(null)) .reference(ofNullable(caseData.getSolicitorReferences()) .map(SolicitorReferences::getRespondentSolicitor1Reference) + .map(s -> s.substring(0, Math.min(s.length(), 24))) .orElse(null) ); organisationId .flatMap(organisationService::findOrganisationById) - .ifPresent(buildOrganisation(solicitorBuilder, null)); + .ifPresent(buildOrganisation(solicitorBuilder, + caseData.getSpecRespondentCorrespondenceAddressdetails())); organisationDetails.ifPresent(buildOrganisationDetails(solicitorBuilder)); return solicitorBuilder.build(); } - private Solicitor buildRespondent2Solicitor(CaseData caseData, String id) { - Solicitor.SolicitorBuilder solicitorBuilder = Solicitor.builder(); + private Solicitor buildRespondent2Solicitor(CaseData caseData) { + Solicitor.SolicitorBuilder solicitorBuilder = Solicitor.builder(); Optional organisationId = getOrganisationId(caseData.getRespondent2OrganisationPolicy()); var organisationDetails = ofNullable( @@ -160,14 +162,19 @@ private Solicitor buildRespondent2Solicitor(CaseData caseData, String id) { return null; } solicitorBuilder - .id(id) + .id(RoboticsDataUtil.RESPONDENT2_SOLICITOR_ID) .isPayee(false) .organisationId(organisationId.orElse(null)) - .reference(caseData.getRespondentSolicitor2Reference()); + .reference(ofNullable(caseData.getSolicitorReferences()) + .map(SolicitorReferences::getRespondentSolicitor2Reference) + .map(s -> s.substring(0, Math.min(s.length(), 24))) + .orElse(null) + ); organisationId .flatMap(organisationService::findOrganisationById) - .ifPresent(buildOrganisation(solicitorBuilder, caseData.getRespondentSolicitor2ServiceAddress())); + .ifPresent(buildOrganisation(solicitorBuilder, + caseData.getSpecRespondent2CorrespondenceAddressdetails())); organisationDetails.ifPresent(buildOrganisationDetails(solicitorBuilder)); @@ -175,7 +182,7 @@ private Solicitor buildRespondent2Solicitor(CaseData caseData, String id) { } private Consumer buildOrganisation( - Solicitor.SolicitorBuilder solicitorBuilder, Address providedServiceAddress + Solicitor.SolicitorBuilder solicitorBuilder, Address providedServiceAddress ) { return organisation -> { List contactInformation = organisation.getContactInformation(); @@ -207,7 +214,7 @@ private Optional getOrganisationId(OrganisationPolicy respondent1Organis } private Consumer buildOrganisationDetails( - Solicitor.SolicitorBuilder solicitorBuilder + Solicitor.SolicitorBuilder solicitorBuilder ) { return organisationDetails -> solicitorBuilder @@ -219,22 +226,23 @@ private Consumer buildOrganisationDetails( .addresses(addressMapper.toRoboticsAddresses(organisationDetails.getAddress())); } - private Solicitor buildApplicantSolicitor(CaseData caseData, String id) { + private Solicitor buildApplicantSolicitor(CaseData caseData) { Optional organisationId = getOrganisationId(caseData.getApplicant1OrganisationPolicy()); - var providedServiceAddress = caseData.getApplicantSolicitor1ServiceAddress(); - Solicitor.SolicitorBuilder solicitorBuilder = Solicitor.builder() - .id(id) + var providedServiceAddress = caseData.getSpecApplicantCorrespondenceAddressdetails(); + Solicitor.SolicitorBuilder solicitorBuilder = Solicitor.builder() + .id(RoboticsDataUtil.APPLICANT_SOLICITOR_ID) .isPayee(true) .organisationId(organisationId.orElse(null)) .contactEmailAddress(caseData.getApplicantSolicitor1UserDetails().getEmail()) .reference(ofNullable(caseData.getSolicitorReferences()) .map(SolicitorReferences::getApplicantSolicitor1Reference) + .map(s -> s.substring(0, Math.min(s.length(), 24))) .orElse(null) ); organisationId .flatMap(organisationService::findOrganisationById) - .ifPresent(buildOrganisation(solicitorBuilder, caseData.getApplicantSolicitor1ServiceAddress())); + .ifPresent(buildOrganisation(solicitorBuilder, providedServiceAddress)); return solicitorBuilder.build(); } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/AmendPartyDetailsCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/AmendPartyDetailsCallbackHandlerTest.java index 6c1605e341a..2c2b18343c6 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/AmendPartyDetailsCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/AmendPartyDetailsCallbackHandlerTest.java @@ -179,7 +179,7 @@ void shouldReturnExpectedSubmittedCallbackResponse_whenInvoked() { assertThat(response).usingRecursiveComparison().isEqualTo( SubmittedCallbackResponse.builder() - .confirmationHeader("# You have updated a legal representative's email address") + .confirmationHeader("# You have updated a legal representative's information") .confirmationBody("
") .build()); } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ChangeSolicitorEmailCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ChangeSolicitorEmailCallbackHandlerTest.java index 5378de5bde1..1d7de6775c3 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ChangeSolicitorEmailCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/ChangeSolicitorEmailCallbackHandlerTest.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.reform.civil.handler.callback.user; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -10,12 +11,17 @@ import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.ccd.client.model.SubmittedCallbackResponse; import uk.gov.hmcts.reform.civil.callback.CallbackParams; +import uk.gov.hmcts.reform.civil.enums.CaseCategory; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; +import uk.gov.hmcts.reform.civil.model.Address; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.model.IdamUserDetails; +import uk.gov.hmcts.reform.civil.model.Party; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.service.CoreCaseUserService; import uk.gov.hmcts.reform.civil.service.UserService; +import uk.gov.hmcts.reform.civil.validation.PostcodeValidator; import uk.gov.hmcts.reform.civil.validation.ValidateEmailService; import uk.gov.hmcts.reform.idam.client.models.UserInfo; @@ -24,6 +30,7 @@ import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -52,6 +59,9 @@ class ChangeSolicitorEmailCallbackHandlerTest extends BaseCallbackHandlerTest { @MockBean private CoreCaseUserService coreCaseUserService; + @MockBean + private PostcodeValidator postcodeValidator; + @BeforeEach void setupTest() { when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); @@ -99,6 +109,33 @@ void shouldSetPartyFlags_WhenInvokedByUserWith_Respondent1Roles() { assertEquals("No", response.getData().get("isRespondent2"), "isRespondent2"); } + @Test + void shouldSetServiceAddress_whenSpec() { + CaseData caseData = CaseDataBuilder.builder() + .atStateNotificationAcknowledged() + .caseAccessCategory(CaseCategory.SPEC_CLAIM) + .build().toBuilder() + .specRespondentCorrespondenceAddressRequired(YesOrNo.YES) + .specRespondentCorrespondenceAddressdetails(Address.builder() + .postCode("mail post code") + .addressLine1("mail line 1") + .build()) + .build(); + params = callbackParamsOf(caseData, ABOUT_TO_START); + + AboutToStartOrSubmitCallbackResponse response = + (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + Assertions.assertThat(response.getData().get("respondentSolicitor1ServiceAddressRequired")) + .isEqualTo("Yes"); + Assertions.assertThat(response.getData().get("respondentSolicitor1ServiceAddress")) + .extracting("AddressLine1") + .isEqualTo("mail line 1"); + Assertions.assertThat(response.getData().get("respondentSolicitor1ServiceAddress")) + .extracting("PostCode") + .isEqualTo("mail post code"); + } + @Test void shouldSetPartyFlags_WhenInvokedByUserWith_Respondent2Roles() { List caseRoles = new ArrayList<>(); @@ -167,6 +204,28 @@ void shouldReturnResponse_WithRespondent1SolicitorEmail() { "respondentSolicitor1EmailAddress"); } + @Test + void shouldReturnResponse1and2_when1v2ss() { + CaseData caseData = CaseDataBuilder.builder() + .atStateNotificationAcknowledged() + .respondentSolicitor1EmailAddress("respondent1solicitor@gmail.com") + .build().toBuilder() + .respondent2(Party.builder() + .companyName("c3") + .type(Party.Type.COMPANY) + .build()) + .respondent2SameLegalRepresentative(YesOrNo.YES) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = + (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + assertEquals("respondent1solicitor@gmail.com", + response.getData().get("respondentSolicitor2EmailAddress"), + "respondentSolicitor2EmailAddress"); + } + @Test void shouldReturnResponse_WithRespondent2SolicitorEmail() { CaseData caseData = CaseDataBuilder.builder() @@ -191,9 +250,231 @@ void shouldClearPartyFlags() { AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); - assertEquals(null, response.getData().get("isApplicant1"), "isApplicant1"); - assertEquals(null, response.getData().get("isRespondent1"), "isRespondent1"); - assertEquals(null, response.getData().get("isRespondent2"), "isRespondent2"); + assertNull(response.getData().get("isApplicant1"), "isApplicant1"); + assertNull(response.getData().get("isRespondent1"), "isRespondent1"); + assertNull(response.getData().get("isRespondent2"), "isRespondent2"); + } + + @Test + void shouldCopyBack_whenSpecApp1() { + List caseRoles = new ArrayList<>(); + caseRoles.add("[APPLICANTSOLICITORONE]"); + when(coreCaseUserService.getUserCaseRoles(anyString(), anyString())).thenReturn(caseRoles); + + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build() + .toBuilder() + .caseAccessCategory(CaseCategory.SPEC_CLAIM) + .applicantSolicitor1ServiceAddressRequired(YesOrNo.YES) + .applicantSolicitor1ServiceAddress(Address.builder() + .addressLine1("mail line 1") + .postCode("mail post code") + .build() + ) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = + (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + Assertions.assertThat(response.getData().get("specApplicantCorrespondenceAddressdetails")) + .extracting("AddressLine1") + .isEqualTo("mail line 1"); + Assertions.assertThat(response.getData().get("specApplicantCorrespondenceAddressdetails")) + .extracting("PostCode") + .isEqualTo("mail post code"); + } + + @Test + void shouldCopyBack_whenSpecDef1() { + List caseRoles = new ArrayList<>(); + caseRoles.add("[RESPONDENTSOLICITORONE]"); + when(coreCaseUserService.getUserCaseRoles(anyString(), anyString())).thenReturn(caseRoles); + + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build() + .toBuilder() + .caseAccessCategory(CaseCategory.SPEC_CLAIM) + .respondentSolicitor1ServiceAddressRequired(YesOrNo.YES) + .respondentSolicitor1ServiceAddress(Address.builder() + .addressLine1("mail line 1") + .postCode("mail post code") + .build() + ) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = + (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + Assertions.assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) + .extracting("AddressLine1") + .isEqualTo("mail line 1"); + Assertions.assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) + .extracting("PostCode") + .isEqualTo("mail post code"); + } + + @Test + void shouldCopyBack_whenSpecDef2() { + List caseRoles = new ArrayList<>(); + caseRoles.add("[RESPONDENTSOLICITORTWO]"); + when(coreCaseUserService.getUserCaseRoles(anyString(), anyString())).thenReturn(caseRoles); + + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build() + .toBuilder() + .caseAccessCategory(CaseCategory.SPEC_CLAIM) + .respondentSolicitor2ServiceAddressRequired(YesOrNo.YES) + .respondentSolicitor2ServiceAddress(Address.builder() + .addressLine1("mail line 1") + .postCode("mail post code") + .build() + ) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = + (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + Assertions.assertThat(response.getData().get("specRespondent2CorrespondenceAddressdetails")) + .extracting("AddressLine1") + .isEqualTo("mail line 1"); + Assertions.assertThat(response.getData().get("specRespondent2CorrespondenceAddressdetails")) + .extracting("PostCode") + .isEqualTo("mail post code"); + } + + @Test + void shouldBackUp_whenNewRequiredIsNo() { + List caseRoles = new ArrayList<>(); + caseRoles.add("[RESPONDENTSOLICITORTWO]"); + when(coreCaseUserService.getUserCaseRoles(anyString(), anyString())).thenReturn(caseRoles); + + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build() + .toBuilder() + .caseAccessCategory(CaseCategory.SPEC_CLAIM) + .respondentSolicitor2ServiceAddressRequired(YesOrNo.NO) + .respondentSolicitor2ServiceAddress(null) + .specRespondent2CorrespondenceAddressdetails(Address.builder() + .addressLine1("mail line 1") + .postCode("mail post code") + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = + (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + Assertions.assertThat(response.getData().get("specRespondent2CorrespondenceAddressdetails")) + .extracting("AddressLine1") + .isEqualTo("mail line 1"); + Assertions.assertThat(response.getData().get("specRespondent2CorrespondenceAddressdetails")) + .extracting("PostCode") + .isEqualTo("mail post code"); + } + + @Test + void shouldBackUp_whenNewRequiredIsNo1v2ss() { + List caseRoles = new ArrayList<>(); + caseRoles.add("[RESPONDENTSOLICITORONE]"); + when(coreCaseUserService.getUserCaseRoles(anyString(), anyString())).thenReturn(caseRoles); + + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build() + .toBuilder() + .respondent2(Party.builder() + .type(Party.Type.COMPANY) + .companyName("c3") + .build()) + .respondent2SameLegalRepresentative(YesOrNo.YES) + .caseAccessCategory(CaseCategory.SPEC_CLAIM) + .respondentSolicitor1ServiceAddressRequired(YesOrNo.NO) + .respondentSolicitor1ServiceAddress(null) + .specRespondentCorrespondenceAddressdetails(Address.builder() + .addressLine1("mail line 1") + .postCode("mail post code") + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = + (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + Assertions.assertThat(response.getData().get("specRespondent2CorrespondenceAddressdetails")) + .extracting("AddressLine1") + .isEqualTo("mail line 1"); + Assertions.assertThat(response.getData().get("specRespondent2CorrespondenceAddressdetails")) + .extracting("PostCode") + .isEqualTo("mail post code"); + } + + @Test + void shouldUpdateReferenceApplicant1() { + List caseRoles = new ArrayList<>(); + caseRoles.add("[APPLICANTSOLICITORONE]"); + when(coreCaseUserService.getUserCaseRoles(anyString(), anyString())).thenReturn(caseRoles); + + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build(); + caseData = caseData.toBuilder() + .isApplicant1(YesOrNo.YES) + .applicant1OrganisationPolicy(caseData.getApplicant1OrganisationPolicy().toBuilder() + .orgPolicyReference("new reference") + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = + (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + //noinspection unchecked + Assertions.assertThat(response.getData().get("solicitorReferences")) + .extracting("applicantSolicitor1Reference") + .isEqualTo("new reference"); + } + + @Test + void shouldUpdateReferenceRespondent1() { + List caseRoles = new ArrayList<>(); + caseRoles.add("[RESPONDENTSOLICITORONE]"); + when(coreCaseUserService.getUserCaseRoles(anyString(), anyString())).thenReturn(caseRoles); + + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build(); + caseData = caseData.toBuilder() + .isRespondent1(YesOrNo.YES) + .respondent1OrganisationPolicy(caseData.getRespondent1OrganisationPolicy().toBuilder() + .orgPolicyReference("new reference") + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = + (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + //noinspection unchecked + Assertions.assertThat(response.getData().get("solicitorReferences")) + .extracting("respondentSolicitor1Reference") + .isEqualTo("new reference"); + } + + @Test + void shouldUpdateReferenceRespondent2() { + List caseRoles = new ArrayList<>(); + caseRoles.add("[RESPONDENTSOLICITORTWO]"); + when(coreCaseUserService.getUserCaseRoles(anyString(), anyString())).thenReturn(caseRoles); + + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build(); + caseData = caseData.toBuilder() + .isRespondent2(YesOrNo.YES) + .respondent2OrganisationPolicy(caseData.getRespondent2OrganisationPolicy().toBuilder() + .orgPolicyReference("new reference") + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + AboutToStartOrSubmitCallbackResponse response = + (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + //noinspection unchecked + Assertions.assertThat(response.getData().get("solicitorReferences")) + .extracting("respondentSolicitor2Reference") + .isEqualTo("new reference"); } } @@ -284,7 +565,7 @@ void shouldReturnExpectedSubmittedCallbackResponse_WhenInvokedByUserWith_Applica SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); - assertEquals("# You have updated a claimant's legal representative's email address", + assertEquals("# You have updated a claimant's legal representative's information", response.getConfirmationHeader(), "confirmationHeader"); assertEquals("
", response.getConfirmationBody(), "confirmationBody"); @@ -299,7 +580,7 @@ void shouldReturnExpectedSubmittedCallbackResponse_WhenInvokedByUserWith_Respond SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); - assertEquals("# You have updated a defendant's legal representative's email address", + assertEquals("# You have updated a defendant's legal representative's information", response.getConfirmationHeader(), "confirmationHeader"); assertEquals("
", response.getConfirmationBody(), "confirmationBody"); @@ -314,7 +595,7 @@ void shouldReturnExpectedSubmittedCallbackResponse_WhenInvokedByUserWith_Respond SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); - assertEquals("# You have updated a defendant's legal representative's email address", + assertEquals("# You have updated a defendant's legal representative's information", response.getConfirmationHeader(), "confirmationHeader"); assertEquals("
", response.getConfirmationBody(), "confirmationBody"); @@ -330,7 +611,7 @@ void shouldReturnExpectedSubmittedCallbackResponse_WhenInvokedByUserWith_Respond SubmittedCallbackResponse response = (SubmittedCallbackResponse) handler.handle(params); - assertEquals("# You have updated a defendant's legal representative's email address", + assertEquals("# You have updated a defendant's legal representative's information", response.getConfirmationHeader(), "confirmationHeader"); assertEquals("
", response.getConfirmationBody(), "confirmationBody"); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandlerTest.java index c568964efb3..8c9f03e7dc7 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/CreateClaimSpecCallbackHandlerTest.java @@ -1838,7 +1838,18 @@ void shouldAssignCaseName1v1_whenCaseIs1v1() { @Test void shouldCopyRespondent1OrgPolicyReferenceForSameRegisteredSolicitorScenario_whenInvoked() { - caseData = CaseDataBuilder.builder().atStateClaimIssued1v2AndSameRepresentative().build(); + caseData = CaseDataBuilder.builder().atStateClaimIssued1v2AndSameRepresentative() + .respondent2(Party.builder() + .type(Party.Type.COMPANY) + .companyName("Company 3") + .build()) + .build().toBuilder() + .specRespondentCorrespondenceAddressRequired(YES) + .specRespondentCorrespondenceAddressdetails(Address.builder() + .postCode("Postcode") + .addressLine1("Address") + .build()) + .build(); var response = (AboutToStartOrSubmitCallbackResponse) handler.handle( callbackParamsOf( caseData, @@ -1852,6 +1863,15 @@ void shouldCopyRespondent1OrgPolicyReferenceForSameRegisteredSolicitorScenario_w .extracting("Organisation").extracting("OrganisationID") .isEqualTo("org1"); assertThat(respondentSolicitor2EmailAddress).isEqualTo("respondentsolicitor@example.com"); + + assertEquals( + response.getData().get("specRespondentCorrespondenceAddressRequired"), + response.getData().get("specRespondent2CorrespondenceAddressRequired") + ); + assertEquals( + response.getData().get("specRespondentCorrespondenceAddressdetails"), + response.getData().get("specRespondent2CorrespondenceAddressdetails") + ); } @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 690f6a08ad0..d77d1c28c22 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 @@ -32,6 +32,7 @@ import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; import uk.gov.hmcts.reform.civil.referencedata.model.LocationRefData; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; +import uk.gov.hmcts.reform.civil.sampledata.PartyBuilder; import uk.gov.hmcts.reform.civil.service.docmosis.DocumentGeneratorService; import uk.gov.hmcts.reform.civil.service.docmosis.DocumentHearingLocationHelper; import uk.gov.hmcts.reform.civil.service.docmosis.caseprogression.JudgeFinalOrderGenerator; @@ -55,6 +56,8 @@ import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.JUDGE_FINAL_ORDER; import static uk.gov.hmcts.reform.civil.enums.CaseState.CASE_PROGRESSION; import static uk.gov.hmcts.reform.civil.enums.CaseState.JUDICIAL_REFERRAL; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.NO; +import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES; import static uk.gov.hmcts.reform.civil.handler.callback.user.GenerateDirectionOrderCallbackHandler.BODY_1v1; import static uk.gov.hmcts.reform.civil.handler.callback.user.GenerateDirectionOrderCallbackHandler.BODY_1v2; import static uk.gov.hmcts.reform.civil.handler.callback.user.GenerateDirectionOrderCallbackHandler.BODY_2v1; @@ -158,6 +161,9 @@ void shouldPopulateFreeFormOrderValues_onMidEventCallback() { void shouldPopulateFields_whenIsCalledAfterSdo() { // Given CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .addRespondent2(YES) + .respondent2(PartyBuilder.builder().individual().build()) + .respondent2SameLegalRepresentative(YES) .ccdState(CASE_PROGRESSION) .finalOrderSelection(FinalOrderSelection.ASSISTED_ORDER).build(); List locations = new ArrayList<>(); @@ -172,6 +178,18 @@ void shouldPopulateFields_whenIsCalledAfterSdo() { assertThat(response.getData()).extracting("orderMadeOnDetailsOrderCourt") .extracting("ownInitiativeText") .isEqualTo(ON_INITIATIVE_SELECTION_TEXT); + assertThat(response.getData()).extracting("finalOrderRepresentation") + .extracting("typeRepresentationComplex") + .extracting("typeRepresentationClaimantOneDynamic") + .isEqualTo("Mr. John Rambo"); + assertThat(response.getData()).extracting("finalOrderRepresentation") + .extracting("typeRepresentationComplex") + .extracting("typeRepresentationDefendantOneDynamic") + .isEqualTo("Mr. Sole Trader"); + assertThat(response.getData()).extracting("finalOrderRepresentation") + .extracting("typeRepresentationComplex") + .extracting("typeRepresentationDefendantTwoDynamic") + .isEqualTo("Mr. John Rambo"); assertThat(response.getData()).extracting("orderMadeOnDetailsOrderCourt") .extracting("ownInitiativeDate") .isEqualTo(LocalDate.now().toString()); @@ -206,10 +224,45 @@ void shouldPopulateFields_whenIsCalledAfterSdo() { .extracting("hearingLocationList").asString().contains("SiteName after Sdo"); } + @Test + void shouldPopulateFields_whenIsCalledAfterSdoDiffSol() { + // Given + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .addRespondent2(YES) + .respondent2(PartyBuilder.builder().individual().build()) + .respondent2SameLegalRepresentative(NO) + .ccdState(CASE_PROGRESSION) + .finalOrderSelection(FinalOrderSelection.ASSISTED_ORDER).build(); + List locations = new ArrayList<>(); + locations.add(LocationRefData.builder().courtName("Court Name").region("Region").build()); + when(locationRefDataService.getCourtLocationsForDefaultJudgments(any())).thenReturn(locations); + CallbackParams params = callbackParamsOf(caseData, MID, PAGE_ID); + String advancedDate = LocalDate.now().plusDays(14).toString(); + when(locationHelper.getHearingLocation(any(), any(), any())).thenReturn(locationRefDataAfterSdo); + // When + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + // Then + assertThat(response.getData()).extracting("finalOrderRepresentation") + .extracting("typeRepresentationComplex") + .extracting("typeRepresentationClaimantOneDynamic") + .isEqualTo("Mr. John Rambo"); + assertThat(response.getData()).extracting("finalOrderRepresentation") + .extracting("typeRepresentationComplex") + .extracting("typeRepresentationDefendantOneDynamic") + .isEqualTo("Mr. Sole Trader"); + assertThat(response.getData()).extracting("finalOrderRepresentation") + .extracting("typeRepresentationComplex") + .extracting("typeRepresentationDefendantTwoDynamic") + .isEqualTo("Mr. John Rambo"); + + } + @Test void shouldPopulateFields_whenIsCalledBeforeSdo() { // Given CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .addApplicant2(YES) + .applicant2(PartyBuilder.builder().individual().build()) .ccdState(JUDICIAL_REFERRAL) .finalOrderSelection(FinalOrderSelection.ASSISTED_ORDER).build(); List locations = new ArrayList<>(); @@ -224,6 +277,18 @@ void shouldPopulateFields_whenIsCalledBeforeSdo() { assertThat(response.getData()).extracting("orderMadeOnDetailsOrderCourt") .extracting("ownInitiativeText") .isEqualTo(ON_INITIATIVE_SELECTION_TEXT); + assertThat(response.getData()).extracting("finalOrderRepresentation") + .extracting("typeRepresentationComplex") + .extracting("typeRepresentationClaimantOneDynamic") + .isEqualTo("Mr. John Rambo"); + assertThat(response.getData()).extracting("finalOrderRepresentation") + .extracting("typeRepresentationComplex") + .extracting("typeRepresentationDefendantOneDynamic") + .isEqualTo("Mr. Sole Trader"); + assertThat(response.getData()).extracting("finalOrderRepresentation") + .extracting("typeRepresentationComplex") + .extracting("typeRepresentationClaimantTwoDynamic") + .isEqualTo("Mr. John Rambo"); assertThat(response.getData()).extracting("orderMadeOnDetailsOrderCourt") .extracting("ownInitiativeDate") .isEqualTo(LocalDate.now().toString()); 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 c551dab2f01..d5d15102a07 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 @@ -105,6 +105,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; 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.callback.CallbackType.ABOUT_TO_START; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; @@ -1192,7 +1193,150 @@ void shouldNullDocuments_whenInvokedAndCaseFileEnabled() { // Then assertThat(response.getData().get("respondent1SpecDefenceResponseDocument")).isNull(); assertThat(response.getData().get("respondent2SpecDefenceResponseDocument")).isNull(); + } + + @Test + void shouldUpdateCorrespondence1_whenProvided() { + // Given + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(mockedStateFlow.isFlagSet(any())).thenReturn(true); + when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).thenReturn(true); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(false); + when(toggleService.isCaseFileViewEnabled()).thenReturn(true); + var testDocument = ResponseDocument.builder() + .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); + + CaseData caseData = CaseData.builder() + .respondent1(PartyBuilder.builder().individual().build()) + .respondent1Copy(PartyBuilder.builder().individual().build()) + .respondent1DQ(Respondent1DQ.builder().build()) + .respondent2DQ(Respondent2DQ.builder().build()) + .ccdCaseReference(354L) + .respondent1SpecDefenceResponseDocument(testDocument) + .respondent2SpecDefenceResponseDocument(testDocument) + .isRespondent1(YesOrNo.YES) + .specAoSRespondentCorrespondenceAddressRequired(YesOrNo.NO) + .specAoSRespondentCorrespondenceAddressdetails( + Address.builder() + .postCode("new postcode") + .build() + ) + .build(); + + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + // Then + assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) + .extracting("PostCode") + .isEqualTo("new postcode"); + assertThat(response.getData().get("specAoSRespondentCorrespondenceAddressdetails")) + .extracting("PostCode") + .isNull(); + } + + @Test + void shouldUpdateCorrespondence1_whenProvided1v2ss() { + // Given + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(mockedStateFlow.isFlagSet(any())).thenReturn(true); + when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORONE))).thenReturn(true); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(false); + when(toggleService.isCaseFileViewEnabled()).thenReturn(true); + var testDocument = ResponseDocument.builder() + .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); + + CaseData caseData = CaseData.builder() + .respondent1(PartyBuilder.builder().individual().build()) + .respondent1Copy(PartyBuilder.builder().individual().build()) + .respondent1DQ(Respondent1DQ.builder().build()) + .respondent2DQ(Respondent2DQ.builder().build()) + .ccdCaseReference(354L) + .respondent1SpecDefenceResponseDocument(testDocument) + .respondent2SpecDefenceResponseDocument(testDocument) + .isRespondent1(YesOrNo.YES) + .specAoSRespondentCorrespondenceAddressRequired(YesOrNo.NO) + .specAoSRespondentCorrespondenceAddressdetails( + Address.builder() + .postCode("new postcode") + .build() + ) + .respondent2(Party.builder() + .type(Party.Type.COMPANY) + .companyName("Company 3") + .build()) + .respondent2SameLegalRepresentative(YES) + .build(); + + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + // Then + assertThat(response.getData().get("specRespondentCorrespondenceAddressdetails")) + .extracting("PostCode") + .isEqualTo("new postcode"); + assertThat(response.getData().get("specAoSRespondentCorrespondenceAddressdetails")) + .extracting("PostCode") + .isNull(); + assertEquals( + response.getData().get("specRespondentCorrespondenceAddressdetails"), + response.getData().get("specRespondent2CorrespondenceAddressdetails") + ); + assertEquals( + response.getData().get("specRespondentCorrespondenceAddressRequired"), + response.getData().get("specRespondent2CorrespondenceAddressRequired") + ); + } + + @Test + void shouldUpdateCorrespondence2_whenProvided() { + // Given + when(userService.getUserInfo(anyString())).thenReturn(UserInfo.builder().uid("uid").build()); + when(mockedStateFlow.isFlagSet(any())).thenReturn(true); + when(stateFlowEngine.evaluate(any(CaseData.class))).thenReturn(mockedStateFlow); + when(coreCaseUserService.userHasCaseRole(any(), any(), eq(RESPONDENTSOLICITORTWO))).thenReturn(true); + when(toggleService.isCaseFileViewEnabled()).thenReturn(true); + var testDocument = ResponseDocument.builder() + .file(Document.builder().documentUrl("fake-url").documentFileName("file-name").documentBinaryUrl("binary-url").build()).build(); + + CaseData caseData = CaseData.builder() + .respondent1(PartyBuilder.builder().individual().build()) + .respondent1Copy(PartyBuilder.builder().individual().build()) + .respondent1DQ(Respondent1DQ.builder().build()) + .respondent2DQ(Respondent2DQ.builder().build()) + .ccdCaseReference(354L) + .respondent1SpecDefenceResponseDocument(testDocument) + .respondent2SpecDefenceResponseDocument(testDocument) + .isRespondent2(YesOrNo.YES) + .specAoSRespondent2CorrespondenceAddressRequired(YesOrNo.NO) + .specAoSRespondent2CorrespondenceAddressdetails( + Address.builder() + .postCode("new postcode") + .build() + ) + .build(); + + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + // Then + assertThat(response.getData().get("specRespondent2CorrespondenceAddressdetails")) + .extracting("PostCode") + .isEqualTo("new postcode"); + assertThat(response.getData().get("specAoSRespondent2CorrespondenceAddressdetails")) + .extracting("PostCode") + .isNull(); } @Test @@ -1864,6 +2008,50 @@ void when1v1_thenSameSolSameResponseNull() { assertThat(response.getData()) .doesNotHaveToString("sameSolicitorSameResponse"); } + + @Test + void whenProvided_thenValidateCorrespondence1() { + // Given + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build() + .toBuilder() + .isRespondent1(YES) + .specAoSRespondentCorrespondenceAddressRequired(YesOrNo.NO) + .specAoSRespondentCorrespondenceAddressdetails(Address.builder() + .postCode("postal code") + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, MID, "confirm-details"); + when(postcodeValidator.validate("postal code")).thenReturn(Collections.emptyList()); + + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + // Then + verify(postcodeValidator).validate("postal code"); + } + + @Test + void whenProvided_thenValidateCorrespondence2() { + // Given + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build() + .toBuilder() + .isRespondent2(YES) + .specAoSRespondent2CorrespondenceAddressRequired(YesOrNo.NO) + .specAoSRespondent2CorrespondenceAddressdetails(Address.builder() + .postCode("postal code") + .build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, MID, "confirm-details"); + when(postcodeValidator.validate("postal code")).thenReturn(Collections.emptyList()); + + // When + AboutToStartOrSubmitCallbackResponse response = (AboutToStartOrSubmitCallbackResponse) handler + .handle(params); + + // Then + verify(postcodeValidator).validate("postal code"); + } } @Nested diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/hearing/HearingNoticeHmcGeneratorTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/hearing/HearingNoticeHmcGeneratorTest.java index d2eed71d803..ab14fb470a3 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/hearing/HearingNoticeHmcGeneratorTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/hearing/HearingNoticeHmcGeneratorTest.java @@ -21,6 +21,7 @@ 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.MappableObject; +import uk.gov.hmcts.reform.civil.model.defaultjudgment.CaseLocationCivil; import uk.gov.hmcts.reform.civil.model.docmosis.DocmosisDocument; import uk.gov.hmcts.reform.civil.model.docmosis.hearing.HearingNoticeHmc; import uk.gov.hmcts.reform.civil.referencedata.LocationRefDataService; @@ -135,6 +136,9 @@ void shouldGenerateHearingNoticeHmc_1v1_whenHearingFeeHasBeenPaid() { CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged() .totalClaimAmount(new BigDecimal(2000)) .build().toBuilder() + .caseManagementLocation(CaseLocationCivil.builder() + .baseLocation(EPIMS) + .build()) .hearingLocation(DynamicList.builder().value(DynamicListElement.builder().label("County Court").build()) .build()) .hearingTimeHourMinute("0800") @@ -185,6 +189,9 @@ void shouldGenerateHearingNoticeHmc_1v1_whenHearingFeeHasNotBeenPaid() { CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged() .totalClaimAmount(new BigDecimal(2000)) .build().toBuilder() + .caseManagementLocation(CaseLocationCivil.builder() + .baseLocation(EPIMS) + .build()) .hearingLocation(DynamicList.builder().value(DynamicListElement.builder().label("County Court").build()) .build()) .hearingTimeHourMinute("0800") @@ -235,6 +242,9 @@ void shouldGenerateHearingNoticeHmc_1v2DS_whenHearingFeeHasBeenPaid() { CaseData caseData = CaseDataBuilder.builder().atState1v2DifferentSolicitorClaimDetailsRespondent2NotifiedTimeExtension() .totalClaimAmount(new BigDecimal(2000)) .build().toBuilder() + .caseManagementLocation(CaseLocationCivil.builder() + .baseLocation(EPIMS) + .build()) .hearingLocation(DynamicList.builder().value(DynamicListElement.builder().label("County Court").build()) .build()) .hearingTimeHourMinute("0800") @@ -289,6 +299,9 @@ void shouldGenerateHearingNoticeHmc_2v1_whenHearingFeeHasBeenPaid() { .atStateBothApplicantsRespondToDefenceAndProceed_2v1() .totalClaimAmount(new BigDecimal(2000)) .build().toBuilder() + .caseManagementLocation(CaseLocationCivil.builder() + .baseLocation(EPIMS) + .build()) .hearingLocation(DynamicList.builder().value(DynamicListElement.builder().label("County Court").build()) .build()) .hearingTimeHourMinute("0800") @@ -341,6 +354,9 @@ void shouldReturnListOfExpectedCaseDocuments() { CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged() .totalClaimAmount(new BigDecimal(2000)) .build().toBuilder() + .caseManagementLocation(CaseLocationCivil.builder() + .baseLocation(EPIMS) + .build()) .hearingLocation(DynamicList.builder().value(DynamicListElement.builder().label("County Court").build()) .build()) .hearingTimeHourMinute("0800")