Skip to content

Commit

Permalink
update handler unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
chak-shing-lo-justice committed Aug 22, 2023
1 parent 48c664a commit f8ce4f7
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import static uk.gov.hmcts.reform.fpl.enums.notification.DocumentUploaderType.SOLICITOR;
import static uk.gov.hmcts.reform.fpl.service.docmosis.DocumentConversionService.PDF;
import static uk.gov.hmcts.reform.fpl.utils.DocumentsHelper.hasExtension;
import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements;

@Slf4j
@Component
Expand All @@ -73,7 +74,7 @@ public class ManageDocumentsUploadedEventHandler {
public static final Map<DocumentType, CafcassRequestEmailContentProvider> CAFCASS_EMAIL_CONTENT_MAP = Map.of(
COURT_BUNDLE, CafcassRequestEmailContentProvider.COURT_BUNDLE,
CASE_SUMMARY, CafcassRequestEmailContentProvider.CASE_SUMMARY,
POSITION_STATEMENTS, CafcassRequestEmailContentProvider.POSITION_STATEMENT_RESPONDENT,
POSITION_STATEMENTS, CafcassRequestEmailContentProvider.POSITION_STATEMENT,
SKELETON_ARGUMENTS, CafcassRequestEmailContentProvider.SKELETON_ARGUMENT
);

Expand All @@ -96,14 +97,12 @@ public void sendDocumentsUploadedNotification(final ManageDocumentsUploadedEvent
List<Element<NotifyDocumentUploaded>> documentsToBeSent =
consolidateMapByConfiguration(event, getConfidentialLevelFunction)
.entrySet().stream()
.filter(entry -> !isHearingDocument(entry.getKey()))
.map(Map.Entry::getValue)
.flatMap(List::stream)
.collect(toList());

if (!documentsToBeSent.isEmpty()) {
List<String> newDocumentNames = documentsToBeSent.stream()
.map(Element::getValue)
List<String> newDocumentNames = unwrapElements(documentsToBeSent).stream()
.map(NotifyDocumentUploaded::getNameForNotification)
.collect(toList());

Expand All @@ -116,40 +115,6 @@ public void sendDocumentsUploadedNotification(final ManageDocumentsUploadedEvent
});
}

// TODO unit test
@Async
@EventListener
public void sendHearingDocumentsUploadedNotification(final ManageDocumentsUploadedEvent event) {
buildConfigurationMapGroupedByRecipient(event)
.forEach((recipients, getConfidentialLevelFunction) -> {
List<HearingDocument> documentsToBeSent =
consolidateMapByConfiguration(event, getConfidentialLevelFunction)
.entrySet().stream()
.filter(entry -> isHearingDocument(entry.getKey()))
.map(Map.Entry::getValue)
.flatMap(List::stream)
.map(Element::getValue)
.map(hearingDoc -> (HearingDocument) hearingDoc)
.collect(toList());

if (!documentsToBeSent.isEmpty()) {
if (isNotEmpty(recipients)) {

Optional<HearingBooking> hearingBookings = event.getCaseData().getHearingDetails().stream()
.filter(element ->
element.getValue().toLabel().equals(documentsToBeSent.get(0).getHearing()))
.findFirst()
.map(Element::getValue);

List<String> newDocumentNames = documentsToBeSent.stream()
.map(doc -> doc.getDocument().getFilename()).collect(toList());
furtherEvidenceNotificationService.sendNotificationWithHearing(event.getCaseData(), recipients,
event.getInitiatedBy().getFullName(), newDocumentNames, hearingBookings);
}
}
});
}

@Async
@EventListener
public void sendDocumentsByPost(final ManageDocumentsUploadedEvent event) {
Expand Down Expand Up @@ -219,27 +184,18 @@ public void sendHearingDocumentsToCafcass(final ManageDocumentsUploadedEvent eve
final CaseData caseData = event.getCaseData();

if (CafcassHelper.isNotifyingCafcassEngland(caseData, cafcassLookupConfiguration)) {
// 1. get available new hearing documents
consolidateMapByConfiguration(event, DocumentUploadedNotificationConfiguration::getSendToCafcassEngland)
.entrySet().stream()
.filter(entry -> isHearingDocument(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
.forEach((docType, hearingDocuments) ->
// 2. for each hearing document type, group by hearing
hearingDocuments.stream()
.map(Element::getValue)
.map(hearingDocument -> (HearingDocument) hearingDocument)
.collect(groupingBy(HearingDocument::getHearing,
mapping(HearingDocument::getDocument, toSet())))
.forEach((hearing, doc) ->
// 3. for each hearing document type and hearing, send to Cafcass
cafcassNotificationService.sendEmail(
caseData,
doc,
CAFCASS_EMAIL_CONTENT_MAP.get(docType),
CourtBundleData.builder()
.hearingDetails(hearing)
.build())));
cafcassNotificationService.sendEmail(
caseData,
unwrapElements(hearingDocuments).stream()
.map(NotifyDocumentUploaded::getDocument)
.collect(toSet()),
CAFCASS_EMAIL_CONTENT_MAP.get(docType),
CourtBundleData.builder().build()));
}
}

Expand Down Expand Up @@ -336,7 +292,7 @@ private Map<DocumentType, List<Element<NotifyDocumentUploaded>>> consolidateMapB
private Set<DocumentReference> getDocumentReferences(
Map<DocumentType, List<Element<NotifyDocumentUploaded>>> documentsMap) {

return documentsMap.values().stream().flatMap(List::stream).collect(toList()).stream()
return documentsMap.values().stream().flatMap(List::stream)
.map(Element::getValue).map(NotifyDocumentUploaded::getDocument)
.collect(toSet());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import lombok.Builder;
import lombok.Getter;
import uk.gov.hmcts.reform.fpl.enums.cfv.ConfidentialLevel;
import uk.gov.hmcts.reform.fpl.model.cafcass.CafcassData;
import uk.gov.hmcts.reform.fpl.service.cafcass.CafcassRequestEmailContentProvider;

import java.util.Map;
import java.util.function.Function;

/**
* Confidential level configuration for document uploaded notification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ public enum CafcassRequestEmailContentProvider {
caseData.getFamilyManCaseNumber(),
"new court bundle"),
(caseData, cafcassData) ->
String.format("A new court bundle for this case was uploaded to the Public Law Portal entitled %s",
cafcassData.getHearingDetails()),
(cafcassData.getHearingDetails() == null || cafcassData.getHearingDetails().isEmpty()) ?
"A new court bundle for this case was uploaded to the Public Law Portal"
: String.format("A new court bundle for this case was uploaded to the Public Law Portal entitled %s",
cafcassData.getHearingDetails()),
CafcassEmailConfiguration::getRecipientForCourtBundle,
true),

Expand All @@ -56,8 +58,10 @@ public enum CafcassRequestEmailContentProvider {
caseData.getFamilyManCaseNumber(),
"new case summary"),
(caseData, cafcassData) ->
String.format("A new case summary for this case was uploaded to the Public Law Portal entitled %s",
cafcassData.getHearingDetails()),
(cafcassData.getHearingDetails() == null || cafcassData.getHearingDetails().isEmpty()) ?
"A new case summary for this case was uploaded to the Public Law Portal"
: String.format("A new case summary for this case was uploaded to the Public Law Portal entitled %s",
cafcassData.getHearingDetails()),
CafcassEmailConfiguration::getRecipientForCourtBundle,
true),

Expand All @@ -83,6 +87,15 @@ public enum CafcassRequestEmailContentProvider {
CafcassEmailConfiguration::getRecipientForCourtBundle,
true),

POSITION_STATEMENT("Position statement",
(caseData, cafcassData) -> String.format(getSubject(),
caseData.getFamilyManCaseNumber(),
"new position statement"),
(caseData, cafcassData) ->
"A new position statement for this case was uploaded to the Public Law Portal",
CafcassEmailConfiguration::getRecipientForCourtBundle,
true),

SKELETON_ARGUMENT("Skeleton Argument",
(caseData, cafcassData) -> String.format(getSubject(),
caseData.getFamilyManCaseNumber(),
Expand Down
1 change: 1 addition & 0 deletions service/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ cafcass:
caseSummary: BUNDLE
positionStatementChild: BUNDLE
positionStatementRespondent: BUNDLE
positionStatement: BUNDLE
other: CORRESPONDENCE
correspondence: CORRESPONDENCE
additionalDocument: APPLICATION
Expand Down
Loading

0 comments on commit f8ce4f7

Please sign in to comment.