Skip to content

Commit

Permalink
DFR-3560: Fix Process Order document stamping (#2117)
Browse files Browse the repository at this point in the history
* Change "Is Final?" field to checkbox

* fix tests in DraftOrderServiceTest

* checkstyle

* Add @requiredargsconstructor

* Tests for ApproveOrderService

* Move methods into HearingProcessor

* refused order population

* remove extra blank line

* Remove blank lines.

* tidy up

* bug fix

* checkstyle fix

* Missing refusal date in the report parameter

* add tobuilder

* Add tests to JudgeApprovalResolverTest

* Making use of ContestedDraftOrderNotApprovedDetailsMapper and refactor the unit tests.

* Remove extra blank line

* add private a constructor

* Fix a bug that not showing judge name

* update judge details logic

* Remove extra blank line.

* Generate Refusal order for PSA.

* rename titleInJudgeDecisionMessage to inlineDocType

* Add tests to JudgeApprovalResolverTest

* Add tests to HearingProcessorTest

* Remove commented tests.

* wrong property

* Improve coverage and improve tests

* FileUtils method for inserting timestamp to a filename.

* insert timestamp to the refusal order filename.

* Add getter for order status

* refactor mock for approvables and verify order status

* Improve coverage

* fix import

* Remove refused order from AgreedDraftOrderCollection

* Java Docs added

* Remove @SPY in ApproveOrderServiceTest

* remove @SPY and improve test setup

* Add email template id

* remove an extra blank line.

* typo

* add judgeFeedback and documentName

* capture submitted by email address and populate them to AgreedDraftOrder and SuggestedDraftOrder.

* Add hearingDate to JudgeApproval

* add test case for the submitted handler.

* apply submitted email only when upload party is null.

* remove a blank line.

* Improve tests in JudgeApprovalResolverTest and add getters

* Setting refusalOrderIdsToBeSent

* clear refusalOrderIdsToBeSent on about-to-start

* throw exception instead

* EL

* Remove test

* revert

* revert

* revert comment

* Email notification logic.

* use @JsonIgnore

* javadoc

* Fix NPE

* Fix NPE

* use @JsonIgnore for getters

* Use fixedDateTime

* code format

* Renamed

* add test case

* checkstyle

* Add a TODO for sending notification by post.

* JavaDoc

* Java docs

* JavaDoc

* JavaDoc

* remove extra spaces

* tidy up

* Rename

* Renamed

* missing colon

* Test case fixed.

* add a comment.

* Sending Post Logic (WIP)

* Refactoring CaseDataService - deprecating methods and making use of FinremCaseData and FinremCaseDetails

* checkstyle

* checkstyle

* update test case

* Added test cases

* Add test cases

* tidy up

* fix

* Change to assertEquals

* Update test cases

* Use anyMap()

* Use anyMap()

* tidy up

* tidy up

* Add test case.

* increase code coverage.

* Use anyMap()

* anyMap()

* checkstyle

* Enable bulkprint

* missing import

* DFR-3334 Add Hearing Judge to Approve Orders Page.

* NL

* Remove notification by post logic

* Check PSA for validating attachments

* Remove unused imports

* Add test case

* Test case for DraftOrdersNotificationRequestMapperTest

* Remove unused injections.

* Update test case to increase code coverage.

* Test case in NotificationServiceTest

* checkstyle

* Test case for refusal order generation

* update test cases.

* checkstyle

* typo

* Comment updated.

* Method renamed

* java doc

* Revert "java doc"

This reverts commit 518fa6b.

* renamed

* missing personalisation

* update test case.

* missing hearingDate

* refactoring

* DFR-3494 Add Hearing Judge to Approve Orders Page (#2028)

* DFR-3334 Add Hearing Judge to Approve Orders Page.

* NL

* Check PSA for validating attachments

* Remove unused imports

---------

Co-authored-by: Ashley Wong <[email protected]>

* Remove an extra blank line.

* Move Approvable, HasSubmittedInfo, RefusalOrderConvertible and HasApprovable in draftorder package.

* checkstyle

* enhanced readibility

* add test case for example.txt.txt

* Fix

* Fix merge conflicts

* checkstyle

* Remove extra line

* DFR-3495 capture judge type (#2050)

* DFR-3495 Capturing Refusal Order Judge Title

* Update test case.

* update unit test

* Fix test case

* Linked with the class by calling Class.getSimpleName()

* Remove an extra blank line.

* typo

* auto configuration

* checkstyle

* Auto Resolving Complex Type

* readability

* compare it in lowercase

* reverting all

* Fix NPE

* Bug fix

* NPE

* Bug fix

* simplifying

* Add a warning message.

* Trigger build

* underscore missing

* change to info

* warning message bug

* update warning message

---------

Co-authored-by: Ashley Wong <[email protected]>

* Add OrderParty property

* Add test for OrderParty static method

* Rename test classes to match source classes

* Update OrderParty enum

* Revert missing unit test

* Increase test coverage

* Refactor test

* Refactor test

* Include other roles that can upload draft orders

* Include other roles that should see upload on behalf of question

* Add orderFiledBy property

* Name change

* Change barrister text value for OrderFiledBy enum

* Refactor switch

* Add javadoc to DraftOrdersCategoriser

* Send refused order notifications

* Refactor

* Fix unit test

* Fix unit test

* Refactor

* Any comment

* Fix document stamping of processed orders

* Refactor

* Refactor

---------

Co-authored-by: Ashley Wong <[email protected]>
Co-authored-by: hamzahtahirhmcts <[email protected]>
Co-authored-by: Ashley Wong <[email protected]>
  • Loading branch information
4 people authored Feb 3, 2025
1 parent 7150535 commit 036de43
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import uk.gov.hmcts.reform.finrem.caseorchestration.service.draftorders.HasApprovableCollectionReader;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.util.Optional.ofNullable;
import static java.util.function.Predicate.not;
Expand Down Expand Up @@ -86,9 +88,11 @@ public GenericAboutToStartOrSubmitCallbackResponse<FinremCaseData> handle(Finrem
.data(caseData).errors(List.of("There was an unexpected error")).build();
}

handleDraftOrderDocuments(caseDetails, userAuthorisation);
handlePsaDocuments(caseDetails, userAuthorisation);
handleAgreedDraftOrdersCollection(caseDetails, userAuthorisation);
Map<String, CaseDocument> stampedDocuments = getStampedDocuments(caseData, userAuthorisation, caseId);

handleDraftOrderDocuments(caseData, stampedDocuments);
handlePsaDocuments(caseData, stampedDocuments);
handleAgreedDraftOrdersCollection(caseData, stampedDocuments);
clearTemporaryFields(caseData);

return GenericAboutToStartOrSubmitCallbackResponse.<FinremCaseData>builder().data(caseData).errors(errors).build();
Expand All @@ -106,78 +110,92 @@ private void handleNewDocumentInUnprocessedApprovedDocuments(FinremCaseData case
});
}

private void handleDraftOrderDocuments(FinremCaseDetails caseDetails, String authorisation) {
FinremCaseData caseData = caseDetails.getData();
private Map<String, CaseDocument> getStampedDocuments(FinremCaseData caseData, String userAuthorisation, String caseId) {
Map<String, CaseDocument> stampedDocuments = new HashMap<>();
StampType stampType = documentHelper.getStampType(caseData);
String documentCategoryId = DocumentCategory.APPROVED_ORDERS.getDocumentCategoryId();
List<DirectionOrderCollection> unprocessedApprovedDocuments = nullSafeUnprocessedApprovedDocuments(caseData);

unprocessedApprovedDocuments.forEach(doc -> {
if (!isNewDocument(doc)) {
CaseDocument originalDocument = doc.getValue().getOriginalDocument();
CaseDocument uploadedDocument = doc.getValue().getUploadDraftDocument();
CaseDocument stampedDocument = genericDocumentService.stampDocument(uploadedDocument, userAuthorisation,
stampType, caseId);
stampedDocument.setCategoryId(documentCategoryId);

stampedDocuments.put(originalDocument.getDocumentUrl(), stampedDocument);
}
});

return stampedDocuments;
}

private void handleDraftOrderDocuments(FinremCaseData caseData, Map<String, CaseDocument> stampedDocuments) {
List<DraftOrderDocReviewCollection> collector = new ArrayList<>();

hasApprovableCollectionReader.filterAndCollectDraftOrderDocs(caseData.getDraftOrdersWrapper().getDraftOrdersReviewCollection(),
collector, APPROVED_BY_JUDGE::equals);

getApprovedDocumentsToProcess(caseData)
.forEach(unprocessedApprovedOrder ->
collector.stream().filter(psa -> doesDocumentMatch(psa, unprocessedApprovedOrder)).forEach(toBeUpdated -> {

StampType stampType = documentHelper.getStampType(caseData);
CaseDocument stampedDoc = genericDocumentService.stampDocument(
unprocessedApprovedOrder.getValue().getUploadDraftDocument(), authorisation, stampType,
String.valueOf(caseDetails.getId()));
stampedDoc.setCategoryId(
DocumentCategory.APPROVED_ORDERS.getDocumentCategoryId());

toBeUpdated.getValue().setOrderStatus(PROCESSED);
toBeUpdated.getValue().setDraftOrderDocument(stampedDoc);
}));
}

private void handlePsaDocuments(FinremCaseDetails caseDetails, String authorisation) {
FinremCaseData caseData = caseDetails.getData();
collector.stream()
.filter(psa -> doesDocumentMatch(psa, unprocessedApprovedOrder))
.map(DraftOrderDocReviewCollection::getValue)
.forEach(draftOrderDocumentReview -> {
CaseDocument originalDocument = draftOrderDocumentReview.getDraftOrderDocument();
CaseDocument stampedDocument = stampedDocuments.get(originalDocument.getDocumentUrl());
draftOrderDocumentReview.setOrderStatus(PROCESSED);
draftOrderDocumentReview.setDraftOrderDocument(stampedDocument);
})
);
}

private void handlePsaDocuments(FinremCaseData caseData, Map<String, CaseDocument> stampedDocuments) {
List<PsaDocReviewCollection> psaCollector = new ArrayList<>();

hasApprovableCollectionReader.filterAndCollectPsaDocs(caseData.getDraftOrdersWrapper().getDraftOrdersReviewCollection(),
psaCollector, APPROVED_BY_JUDGE::equals);

getApprovedDocumentsToProcess(caseData)
.forEach(unprocessedApprovedOrder ->
psaCollector.stream().filter(psa -> doesDocumentMatch(psa, unprocessedApprovedOrder)).forEach(toBeUpdated -> {

StampType stampType = documentHelper.getStampType(caseData);
CaseDocument stampedDoc = genericDocumentService.stampDocument(
unprocessedApprovedOrder.getValue().getUploadDraftDocument(), authorisation, stampType,
String.valueOf(caseDetails.getId()));
stampedDoc.setCategoryId(
DocumentCategory.APPROVED_ORDERS.getDocumentCategoryId());

toBeUpdated.getValue().setOrderStatus(PROCESSED);
toBeUpdated.getValue().setPsaDocument(stampedDoc);
}));
}

private void handleAgreedDraftOrdersCollection(FinremCaseDetails caseDetails, String authorisation) {
FinremCaseData caseData = caseDetails.getData();
psaCollector.stream()
.filter(psa -> doesDocumentMatch(psa, unprocessedApprovedOrder))
.map(PsaDocReviewCollection::getValue)
.forEach(psaDocumentReview -> {
CaseDocument originalDocument = psaDocumentReview.getPsaDocument();
CaseDocument stampedDocument = stampedDocuments.get(originalDocument.getDocumentUrl());
psaDocumentReview.setOrderStatus(PROCESSED);
psaDocumentReview.setPsaDocument(stampedDocument);
})
);
}

private void handleAgreedDraftOrdersCollection(FinremCaseData caseData, Map<String, CaseDocument> stampedDocuments) {
List<AgreedDraftOrderCollection> agreedOrderCollector = new ArrayList<>();

hasApprovableCollectionReader.collectAgreedDraftOrders(caseData.getDraftOrdersWrapper().getAgreedDraftOrderCollection(),
agreedOrderCollector, APPROVED_BY_JUDGE::equals);

getApprovedDocumentsToProcess(caseData)
.forEach(unprocessedApprovedOrder ->
agreedOrderCollector.stream().filter(agreedDraftOrder -> doesDocumentMatch(agreedDraftOrder, unprocessedApprovedOrder))
.forEach(toBeUpdated -> {

StampType stampType = documentHelper.getStampType(caseData);
CaseDocument stampedDoc = genericDocumentService.stampDocument(
unprocessedApprovedOrder.getValue().getUploadDraftDocument(), authorisation, stampType,
String.valueOf(caseDetails.getId()));
stampedDoc.setCategoryId(unprocessedApprovedOrder.getValue().getUploadDraftDocument().getCategoryId());

toBeUpdated.getValue().setOrderStatus(PROCESSED);
// replace the document by the new stamped document
if (toBeUpdated.getValue().getPensionSharingAnnex() != null) {
toBeUpdated.getValue().setPensionSharingAnnex(stampedDoc);
} else if (toBeUpdated.getValue().getDraftOrder() != null) {
toBeUpdated.getValue().setDraftOrder(stampedDoc);
agreedOrderCollector.stream()
.filter(agreedDraftOrder -> doesDocumentMatch(agreedDraftOrder, unprocessedApprovedOrder))
.map(AgreedDraftOrderCollection::getValue)
.forEach(agreedDraftOrder -> {
if (agreedDraftOrder.getDraftOrder() != null) {
CaseDocument originalDocument = agreedDraftOrder.getDraftOrder();
CaseDocument stampedDocument = stampedDocuments.get(originalDocument.getDocumentUrl());
agreedDraftOrder.setOrderStatus(PROCESSED);
agreedDraftOrder.setDraftOrder(stampedDocument);
} else if (agreedDraftOrder.getPensionSharingAnnex() != null) {
CaseDocument originalDocument = agreedDraftOrder.getPensionSharingAnnex();
CaseDocument stampedDocument = stampedDocuments.get(originalDocument.getDocumentUrl());
agreedDraftOrder.setOrderStatus(PROCESSED);
agreedDraftOrder.setPensionSharingAnnex(stampedDocument);
}
}));
})
);
}

private void insertNewDocumentToUploadHearingOrder(FinremCaseData caseData, DirectionOrderCollection unprocessedApprovedOrder) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.hmcts.reform.finrem.caseorchestration.service.judgeapproval;

import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.FinremCaseDetails;
import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.JudgeType;
Expand Down Expand Up @@ -124,6 +125,9 @@ public void processRefusedOrders(FinremCaseDetails finremCaseDetails, DraftOrder
draftOrdersWrapper.setRefusedOrdersCollection(
Stream.concat(existingRefusedOrders.stream(), newRefusedOrders.stream()).toList()
);
if (CollectionUtils.isEmpty(draftOrdersWrapper.getRefusedOrdersCollection())) {
draftOrdersWrapper.setRefusedOrdersCollection(null);
}
}

private void filterRefusedDraftOrderCollections(DraftOrdersWrapper draftOrdersWrapper) {
Expand Down
Loading

0 comments on commit 036de43

Please sign in to comment.