Skip to content

Commit

Permalink
DFR-2689-Auto-date-pension-sharing-annex - add to consented
Browse files Browse the repository at this point in the history
  • Loading branch information
dawudgovuk committed Dec 11, 2024
1 parent 7b7aa5a commit 1cb6bdf
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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 Down Expand Up @@ -60,7 +61,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 Down Expand Up @@ -135,7 +136,13 @@ private Boolean isPensionDocumentsEmpty(Map<String, Object> caseData) {
}

private LocalDate getApprovalDate(Map<String, Object> caseData) {
return Optional.ofNullable(caseData.get(CONTESTED_ORDER_DIRECTION_DATE))
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) {
return Optional.ofNullable(caseData.get(orderDirectionDateKey))
.filter(value -> value instanceof LocalDate || value instanceof String)
.map(value -> {
if (value instanceof LocalDate) {
Expand All @@ -144,14 +151,10 @@ private LocalDate getApprovalDate(Map<String, Object> caseData) {
try {
return LocalDate.parse((String) value);
} catch (Exception e) {
log.info("Invalid Approved date of order for key: '" + CONTESTED_ORDER_DIRECTION_DATE + "': " + e.getMessage());
log.info("Invalid Approved date of order for key: '" + orderDirectionDateKey + "': " + e.getMessage());
return null;
}
}
})
.orElseGet(() -> {
log.info("Approved Date of Order for key: '" + CONTESTED_ORDER_DIRECTION_DATE + "' is null or invalid");
return null;
});
}).get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ public void addGeneratedApprovedConsentOrderDocumentsToCase(String userAuthorisa
CaseDocument consentOrderAnnexStamped =
genericDocumentService.annexStampDocument(finremCaseData.getLatestConsentOrder(),
userAuthorisation, stampType, caseId);
LocalDate approvalDate = finremCaseData.getConsentOrderWrapper().getConsentDateOfOrder();
LocalDate consentDateOfOrder = finremCaseData.getConsentOrderWrapper().getConsentDateOfOrder();
LocalDate approvalDate = (consentDateOfOrder == null) ? finremCaseData.getOrderDirectionDate() : consentDateOfOrder;

ApprovedOrder approvedOrder = ApprovedOrder.builder()
.orderLetter(approvedConsentOrderLetter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class PensionAnnexDateStampService {
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 10 Tf 0 g";
private static final String DEFAULT_PDTYPE_FONT_HELV = "/Helv 12 Tf 0 g";

public CaseDocument appendApprovedDateToDocument(CaseDocument document,
String authToken,
Expand Down Expand Up @@ -74,9 +74,7 @@ private byte[] appendApprovedDateToDocument(byte[] inputDocInBytes, LocalDate ap
&& (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;
if (textBox.getDefaultAppearance().isBlank()) {
textBox.setDefaultAppearance(DEFAULT_PDTYPE_FONT_HELV);
}
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ void shouldAddApprovalDateToPensionOrderDocument() throws Exception {
verifyDateOfOrderField(bytes);
}

@Test
void shouldAddApprovalDateToPensionOrderDocumentWithNoEmbeddedFonts() throws Exception {
byte[] docInBytes = loadResource("/fixtures/P1_pension_sharing_annex_no_embedded_font.pdf");
when(emDownloadService.download(document.getDocumentBinaryUrl(), AUTH_TOKEN))
.thenReturn(docInBytes);
when(emUploadService.upload(any(), anyString(), any()))
.thenReturn(fileUploadResponse());
when(genericDocumentService.toCaseDocument(any(Document.class))).thenCallRealMethod();
service.appendApprovedDateToDocument(document, AUTH_TOKEN, approvalDate, caseId);

verify(emUploadService).upload(filesCaptor.capture(), anyString(), anyString());
List<MultipartFile> uploadedMultipartFiles = filesCaptor.getValue();
byte[] bytes = uploadedMultipartFiles.get(0).getBytes();
verifyDateOfOrderField(bytes);
}

@Test
void shouldNotAddApprovalDateToPensionOrderDocumentIfApprovalDateIsMissing() {
Exception exception = assertThrows(Exception.class, () -> service.appendApprovedDateToDocument(document, AUTH_TOKEN, null, caseId));
Expand Down
Binary file not shown.

0 comments on commit 1cb6bdf

Please sign in to comment.