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

NFDIV-3985 Send letter to applicant when new paper case is created #4141

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0adc075
NFDIV-3985 initial changes
pallavijustice Nov 6, 2024
252f0c4
Merge branch 'master' into NFDIV-3985
pallavijustice Nov 6, 2024
52b555e
NFDIV-3985 Changes to incorporate feedback from review
pallavijustice Nov 6, 2024
13f61e7
Merge branch 'master' into NFDIV-3985
pallavijustice Dec 3, 2024
1a2212d
Merge branch 'master' into NFDIV-3985
pallavijustice Dec 4, 2024
30b08b9
Merge branch 'master' into NFDIV-3985
pallavijustice Dec 9, 2024
4323305
NFDIV-3985 - Moving call to aboutToSubmit
pallavijustice Dec 9, 2024
cbe52e1
NFDIV-3985 - Send correct values for isDivorce field in templateContent.
pallavijustice Dec 9, 2024
9b4c8e5
NFDIV-3985 - Send correct values for isDivorce field in templateContent.
pallavijustice Dec 9, 2024
9257a0e
Merge branch 'master' into NFDIV-3985
pallavijustice Jan 6, 2025
7ef1957
Merge branch 'master' into NFDIV-3985
eliswyndavies Jan 9, 2025
7d5a603
Merge branch 'master' into NFDIV-3985
pallavijustice Jan 14, 2025
9c5c5e5
Merge branch 'master' into NFDIV-3985
pallavijustice Jan 21, 2025
b915409
Merge branch 'master' into NFDIV-3985
pallavijustice Jan 28, 2025
8c7bf55
NFDIV-3985 Store generated document in case documents
pallavijustice Jan 28, 2025
643a186
NFDIV-3985 Fix checkstyle
pallavijustice Jan 28, 2025
588060f
NFDIV-3985 Fix checkstyle
pallavijustice Jan 28, 2025
5fd3719
NFDIV-3985 Update based on review comments.
pallavijustice Jan 28, 2025
4ee0fed
Merge branch 'master' into NFDIV-3985
pallavijustice Feb 5, 2025
c37c391
Merge branch 'master' into NFDIV-3985
pallavijustice Feb 11, 2025
8a38852
Merge branch 'master' into NFDIV-3985
pallavijustice Feb 12, 2025
ce18a7b
NFDIV-4677 Add env to block createPaperCase letter
BWeeks-JusticeGovUK Feb 12, 2025
3a74f84
NFDIV-4677 Test env vars before sending letter
BWeeks-JusticeGovUK Feb 12, 2025
9d1d3cb
NFDIV-4677 Refactor env name
BWeeks-JusticeGovUK Feb 12, 2025
460eb60
NFDIV-4677 Refactor logic
BWeeks-JusticeGovUK Feb 12, 2025
8c5017b
NFDIV-4677 Only force vars if null
BWeeks-JusticeGovUK Feb 12, 2025
e896a78
Merge pull request #4322 from hmcts/NFDIV-4677
BWeeks-JusticeGovUK Feb 13, 2025
a5e7c30
Merge branch 'master' into NFDIV-3985
pallavijustice Feb 14, 2025
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
4 changes: 4 additions & 0 deletions Jenkinsfile_CNP
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ withPipeline(type, product, component) {
env.CITIZEN_UPDATE_CASE_STATE_ENABLED=true
env.SERVICE_AUTH_MICROSERVICE = "nfdiv_case_api"
env.SERVICE_AUTH_PROVIDER_URL = "http://rpe-service-auth-provider-aat.service.core-compute-aat.internal"
env.CREATE_PAPER_CASE_MOCK_NOTIFICATION=true

setCommonEnvVariables()
}
Expand All @@ -185,6 +186,7 @@ withPipeline(type, product, component) {
env.ADMIN_UNLINK_APPLICANT_2_ENABLED=true
env.SERVICE_AUTH_MICROSERVICE = "nfdiv_case_api"
env.SERVICE_AUTH_PROVIDER_URL = "http://rpe-service-auth-provider-aat.service.core-compute-aat.internal"
env.CREATE_PAPER_CASE_MOCK_NOTIFICATION=true
setCommonEnvVariables()
}

Expand All @@ -199,6 +201,7 @@ withPipeline(type, product, component) {
env.IDAM_API_URL_BASE = "https://idam-api.platform.hmcts.net"
env.S2S_URL_BASE = "http://rpe-service-auth-provider-prod.service.core-compute-prod.internal"
env.BEFTA_S2S_CLIENT_ID = "ccd_data"
env.CREATE_PAPER_CASE_MOCK_NOTIFICATION=false

// re-run to generate prod definition
builder.gradle('generateCCDConfig --rerun-tasks')
Expand All @@ -211,6 +214,7 @@ withPipeline(type, product, component) {
env.CCD_DEF_NAME = "demo"
env.IDAM_API_URL_BASE = "https://idam-api.demo.platform.hmcts.net"
env.S2S_URL_BASE = "http://rpe-service-auth-provider-demo.service.core-compute-demo.internal"
env.CREATE_PAPER_CASE_MOCK_NOTIFICATION=true
}

onPerftest {
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ bootWithCCD {
environment 'ROLE_ASSIGNMENT_URL', 'http://localhost:4096'
environment 'CASE_DATA_STORE_BASEURL', 'http://localhost:4452'
environment 'XUI_MO_PORT', '3009'
environment 'CREATE_PAPER_CASE_MOCK_NOTIFICATION', 'true'
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package uk.gov.hmcts.divorce.caseworker.event;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.ccd.sdk.api.CCDConfig;
import uk.gov.hmcts.ccd.sdk.api.CaseDetails;
import uk.gov.hmcts.ccd.sdk.api.ConfigBuilder;
import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse;
import uk.gov.hmcts.divorce.caseworker.service.notification.PaperApplicationReceivedNotification;
import uk.gov.hmcts.divorce.common.ccd.PageBuilder;
import uk.gov.hmcts.divorce.divorcecase.model.CaseData;
import uk.gov.hmcts.divorce.divorcecase.model.State;
import uk.gov.hmcts.divorce.divorcecase.model.UserRole;
import uk.gov.hmcts.divorce.notification.NotificationDispatcher;

import static org.apache.commons.lang3.StringUtils.isBlank;
import static uk.gov.hmcts.ccd.sdk.type.YesOrNo.NO;
import static uk.gov.hmcts.ccd.sdk.type.YesOrNo.YES;
import static uk.gov.hmcts.divorce.divorcecase.model.ApplicationType.JOINT_APPLICATION;
import static uk.gov.hmcts.divorce.divorcecase.model.ApplicationType.SOLE_APPLICATION;
import static uk.gov.hmcts.divorce.divorcecase.model.DivorceOrDissolution.DIVORCE;
import static uk.gov.hmcts.divorce.divorcecase.model.State.NewPaperCase;
import static uk.gov.hmcts.divorce.divorcecase.model.UserRole.CASE_WORKER;
import static uk.gov.hmcts.divorce.divorcecase.model.UserRole.CASE_WORKER_BULK_SCAN;
Expand All @@ -30,6 +34,12 @@ public class CaseworkerCreatePaperCase implements CCDConfig<CaseData, State, Use

public static final String CREATE_PAPER_CASE = "create-paper-case";

@Autowired
private NotificationDispatcher notificationDispatcher;

@Autowired
private PaperApplicationReceivedNotification paperApplicationReceivedNotification;

@Override
public void configure(final ConfigBuilder<CaseData, State, UserRole> configBuilder) {
new PageBuilder(configBuilder
Expand Down Expand Up @@ -62,6 +72,19 @@ public AboutToStartOrSubmitResponse<CaseData, State> aboutToSubmit(final CaseDet
applicant2.setOffline(NO);
}

final boolean mockNotification = Boolean.parseBoolean(System.getenv().get("CREATE_PAPER_CASE_MOCK_NOTIFICATION"));
final boolean notProd = !"prod".equalsIgnoreCase(System.getenv().get("ENVIRONMENT"));
if (notProd && mockNotification) {
if (data.getDivorceOrDissolution() == null) {
data.setDivorceOrDissolution(DIVORCE);
}

if (data.getApplicationType() == null) {
data.setApplicationType(SOLE_APPLICATION);
}
}
notificationDispatcher.send(paperApplicationReceivedNotification, data, details.getId());

return AboutToStartOrSubmitResponse.<CaseData, State>builder()
.data(data)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package uk.gov.hmcts.divorce.caseworker.service.notification;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.ccd.sdk.type.Document;
import uk.gov.hmcts.divorce.divorcecase.model.Applicant;
import uk.gov.hmcts.divorce.divorcecase.model.CaseData;
import uk.gov.hmcts.divorce.document.CaseDataDocumentService;
import uk.gov.hmcts.divorce.document.content.PaperApplicationReceivedTemplateContent;
import uk.gov.hmcts.divorce.document.model.ConfidentialDivorceDocument;
import uk.gov.hmcts.divorce.document.model.DivorceDocument;
import uk.gov.hmcts.divorce.document.print.BulkPrintService;
import uk.gov.hmcts.divorce.document.print.model.Letter;
import uk.gov.hmcts.divorce.document.print.model.Print;
import uk.gov.hmcts.divorce.notification.ApplicantNotification;

import java.util.List;
import java.util.UUID;

import static uk.gov.hmcts.divorce.divorcecase.model.CaseDocuments.addDocumentToTop;
import static uk.gov.hmcts.divorce.document.DocumentConstants.PAPER_APPLICATION_RECEIVED_TEMPLATE_ID;
import static uk.gov.hmcts.divorce.document.model.ConfidentialDocumentsReceived.PAPER_APPLICATION_RECEIVED_CONFIDENTIAL_LETTER;
import static uk.gov.hmcts.divorce.document.model.DocumentType.PAPER_APPLICATION_RECEIVED_LETTER;

@Component
@RequiredArgsConstructor
@Slf4j
public class PaperApplicationReceivedNotification implements ApplicantNotification {

private final BulkPrintService bulkPrintService;
private final CaseDataDocumentService caseDataDocumentService;
private final PaperApplicationReceivedTemplateContent templateContent;

public static final String LETTER_TYPE_PAPER_APPLICATION_RECEIVED = "paper-application-received";
public static final String APPLICANT1_DOCUMENT_NAME = "Paper Application Received Letter - Applicant/Applicant1";
public static final String APPLICANT2_DOCUMENT_NAME = "Paper Application Received Letter - Applicant2";

@Override
public void sendToApplicant1Offline(CaseData caseData, Long caseId) {
log.info("Sending application received letter to applicant 1 for case : {}", caseId);
generateApplicationReceivedLetterAndSend(caseData, caseId, caseData.getApplicant1());
}

@Override
public void sendToApplicant2Offline(CaseData caseData, Long caseId) {
if (!caseData.getApplicationType().isSole()) {
log.info("Sending application received letter to applicant 2 for case : {}", caseId);
generateApplicationReceivedLetterAndSend(caseData, caseId, caseData.getApplicant2());
}
}

private void generateApplicationReceivedLetterAndSend(CaseData caseData, Long caseId, Applicant applicant) {

Document generatedDocument = generateDocument(caseId, applicant, caseData);

updateCaseDataWithDocument(caseData,generatedDocument, applicant);

Letter letter = new Letter(generatedDocument, 1);
String caseIdString = String.valueOf(caseId);

final Print print = new Print(
List.of(letter),
caseIdString,
caseIdString,
LETTER_TYPE_PAPER_APPLICATION_RECEIVED,
applicant.getFullName(),
applicant.getAddressOverseas()
);

final UUID letterId = bulkPrintService.print(print);

log.info("Letter service responded with letter Id {} for case {}", letterId, caseId);
}

private Document generateDocument(final long caseId,
final Applicant applicant,
final CaseData caseData) {

boolean isApplicant1 = applicant.equals(caseData.getApplicant1());
String documentName = isApplicant1 ? APPLICANT1_DOCUMENT_NAME : APPLICANT2_DOCUMENT_NAME;
return caseDataDocumentService.renderDocument(templateContent.getTemplateContent(caseData, caseId, applicant),
caseId,
PAPER_APPLICATION_RECEIVED_TEMPLATE_ID,
applicant.getLanguagePreference(),
documentName);
}

private void updateCaseDataWithDocument(final CaseData caseData, final Document document, final Applicant applicant) {
if (applicant.isConfidentialContactDetails()) {
ConfidentialDivorceDocument divorceDocument = ConfidentialDivorceDocument
.builder()
.documentLink(document)
.documentFileName(document.getFilename())
.confidentialDocumentsReceived(PAPER_APPLICATION_RECEIVED_CONFIDENTIAL_LETTER)
.build();
caseData.getDocuments().setConfidentialDocumentsGenerated(addDocumentToTop(
caseData.getDocuments().getConfidentialDocumentsGenerated(), divorceDocument));
} else {
DivorceDocument divorceDocument = DivorceDocument
.builder()
.documentLink(document)
.documentFileName(document.getFilename())
.documentType(PAPER_APPLICATION_RECEIVED_LETTER)
.build();

caseData.getDocuments().setDocumentsGenerated(addDocumentToTop(
caseData.getDocuments().getDocumentsGenerated(), divorceDocument));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ public final class DocumentConstants {
public static final String NOC_CITIZEN_LETTER_TEMPLATE_ID = "NOC_TO_SOLS_CITIZEN_LETTER";
public static final String NOC_CITIZEN_LETTER_DOCUMENT_NAME = "Noc";

public static final String PAPER_APPLICATION_RECEIVED_TEMPLATE_ID = "NFD_APPLICANT_PAPERCASE_RECEIVED";

public static final String APPLICANT1 = "applicant1";
public static final String APPLICANT2 = "applicant2";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package uk.gov.hmcts.divorce.document.content;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.divorce.divorcecase.model.Applicant;
import uk.gov.hmcts.divorce.divorcecase.model.CaseData;
import uk.gov.hmcts.divorce.divorcecase.util.AddressUtil;

import java.time.Clock;
import java.time.LocalDate;
import java.util.Map;

import static uk.gov.hmcts.divorce.document.content.DocmosisTemplateConstants.CASE_REFERENCE;
import static uk.gov.hmcts.divorce.document.content.DocmosisTemplateConstants.RECIPIENT_ADDRESS;
import static uk.gov.hmcts.divorce.document.content.DocmosisTemplateConstants.RECIPIENT_NAME;
import static uk.gov.hmcts.divorce.notification.CommonContent.IS_DIVORCE;
import static uk.gov.hmcts.divorce.notification.FormatUtil.DATE_TIME_FORMATTER;
import static uk.gov.hmcts.divorce.notification.FormatUtil.formatId;

@Component
@RequiredArgsConstructor
@Slf4j
public class PaperApplicationReceivedTemplateContent {

private final DocmosisCommonContent docmosisCommonContent;
private final Clock clock;

public static final String DATE_OF_RESPONSE = "dateOfResponse";
private static final int SUBMISSION_RESPONSE_DAYS = 28;

public Map<String, Object> getTemplateContent(CaseData caseData, Long caseId, Applicant applicant) {
Map<String, Object> templateContent = docmosisCommonContent
.getBasicDocmosisTemplateContent(applicant.getLanguagePreference());

templateContent.put(CASE_REFERENCE, formatId(caseId));
templateContent.put(RECIPIENT_NAME, applicant.getFullName());
templateContent.put(RECIPIENT_ADDRESS, AddressUtil.getPostalAddress(applicant.getAddress()));
templateContent.put(IS_DIVORCE, caseData.isDivorce());
templateContent.put(DATE_OF_RESPONSE, LocalDate.now(clock)
.plusDays(SUBMISSION_RESPONSE_DAYS).format(DATE_TIME_FORMATTER));

return templateContent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ public enum ConfidentialDocumentsReceived implements HasLabel {
SEPARATION_ORDER_REFUSAL_COVER_LETTER("Separation order refusal cover letter"),

@JsonProperty("conditionalOrderRefusalCoverLetter")
CONDITIONAL_ORDER_REFUSAL_COVER_LETTER("Conditional order refusal cover letter");
CONDITIONAL_ORDER_REFUSAL_COVER_LETTER("Conditional order refusal cover letter"),

@JsonProperty("paperApplicationReceivedLetter")
PAPER_APPLICATION_RECEIVED_CONFIDENTIAL_LETTER("Paper Application received letter");

private final String label;
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ public enum DocumentType implements HasLabel {
GRANT_OF_REPRESENTATION("NoC grant of representation letter", true),

@JsonProperty("requestForInformationResponseDoc")
REQUEST_FOR_INFORMATION_RESPONSE_DOC("RFI response document", true);
REQUEST_FOR_INFORMATION_RESPONSE_DOC("RFI response document", true),

@JsonProperty("paperApplicationReceivedLetter")
PAPER_APPLICATION_RECEIVED_LETTER("Paper Application Received Letter", true);

private final String label;
private final boolean potentiallyConfidential;
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ docmosis:
JUDICIAL_SEPARATION_JOINT_APPLICATION: FL-NFD-APP-ENG-Judicial-Separation-Application-Joint_V1.docx
NFD_NOTICE_OF_CHANGE_CONFIRMATION_APP1__APP2: FL-NFD-GRP-ENG-Grant-Of-Representation-V2.docx
NFD_APP1_SOLICITOR_APPLIED_FOR_FINAL_ORDER: FL-NFD-GOR-ENG-SOLICITOR-APPLIED-FOR-FINAL-ORDER.docx
NFD_APPLICANT_PAPERCASE_RECEIVED: FL-NFD-GOR-ENG-PaperCase-Received-Applicant.docx
NFD_NOTICE_OF_CHANGE_INVITE_APP: FL-NFD-GOR-ENG-Solicitor_stopped_representation_citizen_letter_V1.docx
NFD_SOL_STOPPED_REP_NOTIFY_APP: FL-NFD-GOR-ENG-Solicitor_stopped_representation_notify_citizen_V1.docx
welsh:
Expand Down Expand Up @@ -561,6 +562,7 @@ docmosis:
JUDICIAL_SEPARATION_JOINT_APPLICATION: FL-NFD-APP-ENG-Judicial-Separation-Application-Joint_V1.docx
NFD_NOTICE_OF_CHANGE_CONFIRMATION_APP1__APP2: FL-NFD-GRP-WEL-Grant-Of-Representation.docx
NFD_APP1_SOLICITOR_APPLIED_FOR_FINAL_ORDER: FL-NFD-GOR-WEL-SOLICITOR-APPLIED-FOR-FINAL-ORDER.docx
NFD_APPLICANT_PAPERCASE_RECEIVED: FL-NFD-GOR-WEL-PaperCase-Received-Applicant.docx
NFD_NOTICE_OF_CHANGE_INVITE_APP: FL-NFD-GOR-WEL-Solicitor_stopped_representation_citizen_letter_V1.docx
NFD_SOL_STOPPED_REP_NOTIFY_APP: FL-NFD-GOR-ENG-Solicitor_stopped_representation_notify_citizen_V1.docx #TODO: update Welsh content
templateVars:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
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.ccd.sdk.ConfigBuilderImpl;
import uk.gov.hmcts.ccd.sdk.api.CaseDetails;
import uk.gov.hmcts.ccd.sdk.api.Event;
import uk.gov.hmcts.ccd.sdk.api.callback.AboutToStartOrSubmitResponse;
import uk.gov.hmcts.divorce.caseworker.service.notification.PaperApplicationReceivedNotification;
import uk.gov.hmcts.divorce.divorcecase.model.ApplicationType;
import uk.gov.hmcts.divorce.divorcecase.model.CaseData;
import uk.gov.hmcts.divorce.divorcecase.model.LabelContent;
import uk.gov.hmcts.divorce.divorcecase.model.State;
import uk.gov.hmcts.divorce.divorcecase.model.SupplementaryCaseType;
import uk.gov.hmcts.divorce.divorcecase.model.UserRole;
import uk.gov.hmcts.divorce.notification.NotificationDispatcher;
import uk.gov.hmcts.divorce.testutil.ConfigTestUtil;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
import static uk.gov.hmcts.ccd.sdk.type.YesOrNo.NO;
import static uk.gov.hmcts.ccd.sdk.type.YesOrNo.YES;
import static uk.gov.hmcts.divorce.caseworker.event.CaseworkerCreatePaperCase.CREATE_PAPER_CASE;
Expand All @@ -28,6 +32,11 @@

@ExtendWith(MockitoExtension.class)
public class CaseworkerCreatePaperCaseTest {

@Mock
private NotificationDispatcher notificationDispatcher;
@Mock
private PaperApplicationReceivedNotification paperApplicationReceivedNotification;
@InjectMocks
private CaseworkerCreatePaperCase caseworkerCreatePaperCase;

Expand Down Expand Up @@ -163,4 +172,16 @@ public void shouldSetBothApplicantsOfflineWhenSeparation() {
assertThat(submitResponse.getData().getApplicant1().getOffline()).isEqualTo(YES);
assertThat(submitResponse.getData().getApplicant2().getOffline()).isEqualTo(YES);
}

@Test
public void shouldSendNotificationInAboutToSubmitCallBack() {
final CaseData caseData = caseData();
final CaseDetails<CaseData, State> details = new CaseDetails<>();
details.setId(TEST_CASE_ID);
details.setData(caseData);

AboutToStartOrSubmitResponse<CaseData, State> response = caseworkerCreatePaperCase.aboutToSubmit(details, details);

verify(notificationDispatcher).send(paperApplicationReceivedNotification, caseData, TEST_CASE_ID);
}
}
Loading
Loading