diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01070.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01070.docx index 3e9445b398d..df4bdf5e874 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01070.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01070.docx differ diff --git a/docker/docmosis/templates/CV-UNS-GAP-ENG-01071.docx b/docker/docmosis/templates/CV-UNS-GAP-ENG-01071.docx index 57e6930dbe3..3b9258c333f 100644 Binary files a/docker/docmosis/templates/CV-UNS-GAP-ENG-01071.docx and b/docker/docmosis/templates/CV-UNS-GAP-ENG-01071.docx differ diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationServiceHelper.java b/src/main/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationServiceHelper.java index d6d35fe839d..57bb35d38bd 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationServiceHelper.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/InitiateGeneralApplicationServiceHelper.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; @@ -39,6 +40,7 @@ public class InitiateGeneralApplicationServiceHelper { private final AuthTokenGenerator authTokenGenerator; private final UserService userService; private final CrossAccessUserConfiguration crossAccessUserConfiguration; + public CaseAssignedUserRolesResource userRoles; public boolean isGAApplicantSameAsPCClaimant(CaseData caseData, String organisationIdentifier) { @@ -56,14 +58,12 @@ public GeneralApplication setRespondentDetailsIfPresent(CaseData.CaseDataBuilder || (YES.equals(caseData.getAddRespondent2()) && caseData.getRespondent2OrganisationPolicy() == null)) { throw new IllegalArgumentException("Solicitor Org details are not set correctly."); } - GeneralApplication.GeneralApplicationBuilder applicationBuilder = generalApplication.toBuilder(); String parentCaseId = caseData.getCcdCaseReference().toString(); - String applicant1OrgCaseRole = caseData.getApplicant1OrganisationPolicy().getOrgPolicyCaseAssignedRole(); String respondent1OrgCaseRole = caseData.getRespondent1OrganisationPolicy().getOrgPolicyCaseAssignedRole(); - CaseAssignedUserRolesResource userRoles = getUserRoles(parentCaseId); + userRoles = getUserRoles(parentCaseId); /*Filter the case users to collect solicitors whose ID doesn't match with GA Applicant Solicitor's ID*/ List respondentSolicitors = userRoles.getCaseAssignedUserRoles().stream() @@ -119,7 +119,7 @@ public GeneralApplication setRespondentDetailsIfPresent(CaseData.CaseDataBuilder } } } - + GeneralApplication.GeneralApplicationBuilder applicationBuilder = generalApplication.toBuilder(); applicationBuilder .generalAppApplnSolicitor(applicantBuilder.build()); String applicantPartyName = null; @@ -133,13 +133,13 @@ public GeneralApplication setRespondentDetailsIfPresent(CaseData.CaseDataBuilder GASolicitorDetailsGAspec.GASolicitorDetailsGAspecBuilder specBuilder = GASolicitorDetailsGAspec .builder(); - specBuilder.id(respSol.getUserId()); - if (respSol.getCaseRole() != null) { + log.info(respSol.getCaseRole(), "**", respSol.getUserId()); /*Populate the GA respondent solicitor details in accordance with civil case Applicant Solicitor 1 details if case role of collected user matches with case role of Applicant 1*/ if (respSol.getCaseRole().equals(applicant1OrgCaseRole)) { if (caseData.getApplicantSolicitor1UserDetails() != null) { + specBuilder.id(respSol.getUserId()); specBuilder.email(caseData.getApplicantSolicitor1UserDetails().getEmail()); specBuilder.organisationIdentifier(caseData.getApplicant1OrganisationPolicy() .getOrganisation().getOrganisationID()); @@ -147,14 +147,19 @@ public GeneralApplication setRespondentDetailsIfPresent(CaseData.CaseDataBuilder /*Populate the GA respondent solicitor details in accordance with civil case Respondent Solicitor 1 details if caserole of collected user matches with caserole Respondent Solicitor 1*/ } else if (respSol.getCaseRole().equals(respondent1OrgCaseRole)) { + specBuilder.id(respSol.getUserId()); specBuilder.email(caseData.getRespondentSolicitor1EmailAddress()); specBuilder.organisationIdentifier(getRespondent1SolicitorOrgId(caseData)); /*Populate the GA respondent solicitor details in accordance with civil case Respondent Solicitor 2 details if it's 1 V 2 Different Solicitor scenario*/ } else { - specBuilder.email(caseData.getRespondentSolicitor2EmailAddress()); - specBuilder.organisationIdentifier(getRespondent2SolicitorOrgId(caseData)); + if (Objects.nonNull(caseData.getAddRespondent2()) + && caseData.getAddRespondent2().equals(YES)) { + specBuilder.id(respSol.getUserId()); + specBuilder.email(caseData.getRespondentSolicitor2EmailAddress()); + specBuilder.organisationIdentifier(getRespondent2SolicitorOrgId(caseData)); + } } /*Set the GA Respondent solicitor details to Empty if above checks are failed*/ } else { @@ -167,7 +172,10 @@ public GeneralApplication setRespondentDetailsIfPresent(CaseData.CaseDataBuilder } GASolicitorDetailsGAspec gaSolicitorDetailsGAspec = specBuilder.build(); - respondentSols.add(element(gaSolicitorDetailsGAspec)); + if (Objects.nonNull(gaSolicitorDetailsGAspec.getId())) { + respondentSols.add(element(gaSolicitorDetailsGAspec)); + } + }); applicantPartyName = getApplicantPartyName(userRoles, userDetails, caseData); applicationBuilder.applicantPartyName(applicantPartyName); @@ -252,8 +260,12 @@ public boolean isGAApplicantSameAsParentCaseClaimant(CaseData caseData, String a } public CaseAssignedUserRolesResource getUserRoles(String parentCaseId) { - return caseAccessDataStoreApi.getUserRoles( - getCaaAccessToken(), authTokenGenerator.generate(), List.of(parentCaseId)); + if (Objects.isNull(userRoles)) { + userRoles = caseAccessDataStoreApi.getUserRoles( + getCaaAccessToken(), authTokenGenerator.generate(), List.of(parentCaseId)); + } + log.info("UserRoles from API :" + userRoles); + return userRoles; } public String getCaaAccessToken() { diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/InitiateGeneralApplicationServiceHelperTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/InitiateGeneralApplicationServiceHelperTest.java index 9f2c10dcfc0..a7d8476c88f 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/InitiateGeneralApplicationServiceHelperTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/user/InitiateGeneralApplicationServiceHelperTest.java @@ -1,5 +1,6 @@ package uk.gov.hmcts.reform.civil.handler.callback.user; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -95,6 +96,11 @@ void setup() { .caseAssignedUserRoles(getCaseAssignedApplicantUserRoles()).build()); } + @AfterEach + void setUserRolesAsNull() { + helper.userRoles = null; + } + public List getCaseAssignedApplicantUserRoles() { return List.of( CaseAssignedUserRole.builder().caseDataId("1").userId(STRING_NUM_CONSTANT) @@ -268,6 +274,7 @@ void shouldSetApplicantSolicitorOrgIDTo200() { .respondentSolicitor1EmailAddress(RESPONDENT_EMAIL_ID_CONSTANT) .applicant1(Party.builder().type(COMPANY).companyName("Applicant1").build()) .respondent2(Party.builder().type(COMPANY).companyName("Respondent1").build()) + .addRespondent2(YesOrNo.YES) .applicant1OrganisationPolicy(OrganisationPolicy.builder() .organisation(Organisation.builder().organisationID("200").build()) .orgPolicyCaseAssignedRole(APPLICANTSOLICITORONE.getFormattedName()) @@ -309,6 +316,7 @@ void shouldSetApplicantSolicitorOrgIDTo100() { .applicant2(Party.builder().type(COMPANY).companyName("Applicant2").build()) .respondent1(Party.builder().type(COMPANY).companyName("Respondent1").build()) .respondent2(Party.builder().type(COMPANY).companyName("Respondent2").build()) + .addRespondent2(YesOrNo.YES) .applicant1OrganisationPolicy(OrganisationPolicy.builder() .organisation(Organisation.builder().organisationID("200").build()) .orgPolicyCaseAssignedRole(APPLICANTSOLICITORONE.getFormattedName()) diff --git a/src/test/java/uk/gov/hmcts/reform/civil/sampledata/GeneralApplicationDetailsBuilder.java b/src/test/java/uk/gov/hmcts/reform/civil/sampledata/GeneralApplicationDetailsBuilder.java index cdd3e35fc73..0caef94ebf2 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/sampledata/GeneralApplicationDetailsBuilder.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/sampledata/GeneralApplicationDetailsBuilder.java @@ -1588,6 +1588,7 @@ public CaseData getVaryJudgmentWithN245TestData() { .ccdCaseReference(1L) .applicant1(Party.builder().type(Party.Type.COMPANY).companyName("Applicant1").build()) .respondent1(Party.builder().type(Party.Type.COMPANY).companyName("Respondent1").build()) + .addRespondent2(NO) .courtLocation(CourtLocation.builder() .caseLocation(CaseLocationCivil.builder() .region("2")