Skip to content

Commit

Permalink
CIV-15693 Update settle and discontinue document (#5800)
Browse files Browse the repository at this point in the history
* civ-15693 updated template

* fixed SETTLE_CLAIM_MARKED_PAID_IN_FULL_LIP_DEFENDANT_LETTER

* added docs in service

* fix

* remove doc

* delete old file
  • Loading branch information
sherlynkhaw authored Nov 19, 2024
1 parent bb4c182 commit 34a32ad
Show file tree
Hide file tree
Showing 14 changed files with 191 additions and 44 deletions.
Binary file modified docker/docmosis/templates/CV-CMC-LET-ENG-LIP-SD0002.docx
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
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.model.Party;
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;
import static uk.gov.hmcts.reform.civil.enums.YesOrNo.YES;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -57,31 +58,52 @@ private CallbackResponse aboutToSubmit(CallbackParams callbackParams) {
CaseData caseData = callbackParams.getCaseData();
updateCamundaVars(caseData);
CaseData.CaseDataBuilder<?, ?> caseDataBuilder = caseData.toBuilder();
buildDocument(callbackParams, caseDataBuilder);
CaseData updatedData = caseDataBuilder.build();
buildDocuments(callbackParams, caseDataBuilder);

if (nonNull(updatedData.getNoticeOfDiscontinueCWDoc())) {
assignDiscontinuanceCategoryId(updatedData.getNoticeOfDiscontinueCWDoc());
} else {
assignDiscontinuanceCategoryId(updatedData.getNoticeOfDiscontinueAllParitiesDoc());
}
return AboutToStartOrSubmitCallbackResponse.builder()
.data(updatedData.toMap(objectMapper))
.data(caseDataBuilder.build().toMap(objectMapper))
.build();
}

private void buildDocument(CallbackParams callbackParams, CaseData.CaseDataBuilder<?, ?> caseDataBuilder) {
private void buildDocuments(CallbackParams callbackParams, CaseData.CaseDataBuilder<?, ?> caseDataBuilder) {
CaseData caseData = callbackParams.getCaseData();
CaseDocument caseDocument = formGenerator.generateDocs(
callbackParams.getCaseData(),
callbackParams.getParams().get(BEARER_TOKEN).toString());

CaseDocument applicant1DiscontinueDoc = generateForm(caseData.getApplicant1(), callbackParams);
CaseDocument respondent1DiscontinueDoc = generateForm(caseData.getRespondent1(), callbackParams);
CaseDocument respondent2DiscontinueDoc = null;

if (YES.equals(caseData.getAddRespondent2()) && caseData.getRespondent2() != null) {
respondent2DiscontinueDoc = generateForm(caseData.getRespondent2(), callbackParams);
}

if (caseData.isJudgeOrderVerificationRequired()) {
caseDataBuilder.noticeOfDiscontinueCWDoc(caseDocument);
caseDataBuilder.applicant1NoticeOfDiscontinueCWViewDoc(applicant1DiscontinueDoc);
caseDataBuilder.respondent1NoticeOfDiscontinueCWViewDoc(respondent1DiscontinueDoc);
assignDiscontinuanceCategoryId(caseDataBuilder.build().getApplicant1NoticeOfDiscontinueCWViewDoc());
assignDiscontinuanceCategoryId(caseDataBuilder.build().getRespondent1NoticeOfDiscontinueCWViewDoc());

if (respondent2DiscontinueDoc != null) {
caseDataBuilder.respondent2NoticeOfDiscontinueCWViewDoc(respondent2DiscontinueDoc);
assignDiscontinuanceCategoryId(caseDataBuilder.build().getRespondent2NoticeOfDiscontinueCWViewDoc());
}
} else {
caseDataBuilder.noticeOfDiscontinueAllParitiesDoc(caseDocument);
caseDataBuilder.applicant1NoticeOfDiscontinueAllPartyViewDoc(applicant1DiscontinueDoc);
caseDataBuilder.respondent1NoticeOfDiscontinueAllPartyViewDoc(respondent1DiscontinueDoc);
assignDiscontinuanceCategoryId(caseDataBuilder.build().getApplicant1NoticeOfDiscontinueAllPartyViewDoc());
assignDiscontinuanceCategoryId(caseDataBuilder.build().getRespondent1NoticeOfDiscontinueAllPartyViewDoc());

if (respondent2DiscontinueDoc != null) {
caseDataBuilder.respondent2NoticeOfDiscontinueAllPartyViewDoc(respondent2DiscontinueDoc);
assignDiscontinuanceCategoryId(caseDataBuilder.build().getRespondent2NoticeOfDiscontinueAllPartyViewDoc());
}
}
}

private CaseDocument generateForm(Party party, CallbackParams callbackParams) {
return formGenerator.generateDocs(
callbackParams.getCaseData(), party, callbackParams.getParams().get(BEARER_TOKEN).toString());
}

private void assignDiscontinuanceCategoryId(CaseDocument caseDocument) {
assignCategoryId.assignCategoryIdToCaseDocument(caseDocument, DocCategory.NOTICE_OF_DISCONTINUE.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,44 @@ private CallbackResponse updateVisibilityNoticeDiscontinuance(CallbackParams cal
updateCamundaVars(caseData);
if (ConfirmOrderGivesPermission.YES.equals(caseData.getConfirmOrderGivesPermission())) {
CaseData.CaseDataBuilder<?, ?> caseDataBuilder = caseData.toBuilder();
caseDataBuilder.noticeOfDiscontinueAllParitiesDoc(caseData.getNoticeOfDiscontinueCWDoc());
caseDataBuilder.noticeOfDiscontinueCWDoc(null);

updateVisibilityForAllParties(caseData, caseDataBuilder);
removeCaseWorkerViewDocuments(caseDataBuilder);

CaseData updatedData = caseDataBuilder.build();
assignCategoryId.assignCategoryIdToCaseDocument(updatedData.getNoticeOfDiscontinueAllParitiesDoc(), DocCategory.NOTICE_OF_DISCONTINUE.getValue());
assignCategoryIdForAllParties(updatedData);

return AboutToStartOrSubmitCallbackResponse.builder()
.data(updatedData.toMap(objectMapper))
.build();
}
return AboutToStartOrSubmitCallbackResponse.builder().build();
}

private void updateVisibilityForAllParties(CaseData caseData, CaseData.CaseDataBuilder<?, ?> caseDataBuilder) {
caseDataBuilder
.applicant1NoticeOfDiscontinueAllPartyViewDoc(caseData.getApplicant1NoticeOfDiscontinueCWViewDoc())
.respondent1NoticeOfDiscontinueAllPartyViewDoc(caseData.getRespondent1NoticeOfDiscontinueCWViewDoc());

if (caseData.getRespondent2NoticeOfDiscontinueCWViewDoc() != null) {
caseDataBuilder
.respondent2NoticeOfDiscontinueAllPartyViewDoc(caseData.getRespondent2NoticeOfDiscontinueCWViewDoc());
}
}

private void removeCaseWorkerViewDocuments(CaseData.CaseDataBuilder<?, ?> caseDataBuilder) {
caseDataBuilder
.applicant1NoticeOfDiscontinueCWViewDoc(null)
.respondent1NoticeOfDiscontinueCWViewDoc(null)
.respondent2NoticeOfDiscontinueCWViewDoc(null);
}

private void assignCategoryIdForAllParties(CaseData caseData) {
assignCategoryId.assignCategoryIdToCaseDocument(caseData.getApplicant1NoticeOfDiscontinueAllPartyViewDoc(), DocCategory.NOTICE_OF_DISCONTINUE.getValue());
assignCategoryId.assignCategoryIdToCaseDocument(caseData.getRespondent1NoticeOfDiscontinueAllPartyViewDoc(), DocCategory.NOTICE_OF_DISCONTINUE.getValue());
assignCategoryId.assignCategoryIdToCaseDocument(caseData.getRespondent2NoticeOfDiscontinueAllPartyViewDoc(), DocCategory.NOTICE_OF_DISCONTINUE.getValue());
}

private void updateCamundaVars(CaseData caseData) {
runTimeService.setVariable(
caseData.getBusinessProcess().getProcessInstanceId(),
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/uk/gov/hmcts/reform/civil/model/CaseData.java
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,13 @@ public boolean hasNoOngoingBusinessProcess() {
private SettlementReason settleReason;
private final MarkPaidConsentList markPaidConsent;
private YesOrNo claimantsConsentToDiscontinuance;
private CaseDocument noticeOfDiscontinueCWDoc;
private CaseDocument noticeOfDiscontinueAllParitiesDoc;
private CaseDocument applicant1NoticeOfDiscontinueCWViewDoc;
private CaseDocument respondent1NoticeOfDiscontinueCWViewDoc;
private CaseDocument respondent2NoticeOfDiscontinueCWViewDoc;
private CaseDocument applicant1NoticeOfDiscontinueAllPartyViewDoc;
private CaseDocument respondent1NoticeOfDiscontinueAllPartyViewDoc;
private CaseDocument respondent2NoticeOfDiscontinueAllPartyViewDoc;

@JsonUnwrapped
private FeePaymentOutcomeDetails feePaymentOutcomeDetails;
private LocalDate coscSchedulerDeadline;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@ public class NoticeOfDiscontinuanceForm implements MappableObject {
private String typeOfDiscontinuance;
private String typeOfDiscontinuanceTxt;
private String partOfDiscontinuanceTxt;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd MMMM yyyy")
@JsonSerialize(using = LocalDateSerializer.class)
private final LocalDate letterIssueDate;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd MMMM yyyy")
@JsonSerialize(using = LocalDateSerializer.class)
private final LocalDate dateOfEvent;
private final String coverLetterName;
private final String addressLine1;
private final String addressLine2;
private final String addressLine3;
private final String postCode;
private final String claimReferenceNumber;
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public enum DocmosisTemplates {
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"),
NOTICE_OF_DISCONTINUANCE_PDF("CV-SPC-GNO-ENG-SD0001.docx", "notice_of_discontinuance_%s.pdf"),
NOTICE_OF_DISCONTINUANCE_PDF("CV-SPC-GNO-ENG-SD0002.docx", "notice_of_discontinuance_%s.pdf"),
CERTIFICATE_OF_DEBT_PAYMENT("CV-SPC-STD-ENG-N441A.docx", "Certificate_of_debt_payment_%s.pdf"),
COVER_LETTER("CV-SPC-LET-ENG-COVER-LETTER.docx", "cover_letter.pdf");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
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.Party;
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 java.time.LocalDate;
import static java.util.Objects.nonNull;
import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.NOTICE_OF_DISCONTINUANCE_PDF;

Expand All @@ -27,8 +28,8 @@ public class NoticeOfDiscontinuanceFormGenerator implements TemplateDataGenerato
private final DocumentManagementService documentManagementService;
private final DocumentGeneratorService documentGeneratorService;

public CaseDocument generateDocs(CaseData caseData, String authorisation) {
NoticeOfDiscontinuanceForm templateData = getNoticeOfDiscontinueData(caseData);
public CaseDocument generateDocs(CaseData caseData, Party party, String authorisation) {
NoticeOfDiscontinuanceForm templateData = getNoticeOfDiscontinueData(caseData, party);
DocmosisTemplates docmosisTemplate = NOTICE_OF_DISCONTINUANCE_PDF;
DocmosisDocument docmosisDocument =
documentGeneratorService.generateDocmosisDocument(templateData, docmosisTemplate);
Expand All @@ -47,9 +48,17 @@ private String getFileName(CaseData caseData, DocmosisTemplates docmosisTemplate
return String.format(docmosisTemplate.getDocumentTitle(), caseData.getLegacyCaseReference());
}

private NoticeOfDiscontinuanceForm getNoticeOfDiscontinueData(CaseData caseData) {
private NoticeOfDiscontinuanceForm getNoticeOfDiscontinueData(CaseData caseData, Party party) {
var noticeOfDiscontinueBuilder = NoticeOfDiscontinuanceForm.builder()
.caseNumber(caseData.getLegacyCaseReference())
.claimReferenceNumber(caseData.getLegacyCaseReference())
.letterIssueDate(LocalDate.now())
.dateOfEvent(LocalDate.now())
.coverLetterName(party.getPartyName())
.addressLine1(party.getPrimaryAddress().getAddressLine1())
.addressLine2(party.getPrimaryAddress().getAddressLine2())
.addressLine3(party.getPrimaryAddress().getAddressLine3())
.postCode(party.getPrimaryAddress().getPostCode())
.claimant1Name(caseData.getApplicant1().getPartyName())
.claimant2Name(nonNull(caseData.getApplicant2()) ? caseData.getApplicant2().getPartyName() : null)
.defendant1Name(caseData.getRespondent1().getPartyName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class NoticeOfDiscontinuanceLiPLetterGenerator {
private static final String NOTICE_OF_DISCONTINUANCE_LETTER = "notice-of-discontinuance";

public void printNoticeOfDiscontinuanceLetter(CaseData caseData, String authorisation) {
CaseDocument discontinuanceCaseDocument = caseData.getNoticeOfDiscontinueAllParitiesDoc();
CaseDocument discontinuanceCaseDocument = caseData.getRespondent1NoticeOfDiscontinueAllPartyViewDoc();
if (nonNull(discontinuanceCaseDocument)) {
String documentUrl = discontinuanceCaseDocument.getDocumentLink().getDocumentUrl();
String documentId = documentUrl.substring(documentUrl.lastIndexOf("/") + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT;
Expand Down Expand Up @@ -78,11 +79,11 @@ void shouldUpdateCamundaVariables_whenInvoked(Boolean toggleState) {

@Test
void shouldGenerateNoticeOfDiscontinueDocForCW_whenCourtPermissionRequired() {
when(formGenerator.generateDocs(any(CaseData.class), anyString())).thenReturn(getCaseDocument());
when(formGenerator.generateDocs(any(CaseData.class), any(Party.class), anyString())).thenReturn(getCaseDocument());

CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder()
.respondent1(getPartyDetails())
.applicant1(getPartyDetails())
.respondent1(getRespondent1PartyDetails())
.applicant1(getApplicant1PartyDetails())
.courtPermissionNeeded(SettleDiscontinueYesOrNoList.YES)
.isPermissionGranted(SettleDiscontinueYesOrNoList.YES)
.businessProcess(BusinessProcess.builder().processInstanceId(PROCESS_INSTANCE_ID).build())
Expand All @@ -93,19 +94,20 @@ void shouldGenerateNoticeOfDiscontinueDocForCW_whenCourtPermissionRequired() {

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

verify(formGenerator).generateDocs(any(CaseData.class), eq("BEARER_TOKEN"));
verify(formGenerator, times(2)).generateDocs(any(CaseData.class), any(Party.class), eq("BEARER_TOKEN"));

CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class);
assertThat(updatedData.getNoticeOfDiscontinueCWDoc()).isNotNull();
assertThat(updatedData.getApplicant1NoticeOfDiscontinueCWViewDoc()).isNotNull();
assertThat(updatedData.getRespondent1NoticeOfDiscontinueCWViewDoc()).isNotNull();
}

@Test
void shouldGenerateNoticeOfDiscontinueDocForAllParties_whenNoCourtPermissionRequired() {
when(formGenerator.generateDocs(any(CaseData.class), anyString())).thenReturn(getCaseDocument());
when(formGenerator.generateDocs(any(CaseData.class), any(Party.class), anyString())).thenReturn(getCaseDocument());

CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder()
.respondent1(getPartyDetails())
.applicant1(getPartyDetails())
.respondent1(getRespondent1PartyDetails())
.applicant1(getApplicant1PartyDetails())
.courtPermissionNeeded(SettleDiscontinueYesOrNoList.NO)
.typeOfDiscontinuance(DiscontinuanceTypeList.PART_DISCONTINUANCE)
.businessProcess(BusinessProcess.builder().processInstanceId(PROCESS_INSTANCE_ID).build())
Expand All @@ -115,10 +117,11 @@ void shouldGenerateNoticeOfDiscontinueDocForAllParties_whenNoCourtPermissionRequ

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

verify(formGenerator).generateDocs(any(CaseData.class), eq("BEARER_TOKEN"));
verify(formGenerator, times(2)).generateDocs(any(CaseData.class), any(Party.class), eq("BEARER_TOKEN"));

CaseData updatedData = mapper.convertValue(response.getData(), CaseData.class);
assertThat(updatedData.getNoticeOfDiscontinueAllParitiesDoc()).isNotNull();
assertThat(updatedData.getApplicant1NoticeOfDiscontinueAllPartyViewDoc()).isNotNull();
assertThat(updatedData.getRespondent1NoticeOfDiscontinueAllPartyViewDoc()).isNotNull();
}
}

Expand All @@ -134,13 +137,27 @@ void handleEventsReturnsTheExpectedCallbackEvent() {
assertThat(handler.handledEvents()).contains(GEN_NOTICE_OF_DISCONTINUANCE);
}

private Party getPartyDetails() {
private Party getRespondent1PartyDetails() {
return PartyBuilder.builder().individual().build().toBuilder()
.individualFirstName("John")
.individualLastName("Doe")
.build();
}

private Party getRespondent2PartyDetails() {
return PartyBuilder.builder().individual().build().toBuilder()
.individualFirstName("Jane")
.individualLastName("Doe")
.build();
}

private Party getApplicant1PartyDetails() {
return PartyBuilder.builder().individual().build().toBuilder()
.individualFirstName("Carl")
.individualLastName("Foster")
.build();
}

private CaseDocument getCaseDocument() {
return CaseDocument.builder()
.createdBy("John")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void shouldDownloadDocumentAndPrintLetterSuccessfully() {
CaseData caseData = CaseDataBuilder.builder().atStateNotificationAcknowledged().build().toBuilder()
.respondent1Represented(YesOrNo.NO)
.courtPermissionNeeded(SettleDiscontinueYesOrNoList.NO)
.noticeOfDiscontinueAllParitiesDoc(caseDocument).build();
.respondent1NoticeOfDiscontinueAllPartyViewDoc(caseDocument).build();

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

0 comments on commit 34a32ad

Please sign in to comment.