generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 6
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
pallavijustice
wants to merge
28
commits into
master
Choose a base branch
from
NFDIV-3985
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
0adc075
NFDIV-3985 initial changes
pallavijustice 252f0c4
Merge branch 'master' into NFDIV-3985
pallavijustice 52b555e
NFDIV-3985 Changes to incorporate feedback from review
pallavijustice 13f61e7
Merge branch 'master' into NFDIV-3985
pallavijustice 1a2212d
Merge branch 'master' into NFDIV-3985
pallavijustice 30b08b9
Merge branch 'master' into NFDIV-3985
pallavijustice 4323305
NFDIV-3985 - Moving call to aboutToSubmit
pallavijustice cbe52e1
NFDIV-3985 - Send correct values for isDivorce field in templateContent.
pallavijustice 9b4c8e5
NFDIV-3985 - Send correct values for isDivorce field in templateContent.
pallavijustice 9257a0e
Merge branch 'master' into NFDIV-3985
pallavijustice 7ef1957
Merge branch 'master' into NFDIV-3985
eliswyndavies 7d5a603
Merge branch 'master' into NFDIV-3985
pallavijustice 9c5c5e5
Merge branch 'master' into NFDIV-3985
pallavijustice b915409
Merge branch 'master' into NFDIV-3985
pallavijustice 8c7bf55
NFDIV-3985 Store generated document in case documents
pallavijustice 643a186
NFDIV-3985 Fix checkstyle
pallavijustice 588060f
NFDIV-3985 Fix checkstyle
pallavijustice 5fd3719
NFDIV-3985 Update based on review comments.
pallavijustice 4ee0fed
Merge branch 'master' into NFDIV-3985
pallavijustice c37c391
Merge branch 'master' into NFDIV-3985
pallavijustice 8a38852
Merge branch 'master' into NFDIV-3985
pallavijustice ce18a7b
NFDIV-4677 Add env to block createPaperCase letter
BWeeks-JusticeGovUK 3a74f84
NFDIV-4677 Test env vars before sending letter
BWeeks-JusticeGovUK 9d1d3cb
NFDIV-4677 Refactor env name
BWeeks-JusticeGovUK 460eb60
NFDIV-4677 Refactor logic
BWeeks-JusticeGovUK 8c5017b
NFDIV-4677 Only force vars if null
BWeeks-JusticeGovUK e896a78
Merge pull request #4322 from hmcts/NFDIV-4677
BWeeks-JusticeGovUK a5e7c30
Merge branch 'master' into NFDIV-3985
pallavijustice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...v/hmcts/divorce/caseworker/service/notification/PaperApplicationReceivedNotification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
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.NFD_PAPER_APPLICATION_RECEIVED_DOCUMENT_NAME; | ||
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 == 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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...n/java/uk/gov/hmcts/divorce/document/content/PaperApplicationReceivedTemplateContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be fine as it is, but I think we'd usually use .equals() here to do the check based on object equality (values of the instance vars due to the Lombok Data annotation) rather than references in memory?