Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIV-10754 Refactored Initiate General Application helper class #3525

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {

Expand All @@ -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<CaseAssignedUserRole> respondentSolicitors = userRoles.getCaseAssignedUserRoles().stream()
Expand All @@ -75,7 +75,7 @@ public GeneralApplication setRespondentDetailsIfPresent(CaseData.CaseDataBuilder
* */
GASolicitorDetailsGAspec.GASolicitorDetailsGAspecBuilder applicantBuilder = GASolicitorDetailsGAspec
.builder();

GeneralApplication.GeneralApplicationBuilder applicationBuilder = generalApplication.toBuilder();
applicantBuilder
.id(userDetails.getId())
.email(userDetails.getEmail())
Expand Down Expand Up @@ -234,15 +234,10 @@ public String getApplicantPartyName(CaseAssignedUserRolesResource userRoles, Use
public boolean isGAApplicantSameAsParentCaseClaimant(CaseData caseData, String authToken) {
String parentCaseId = caseData.getCcdCaseReference().toString();
List<String> userRolesCaching = userRoleCaching.getUserRoles(authToken, parentCaseId);

boolean isApplicantSolicitor = UserRoleUtils.isApplicantSolicitor(userRolesCaching);

String applicant1OrgCaseRole = caseData.getApplicant1OrganisationPolicy().getOrgPolicyCaseAssignedRole();

if (!CollectionUtils.isEmpty(userRolesCaching) && userRolesCaching.size() == 1 && isApplicantSolicitor) {

String applnSol = userRolesCaching.get(0);

if (applnSol != null && applnSol.equals(applicant1OrgCaseRole)) {
return true;
}
Expand All @@ -252,8 +247,11 @@ 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));
}
return userRoles;
}

public String getCaaAccessToken() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -95,6 +96,11 @@ void setup() {
.caseAssignedUserRoles(getCaseAssignedApplicantUserRoles()).build());
}

@AfterEach
void setUserRolesAsNull() {
helper.userRoles = null;
}

public List<CaseAssignedUserRole> getCaseAssignedApplicantUserRoles() {
return List.of(
CaseAssignedUserRole.builder().caseDataId("1").userId(STRING_NUM_CONSTANT)
Expand Down
Loading