Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.apache.commons.lang.NullArgumentException;
import org.apache.commons.lang.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
Expand Down Expand Up @@ -78,6 +79,9 @@ public class NotificationServiceCIC {

private static final long TWO_MEGABYTES = 2_048_000;

@Value("${uk.gov.notify.email.documentDescriptionEnabled}")
private boolean documentDescriptionEnabled;

public void saveEmailCorrespondence(String templateName,
SendEmailResponse sendEmailResponse,
String sentTo,
Expand Down Expand Up @@ -278,6 +282,7 @@ private void addAttachmentsToTemplateVars(Map<String, Object> templateVars,
final String docName = uploadDocumentEntry.getKey();
final String item = uploadDocumentEntry.getValue();

//TODO for CASE_ISSUED_RESPONDENT_EMAIL add doc name plus description
if (docName.contains(DOC_AVAILABLE)) {
templateVars.put(docName, item);
} else {
Expand All @@ -290,11 +295,19 @@ private void addLinkOrDocumentDetails(Map<String, Object> templateVars,
List<CaseworkerCICDocument> selectedDocuments,
String item,
String docName) {
final User user = idamService.retrieveUser(request.getHeader(AUTHORIZATION));
final String authorisation = user.getAuthToken();
final String serviceAuthorization = authTokenGenerator.generate();

if (StringUtils.isNotEmpty(item)) {

if (documentDescriptionEnabled) {
addDocumentNameAndDescription(templateVars, selectedDocuments, item, docName);
return;
}

final User user = idamService.retrieveUser(request.getHeader(AUTHORIZATION));
final String authorisation = user.getAuthToken();
final String serviceAuthorization = authTokenGenerator.generate();


ResponseEntity<byte[]> documentBinaryResponse =
caseDocumentClientApi.getDocumentBinary(authorisation, serviceAuthorization, UUID.fromString(item));
if (!documentBinaryResponse.getStatusCode().is2xxSuccessful()) {
Expand Down Expand Up @@ -326,17 +339,44 @@ private static void addDocumentDetails(Map<String, Object> templateVars,
List<CaseworkerCICDocument> selectedDocuments,
String item,
String docName) {
CaseworkerCICDocument document = selectedDocuments.stream()
.filter(doc -> doc.getDocumentLink().getBinaryUrl().contains(item))
.findFirst()
.orElseThrow(() -> new NotificationException(
new Exception(String.format("Unable to find document details for document id: %s", item))));

CaseworkerCICDocument document = getcaseworkerCICDocument(selectedDocuments, item);

String documentNotification = String.format("%nFilename: %s%nDescription: %s%nUpload Date: %s",
document.getDocumentLink().getFilename(), document.getDocumentEmailContent(), document.getDate());
templateVars.put(docName, documentNotification);
}

private static void addDocumentNameAndDescription(Map<String, Object> templateVars,
List<CaseworkerCICDocument> selectedDocuments,
String item,
String docName) {
CaseworkerCICDocument document = getcaseworkerCICDocument(selectedDocuments, item);

String filename = Objects.requireNonNull(
document.getDocumentLink().getFilename(),
"Filename must not be null"
);

String description = Objects.toString(document.getDocumentEmailContent(), "");

String documentNotification = """
Filename: %s
Description: %s
""".formatted(filename, description);

templateVars.put(docName, documentNotification);
}

private static CaseworkerCICDocument getcaseworkerCICDocument(List<CaseworkerCICDocument> selectedDocuments, String item) {
return selectedDocuments.stream()
.filter(doc -> doc.getDocumentLink().getBinaryUrl().contains(item))
.findFirst()
.orElseThrow(() -> new NotificationException(
new Exception(String.format("Unable to find document details for document id: %s", item))));
}


private JSONObject getJsonFileAttachment(byte[] fileContents) {
JSONObject jsonObject = null;
try {
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 @@ -78,6 +78,7 @@ uk:
sptribskey: ${UK_GOV_NOTIFY_API_KEY_1:dummy}
baseUrl: https://api.notifications.service.gov.uk
email:
documentDescriptionEnabled: ${DOCUMENT_DESCRIPTION_ENABLED:true}
templateVars:
signInProfessionalUsersUrl: ${NOTIFY_TEMPLATE_SIGN_IN_PROFESSIONAL_USERS_URL:https://manage-case.aat.platform.hmcts.net/cases/case-details/}
respondentName: 'Appeals Team'
Expand All @@ -92,6 +93,7 @@ uk:
CASE_ISSUED_CITIZEN_EMAIL: '03a0bbaa-10ee-4304-a1b1-6fdf76a2fd69'
CASE_ISSUED_CITIZEN_POST: 'eedc916f-088f-4653-99ed-b954e1dbd58d'
CASE_ISSUED_RESPONDENT_EMAIL: 'd90a4a2d-1406-48d3-a319-924cc8f67d5e'
CASE_ISSUED_RESPONDENT_EMAIL_UPDATED: 'ada24c59-1378-42ac-8361-f322253c82ac'
CASE_LINKED_EMAIL: '14633cea-db23-4a44-a477-3f3b37202b72'
CASE_LINKED_POST: 'd69207af-ed64-4a60-b0a3-224d429d8b17'
CASE_STAYED_EMAIL: '474266c4-f583-43b6-b464-3faad6567037'#
Expand Down
Loading