Skip to content

Commit

Permalink
CIV-14385 Bulk print Lip - Notice of Discontinue (#5116)
Browse files Browse the repository at this point in the history
* CIV-14146: Added midEvent and validations

* CIV-14128:Updated midEvent and caseData fields

* CIV-14128: Added more unit tests

* CIV-14128: Fix checkstyle errors

* CIV-14146: Fix checkstyle errors

* CIV-14146: Remove this field as this is not needed for now

* CIV-14146: Organized imports

* CIV-14146: Updated tests

* CIV-14194 initial commit

* CIV-14244 Discontinue Claim notification

* CIV-14244 Discontinue Claim notification

* CIV-14194 test cases added

* CIV-14194 removed extra space

* CIV-14194 testcase updated

* CIV-14244 Discontinue Claim notification

* CIV-14244 Discontinue Claim notification

* CIV-14244 Discontinue Claim notification

* CIV-14244 Discontinue Claim notification

* CIV-14244 Discontinue Claim notification

* CIV-14244 Discontinue Claim notification

* CIV-14244 Discontinue Claim notification

* CIV-14244 Discontinue Claim notification

* CIV-14244 Flow flag condition updated

* CIV-14244 Flow flag condition updated

* CIV-14259 initial commit

* CIV-14244 Flow flag condition updated

* CIV-14244 Resolve imports sonar issue

* CIV-14244 Notification properties update

* CIV-14244 Fixin error test

* CIV-14244 Fixin error test

* CIV-14244 Unused util

* CIV-14244 Test class for GenerateNoticeOfDiscontinueClaim

* CIV-14244 Duplication error

* CIV-14259 testcase added

* CIV-14259 changes

* Civ-14259 checkstyle fixed

* CIV-14244 Fixing error for the condition to discontinue.

* CIV-14244 Deleting the states not needed in the flowstate

* CIV-14244 Update the flag for camunda into runtime

* CIV-14244 Reverting changes for flowFlag on stateflowEngine

* CIV-14244 Reverting changes for flowFlag on stateflowEngine

* CIV-14259 code refactored

* CIV-14244 Reverting changes for flowFlag on stateflowEngine

* CIV-14259 merge issue fixed

* removed toString()

* CIV-14244 Forgot upload the Defentand2 blank handler for continue with the camunda flow.

* CIV-14244 Error on test name

* CIV-14385 initial commit

* Update Jenkinsfile_CNP

* Update Jenkinsfile_CNP

* CIV-14259 template name updated

* CIV-14259 testing issue fixed

* CIV-14259 review comments updated

* checkstyle fixed

* CIV-14244 Fixing defendant2 notification error

* CIV-14259 template updated

* CIV-14385 code updated

* CIV-14385 checkstyle fixed

* CIV-14259 ConfirmOrderGivesPermission changes

---------

Co-authored-by: JamiS <[email protected]>
Co-authored-by: sjamihmcts <[email protected]>
Co-authored-by: Azam <[email protected]>
Co-authored-by: Omaira-Melo-Hmcts <[email protected]>
Co-authored-by: sherlynkhaw <[email protected]>
Co-authored-by: krishnanuthalapati <[email protected]>
  • Loading branch information
7 people committed Jul 23, 2024
1 parent 6068882 commit 6592e54
Show file tree
Hide file tree
Showing 4 changed files with 271 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis;

import lombok.RequiredArgsConstructor;
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.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.model.CaseData;
import uk.gov.hmcts.reform.civil.service.docmosis.settlediscontinue.NoticeOfDiscontinuanceLiPLetterGenerator;

import java.util.List;
import java.util.Map;

import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.SEND_DISCONTINUANCE_LETTER_LIP_DEFENDANT1;

@Service
@RequiredArgsConstructor
public class PostNoticeOfDiscontinuanceLetterLiPDefendant1Handler extends CallbackHandler {

private static final List<CaseEvent> EVENTS = List.of(
SEND_DISCONTINUANCE_LETTER_LIP_DEFENDANT1);

public static final String TASK_ID = "PostNoticeOfDiscontinuanceDefendant1LIP";
private final NoticeOfDiscontinuanceLiPLetterGenerator lipLetterGenerator;

@Override
protected Map<String, Callback> callbacks() {
return Map.of(
callbackKey(ABOUT_TO_SUBMIT),
this::sendNoticeOfDiscontinuanceLetterToLiPDefendant1
);
}

@Override
public String camundaActivityId(CallbackParams callbackParams) {
return TASK_ID;
}

@Override
public List<CaseEvent> handledEvents() {
return EVENTS;
}

private CallbackResponse sendNoticeOfDiscontinuanceLetterToLiPDefendant1(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
if (caseData.isRespondent1LiP()) {
generateNoticeOfDiscontinuanceLiPDefendantLetter(callbackParams);
}
return AboutToStartOrSubmitCallbackResponse.builder().build();
}

private void generateNoticeOfDiscontinuanceLiPDefendantLetter(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
lipLetterGenerator.printNoticeOfDiscontinuanceLetter(caseData, callbackParams.getParams().get(BEARER_TOKEN).toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package uk.gov.hmcts.reform.civil.service.docmosis.settlediscontinue;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.reform.civil.documentmanagement.DocumentDownloadException;
import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.service.BulkPrintService;
import uk.gov.hmcts.reform.civil.service.documentmanagement.DocumentDownloadService;

import java.io.IOException;
import java.util.List;

import static java.util.Objects.nonNull;

@Slf4j
@RequiredArgsConstructor
@Service
public class NoticeOfDiscontinuanceLiPLetterGenerator {

private final DocumentDownloadService documentDownloadService;
private final BulkPrintService bulkPrintService;
private static final String NOTICE_OF_DISCONTINUANCE_LETTER = "notice-of-discontinuance";

public void printNoticeOfDiscontinuanceLetter(CaseData caseData, String authorisation) {
CaseDocument discontinuanceCaseDocument = caseData.getNoticeOfDiscontinueAllParitiesDoc();
if (nonNull(discontinuanceCaseDocument)) {
String documentUrl = discontinuanceCaseDocument.getDocumentLink().getDocumentUrl();
String documentId = documentUrl.substring(documentUrl.lastIndexOf("/") + 1);
byte[] letterContent;
try {
letterContent = documentDownloadService.downloadDocument(authorisation, documentId).file().getInputStream().readAllBytes();
} catch (IOException e) {
log.error("Failed getting letter content for Notice of Discontinuance LiP Letter ");
throw new DocumentDownloadException(discontinuanceCaseDocument.getDocumentLink().getDocumentFileName(), e);
}
List<String> recipients = getRecipientsList(caseData);
bulkPrintService.printLetter(letterContent, caseData.getLegacyCaseReference(),
caseData.getLegacyCaseReference(), NOTICE_OF_DISCONTINUANCE_LETTER, recipients);
}
}

private List<String> getRecipientsList(CaseData caseData) {
return List.of(caseData.getRespondent1().getPartyName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package uk.gov.hmcts.reform.civil.handler.callback.camunda.docmosis;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse;
import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest;
import uk.gov.hmcts.reform.civil.callback.CallbackParams;
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.YesOrNo;
import uk.gov.hmcts.reform.civil.enums.settlediscontinue.SettleDiscontinueYesOrNoList;
import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder;
import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder;
import uk.gov.hmcts.reform.civil.sampledata.CaseDocumentBuilder;
import uk.gov.hmcts.reform.civil.service.docmosis.settlediscontinue.NoticeOfDiscontinuanceLiPLetterGenerator;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
import static uk.gov.hmcts.reform.civil.callback.CallbackParams.Params.BEARER_TOKEN;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.SEND_DISCONTINUANCE_LETTER_LIP_DEFENDANT1;

@ExtendWith(MockitoExtension.class)
public class PostNoticeOfDiscontinuanceLetterLiPDefendant1HandlerTest extends BaseCallbackHandlerTest {

@Mock
private NoticeOfDiscontinuanceLiPLetterGenerator letterGenerator;
@InjectMocks
private PostNoticeOfDiscontinuanceLetterLiPDefendant1Handler handler;
public static final String TASK_ID_DEFENDANT = "PostNoticeOfDiscontinuanceDefendant1LIP";
private static final CaseDocument caseDocument = CaseDocumentBuilder.builder()
.documentName("document name")
.documentType(DocumentType.NOTICE_OF_DISCONTINUANCE)
.build();

@Test
void handleEventsReturnsTheExpectedCallbackEvent() {
assertThat(handler.handledEvents()).contains(SEND_DISCONTINUANCE_LETTER_LIP_DEFENDANT1);
}

@Test
void shouldReturnCorrectCamundaActivityId_whenInvoked() {
assertThat(handler.camundaActivityId(CallbackParamsBuilder.builder().request(CallbackRequest.builder().eventId(
SEND_DISCONTINUANCE_LETTER_LIP_DEFENDANT1.name()).build())
.build())).isEqualTo(TASK_ID_DEFENDANT);
}

@Test
void shouldDownloadDocumentAndPrintLetterSuccessfully() {
CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder()
.respondent1Represented(YesOrNo.NO)
.courtPermissionNeeded(SettleDiscontinueYesOrNoList.NO)
.noticeOfDiscontinueAllParitiesDoc(caseDocument).build();

CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT);
params.getRequest().setEventId(SEND_DISCONTINUANCE_LETTER_LIP_DEFENDANT1.name());

var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params);

assertThat(response.getErrors()).isNull();
verify(letterGenerator).printNoticeOfDiscontinuanceLetter(
caseData,
params.getParams().get(BEARER_TOKEN).toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package uk.gov.hmcts.reform.civil.service.docmosis.settlediscontinue;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.core.io.ByteArrayResource;
import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument;
import uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType;
import uk.gov.hmcts.reform.civil.documentmanagement.model.DownloadedDocumentResponse;
import uk.gov.hmcts.reform.civil.enums.YesOrNo;
import uk.gov.hmcts.reform.civil.model.CaseData;
import uk.gov.hmcts.reform.civil.model.Party;
import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder;
import uk.gov.hmcts.reform.civil.sampledata.CaseDocumentBuilder;
import uk.gov.hmcts.reform.civil.sampledata.PartyBuilder;
import uk.gov.hmcts.reform.civil.service.BulkPrintService;
import uk.gov.hmcts.reform.civil.service.documentmanagement.DocumentDownloadService;

import java.util.List;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
class NoticeOfDiscontinuanceLiPLetterGeneratorTest {

@Mock
private BulkPrintService bulkPrintService;
@Mock
private DocumentDownloadService documentDownloadService;
@InjectMocks
private NoticeOfDiscontinuanceLiPLetterGenerator liPLetterGenerator;
private static final String NOTICE_OF_DISCONTINUANCE_LETTER = "notice-of-discontinuance";
private static final String BEARER_TOKEN = "Bearer Token";

static final byte[] LETTER_CONTENT = new byte[]{37, 80, 68, 70, 45, 49, 46, 53, 10, 37, -61, -92};

private static final CaseDocument caseDocument = CaseDocumentBuilder.builder()
.documentName("document name")
.documentType(DocumentType.NOTICE_OF_DISCONTINUANCE)
.build();

@Test
void shouldDownloadDocumentAndPrintLetterSuccessfully() {
Party applicant = PartyBuilder.builder().soleTrader().build();
Party defendant = PartyBuilder.builder().soleTrader().build();
CaseData caseData = CaseDataBuilder.builder().build().toBuilder()
.respondent1Represented(YesOrNo.NO)
.applicant1(applicant)
.respondent1(defendant)
.noticeOfDiscontinueAllParitiesDoc(caseDocument).build();

given(documentDownloadService.downloadDocument(
any(),
any()
)).willReturn(new DownloadedDocumentResponse(new ByteArrayResource(LETTER_CONTENT), "test", "test"));

liPLetterGenerator.printNoticeOfDiscontinuanceLetter(caseData, BEARER_TOKEN);

verify(bulkPrintService)
.printLetter(
LETTER_CONTENT,
caseData.getLegacyCaseReference(),
caseData.getLegacyCaseReference(),
NOTICE_OF_DISCONTINUANCE_LETTER,
List.of(caseData.getRespondent1().getPartyName()));
}

@Test
void shouldNotDownloadDocumentAndPrintLetterSuccessfully() {
Party applicant = PartyBuilder.builder().soleTrader().build();
Party defendant = PartyBuilder.builder().soleTrader().build();
CaseData caseData = CaseDataBuilder.builder().build().toBuilder()
.respondent1Represented(YesOrNo.NO)
.applicant1(applicant)
.respondent1(defendant)
.noticeOfDiscontinueAllParitiesDoc(null).build();

liPLetterGenerator.printNoticeOfDiscontinuanceLetter(caseData, BEARER_TOKEN);

verify(bulkPrintService, never())
.printLetter(
LETTER_CONTENT,
caseData.getLegacyCaseReference(),
caseData.getLegacyCaseReference(),
NOTICE_OF_DISCONTINUANCE_LETTER,
List.of(caseData.getRespondent1().getPartyName()));
}
}

0 comments on commit 6592e54

Please sign in to comment.