Skip to content

Commit

Permalink
fix getting new document uploaded
Browse files Browse the repository at this point in the history
  • Loading branch information
chak-shing-lo-justice committed Aug 14, 2023
1 parent 3a30a19 commit f97e8b0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void sendNotification(final ManageDocumentsUploadedEvent event, Set<Stri
if (isNotEmpty(recipients)) {
List<String> newDocumentNames = documentsToBeSent.values().stream().flatMap(List::stream)
.map(Element::getValue)
.map(NotifyDocumentUploaded::getName)
.map(NotifyDocumentUploaded::getNameForNotification)
.collect(toList());

if (!newDocumentNames.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public class DocumentUploadedNotificationConfiguration {
.sendToDesignatedLA(ConfidentialLevel.LA)
.sendToSecondaryLA(ConfidentialLevel.LA)
.sendToLegalRepresentative(ConfidentialLevel.LA)
.sendToJudge(ConfidentialLevel.CTSC)
.sendToCTSC(ConfidentialLevel.CTSC)
.sendToCafcassRepresentative(ConfidentialLevel.LA)
.sendToTranslationTeam(ConfidentialLevel.CTSC)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package uk.gov.hmcts.reform.fpl.model.interfaces;

import com.fasterxml.jackson.annotation.JsonIgnore;
import uk.gov.hmcts.reform.fpl.model.common.DocumentReference;

public interface NotifyDocumentUploaded {
DocumentReference getDocument();

default String getName() {
@JsonIgnore
default String getNameForNotification() {
return getDocument().getFilename();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -88,6 +89,7 @@
import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.getDynamicListSelectedValue;
import static uk.gov.hmcts.reform.fpl.utils.ElementUtils.unwrapElements;

@Slf4j
@Service
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class ManageDocumentService {
Expand Down Expand Up @@ -1165,26 +1167,37 @@ public ManageDocumentsUploadedEvent buildManageDocumentsUploadedEvent(CaseData c

for(DocumentType documentType : DocumentType.values()) {
for(ConfidentialLevel confidentialLevel : resultMapByConfidentialLevel.keySet()) {
String fieldName = documentType.getBaseFieldNameResolver().apply(confidentialLevel);

List documentList = ObjectHelper.getFieldValue(caseData, fieldName, List.class);
List documentListBefore = ObjectHelper.getFieldValue(caseDataBefore, fieldName, List.class);

if (DocumentType.COURT_BUNDLE.equals(documentType) || DocumentType.CASE_SUMMARY.equals(documentType)
|| DocumentType.POSITION_STATEMENTS.equals(documentType)
|| DocumentType.SKELETON_ARGUMENTS.equals(documentType)) {
// TODO
} else {
// Handle ManagedDocument list
for (Object document : documentList) {
if (documentListBefore.contains(document)) {
Map<DocumentType, List<Element<NotifyDocumentUploaded>>> resultMap =
resultMapByConfidentialLevel.get(confidentialLevel);

if (resultMap.containsKey(documentType)) {
resultMap.get(documentType).add((Element<NotifyDocumentUploaded>) document);
if (documentType.getBaseFieldNameResolver() != null) {
String fieldName = documentType.getBaseFieldNameResolver().apply(confidentialLevel);

try {
List documentList = Optional.ofNullable(ObjectHelper
.getFieldValue(caseData, fieldName, List.class)).orElse(List.of());
List documentListBefore = Optional.ofNullable(ObjectHelper
.getFieldValue(caseDataBefore, fieldName, List.class)).orElse(List.of());

if (DocumentType.COURT_BUNDLE.equals(documentType) || DocumentType.CASE_SUMMARY.equals(documentType)
|| DocumentType.POSITION_STATEMENTS.equals(documentType)
|| DocumentType.SKELETON_ARGUMENTS.equals(documentType)) {
// TODO
} else {
// Handle ManagedDocument list
for (Object document : documentList) {
if (!documentListBefore.contains(document)) {
Map<DocumentType, List<Element<NotifyDocumentUploaded>>> newDocMap =
resultMapByConfidentialLevel.get(confidentialLevel);

List<Element<NotifyDocumentUploaded>> docList =
Optional.ofNullable(newDocMap.get(documentType)).orElse(new ArrayList<>());

docList.add((Element<NotifyDocumentUploaded>) document);
newDocMap.putIfAbsent(documentType, docList);
}
}
}
} catch (NoSuchMethodException e) {
log.error("Case File View: No getter for {}. Check configuration of document type: {}",
fieldName, documentType);
}
}
}
Expand Down

0 comments on commit f97e8b0

Please sign in to comment.