Skip to content
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

Dfr 2689 auto date pension sharing annex #1944

Open
wants to merge 79 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
7094b06
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Oct 24, 2024
7e48f09
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Oct 30, 2024
260d15e
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Oct 31, 2024
ea72947
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Oct 31, 2024
0e7ded6
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Oct 31, 2024
cfa1714
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 4, 2024
40dbf6d
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 5, 2024
8932c5c
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 5, 2024
ddf98be
Revert "DFR-2689-Auto-date-pension-sharing-annex"
dawudgovuk Nov 5, 2024
841ed33
WIP
al-hmcts Nov 5, 2024
3c369cd
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 6, 2024
d4d0b6c
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 6, 2024
0f9dc9a
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 6, 2024
56b9a35
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 6, 2024
7a2069d
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 6, 2024
e0e1adb
Add document setup
al-hmcts Nov 6, 2024
12a7ce9
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 6, 2024
845f86a
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 6, 2024
4da16c1
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 6, 2024
3f7a4e0
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 6, 2024
56e4d04
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 6, 2024
9599a67
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 6, 2024
2b35f08
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 6, 2024
9f091cd
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 7, 2024
da5c505
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 7, 2024
8cee1be
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 7, 2024
eb6df0d
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 7, 2024
d081922
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 7, 2024
984e65c
DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 7, 2024
80a6497
DFR-2689-Auto-date-pension-sharing-annex-review-points
dawudgovuk Nov 8, 2024
e5fe041
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 11, 2024
4e212f9
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 11, 2024
5bcb9fd
DFR-2689-Auto-date-pension-sharing-annex-review-points
dawudgovuk Nov 11, 2024
994305a
DFR-2689-Auto-date-pension-sharing-annex-review-points
dawudgovuk Nov 11, 2024
bb84bdb
DFR-2689-Auto-date-pension-sharing-annex-review-2
dawudgovuk Nov 12, 2024
9ff5d3c
DFR-2689-Auto-date-pension-sharing-annex-review-2
dawudgovuk Nov 13, 2024
2cfdc3f
Fix unit test
jthmcts Nov 13, 2024
af21e72
Update exception
jthmcts Nov 13, 2024
3ddc316
DFR-2689-Auto-date-pension-sharing-annex-review-2
dawudgovuk Nov 13, 2024
e272586
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
al-hmcts Nov 13, 2024
f16bb5f
DFR-2689-Auto-date-pension-sharing-annex-review-2
dawudgovuk Nov 13, 2024
de1d712
DFR-2689-Auto-date-pension-sharing-annex-review-2
dawudgovuk Nov 13, 2024
4d4429d
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 13, 2024
415f63f
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 15, 2024
c24ccb9
DFR-2689-Auto-date-pension-sharing-annex-review-2-pdf-font
dawudgovuk Nov 15, 2024
7f7121a
DFR-2689-Auto-date-pension-sharing-annex-embed-pdf-font
dawudgovuk Nov 19, 2024
c948001
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 19, 2024
44a7742
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 19, 2024
c63fefa
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 19, 2024
f2a0d50
DFR-2689-Auto-date-pension-sharing-annex-embed-pdf-font
dawudgovuk Nov 19, 2024
0996972
DFR-2689-Auto-date-pension-sharing-annex-embed-pdf-font
dawudgovuk Nov 20, 2024
da14197
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 20, 2024
02b5ffc
DFR-2689-Auto-date-pension-sharing-annex-embed-pdf-font
dawudgovuk Nov 21, 2024
a88295b
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 21, 2024
0e38166
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 21, 2024
9ded039
DFR-2689-Auto-date-pension-sharing-annex-embed-pdf-font
dawudgovuk Nov 21, 2024
7265355
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 22, 2024
d5cc76b
DFR-2689-Auto-date-pension-sharing-annex-embed-pdf-font
dawudgovuk Nov 22, 2024
2681d54
DFR-2689-Auto-date-pension-sharing-annex-embed-pdf-font
dawudgovuk Nov 22, 2024
e4d9837
DFR-2689-Auto-date-pension-sharing-annex-embed-pdf-font
dawudgovuk Nov 22, 2024
9c9c924
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 25, 2024
89bc764
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 25, 2024
1c3564b
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 26, 2024
f1c78ad
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Nov 26, 2024
7b7aa5a
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Dec 9, 2024
1cb6bdf
DFR-2689-Auto-date-pension-sharing-annex - add to consented
dawudgovuk Dec 11, 2024
1b08006
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Dec 11, 2024
cca4045
DFR-2689-Auto-date-pension-sharing-annex - add to consented
dawudgovuk Dec 11, 2024
eb40926
DFR-2689-Auto-date-pension-sharing-annex - add Embedded Font
dawudgovuk Dec 12, 2024
eeb49a2
DFR-2689-Auto-date-pension-sharing-annex - add Embedded Font
dawudgovuk Dec 12, 2024
786b9c6
DFR-2689-Auto-date-pension-sharing-annex - add Embedded Font
dawudgovuk Dec 12, 2024
044c8de
DFR-2689-Auto-date-pension-sharing-annex - add Embedded Font
dawudgovuk Dec 12, 2024
7af8874
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Dec 12, 2024
9a03e33
DFR-2689-Auto-date-pension-sharing-annex - add Embedded Font
dawudgovuk Dec 12, 2024
7e0eb32
DFR-2689-Auto-date-pension-sharing-annex - add Embedded Font
dawudgovuk Dec 12, 2024
e7b0fc6
DFR-2689-Auto-date-pension-sharing-annex - add Embedded Font
dawudgovuk Dec 13, 2024
182e573
Merge branch 'master' into DFR-2689-Auto-date-pension-sharing-annex
dawudgovuk Dec 13, 2024
5961746
DFR-2689-Auto-date-pension-sharing-annex - Use Acroform DA
dawudgovuk Dec 13, 2024
3e4fd79
DFR-2689-Auto-date-pension-sharing-annex - Use Acroform DA
dawudgovuk Dec 13, 2024
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 @@ -2,6 +2,10 @@

public class StampDocumentException extends RuntimeException {

public StampDocumentException(String message) {
super(message);
}

public StampDocumentException(String message, Throwable cause) {
super(message, cause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import uk.gov.hmcts.reform.finrem.caseorchestration.service.GenericDocumentService;
import uk.gov.hmcts.reform.finrem.caseorchestration.service.StampType;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -30,6 +31,8 @@
import static org.springframework.util.ObjectUtils.isEmpty;
import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ConsentedStatus.CONSENT_ORDER_MADE;
import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CCDConfigConstant.APPROVED_ORDER_COLLECTION;
import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CCDConfigConstant.CONSENTED_ORDER_DIRECTION_DATE;
import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CCDConfigConstant.CONTESTED_ORDER_DIRECTION_DATE;
import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CCDConfigConstant.LATEST_CONSENT_ORDER;
import static uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CCDConfigConstant.STATE;

Expand All @@ -44,7 +47,6 @@ public class ApprovedConsentOrderAboutToSubmitHandler implements CallbackHandler
private final DocumentHelper documentHelper;
private final ObjectMapper mapper;


@Override
public boolean canHandle(final CallbackType callbackType, final CaseType caseType,
final EventType eventType) {
Expand All @@ -58,7 +60,7 @@ public GenericAboutToStartOrSubmitCallbackResponse<Map<String, Object>> handle(C
String userAuthorisation) {
CaseDetails caseDetails = callbackRequest.getCaseDetails();
CaseDetails caseDetailsBefore = callbackRequest.getCaseDetailsBefore();
String caseId = String.valueOf(caseDetails.getId());
String caseId = String.valueOf(caseDetails.getId());
log.info("ConsentOrderApprovedAboutToSubmitHandle handle Case ID {}", caseId);

CaseDocument latestConsentOrder = getLatestConsentOrder(caseDetails.getData());
Expand All @@ -77,7 +79,6 @@ private void generateAndPrepareDocuments(String authToken, CaseDetails caseDetai
CaseDetails caseDetailsBefore, CaseDocument latestConsentOrder) {
String caseId = caseDetails.getId().toString();
log.info("Generating and preparing documents for latest consent order, Case ID: {}", caseId);

Map<String, Object> caseData = caseDetails.getData();
StampType stampType = documentHelper.getStampType(caseData);
CaseDocument approvedConsentOrderLetter = consentOrderApprovedDocumentService.generateApprovedConsentOrderLetter(caseDetails, authToken);
Expand All @@ -92,9 +93,9 @@ private void generateAndPrepareDocuments(String authToken, CaseDetails caseDetai
if (Boolean.FALSE.equals(isPensionDocumentsEmpty(caseData))) {
log.info("Pension Documents not empty for case - stamping Pension Documents and adding to approvedOrder for Case ID: {}",
caseId);

LocalDate approvalDate = getApprovalDate(caseData);
List<PensionTypeCollection> stampedPensionDocs = consentOrderApprovedDocumentService.stampPensionDocuments(
documentHelper.getPensionDocuments(caseData), authToken, stampType, caseId);
documentHelper.getPensionDocuments(caseData), authToken, stampType, approvalDate, caseId);
log.info("Generated StampedPensionDocs = {} for Case ID: {}", stampedPensionDocs, caseDetails.getId());
approvedOrder.setPensionDocuments(stampedPensionDocs);
}
Expand Down Expand Up @@ -132,4 +133,23 @@ private Boolean isPensionDocumentsEmpty(Map<String, Object> caseData) {
List<CaseDocument> pensionDocumentsData = documentHelper.getPensionDocumentsData(caseData);
return pensionDocumentsData.isEmpty();
}

private LocalDate getApprovalDate(Map<String, Object> caseData) {
return (caseData.get(CONTESTED_ORDER_DIRECTION_DATE) != null)
? parseLocalDate(caseData, CONTESTED_ORDER_DIRECTION_DATE)
: parseLocalDate(caseData, CONSENTED_ORDER_DIRECTION_DATE);
}

static LocalDate parseLocalDate(Map<String, Object> caseData, String orderDirectionDateKey) {
dawudgovuk marked this conversation as resolved.
Show resolved Hide resolved
if (caseData.get(orderDirectionDateKey) instanceof LocalDate) {
return (LocalDate) caseData.get(orderDirectionDateKey);
} else {
try {
return LocalDate.parse((String) caseData.get(orderDirectionDateKey));
} catch (Exception e) {
log.info("Invalid Approved date of order for key: '" + orderDirectionDateKey + "': " + e.getMessage());
return null;
}
}
Copy link
Contributor

@ptrelease ptrelease Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a test needed/updated for this change?

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import uk.gov.hmcts.reform.finrem.caseorchestration.model.document.BulkPrintDocument;
import uk.gov.hmcts.reform.finrem.caseorchestration.service.documentcatergory.ApprovedConsentOrderDocumentCategoriser;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -64,6 +65,7 @@ public class ConsentOrderApprovedDocumentService {
private final FinremCaseDetailsMapper finremCaseDetailsMapper;
private final BulkPrintCoverLetterDetailsMapper bulkPrintLetterDetailsMapper;
private final ApprovedConsentOrderDocumentCategoriser approvedConsentOrderCategoriser;
private final PensionAnnexDateStampService pensionAnnexDateStampService;

public CaseDocument generateApprovedConsentOrderLetter(CaseDetails caseDetails, String authToken) {
String fileName;
Expand Down Expand Up @@ -118,19 +120,27 @@ public CaseDocument generateApprovedConsentOrderCoverLetter(FinremCaseDetails ca
public List<PensionTypeCollection> stampPensionDocuments(List<PensionTypeCollection> pensionList,
String authToken,
StampType stampType,
LocalDate approvalDate,
String caseId) {
return pensionList.stream()
.filter(pensionCollectionData -> pensionCollectionData.getTypedCaseDocument().getPensionDocument() != null)
.map(pensionCollectionData -> stampPensionDocuments(pensionCollectionData, authToken, stampType, caseId))
.map(pensionCollectionData -> stampPensionDocuments(pensionCollectionData, authToken, stampType, approvalDate, caseId))
.toList();
}

private PensionTypeCollection stampPensionDocuments(PensionTypeCollection pensionDocument,
String authToken,
StampType stampType,
LocalDate approvalDate,
String caseId) {
CaseDocument document = pensionDocument.getTypedCaseDocument().getPensionDocument();
CaseDocument stampedDocument = genericDocumentService.stampDocument(document, authToken, stampType, caseId);
try {
stampedDocument = pensionAnnexDateStampService.appendApprovedDateToDocument(stampedDocument,
authToken, approvalDate, caseId);
} catch (Exception ex) {
log.info("Failed to add date stamp to Pension Sharing Annex document. Case ID: {} Exception: {}", caseId, ex.getMessage());
}
PensionTypeCollection stampedPensionData = documentHelper.deepCopy(pensionDocument, PensionTypeCollection.class);
stampedPensionData.getTypedCaseDocument().setPensionDocument(stampedDocument);
return stampedPensionData;
Expand Down Expand Up @@ -210,7 +220,8 @@ private List<PensionTypeCollection> consentInContestedStampPensionDocuments(Finr
String caseId) {
List<PensionTypeCollection> pensionDocs = getContestedConsentPensionDocuments(caseData);
StampType stampType = documentHelper.getStampType(caseData);
return stampPensionDocuments(pensionDocs, authToken, stampType, caseId);
LocalDate approvalDate = caseData.getConsentOrderWrapper().getConsentDateOfOrder();
return stampPensionDocuments(pensionDocs, authToken, stampType, approvalDate, caseId);
}

private List<PensionTypeCollection> getContestedConsentPensionDocuments(FinremCaseData caseData) {
Expand Down Expand Up @@ -335,6 +346,8 @@ public void addGeneratedApprovedConsentOrderDocumentsToCase(String userAuthorisa
CaseDocument consentOrderAnnexStamped =
genericDocumentService.annexStampDocument(finremCaseData.getLatestConsentOrder(),
userAuthorisation, stampType, caseId);
LocalDate consentDateOfOrder = finremCaseData.getConsentOrderWrapper().getConsentDateOfOrder();
LocalDate approvalDate = (consentDateOfOrder == null) ? finremCaseData.getOrderDirectionDate() : consentDateOfOrder;

ApprovedOrder approvedOrder = ApprovedOrder.builder()
.orderLetter(approvedConsentOrderLetter)
Expand All @@ -347,7 +360,7 @@ public void addGeneratedApprovedConsentOrderDocumentsToCase(String userAuthorisa
+ "stamping Pension Documents and adding to approvedOrder for Case ID: {}",
caseId);
List<PensionTypeCollection> stampedPensionDocs = stampPensionDocuments(pensionCollection,
userAuthorisation, stampType, caseId);
userAuthorisation, stampType, approvalDate, caseId);
log.info("Generated StampedPensionDocs = {} for Case ID: {}", stampedPensionDocs, caseId);
approvedOrder.setPensionDocuments(stampedPensionDocs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public CaseDocument stampDocument(CaseDocument document,
StampType stampType,
String caseId) {
CaseDocument pdfCaseDocument = convertDocumentIfNotPdfAlready(document, authorisationToken, caseId);
log.info("Pdf converation if document is not pdf origial {} pdfdocument {} for Case ID: {}",
log.info("Pdf conversion if document is not pdf original {} pdfdocument {} for Case ID: {}",
document.getDocumentFilename(), pdfCaseDocument.getDocumentFilename(), caseId);
Document stampedDocument = pdfStampingService.stampDocument(
Document.builder().url(pdfCaseDocument.getDocumentUrl())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package uk.gov.hmcts.reform.finrem.caseorchestration.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
import org.apache.pdfbox.pdmodel.interactive.form.PDField;
import org.apache.pdfbox.pdmodel.interactive.form.PDTextField;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import uk.gov.hmcts.reform.finrem.caseorchestration.error.DocumentStorageException;
import uk.gov.hmcts.reform.finrem.caseorchestration.error.StampDocumentException;
import uk.gov.hmcts.reform.finrem.caseorchestration.model.FinremMultipartFile;
import uk.gov.hmcts.reform.finrem.caseorchestration.model.ccd.CaseDocument;
import uk.gov.hmcts.reform.finrem.caseorchestration.model.document.Document;
import uk.gov.hmcts.reform.finrem.caseorchestration.model.evidence.FileUploadResponse;
import uk.gov.hmcts.reform.finrem.caseorchestration.service.evidencemanagement.EvidenceManagementDownloadService;
import uk.gov.hmcts.reform.finrem.caseorchestration.service.evidencemanagement.EvidenceManagementUploadService;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Optional;

import static org.springframework.http.MediaType.APPLICATION_PDF_VALUE;
import static uk.gov.hmcts.reform.finrem.caseorchestration.service.DocumentManagementService.CONVERTER;

@Service
@RequiredArgsConstructor
@Slf4j
public class PensionAnnexDateStampService {
private final EvidenceManagementUploadService emUploadService;
private final EvidenceManagementDownloadService emDownloadService;
private final GenericDocumentService genericDocumentService;
static final String FORM_P1_DATE_OF_ORDER_TEXTBOX_NAME = "Date the court made/varied/discharged an order";
static final String DATE_STAMP_PATTERN = "dd MMMM yyyy";
private static final String DEFAULT_PDTYPE_FONT_HELV = "/Helv 12 Tf 0 g";

public CaseDocument appendApprovedDateToDocument(CaseDocument document,
String authToken,
LocalDate approvalDate,
String caseId) throws Exception {
log.info("Adding date stamp to Pension Sharing Annex for Case id: {}", caseId);
Optional<LocalDate> optionalApprovalDate = Optional.ofNullable(approvalDate);
if (optionalApprovalDate.isPresent()) {
byte[] docInBytes = emDownloadService.download(document.getDocumentBinaryUrl(), authToken);
byte[] approvedDoc = appendApprovedDateToDocument(docInBytes, approvalDate);
MultipartFile multipartFile =
FinremMultipartFile.builder().name(document.getDocumentFilename()).content(approvedDoc)
.contentType(APPLICATION_PDF_VALUE).build();
List<FileUploadResponse> uploadResponse =
emUploadService.upload(Collections.singletonList(multipartFile), caseId, authToken);
FileUploadResponse fileSaved = Optional.of(uploadResponse.get(0))
.filter(response -> response.getStatus() == HttpStatus.OK)
.orElseThrow(() -> new DocumentStorageException("Failed to store document Case id: " + caseId));
Document dateStampedDocument = CONVERTER.apply(fileSaved);
return genericDocumentService.toCaseDocument(dateStampedDocument);
} else {
throw new StampDocumentException("Missing or Invalid Approved Date of Order for Case id: " + caseId);
}
}

private byte[] appendApprovedDateToDocument(byte[] inputDocInBytes, LocalDate approvalDate) throws StampDocumentException, IOException {
PDDocument doc = Loader.loadPDF(inputDocInBytes);
doc.setAllSecurityToBeRemoved(true);
Optional<PDAcroForm> acroForm = Optional.ofNullable(doc.getDocumentCatalog().getAcroForm());
if (acroForm.isPresent() && acroForm.get().getField(FORM_P1_DATE_OF_ORDER_TEXTBOX_NAME) != null
&& (acroForm.get().getField(FORM_P1_DATE_OF_ORDER_TEXTBOX_NAME) instanceof PDTextField)) {
PDField field = acroForm.get().getField(FORM_P1_DATE_OF_ORDER_TEXTBOX_NAME);
PDTextField textBox = (PDTextField) field;
textBox.setDefaultAppearance(DEFAULT_PDTYPE_FONT_HELV);
textBox.setValue(approvalDate.format(DateTimeFormatter.ofPattern(DATE_STAMP_PATTERN).withLocale(Locale.UK)));
ByteArrayOutputStream outputBytes = new ByteArrayOutputStream();
doc.save(outputBytes);
doc.close();
return outputBytes.toByteArray();
} else {
throw new StampDocumentException("Pension Order document PDF is flattened / not editable.");
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like textBox.getDefaultAppearance() returns a string. So you could try isBlank rather than the null and empty check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd pass case id in, so I could include in the exception. Just slightly easier for support :-D

Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void given_case_when_NotPaperApplication_then_shouldNotTriggerConsentOrderApprov
}

@Test
void givenCase_whenNoPendsion_thenShouldUpdateStateToConsentOrderMadeAndBulkPrint() {
void givenCase_whenNoPension_thenShouldUpdateStateToConsentOrderMadeAndBulkPrint() {
CallbackRequest callbackRequest =
doValidCaseDataSetUp(NO_PENSION_VALID_JSON);
whenServiceGeneratesDocument().thenReturn(caseDocument());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New function getApprovalDate has been added to this handler. That can either take caseData with a LocalDate or String and responds with a null or OK string. Given that, suggest a test.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import uk.gov.hmcts.reform.finrem.caseorchestration.service.evidencemanagement.EvidenceManagementUploadService;

import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -318,7 +319,7 @@ public void givenNullDocumentInPensionDocuments_whenStampingDocuments_thenTheNul
asList(pensionDocumentData(), pensionCollectionDataWithNullDocument);

List<PensionTypeCollection> stampPensionDocuments = consentOrderApprovedDocumentService
.stampPensionDocuments(pensionDocuments, AUTH_TOKEN, StampType.FAMILY_COURT_STAMP, caseId);
.stampPensionDocuments(pensionDocuments, AUTH_TOKEN, StampType.FAMILY_COURT_STAMP, LocalDate.now(), caseId);

assertThat(stampPensionDocuments, hasSize(1));
}
Expand Down
Loading