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

DFR-2903 Change organisation request exception in NOC code #1781

Merged
merged 26 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4941131
DFR-2903 Change organisation request exception in NOC code
Jul 15, 2024
7b976fb
Merge branch 'master' into DFR-2903_Change_organisation_request_excep…
so99y Jul 15, 2024
df71b9b
Merge branch 'master' into DFR-2903_Change_organisation_request_excep…
so99y Jul 15, 2024
b58da56
Merge branch 'master' into DFR-2903_Change_organisation_request_excep…
so99y Jul 16, 2024
1dea94d
WIP
Jul 17, 2024
bdff3d4
Merge branch 'master' into DFR-2903_Change_organisation_request_excep…
so99y Jul 17, 2024
a583f4e
Merge branch 'DFR-2903_Change_organisation_request_exception_in_noc' …
Jul 17, 2024
d6a9d62
Add test case for the changes.
Jul 17, 2024
a4028c4
Merge branch 'master' into DFR-2903_Change_organisation_request_excep…
so99y Jul 17, 2024
11bd32b
checkstyle
Jul 17, 2024
80faf8b
remove unnecessary file
Jul 17, 2024
2512cfc
Fix test case
Jul 17, 2024
33d9d08
Merge branch 'master' into DFR-2903_Change_organisation_request_excep…
so99y Jul 18, 2024
9018d01
Merge branch 'master' into DFR-2903_Change_organisation_request_excep…
so99y Jul 19, 2024
f726c09
add case id to error message.
Jul 19, 2024
7f84a7c
Merge branch 'master' into DFR-2903_Change_organisation_request_excep…
so99y Jul 22, 2024
7a53754
try to make 400 bad request
Jul 22, 2024
c5a6fea
Fix unit test
Jul 22, 2024
7633619
Fix unit tests
Jul 22, 2024
e24383f
Fix unit test again
Jul 22, 2024
7178307
Merge branch 'master' into DFR-2903_Change_organisation_request_excep…
so99y Jul 23, 2024
3279fb8
Revert "try to make 400 bad request"
Jul 24, 2024
7b4a341
Merge branch 'master' into DFR-2903_Change_organisation_request_excep…
so99y Jul 24, 2024
5b5130b
Merge branch 'master' into DFR-2903_Change_organisation_request_excep…
so99y Jul 25, 2024
9ffe766
Merge branch 'master' into DFR-2903_Change_organisation_request_excep…
so99y Jul 30, 2024
ac45ff8
Merge branch 'master' into DFR-2903_Change_organisation_request_excep…
so99y Jul 31, 2024
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 @@ -42,4 +42,12 @@ public class ChangeOrganisationRequest {
@JsonProperty("ApprovalStatus")
private ChangeOrganisationApprovalStatus approvalStatus;

public DynamicList getCaseRoleId() {
if (caseRoleId == null) {
return DynamicList.builder().build();
} else {
return caseRoleId;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.tika.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails;
Expand All @@ -27,6 +28,7 @@

import java.util.Map;

import static java.lang.String.format;
import static uk.gov.hmcts.reform.finrem.caseorchestration.OrchestrationConstants.YES_VALUE;
import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CCDConfigConstant.APPLICANT;
import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CCDConfigConstant.APPLICANT_REPRESENTED;
Expand All @@ -40,6 +42,7 @@
import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CCDConfigConstant.INTVR_SOLICITOR_1_POLICY;
import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CCDConfigConstant.INTVR_SOLICITOR_2_POLICY;
import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CCDConfigConstant.INTVR_SOLICITOR_3_POLICY;
import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CCDConfigConstant.INTVR_SOLICITOR_4_POLICY;
import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CCDConfigConstant.IS_NOC_REJECTED;
import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CCDConfigConstant.RESPONDENT;
import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CCDConfigConstant.RESP_SOLICITOR_ADDRESS;
Expand Down Expand Up @@ -98,7 +101,7 @@ public Map<String, Object> updateRepresentationAsSolicitor(CaseDetails caseDetai

private UserDetails getInvokerDetails(String authToken, CaseDetails caseDetails) {
AuditEvent auditEvent = auditEventService.getLatestAuditEventByName(caseDetails.getId().toString(), NOC_EVENT)
.orElseThrow(() -> new IllegalStateException(String.format("Could not find %s event in audit", NOC_EVENT)));
.orElseThrow(() -> new IllegalStateException(format("Could not find %s event in audit", NOC_EVENT)));
so99y marked this conversation as resolved.
Show resolved Hide resolved

return idamClient.getUserByUserId(authToken, auditEvent.getUserId());
}
Expand All @@ -123,17 +126,23 @@ private Map<String, Object> updateRepresentationUpdateHistory(CaseDetails caseDe
return caseData;
}

private boolean isApplicant(CaseDetails caseDetails, ChangeOrganisationRequest changeRequest) {
if (StringUtils.isEmpty(changeRequest.getCaseRoleId().getValueCode())) {
throw new UnsupportedOperationException(format("%s - unexpected empty caseRoleId", caseDetails.getId()));
}
return APP_SOLICITOR_POLICY.equals(changeRequest.getCaseRoleId().getValueCode());
}

private Map<String, Object> updateCaseDataWithNewSolDetails(CaseDetails caseDetails,
ChangedRepresentative addedSolicitor,
ChangeOrganisationRequest changeRequest) {

Map<String, Object> caseData = caseDetails.getData();
boolean isApplicant = changeRequest.getCaseRoleId().getValueCode().equals(APP_SOLICITOR_POLICY);
boolean isApplicant = isApplicant(caseDetails, changeRequest);
boolean isConsented = caseDataService.isConsentedApplication(caseDetails);
addSolicitorAddressToCaseData(addedSolicitor, caseDetails, changeRequest, isConsented);

caseData.put(changeRequest.getCaseRoleId().getValueCode().equals(APP_SOLICITOR_POLICY)
? APPLICANT_REPRESENTED : getRespondentRepresentedKey(caseDetails), YES_VALUE);
caseData.put(isApplicant ? APPLICANT_REPRESENTED : getRespondentRepresentedKey(caseDetails), YES_VALUE);

Map<String, Object> updatedCaseData = updateSolicitorDetailsService.updateSolicitorContactDetails(
addedSolicitor, caseData, isConsented, isApplicant);
Expand Down Expand Up @@ -163,7 +172,7 @@ private void addSolicitorAddressToCaseData(ChangedRepresentative addedSolicitor,
CaseDetails caseDetails,
ChangeOrganisationRequest changeRequest,
boolean isConsented) {
final boolean isApplicant = changeRequest.getCaseRoleId().getValueCode().equals(APP_SOLICITOR_POLICY);
final boolean isApplicant = isApplicant(caseDetails, changeRequest);
String appSolicitorAddressField = isConsented ? CONSENTED_SOLICITOR_ADDRESS : CONTESTED_SOLICITOR_ADDRESS;
String solicitorAddressField = isApplicant ? appSolicitorAddressField : RESP_SOLICITOR_ADDRESS;

Expand Down Expand Up @@ -207,7 +216,7 @@ private ChangeOfRepresentationRequest buildChangeOfRepresentationRequest(CaseDet
ChangeOrganisationRequest changeRequest) {
return ChangeOfRepresentationRequest.builder()
.by(addedSolicitor.getName())
.party(changeRequest.getCaseRoleId().getValueCode().equals(APP_SOLICITOR_POLICY) ? APPLICANT : RESPONDENT)
.party(isApplicant(caseDetails, changeRequest) ? APPLICANT : RESPONDENT)
.clientName(buildFullName(changeRequest, caseDetails))
.current(current)
.addedRepresentative(addedSolicitor)
Expand All @@ -216,17 +225,21 @@ private ChangeOfRepresentationRequest buildChangeOfRepresentationRequest(CaseDet
}

private String buildFullName(ChangeOrganisationRequest changeRequest, CaseDetails caseDetails) {
if (changeRequest.getCaseRoleId().getValueCode().equals(APP_SOLICITOR_POLICY)) {
if (isApplicant(caseDetails, changeRequest)) {
return caseDataService.buildFullApplicantName(caseDetails);
} else if (changeRequest.getCaseRoleId().getValueCode().equals(RESP_SOLICITOR_POLICY)) {
} else if (RESP_SOLICITOR_POLICY.equals(changeRequest.getCaseRoleId().getValueCode())) {
return caseDataService.buildFullRespondentName(caseDetails);
} else if (changeRequest.getCaseRoleId().getValueCode().equals(INTVR_SOLICITOR_1_POLICY)) {
} else if (INTVR_SOLICITOR_1_POLICY.equals(changeRequest.getCaseRoleId().getValueCode())) {
return caseDataService.buildFullIntervener1Name(caseDetails);
} else if (changeRequest.getCaseRoleId().getValueCode().equals(INTVR_SOLICITOR_2_POLICY)) {
} else if (INTVR_SOLICITOR_2_POLICY.equals(changeRequest.getCaseRoleId().getValueCode())) {
return caseDataService.buildFullIntervener2Name(caseDetails);
} else if (changeRequest.getCaseRoleId().getValueCode().equals(INTVR_SOLICITOR_3_POLICY)) {
} else if (INTVR_SOLICITOR_3_POLICY.equals(changeRequest.getCaseRoleId().getValueCode())) {
return caseDataService.buildFullIntervener3Name(caseDetails);
} else if (INTVR_SOLICITOR_4_POLICY.equals(changeRequest.getCaseRoleId().getValueCode())) {
return caseDataService.buildFullIntervener4Name(caseDetails);
} else {
throw new UnsupportedOperationException(format("%s - Unrecognised caseRoleId: %s",
caseDetails.getId(), changeRequest.getCaseRoleId().getValueCode()));
}
return caseDataService.buildFullIntervener4Name(caseDetails);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public RemovedSolicitorService(CaseDataService caseDataService,
public ChangedRepresentative getRemovedSolicitorAsSolicitor(CaseDetails caseDetails,
ChangeOrganisationRequest changeRequest) {
log.info("Remove solicitor for Case ID: {}", caseDetails.getId());
final boolean isApplicant = changeRequest.getCaseRoleId() != null
&& changeRequest.getCaseRoleId().getValueCode().equals(APP_SOLICITOR_POLICY);
final boolean isApplicant = APP_SOLICITOR_POLICY.equals(changeRequest.getCaseRoleId().getValueCode());

if (!caseDataService.isLitigantRepresented(caseDetails, isApplicant)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -116,10 +117,6 @@ public class UpdateRepresentationServiceTest extends BaseServiceTest {

private UserDetails testAppSolicitor;
private UserDetails testRespSolicitor;
private UserDetails testIntvr1Solicitor;
private UserDetails testIntvr2Solicitor;
private UserDetails testIntvr3Solicitor;
private UserDetails testIntvr4Solicitor;

private Organisation applicantOrg;
private Organisation respondentOrg;
Expand Down Expand Up @@ -156,30 +153,6 @@ public void setUp() {
.email("[email protected]")
.build();

testIntvr1Solicitor = UserDetails.builder()
.forename("Henry")
.surname("Solicitor")
.email("[email protected]")
.build();

testIntvr2Solicitor = UserDetails.builder()
.forename("Paul")
.surname("Solicitor")
.email("[email protected]")
.build();

testIntvr3Solicitor = UserDetails.builder()
.forename("Ashwin")
.surname("Solicitor")
.email("[email protected]")
.build();

testIntvr4Solicitor = UserDetails.builder()
.forename("Maria")
.surname("Solicitor")
.email("[email protected]")
.build();

applicantOrg = Organisation.builder()
.organisationName("FRApplicantSolicitorFirm")
.organisationID("A31PTVA")
Expand Down Expand Up @@ -361,6 +334,70 @@ public void givenConsentedCaseAndEmptyChangeOfReps_WhenUpdateRepresentation_then
assertEquals(POSTCODE, solicitorAddress.getPostCode());
}

@Test
public void givenConsentedCaseAndEmptyChangeOfReps_WhenChangeOfRequestCaseRoleIdIsNull_thenThrowUnsupportedOperationException() throws Exception {
String fixture = "consentedAppSolicitorAdding";
setUpMockContext(testAppSolicitor, orgResponse, this::getChangeOfRepsAppContested, fixture, true);
when(addedSolicitorService.getAddedSolicitorAsSolicitor(any(), any())).thenReturn(
ChangedRepresentative.builder()
.name(testAppSolicitor.getFullName())
.email(testAppSolicitor.getEmail())
.organisation(Organisation.builder()
.organisationID("A31PTVA")
.organisationName("FRApplicantSolicitorFirm")
.build())
.build()
);
setUpCaseDetails("consentedAppSolicitorAdding/after-update-details.json");
try (InputStream resourceAsStream = getClass()
.getResourceAsStream(PATH + "consentedAppSolicitorAdding/change-of-representatives-before.json")) {
initialDetails = mapper.readValue(resourceAsStream, CallbackRequest.class)
.getCaseDetails();
Map<String, Object> changeOrganisationRequestField = (Map<String, Object>) initialDetails.getData().get("changeOrganisationRequestField");
changeOrganisationRequestField.put("CaseRoleId", null);
}

UnsupportedOperationException ex = assertThrows(UnsupportedOperationException.class, () -> updateRepresentationService
.updateRepresentationAsSolicitor(initialDetails, "bebe"));

String expectedMessage = "12345678 - unexpected empty caseRoleId";
String actualMessage = ex.getMessage();
assertEquals(expectedMessage, actualMessage);
}

@Test
public void givenConsentedCaseAndEmptyChangeOfReps_WhenChangeOfRequestCaseRoleIdIsUnrecognised_thenThrowUnsupportedOperationException()
throws Exception {
String fixture = "consentedAppSolicitorAdding";
setUpMockContext(testAppSolicitor, orgResponse, this::getChangeOfRepsAppContested, fixture, true);
when(addedSolicitorService.getAddedSolicitorAsSolicitor(any(), any())).thenReturn(
ChangedRepresentative.builder()
.name(testAppSolicitor.getFullName())
.email(testAppSolicitor.getEmail())
.organisation(Organisation.builder()
.organisationID("A31PTVA")
.organisationName("FRApplicantSolicitorFirm")
.build())
.build()
);
setUpCaseDetails("consentedAppSolicitorAdding/after-update-details.json");
try (InputStream resourceAsStream = getClass()
.getResourceAsStream(PATH + "consentedAppSolicitorAdding/change-of-representatives-before.json")) {
initialDetails = mapper.readValue(resourceAsStream, CallbackRequest.class)
.getCaseDetails();
Map<String, Object> changeOrganisationRequestField = (Map<String, Object>) initialDetails.getData().get("changeOrganisationRequestField");
Map<String, Object> caseRoleId = (Map<String, Object>) changeOrganisationRequestField.get("CaseRoleId");
caseRoleId.put("value", Map.of("code", "[INTVRSOLICITOR5]", "label", "[INTVRSOLICITOR5]"));
}

UnsupportedOperationException ex = assertThrows(UnsupportedOperationException.class, () -> updateRepresentationService
.updateRepresentationAsSolicitor(initialDetails, "bebe"));

String expectedMessage = "12345678 - Unrecognised caseRoleId: [INTVRSOLICITOR5]";
String actualMessage = ex.getMessage();
assertEquals(expectedMessage, actualMessage);
}

@Test
public void givenEmptyChangeOfRepsAndRespSolicitor_WhenUpdateRepresentation_thenReturnCorrectCaseData() throws Exception {
String fixture = "RespSolicitorAdding";
Expand Down