diff --git a/docker/docmosis/templates/CV-CMC-GNO-ENG-SD0001.docx b/docker/docmosis/templates/CV-CMC-GNO-ENG-SD0001.docx new file mode 100644 index 00000000000..5283009d2eb Binary files /dev/null and b/docker/docmosis/templates/CV-CMC-GNO-ENG-SD0001.docx differ diff --git a/src/main/java/uk/gov/hmcts/reform/civil/documentmanagement/model/DocumentType.java b/src/main/java/uk/gov/hmcts/reform/civil/documentmanagement/model/DocumentType.java index 6285627d660..9546800821e 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/documentmanagement/model/DocumentType.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/documentmanagement/model/DocumentType.java @@ -55,5 +55,6 @@ public enum DocumentType { JUDGMENT_BY_ADMISSION_DEFENDANT, JUDGMENT_BY_DETERMINATION_CLAIMANT, JUDGMENT_BY_DETERMINATION_DEFENDANT, - ORDER_NOTICE_TRANSLATED_DOCUMENT; + ORDER_NOTICE_TRANSLATED_DOCUMENT, + NOTICE_OF_DISCONTINUANCE; } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/enums/DocCategory.java b/src/main/java/uk/gov/hmcts/reform/civil/enums/DocCategory.java index 53b193e557a..599c0c04058 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/enums/DocCategory.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/enums/DocCategory.java @@ -13,7 +13,8 @@ public enum DocCategory { DQ_APP1("DQApplicant"), DQ_DEF1("DQRespondent"), DQ_DEF2("DQRespondentTwo"), - HEARING_NOTICES("hearingNotices"); + HEARING_NOTICES("hearingNotices"), + NOTICE_OF_DISCONTINUE("discontinueNotices"); private final String value; } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDiscontinueClaimCallbackHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDiscontinueClaimCallbackHandler.java index 0af36839f49..fa906931815 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDiscontinueClaimCallbackHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDiscontinueClaimCallbackHandler.java @@ -11,24 +11,31 @@ 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.documentmanagement.model.CaseDocument; +import uk.gov.hmcts.reform.civil.enums.DocCategory; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.service.docmosis.settlediscontinue.NoticeOfDiscontinuanceFormGenerator; +import uk.gov.hmcts.reform.civil.utils.AssignCategoryId; import java.util.List; import java.util.Map; +import static java.util.Objects.nonNull; +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.GEN_NOTICE_OF_DISCONTINUANCE; @Service @RequiredArgsConstructor -@SuppressWarnings("unchecked") public class GenerateDiscontinueClaimCallbackHandler extends CallbackHandler { private static final List EVENTS = List.of( - GEN_NOTICE_OF_DISCONTINUANCE + GEN_NOTICE_OF_DISCONTINUANCE ); private static final String TASK_ID = "GenerateNoticeOfDiscontinueClaim"; private final ObjectMapper objectMapper; - + private final AssignCategoryId assignCategoryId; + private final NoticeOfDiscontinuanceFormGenerator formGenerator; private final RuntimeService runTimeService; @Override @@ -49,8 +56,35 @@ public String camundaActivityId(CallbackParams callbackParams) { private CallbackResponse aboutToSubmit(CallbackParams callbackParams) { CaseData caseData = callbackParams.getCaseData(); + CaseData.CaseDataBuilder caseDataBuilder = caseData.toBuilder(); updateCamundaVars(caseData); - return AboutToStartOrSubmitCallbackResponse.builder().build(); + buildDocument(callbackParams, caseDataBuilder); + CaseData updatedData = caseDataBuilder.build(); + + if (nonNull(updatedData.getNoticeOfDiscontinueCWDoc())) { + assignDiscontinuanceCategoryId(updatedData.getNoticeOfDiscontinueCWDoc()); + } else { + assignDiscontinuanceCategoryId(updatedData.getNoticeOfDiscontinueAllParitiesDoc()); + } + return AboutToStartOrSubmitCallbackResponse.builder() + .data(updatedData.toMap(objectMapper)) + .build(); + } + + private void buildDocument(CallbackParams callbackParams, CaseData.CaseDataBuilder caseDataBuilder) { + CaseData caseData = callbackParams.getCaseData(); + CaseDocument caseDocument = formGenerator.generateDocs( + callbackParams.getCaseData(), + callbackParams.getParams().get(BEARER_TOKEN).toString()); + if (caseData.isJudgeOrderVerificationRequired()) { + caseDataBuilder.noticeOfDiscontinueCWDoc(caseDocument); + } else { + caseDataBuilder.noticeOfDiscontinueAllParitiesDoc(caseDocument); + } + } + + private void assignDiscontinuanceCategoryId(CaseDocument caseDocument) { + assignCategoryId.assignCategoryIdToCaseDocument(caseDocument, DocCategory.NOTICE_OF_DISCONTINUE.getValue()); } private void updateCamundaVars(CaseData caseData) { diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/PostNoticeOfDiscontinuanceLetterLiPDefendant1Handler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/PostNoticeOfDiscontinuanceLetterLiPDefendant1Handler.java new file mode 100644 index 00000000000..7ee3b99943a --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/PostNoticeOfDiscontinuanceLetterLiPDefendant1Handler.java @@ -0,0 +1,66 @@ +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.enums.YesOrNo; +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 EVENTS = List.of( + SEND_DISCONTINUANCE_LETTER_LIP_DEFENDANT1); + + public static final String TASK_ID = "PostNoticeOfDiscontinuanceDefendant1LIP"; + private final NoticeOfDiscontinuanceLiPLetterGenerator lipLetterGenerator; + + @Override + protected Map callbacks() { + return Map.of( + callbackKey(ABOUT_TO_SUBMIT), + this::sendNoticeOfDiscontinuanceLetterToLiPDefendant1 + ); + } + + @Override + public String camundaActivityId(CallbackParams callbackParams) { + return TASK_ID; + } + + @Override + public List handledEvents() { + return EVENTS; + } + + private CallbackResponse sendNoticeOfDiscontinuanceLetterToLiPDefendant1(CallbackParams callbackParams) { + CaseData caseData = callbackParams.getCaseData(); + if (isRespondent1Lip(caseData)) { + generateNoticeOfDiscontinuanceLiPDefendantLetter(callbackParams); + } + return AboutToStartOrSubmitCallbackResponse.builder().build(); + } + + private boolean isRespondent1Lip(CaseData caseData) { + return YesOrNo.NO.equals(caseData.getRespondent1Represented()); + } + + private void generateNoticeOfDiscontinuanceLiPDefendantLetter(CallbackParams callbackParams) { + CaseData caseData = callbackParams.getCaseData(); + lipLetterGenerator.printNoticeOfDiscontinuanceLetter(caseData, callbackParams.getParams().get(BEARER_TOKEN).toString()); + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotifyDefendantClaimDiscontinuedNotificationHandler.java b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotifyDefendantClaimDiscontinuedNotificationHandler.java index 39b7c091f6e..ffc1a58d4d7 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotifyDefendantClaimDiscontinuedNotificationHandler.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotifyDefendantClaimDiscontinuedNotificationHandler.java @@ -19,6 +19,7 @@ import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_DISCONTINUANCE_DEFENDANT1; import static uk.gov.hmcts.reform.civil.utils.NotificationUtils.getRespondentLegalOrganizationName; +import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getAllPartyNames; @Service @RequiredArgsConstructor @@ -62,6 +63,13 @@ private CallbackResponse notifyDefendantClaimDiscontinued(CallbackParams callbac addProperties(caseData), getReferenceTemplate(caseData) ); + } else { + notificationService.sendMail( + caseData.getRespondent1().getPartyEmail(), + getLIPTemplate(), + addPropertiesLip(caseData), + getReferenceTemplate(caseData) + ); } return AboutToStartOrSubmitCallbackResponse.builder().build(); @@ -71,6 +79,10 @@ private String getLRTemplate() { return notificationsProperties.getNotifyClaimDiscontinuedLRTemplate(); } + private String getLIPTemplate() { + return notificationsProperties.getNotifyLipUpdateTemplate(); + } + private String getReferenceTemplate(CaseData caseData) { return String.format(REFERENCE_TEMPLATE, caseData.getLegacyCaseReference()); } @@ -84,4 +96,12 @@ public Map addProperties(CaseData caseData) { getRespondentLegalOrganizationName(caseData.getRespondent1OrganisationPolicy(), organisationService) ); } + + public Map addPropertiesLip(CaseData caseData) { + return Map.of( + CLAIMANT_V_DEFENDANT, getAllPartyNames(caseData), + CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(), + PARTY_NAME, caseData.getRespondent1().getPartyName() + ); + } } diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java b/src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java index 84c8709e467..66b4f0678d7 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java @@ -687,7 +687,9 @@ public boolean hasNoOngoingBusinessProcess() { private SettleDiscontinueYesOrNoList isDiscontinuingAgainstBothDefendants; private SettlementReason settleReason; private final MarkPaidConsentList markPaidConsent; - + private YesOrNo claimantsConsentToDiscontinuance; + private CaseDocument noticeOfDiscontinueCWDoc; + private CaseDocument noticeOfDiscontinueAllParitiesDoc; @JsonUnwrapped private FeePaymentOutcomeDetails feePaymentOutcomeDetails; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/settleanddiscontinue/NoticeOfDiscontinuanceForm.java b/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/settleanddiscontinue/NoticeOfDiscontinuanceForm.java new file mode 100644 index 00000000000..b96f0c17b3c --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/model/docmosis/settleanddiscontinue/NoticeOfDiscontinuanceForm.java @@ -0,0 +1,40 @@ +package uk.gov.hmcts.reform.civil.model.docmosis.settleanddiscontinue; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import uk.gov.hmcts.reform.civil.model.common.MappableObject; + +import java.time.LocalDate; + +@Getter +@Builder +@AllArgsConstructor +@EqualsAndHashCode +public class NoticeOfDiscontinuanceForm implements MappableObject { + + private final String caseNumber; + private final String claimant1Name; + private final String claimant2Name; + private final String defendant1Name; + private final String defendant2Name; + private final String claimantNum; + private final String defendantNum; + private String claimantWhoIsDiscontinue; + private String claimantsConsentToDiscontinuance; + private String courtPermission; + private String permissionGranted; + private String judgeName; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy") + @JsonSerialize(using = LocalDateSerializer.class) + private LocalDate judgementDate; + private String discontinuingAgainstBothDefendants; + private String discontinuingAgainstOneDefendant; + private String typeOfDiscontinuance; + private String typeOfDiscontinuanceTxt; + private String partOfDiscontinuanceTxt; +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/DocmosisTemplates.java b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/DocmosisTemplates.java index c1ab6575272..0564c26b724 100644 --- a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/DocmosisTemplates.java +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/DocmosisTemplates.java @@ -91,7 +91,8 @@ public enum DocmosisTemplates { JUDGMENT_BY_ADMISSION_CLAIMANT("CV-SPC-DEC-ENG-00916.docx", "Judgment_by_admission_claimant.pdf"), JUDGMENT_BY_ADMISSION_DEFENDANT("CV-SPC-DEC-ENG-00915.docx", "Judgment_by_admission_defendant.pdf"), JUDGMENT_BY_DETERMINATION_CLAIMANT("CV-SPC-DEC-ENG-00982.docx", "Judgment_by_determination_claimant.pdf"), - JUDGMENT_BY_DETERMINATION_DEFENDANT("CV-SPC-DEC-ENG-00981.docx", "Judgment_by_determination_defendant.pdf"); + JUDGMENT_BY_DETERMINATION_DEFENDANT("CV-SPC-DEC-ENG-00981.docx", "Judgment_by_determination_defendant.pdf"), + NOTICE_OF_DISCONTINUANCE_PDF("CV-CMC-GNO-ENG-SD0001.docx", "notice_of_discontinuance_%s.pdf"); private final String template; private final String documentTitle; diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/settlediscontinue/NoticeOfDiscontinuanceFormGenerator.java b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/settlediscontinue/NoticeOfDiscontinuanceFormGenerator.java new file mode 100644 index 00000000000..079fa6e8a34 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/settlediscontinue/NoticeOfDiscontinuanceFormGenerator.java @@ -0,0 +1,102 @@ +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.DocumentManagementService; +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.PDF; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; +import uk.gov.hmcts.reform.civil.enums.settlediscontinue.SettleDiscontinueYesOrNoList; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.docmosis.DocmosisDocument; +import uk.gov.hmcts.reform.civil.model.docmosis.settleanddiscontinue.NoticeOfDiscontinuanceForm; +import uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates; +import uk.gov.hmcts.reform.civil.service.docmosis.DocumentGeneratorService; +import uk.gov.hmcts.reform.civil.service.docmosis.TemplateDataGenerator; + +import static java.util.Objects.nonNull; +import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.NOTICE_OF_DISCONTINUANCE_PDF; + +@Slf4j +@Service +@RequiredArgsConstructor +public class NoticeOfDiscontinuanceFormGenerator implements TemplateDataGenerator { + + private final DocumentManagementService documentManagementService; + private final DocumentGeneratorService documentGeneratorService; + + public CaseDocument generateDocs(CaseData caseData, String authorisation) { + NoticeOfDiscontinuanceForm templateData = getNoticeOfDiscontinueData(caseData); + DocmosisTemplates docmosisTemplate = NOTICE_OF_DISCONTINUANCE_PDF; + DocmosisDocument docmosisDocument = + documentGeneratorService.generateDocmosisDocument(templateData, docmosisTemplate); + + return documentManagementService.uploadDocument( + authorisation, + new PDF( + getFileName(caseData, docmosisTemplate), + docmosisDocument.getBytes(), + DocumentType.NOTICE_OF_DISCONTINUANCE + ) + ); + } + + private String getFileName(CaseData caseData, DocmosisTemplates docmosisTemplate) { + return String.format(docmosisTemplate.getDocumentTitle(), caseData.getLegacyCaseReference()); + } + + private NoticeOfDiscontinuanceForm getNoticeOfDiscontinueData(CaseData caseData) { + var noticeOfDiscontinueBuilder = NoticeOfDiscontinuanceForm.builder() + .caseNumber(caseData.getLegacyCaseReference()) + .claimant1Name(caseData.getApplicant1().getPartyName()) + .claimant2Name(nonNull(caseData.getApplicant2()) ? caseData.getApplicant2().getPartyName() : null) + .defendant1Name(caseData.getRespondent1().getPartyName()) + .defendant2Name(nonNull(caseData.getRespondent2()) ? caseData.getRespondent2().getPartyName() : null) + .claimantNum(nonNull(caseData.getApplicant2()) ? "Claimant 1" : "Claimant") + .defendantNum(nonNull(caseData.getRespondent2()) ? "Defendant 1" : "Defendant") + .claimantWhoIsDiscontinue(getClaimantWhoIsDiscontinue(caseData)) + .claimantsConsentToDiscontinuance(nonNull(caseData.getClaimantsConsentToDiscontinuance()) + ? getConsentToDiscontinue(caseData) : null) + .courtPermission(nonNull(caseData.getCourtPermissionNeeded()) + ? caseData.getCourtPermissionNeeded().getDisplayedValue() : null) + .permissionGranted(nonNull(caseData.getIsPermissionGranted()) + ? caseData.getIsPermissionGranted().getDisplayedValue() : null) + .judgeName(isCourtPermissionGranted(caseData) + ? caseData.getPermissionGrantedComplex().getPermissionGrantedJudge() : null) + .judgementDate(isCourtPermissionGranted(caseData) + ? caseData.getPermissionGrantedComplex().getPermissionGrantedDate() : null) + .typeOfDiscontinuance(caseData.getTypeOfDiscontinuance().toString()) + .typeOfDiscontinuanceTxt(caseData.getTypeOfDiscontinuance().getType()) + .partOfDiscontinuanceTxt(caseData.getPartDiscontinuanceDetails()) + .discontinuingAgainstOneDefendant(getDiscontinueAgainstOneDefendant(caseData)) + .discontinuingAgainstBothDefendants(nonNull(caseData.getIsDiscontinuingAgainstBothDefendants()) + ? caseData.getIsDiscontinuingAgainstBothDefendants().getDisplayedValue() : null); + return noticeOfDiscontinueBuilder.build(); + } + + private String getClaimantWhoIsDiscontinue(CaseData caseData) { + return (nonNull(caseData.getClaimantWhoIsDiscontinuing()) + && nonNull(caseData.getClaimantWhoIsDiscontinuing().getValue())) + ? caseData.getClaimantWhoIsDiscontinuing().getValue().getLabel() + : caseData.getApplicant1().getPartyName(); + } + + private String getDiscontinueAgainstOneDefendant(CaseData caseData) { + return (nonNull(caseData.getDiscontinuingAgainstOneDefendant()) + && nonNull(caseData.getDiscontinuingAgainstOneDefendant().getValue())) + ? caseData.getDiscontinuingAgainstOneDefendant().getValue().getLabel() + : null; + } + + private String getConsentToDiscontinue(CaseData caseData) { + return YesOrNo.YES.equals( + caseData.getClaimantsConsentToDiscontinuance()) ? "Yes" : "No"; + } + + private boolean isCourtPermissionGranted(CaseData caseData) { + return nonNull(caseData.getIsPermissionGranted()) + && SettleDiscontinueYesOrNoList.YES.equals(caseData.getIsPermissionGranted()); + } +} diff --git a/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/settlediscontinue/NoticeOfDiscontinuanceLiPLetterGenerator.java b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/settlediscontinue/NoticeOfDiscontinuanceLiPLetterGenerator.java new file mode 100644 index 00000000000..dd42ef72208 --- /dev/null +++ b/src/main/java/uk/gov/hmcts/reform/civil/service/docmosis/settlediscontinue/NoticeOfDiscontinuanceLiPLetterGenerator.java @@ -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 recipients = getRecipientsList(caseData); + bulkPrintService.printLetter(letterContent, caseData.getLegacyCaseReference(), + caseData.getLegacyCaseReference(), NOTICE_OF_DISCONTINUANCE_LETTER, recipients); + } + } + + private List getRecipientsList(CaseData caseData) { + return List.of(caseData.getRespondent1().getPartyName()); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDiscontinueClaimCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDiscontinueClaimCallbackHandlerTest.java index 48cc0f2fd0a..f7705a3fc76 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDiscontinueClaimCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/GenerateDiscontinueClaimCallbackHandlerTest.java @@ -3,30 +3,45 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.camunda.bpm.engine.RuntimeService; import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.junit.jupiter.SpringExtension; -import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest; +import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; 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.Document; +import uk.gov.hmcts.reform.civil.enums.settlediscontinue.DiscontinuanceTypeList; 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.BusinessProcess; 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.PartyBuilder; +import uk.gov.hmcts.reform.civil.service.docmosis.settlediscontinue.NoticeOfDiscontinuanceFormGenerator; +import uk.gov.hmcts.reform.civil.utils.AssignCategoryId; +import java.time.LocalDateTime; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; import static uk.gov.hmcts.reform.civil.callback.CaseEvent.GEN_NOTICE_OF_DISCONTINUANCE; +import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.NOTICE_OF_DISCONTINUANCE; @ExtendWith(SpringExtension.class) @SpringBootTest(classes = { GenerateDiscontinueClaimCallbackHandler.class, JacksonAutoConfiguration.class, + AssignCategoryId.class }) class GenerateDiscontinueClaimCallbackHandlerTest extends BaseCallbackHandlerTest { @@ -35,34 +50,91 @@ class GenerateDiscontinueClaimCallbackHandlerTest extends BaseCallbackHandlerTes @Autowired private GenerateDiscontinueClaimCallbackHandler handler; @MockBean + private NoticeOfDiscontinuanceFormGenerator formGenerator; + @MockBean private RuntimeService runTimeService; - - private static final String processId = "process-id"; + public static final String PROCESS_INSTANCE_ID = "processInstanceId"; @Nested class AboutToSubmitCallback { + @Test + void shouldGenerateNoticeOfDiscontinueDocForCW_whenCourtPermissionRequired() { + when(formGenerator.generateDocs(any(CaseData.class), anyString())).thenReturn(getCaseDocument()); - @ParameterizedTest - @ValueSource(booleans = {true, false}) - void shouldUpdateCamundaVariables_whenInvoked(Boolean toggleState) { - //Given - CaseData caseData = CaseDataBuilder.builder() - .businessProcess(BusinessProcess.builder().processInstanceId(processId).build()).build(); - caseData.setCourtPermissionNeeded( - toggleState ? SettleDiscontinueYesOrNoList.YES : SettleDiscontinueYesOrNoList.NO); - - CallbackParams params = CallbackParams.builder() - .caseData(caseData) - .type(ABOUT_TO_SUBMIT) - .request(CallbackRequest.builder() - .eventId(GEN_NOTICE_OF_DISCONTINUANCE.name()) - .build()) - .build(); - //When - handler.handle(params); - //Then - verify(runTimeService).setVariable(processId, "JUDGE_ORDER_VERIFICATION_REQUIRED", toggleState); + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .respondent1(getPartyDetails()) + .applicant1(getPartyDetails()) + .courtPermissionNeeded(SettleDiscontinueYesOrNoList.YES) + .isPermissionGranted(SettleDiscontinueYesOrNoList.YES) + .businessProcess(BusinessProcess.builder().processInstanceId(PROCESS_INSTANCE_ID).build()) + .typeOfDiscontinuance(DiscontinuanceTypeList.PART_DISCONTINUANCE) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + params.getRequest().setEventId(GEN_NOTICE_OF_DISCONTINUANCE.name()); + + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + verify(formGenerator).generateDocs(any(CaseData.class), eq("BEARER_TOKEN")); + + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(updatedData.getNoticeOfDiscontinueCWDoc()).isNotNull(); } + + @Test + void shouldGenerateNoticeOfDiscontinueDocForAllParties_whenNoCourtPermissionRequired() { + when(formGenerator.generateDocs(any(CaseData.class), anyString())).thenReturn(getCaseDocument()); + + CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder() + .respondent1(getPartyDetails()) + .applicant1(getPartyDetails()) + .courtPermissionNeeded(SettleDiscontinueYesOrNoList.NO) + .typeOfDiscontinuance(DiscontinuanceTypeList.PART_DISCONTINUANCE) + .businessProcess(BusinessProcess.builder().processInstanceId(PROCESS_INSTANCE_ID).build()) + .build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + params.getRequest().setEventId(GEN_NOTICE_OF_DISCONTINUANCE.name()); + + var response = (AboutToStartOrSubmitCallbackResponse) handler.handle(params); + + verify(formGenerator).generateDocs(any(CaseData.class), eq("BEARER_TOKEN")); + + CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class); + assertThat(updatedData.getNoticeOfDiscontinueAllParitiesDoc()).isNotNull(); + } + + } + + @Test + void shouldReturnCorrectActivityId_whenRequested() { + CaseData caseData = CaseDataBuilder.builder().atStateClaimDetailsNotified().build(); + CallbackParams params = callbackParamsOf(caseData, ABOUT_TO_SUBMIT); + assertThat(handler.camundaActivityId(params)).isEqualTo("GenerateNoticeOfDiscontinueClaim"); + } + + @Test + void handleEventsReturnsTheExpectedCallbackEvent() { + assertThat(handler.handledEvents()).contains(GEN_NOTICE_OF_DISCONTINUANCE); } + private Party getPartyDetails() { + return PartyBuilder.builder().individual().build().toBuilder() + .individualFirstName("John") + .individualLastName("Doe") + .build(); + } + + private CaseDocument getCaseDocument() { + return CaseDocument.builder() + .createdBy("John") + .documentName("document name") + .documentSize(0L) + .documentType(NOTICE_OF_DISCONTINUANCE) + .createdDatetime(LocalDateTime.now()) + .documentLink(Document.builder() + .documentUrl("fake-url") + .documentFileName("file-name") + .documentBinaryUrl("binary-url") + .build()) + .build(); + } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/PostNoticeOfDiscontinuanceLetterLiPDefendant1HandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/PostNoticeOfDiscontinuanceLetterLiPDefendant1HandlerTest.java new file mode 100644 index 00000000000..7a7dd2e4f37 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/docmosis/PostNoticeOfDiscontinuanceLetterLiPDefendant1HandlerTest.java @@ -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()); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotifyDefendantClaimDiscontinuedNotificationHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotifyDefendantClaimDiscontinuedNotificationHandlerTest.java index 6b335ef37c4..7cb3031db92 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotifyDefendantClaimDiscontinuedNotificationHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/notification/NotifyDefendantClaimDiscontinuedNotificationHandlerTest.java @@ -9,12 +9,15 @@ import org.springframework.boot.test.mock.mockito.MockBean; import uk.gov.hmcts.reform.ccd.client.model.CallbackRequest; import uk.gov.hmcts.reform.civil.callback.CallbackParams; -import uk.gov.hmcts.reform.civil.callback.CaseEvent; +import uk.gov.hmcts.reform.civil.enums.CaseCategory; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.Party; import uk.gov.hmcts.reform.civil.notify.NotificationService; import uk.gov.hmcts.reform.civil.notify.NotificationsProperties; import uk.gov.hmcts.reform.civil.prd.model.Organisation; +import uk.gov.hmcts.reform.civil.sampledata.CallbackParamsBuilder; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; import uk.gov.hmcts.reform.civil.service.OrganisationService; @@ -26,8 +29,12 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; +import static uk.gov.hmcts.reform.civil.callback.CaseEvent.NOTIFY_DISCONTINUANCE_DEFENDANT1; +import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.CLAIMANT_V_DEFENDANT; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.CLAIM_REFERENCE_NUMBER; import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.LEGAL_ORG_NAME; +import static uk.gov.hmcts.reform.civil.handler.callback.camunda.notification.NotificationData.PARTY_NAME; +import static uk.gov.hmcts.reform.civil.utils.PartyUtils.getAllPartyNames; @SpringBootTest(classes = { NotifyDefendantClaimDiscontinuedNotificationHandler.class, @@ -59,6 +66,8 @@ class AboutToSubmitCallback { void setup() { when(notificationsProperties.getNotifyClaimDiscontinuedLRTemplate()).thenReturn( TEMPLATE_ID); + when(notificationsProperties.getNotifyLipUpdateTemplate()).thenReturn( + TEMPLATE_ID); when(organisationService.findOrganisationById(anyString())) .thenReturn(Optional.of(Organisation.builder().name("Test Org Name").build())); } @@ -75,7 +84,7 @@ void shouldNotifyDefendantLRClaimDiscontinued_whenInvoked() { .caseData(caseData) .type(ABOUT_TO_SUBMIT) .request(CallbackRequest.builder() - .eventId(CaseEvent.NOTIFY_DISCONTINUANCE_DEFENDANT1.name()) + .eventId(NOTIFY_DISCONTINUANCE_DEFENDANT1.name()) .build()) .build(); @@ -88,6 +97,42 @@ void shouldNotifyDefendantLRClaimDiscontinued_whenInvoked() { "defendant-claim-discontinued-000DC001" ); } + + @Test + void shouldNotifyRespondentLip_whenInvoked() { + CaseData caseData = CaseDataBuilder.builder().buildJudgmentOnlineCaseDataWithDeterminationMeans(); + caseData = caseData.toBuilder() + .applicant1(Party.builder() + .individualFirstName("Applicant1").individualLastName("ApplicantLastName").partyName("Applicant1") + .type(Party.Type.INDIVIDUAL).partyEmail("applicantLip@example.com").build()) + .respondent1(Party.builder().partyName("Respondent1").individualFirstName("Respondent1").individualLastName("RespondentLastName") + .type(Party.Type.INDIVIDUAL).partyEmail("respondentLip@example.com").build()) + .respondent1Represented(null) + .legacyCaseReference("000DC001") + .specRespondent1Represented(YesOrNo.NO) + .caseAccessCategory(CaseCategory.SPEC_CLAIM).build(); + + CallbackParams params = CallbackParamsBuilder.builder().of(ABOUT_TO_SUBMIT, caseData).request( + CallbackRequest.builder().eventId(NOTIFY_DISCONTINUANCE_DEFENDANT1.name()).build() + ).build(); + + handler.handle(params); + + verify(notificationService, times(1)).sendMail( + "respondentLip@example.com", + TEMPLATE_ID, + getNotificationLipDataMap(caseData), + "defendant-claim-discontinued-000DC001" + ); + } + } + + private Map getNotificationLipDataMap(CaseData caseData) { + return Map.of( + CLAIMANT_V_DEFENDANT, getAllPartyNames(caseData), + CLAIM_REFERENCE_NUMBER, caseData.getLegacyCaseReference(), + PARTY_NAME, caseData.getRespondent1().getPartyName() + ); } public Map addProperties(CaseData caseData) { diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/settlediscontinue/NoticeOfDiscontinuanceFormGeneratorTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/settlediscontinue/NoticeOfDiscontinuanceFormGeneratorTest.java new file mode 100644 index 00000000000..368c8296334 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/settlediscontinue/NoticeOfDiscontinuanceFormGeneratorTest.java @@ -0,0 +1,96 @@ +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 uk.gov.hmcts.reform.civil.documentmanagement.DocumentManagementService; +import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; +import uk.gov.hmcts.reform.civil.documentmanagement.model.PDF; +import uk.gov.hmcts.reform.civil.enums.YesOrNo; +import uk.gov.hmcts.reform.civil.enums.settlediscontinue.DiscontinuanceTypeList; +import uk.gov.hmcts.reform.civil.enums.settlediscontinue.SettleDiscontinueYesOrNoList; +import uk.gov.hmcts.reform.civil.model.CaseData; +import uk.gov.hmcts.reform.civil.model.PermissionGranted; +import uk.gov.hmcts.reform.civil.model.common.DynamicList; +import uk.gov.hmcts.reform.civil.model.common.DynamicListElement; +import uk.gov.hmcts.reform.civil.model.docmosis.DocmosisDocument; +import uk.gov.hmcts.reform.civil.model.docmosis.settleanddiscontinue.NoticeOfDiscontinuanceForm; +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.docmosis.DocumentGeneratorService; + +import java.time.LocalDate; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.NOTICE_OF_DISCONTINUANCE; +import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.NOTICE_OF_DISCONTINUANCE_PDF; + +@ExtendWith(MockitoExtension.class) +class NoticeOfDiscontinuanceFormGeneratorTest { + + private static final String BEARER_TOKEN = "Bearer Token"; + private static final byte[] bytes = {1, 2, 3, 4, 5, 6}; + private static final String REFERENCE_NUMBER = "000MC015"; + @Mock + private DocumentGeneratorService documentGeneratorService; + @Mock + private DocumentManagementService documentManagementService; + @InjectMocks + private NoticeOfDiscontinuanceFormGenerator formGenerator; + + @Test + void shouldGenerateNoticeOfDiscontinuanceDoc_whenValidDataIsProvided() { + String fileName = String.format( + NOTICE_OF_DISCONTINUANCE_PDF.getDocumentTitle(), REFERENCE_NUMBER); + + CaseDocument caseDocument = CaseDocumentBuilder.builder() + .documentName(fileName) + .documentType(NOTICE_OF_DISCONTINUANCE) + .build(); + + when(documentGeneratorService.generateDocmosisDocument(any(NoticeOfDiscontinuanceForm.class), eq(NOTICE_OF_DISCONTINUANCE_PDF))) + .thenReturn(new DocmosisDocument(NOTICE_OF_DISCONTINUANCE_PDF.getDocumentTitle(), bytes)); + + when(documentManagementService + .uploadDocument(BEARER_TOKEN, new PDF(fileName, bytes, NOTICE_OF_DISCONTINUANCE))) + .thenReturn(caseDocument); + + CaseData caseData = getCaseData(); + + CaseDocument caseDoc = formGenerator.generateDocs(caseData, BEARER_TOKEN); + assertThat(caseDoc).isNotNull(); + + verify(documentManagementService) + .uploadDocument(BEARER_TOKEN, new PDF(fileName, bytes, NOTICE_OF_DISCONTINUANCE)); + } + + private CaseData getCaseData() { + return CaseDataBuilder.builder().atStateClaimIssued().build().toBuilder() + .legacyCaseReference(REFERENCE_NUMBER) + .respondent1(PartyBuilder.builder().individual().build().toBuilder().individualFirstName("John").individualLastName("Doe").build()) + .applicant1(PartyBuilder.builder().individual().build().toBuilder().individualFirstName("James").individualLastName("White").build()) + .applicant2(PartyBuilder.builder().individual().build().toBuilder().individualFirstName("Jan").individualLastName("Black").build()) + .claimantWhoIsDiscontinuing(DynamicList.builder() + .value(DynamicListElement.builder() + .label("Both") + .build()) + .build()) + .claimantsConsentToDiscontinuance(YesOrNo.YES) + .courtPermissionNeeded(SettleDiscontinueYesOrNoList.YES) + .isPermissionGranted(SettleDiscontinueYesOrNoList.YES) + .permissionGrantedComplex(PermissionGranted.builder() + .permissionGrantedJudge("Judge Name") + .permissionGrantedDate(LocalDate.parse("2022-02-01")) + .build()) + .typeOfDiscontinuance(DiscontinuanceTypeList.PART_DISCONTINUANCE) + .partDiscontinuanceDetails("partial part") + .build(); + } +} diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/settlediscontinue/NoticeOfDiscontinuanceLiPLetterGeneratorTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/settlediscontinue/NoticeOfDiscontinuanceLiPLetterGeneratorTest.java new file mode 100644 index 00000000000..5527a2eba50 --- /dev/null +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/docmosis/settlediscontinue/NoticeOfDiscontinuanceLiPLetterGeneratorTest.java @@ -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())); + } +}