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

DTSCCI-313 check defendant is linked for civil claims #5098

Merged
merged 36 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4343472
check if civil claim is linked.
velimd Jul 11, 2024
a37dacc
clean up functionality to use 1 endpoint for both ocmc and civil cases.
velimd Jul 16, 2024
8672ef6
Merge branch 'master' into DTSCCI-313
velimd Jul 16, 2024
fbb9b86
Merge branch 'master' into DTSCCI-313
velimd Jul 16, 2024
345de90
Merge branch 'master' into DTSCCI-313
velimd Jul 17, 2024
67e1f09
remove unnecessary try catch
velimd Jul 17, 2024
267b64b
fix build
velimd Jul 17, 2024
7cc23a7
add test for sonar
velimd Jul 17, 2024
3aac625
add test for sonar (2)
velimd Jul 17, 2024
33da464
clean + test
velimd Jul 18, 2024
0702954
Merge branch 'master' into DTSCCI-313
velimd Jul 18, 2024
a158490
improve test
velimd Jul 18, 2024
b0e7f7e
Merge remote-tracking branch 'origin/DTSCCI-313' into DTSCCI-313
velimd Jul 18, 2024
cfa605a
Merge branch 'master' into DTSCCI-313
nigeldunne Jul 19, 2024
3025051
Merge branch 'master' into DTSCCI-313
mfallonhmcts Jul 24, 2024
8c909dd
Merge branch 'master' into DTSCCI-313
mfallonhmcts Jul 25, 2024
8e523fb
Merge branch 'master' into DTSCCI-313
mfallonhmcts Jul 25, 2024
020300b
Merge branch 'master' into DTSCCI-313
mfallonhmcts Jul 26, 2024
fa8028d
Merge branch 'master' into DTSCCI-313
mfallonhmcts Jul 29, 2024
d3e832c
Merge branch 'master' into DTSCCI-313
mfallonhmcts Jul 29, 2024
b621e76
Merge branch 'master' into DTSCCI-313
mfallonhmcts Jul 30, 2024
4947df2
Merge branch 'master' into DTSCCI-313
mfallonhmcts Jul 30, 2024
c65989e
Merge branch 'master' into DTSCCI-313
mfallonhmcts Jul 31, 2024
9cf461a
Merge branch 'master' into DTSCCI-313
mfallonhmcts Jul 31, 2024
d15aba0
Merge branch 'master' into DTSCCI-313
mfallonhmcts Aug 1, 2024
c3e5c1b
Merge branch 'master' into DTSCCI-313
mfallonhmcts Aug 8, 2024
6011ada
Merge branch 'master' into DTSCCI-313
mfallonhmcts Aug 8, 2024
0e682c4
Merge branch 'master' into DTSCCI-313
mfallonhmcts Aug 8, 2024
6bca9f0
Merge branch 'master' into DTSCCI-313
mfallonhmcts Aug 9, 2024
6954530
Merge branch 'master' into DTSCCI-313
mfallonhmcts Aug 9, 2024
63b01c7
Merge branch 'master' into DTSCCI-313
mfallonhmcts Aug 9, 2024
7751945
Merge branch 'master' into DTSCCI-313
mfallonhmcts Aug 9, 2024
efe1a72
Merge branch 'master' into DTSCCI-313
mfallonhmcts Aug 12, 2024
a80fc02
Merge branch 'master' into DTSCCI-313
mfallonhmcts Aug 12, 2024
0ce0b20
Merge branch 'master' into DTSCCI-313
mfallonhmcts Aug 12, 2024
682d219
Merge branch 'master' into DTSCCI-313
mfallonhmcts Aug 15, 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 @@ -4,7 +4,9 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails;
import uk.gov.hmcts.reform.civil.CaseDefinitionConstants;
import uk.gov.hmcts.reform.civil.controllers.BaseIntegrationTest;
import uk.gov.hmcts.reform.civil.model.DefendantLinkStatus;
import uk.gov.hmcts.reform.civil.service.AssignCaseService;
import uk.gov.hmcts.reform.civil.service.CoreCaseDataService;
import uk.gov.hmcts.reform.civil.service.citizen.defendant.LipDefendantCaseAssignmentService;
Expand All @@ -27,7 +29,7 @@ public class CaseAssignmentControllerTest extends BaseIntegrationTest {
private static final String VALIDATE_OCMC_PIN_URL = CASES_URL + "/reference/{caseReference}/ocmc";
private static final String ASSIGN_CASE = CASES_URL + "/case/{caseId}/{caseRole}";

private static final String DEFENDENT_LINK_CHECK_URL = CASES_URL + "/reference/{caseReference}/ocmc";
private static final String DEFENDENT_LINK_CHECK_URL = CASES_URL + "/reference/{caseReference}/defendant-link-status";

@MockBean
private CaseLegacyReferenceSearchService caseByLegacyReferenceSearchService;
Expand Down Expand Up @@ -101,20 +103,56 @@ void givenCorrectParams_whenAssignClaim_forDefendant_shouldReturnStatusOk() {
doPost("authorization", "12345", ASSIGN_CASE, "123", "DEFENDANT")
.andExpect(status().isOk());
}

@Test
@SneakyThrows
void givenCorrectClaim_whenDefendantLinkedStatusFalse_shouldReturnStatusOk() {
void givenCorrectOcmcClaim_whenDefendantLinkedStatusFalse_shouldReturnStatusOk() {
CaseDetails caseDetails = givenCaseIsFound();
caseDetails.setCaseTypeId(CaseDefinitionConstants.CMC_CASE_TYPE);
when(defendantPinToPostLRspecService.isOcmcDefendantLinked(anyString())).thenReturn(false);
DefendantLinkStatus defendantLinkStatus = new DefendantLinkStatus(true, false);

doGet("", DEFENDENT_LINK_CHECK_URL, "620MC123")
.andExpect(content().json(toJson(defendantLinkStatus)))
.andExpect(status().isOk());
}

@Test
@SneakyThrows
void givenCorrectClaim_whenDefendantLinkedStatusTrue_shouldReturnStatusOk() {
void givenCorrectOcmcClaim_whenDefendantLinkedStatusTrue_shouldReturnStatusOk() {
CaseDetails caseDetails = givenCaseIsFound();
caseDetails.setCaseTypeId(CaseDefinitionConstants.CMC_CASE_TYPE);
when(defendantPinToPostLRspecService.isOcmcDefendantLinked(anyString())).thenReturn(true);
DefendantLinkStatus defendantLinkStatus = new DefendantLinkStatus(true, true);

doGet("", DEFENDENT_LINK_CHECK_URL, "620MC123")
.andExpect(content().json(toJson(defendantLinkStatus)))
.andExpect(status().isOk());
}

@Test
@SneakyThrows
void givenCorrectClaim_whenDefendantLinkedStatusFalse_shouldReturnStatusOk() {
CaseDetails caseDetails = givenCaseIsFound();
caseDetails.setCaseTypeId(CaseDefinitionConstants.CASE_TYPE);
when(defendantPinToPostLRspecService.isDefendantLinked(any())).thenReturn(false);
DefendantLinkStatus defendantLinkStatus = new DefendantLinkStatus(false, false);

doGet("", DEFENDENT_LINK_CHECK_URL, "620MC123")
.andExpect(content().json(toJson(defendantLinkStatus)))
.andExpect(status().isOk());
}

@Test
@SneakyThrows
void givenCorrectClaim_whenDefendantLinkedStatusTrue_shouldReturnStatusOk() {
CaseDetails caseDetails = givenCaseIsFound();
caseDetails.setCaseTypeId(CaseDefinitionConstants.CASE_TYPE);
when(defendantPinToPostLRspecService.isDefendantLinked(any())).thenReturn(true);
DefendantLinkStatus defendantLinkStatus = new DefendantLinkStatus(false, true);

doGet("", DEFENDENT_LINK_CHECK_URL, "620MC123")
.andExpect(content().json(toJson(defendantLinkStatus)))
.andExpect(status().isOk());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails;
import uk.gov.hmcts.reform.civil.CaseDefinitionConstants;
import uk.gov.hmcts.reform.civil.enums.CaseRole;
import uk.gov.hmcts.reform.civil.model.DefendantLinkStatus;
import uk.gov.hmcts.reform.civil.model.citizenui.dto.PinDto;
import uk.gov.hmcts.reform.civil.service.AssignCaseService;
import uk.gov.hmcts.reform.civil.service.CoreCaseDataService;
Expand Down Expand Up @@ -77,18 +79,26 @@ public ResponseEntity<String> validateOcmcPin(
}

@GetMapping(path = {
"/reference/{caseReference}/ocmc"
"/reference/{caseReference}/defendant-link-status"
})
@Operation(summary = "Check whether a claim is linked to a defendant")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "401", description = "Not Authorized"),
@ApiResponse(responseCode = "400", description = "Bad Request")})
public ResponseEntity<Boolean> isOcmcDefendantLinked(
public ResponseEntity<DefendantLinkStatus> isDefendantLinked(
@PathVariable("caseReference") String caseReference) {
log.info("Check claim reference {} is linked to defendant", caseReference);
boolean status = defendantPinToPostLRspecService.isOcmcDefendantLinked(caseReference);
return new ResponseEntity<>(status, HttpStatus.OK);
CaseDetails caseDetails = caseByLegacyReferenceSearchService.getCaseDataByLegacyReference(caseReference);
boolean isOcmcCase = caseDetails.getCaseTypeId().equals(CaseDefinitionConstants.CMC_CASE_TYPE);
boolean status;
if (isOcmcCase) {
status = defendantPinToPostLRspecService.isOcmcDefendantLinked(caseReference);
} else {
status = defendantPinToPostLRspecService.isDefendantLinked(caseDetails);
}
DefendantLinkStatus defendantLinkStatus = new DefendantLinkStatus(isOcmcCase, status);
return new ResponseEntity<>(defendantLinkStatus, HttpStatus.OK);
}

@PostMapping(path = "/case/{caseId}/{caseRole}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package uk.gov.hmcts.reform.civil.model;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class DefendantLinkStatus {

private boolean isOcmcCase;
private boolean linked;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uk.gov.hmcts.reform.civil.service.pininpost;

import feign.FeignException;
import feign.Response;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -11,6 +10,7 @@
import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.DefendantPinToPostLRspec;
import uk.gov.hmcts.reform.civil.model.IdamUserDetails;
import uk.gov.hmcts.reform.civil.service.CoreCaseDataService;
import uk.gov.hmcts.reform.civil.service.claimstore.ClaimStoreService;
import uk.gov.hmcts.reform.civil.service.pininpost.exception.PinNotMatchException;
Expand Down Expand Up @@ -45,21 +45,16 @@ public void validatePin(CaseDetails caseDetails, String pin) {
}

public Map<String, Object> removePinInPostData(CaseDetails caseDetails) {
try {
CaseData caseData = caseDetailsConverter.toCaseData(caseDetails);
DefendantPinToPostLRspec pinInPostData = caseData.getRespondent1PinToPostLRspec();
DefendantPinToPostLRspec updatePinInPostData = DefendantPinToPostLRspec.builder()
.citizenCaseRole(pinInPostData.getCitizenCaseRole())
.respondentCaseRole(pinInPostData.getRespondentCaseRole())
.expiryDate(pinInPostData.getExpiryDate()).build();
CaseData caseData = caseDetailsConverter.toCaseData(caseDetails);
DefendantPinToPostLRspec pinInPostData = caseData.getRespondent1PinToPostLRspec();
DefendantPinToPostLRspec updatePinInPostData = DefendantPinToPostLRspec.builder()
.citizenCaseRole(pinInPostData.getCitizenCaseRole())
.respondentCaseRole(pinInPostData.getRespondentCaseRole())
.expiryDate(pinInPostData.getExpiryDate()).build();

Map<String, Object> data = new HashMap<>();
data.put("respondent1PinToPostLRspec", updatePinInPostData);
return data;
} catch (FeignException e) {
log.error(String.format("Updating case data failed: %s", e.contentUTF8()));
throw e;
}
Map<String, Object> data = new HashMap<>();
data.put("respondent1PinToPostLRspec", updatePinInPostData);
return data;
}

public DefendantPinToPostLRspec buildDefendantPinToPost() {
Expand Down Expand Up @@ -100,4 +95,10 @@ public boolean isOcmcDefendantLinked(String caseReference) {
log.info("ocmc case reference {} defendent status is {}", caseReference, status.isLinked());
return status.isLinked();
}

public boolean isDefendantLinked(CaseDetails caseDetails) {
CaseData caseData = caseDetailsConverter.toCaseData(caseDetails);
IdamUserDetails defendantUserDetails = caseData.getDefendantUserDetails();
return defendantUserDetails != null && defendantUserDetails.getId() != null && defendantUserDetails.getEmail() != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import uk.gov.hmcts.reform.civil.model.BusinessProcess;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.DefendantPinToPostLRspec;
import uk.gov.hmcts.reform.civil.model.IdamUserDetails;
import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder;
import uk.gov.hmcts.reform.civil.sampledata.CaseDetailsBuilder;
import uk.gov.hmcts.reform.civil.service.claimstore.ClaimStoreService;
Expand Down Expand Up @@ -149,7 +150,7 @@ void shouldResetPinExpiryDateSuccessfully() {
}

@Test
void shouldReturnTrueIfDefendantIsLinked() {
void shouldReturnTrueIfOcmcDefendantIsLinked() {
when(claimStoreService.isOcmcDefendantLinked("620MC123")).thenReturn(createDefendantLinkStatus(true));

boolean status = defendantPinToPostLRspecService.isOcmcDefendantLinked("620MC123");
Expand All @@ -158,14 +159,62 @@ void shouldReturnTrueIfDefendantIsLinked() {
}

@Test
void shouldReturnFalseIfDefendantIsNotLinked() {
void shouldReturnFalseIfOcmcDefendantIsNotLinked() {
when(claimStoreService.isOcmcDefendantLinked("620MC123")).thenReturn(createDefendantLinkStatus(false));

boolean status = defendantPinToPostLRspecService.isOcmcDefendantLinked("620MC123");

assertFalse(status);
}

@Test
void shouldReturnTrueIfDefendantIsLinked() {
CaseData caseData = new CaseDataBuilder()
.defendantUserDetails(
IdamUserDetails.builder()
.id("1234")
.email("[email protected]")
.build())
.build();
CaseDetails caseDetails = createCaseDetails(caseData);
when(caseDetailsConverter.toCaseData(caseDetails)).thenReturn(caseData);
boolean status = defendantPinToPostLRspecService.isDefendantLinked(caseDetails);

assertTrue(status);
}

@Test
void shouldReturnFalseIfDefendantIsNotLinked() {
CaseData caseData = new CaseDataBuilder().defendantUserDetails(null).build();
CaseDetails caseDetails = createCaseDetails(caseData);
when(caseDetailsConverter.toCaseData(caseDetails)).thenReturn(caseData);
boolean status = defendantPinToPostLRspecService.isDefendantLinked(caseDetails);

assertFalse(status);
}

@Test
void shouldReturnFalseIfUserDetailsEmailIsEmpty() {
CaseData caseData = new CaseDataBuilder().defendantUserDetails(IdamUserDetails.builder().id("1234").build()).build();
CaseDetails caseDetails = createCaseDetails(caseData);
when(caseDetailsConverter.toCaseData(caseDetails)).thenReturn(caseData);
boolean status = defendantPinToPostLRspecService.isDefendantLinked(caseDetails);

assertFalse(status);
}

@Test
void shouldReturnFalseIfUserDetailsIdIsEmpty() {
CaseData caseData = new CaseDataBuilder().defendantUserDetails(
IdamUserDetails.builder().email("[email protected]").build()
).build();
CaseDetails caseDetails = createCaseDetails(caseData);
when(caseDetailsConverter.toCaseData(caseDetails)).thenReturn(caseData);
boolean status = defendantPinToPostLRspecService.isDefendantLinked(caseDetails);

assertFalse(status);
}

private CaseData createCaseDataWithPin(String accessCode, int daysToExpiry) {
return new CaseDataBuilder().atStateClaimSubmitted()
.addRespondent1PinToPostLRspec(createPinToPost(accessCode, LocalDate.now().plusDays(daysToExpiry)))
Expand Down
Loading