use of uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatCallbackRequest in project probate-back-office by hmcts.
the class ExceptionRecordService method updateCaveatCaseFromExceptionRecord.
public SuccessfulCaveatUpdateResponse updateCaveatCaseFromExceptionRecord(CaveatCaseUpdateRequest erCaseUpdateRequest) {
List<String> errors = new ArrayList<String>();
ExceptionRecordRequest erRequest = erCaseUpdateRequest.getExceptionRecord();
ExceptionRecordCaveatDetails exceptionRecordCaveatDetails = erCaseUpdateRequest.getCaveatDetails();
CaveatDetails caveatDetails = new CaveatDetails(exceptionRecordCaveatDetails.getData(), null, exceptionRecordCaveatDetails.getExceptionRecordId());
HashMap<String, String> ocrFieldValues = new HashMap<String, String>();
List<OCRField> ocrFields = erRequest.getOcrFields();
String caseReference = null;
ocrFields.forEach(ocrField -> {
ocrFieldValues.put(ocrField.getName(), ocrField.getValue());
});
try {
log.info("About to update Caveat expiry date extention for case: {}", erRequest.getExceptionRecordId());
if (StringUtils.isNotBlank(ocrFieldValues.get(CAVEAT_EXTEND_CASE_REFERENCE_KEY)) && (StringUtils.isNotBlank(caveatDetails.getId().toString()))) {
caseReference = ocrFieldValues.get(CAVEAT_EXTEND_CASE_REFERENCE_KEY);
}
Assert.notEmpty(erRequest.getScannedDocuments(), "Missing scanned documents in Exception Record");
// Create CaveatCallbackRequest
CaveatCallbackRequest caveatCallbackRequest = new CaveatCallbackRequest(caveatDetails);
// Add scanned documents
log.info("Mapping Caveat Scanned Documents to case.");
uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatData caveatData = caveatDetails.getData();
int originalScannedNumber = caveatCallbackRequest.getCaseDetails().getData().getScannedDocuments().size();
caveatCallbackRequest.getCaseDetails().getData().setScannedDocuments(mergeScannedDocuments(caveatData.getScannedDocuments(), erRequest.getScannedDocuments(), erRequest.getExceptionRecordId()));
Assert.isTrue(originalScannedNumber < caveatDetails.getData().getScannedDocuments().size(), "Number of scanned documents has not increased");
// Validate caveat extension
log.info("Validating caveat extension.");
CaveatCallbackResponse caveatCallbackResponse = eventValidationService.validateCaveatRequest(caveatCallbackRequest, validationRuleCaveatsExpiry);
if (caveatCallbackResponse.getErrors().isEmpty()) {
LocalDate defaultExpiry = caveatCallbackRequest.getCaseDetails().getData().getExpiryDate().plusMonths(CAVEAT_EXPIRY_EXTENSION_PERIOD_IN_MONTHS);
log.info("No errors found with validateCaveatRequest, updating expiryDate to {} in request.", defaultExpiry.format(CaveatCallbackResponseTransformer.dateTimeFormatter));
caveatCallbackRequest.getCaseDetails().getData().setExpiryDate(defaultExpiry);
log.info("Calling caveatExtend to notify of caveator of extension.");
caveatCallbackResponse = caveatNotificationService.caveatExtend(caveatCallbackRequest);
if (!caveatDetails.getId().toString().equals(caseReference)) {
if (caveatCallbackResponse.getWarnings() == null) {
caveatCallbackResponse.setWarnings(new ArrayList());
}
caveatCallbackResponse.getWarnings().add("Case retrieved does not match OCR data for caseReference");
}
log.info("Call to caveatExtend was successful.");
} else {
throw new OCRMappingException(caveatCallbackResponse.getErrors().get(0));
}
return SuccessfulCaveatUpdateResponse.builder().caseUpdateDetails(ResponseCaveatDetails.builder().caseData(caveatCallbackResponse.getCaveatData()).build()).warnings(caveatCallbackResponse.getWarnings()).build();
} catch (Exception e) {
log.error("Error Extending Caveat case from Exception Record", e);
throw new OCRMappingException(e.getMessage());
}
}
use of uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatCallbackRequest in project probate-back-office by hmcts.
the class CaveatNotificationServiceTest method testCaveatRaiseWithEmail.
@Test
public void testCaveatRaiseWithEmail() throws NotificationClientException {
caveatData = CaveatData.builder().caveatRaisedEmailNotificationRequested("Yes").build();
documents.add(sentEmail);
responseCaveatData = ResponseCaveatData.builder().notificationsGenerated(DOCUMENTS_LIST).build();
caveatDetails = new CaveatDetails(caveatData, LAST_MODIFIED, ID);
caveatCallbackRequest = new CaveatCallbackRequest(caveatDetails);
paymentResponse = PaymentResponse.builder().build();
when(eventValidationService.validateCaveatRequest(any(CaveatCallbackRequest.class), any(List.class))).thenReturn(caveatCallbackResponse.builder().errors(new ArrayList<>()).build());
when(notificationService.sendCaveatEmail(State.CAVEAT_RAISED, caveatDetails)).thenReturn(Document.builder().documentFileName(SENT_EMAIL_FILE_NAME).build());
caveatCallbackResponse = CaveatCallbackResponse.builder().caveatData(responseCaveatData).build();
when(caveatCallbackResponseTransformer.caveatRaised(caveatCallbackRequest, paymentResponse, documents, null)).thenReturn(caveatCallbackResponse);
caveatNotificationService.caveatRaise(caveatCallbackRequest);
assertEquals(1, caveatCallbackResponse.getCaveatData().getNotificationsGenerated().size());
}
use of uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatCallbackRequest in project probate-back-office by hmcts.
the class CaveatNotificationServiceTest method testCaveatExtendWithNoEmailBulkPrintValidSendLetter.
@Test
public void testCaveatExtendWithNoEmailBulkPrintValidSendLetter() throws NotificationClientException {
caveatData = CaveatData.builder().caveatRaisedEmailNotificationRequested("No").sendToBulkPrintRequested("Yes").build();
responseCaveatData = ResponseCaveatData.builder().registryLocation("leeds").caveatorEmailAddress("caveator@probate-test.com").deceasedForenames("name").deceasedSurname("name").caveatRaisedEmailNotificationRequested("Yes").notificationsGenerated(DOCUMENTS_LIST_CAVEAT_EXTENDED).build();
documents.add(coversheet);
documents.add(caveatExtended);
caveatCallbackResponse = CaveatCallbackResponse.builder().caveatData(responseCaveatData).build();
caveatDetails = new CaveatDetails(caveatData, LAST_MODIFIED, ID);
caveatCallbackRequest = new CaveatCallbackRequest(caveatDetails);
SendLetterResponse sendLetterResponse = new SendLetterResponse(UUID.randomUUID());
when(caveatDocmosisService.caseDataAsPlaceholders(caveatDetails)).thenReturn(placeholders);
when(pdfManagementService.generateDocmosisDocumentAndUpload(placeholders, CAVEAT_COVERSHEET)).thenReturn(coversheet);
when(pdfManagementService.generateDocmosisDocumentAndUpload(placeholders, CAVEAT_EXTENDED)).thenReturn(caveatExtended);
when(bulkPrintService.sendToBulkPrintForCaveat(caveatCallbackRequest, caveatExtended, coversheet)).thenReturn(sendLetterResponse);
when(eventValidationService.validateCaveatBulkPrintResponse(eq(sendLetterResponse.letterId.toString()), any(List.class))).thenReturn(caveatCallbackResponse.builder().errors(new ArrayList<>()).build());
when(caveatCallbackResponseTransformer.caveatExtendExpiry(caveatCallbackRequest, documents, sendLetterResponse.letterId.toString())).thenReturn(caveatCallbackResponse);
caveatNotificationService.caveatExtend(caveatCallbackRequest);
assertEquals(2, caveatCallbackResponse.getCaveatData().getNotificationsGenerated().size());
}
use of uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatCallbackRequest in project probate-back-office by hmcts.
the class CaveatNotificationServiceTest method testWithDrawEmail.
@Test
public void testWithDrawEmail() throws NotificationClientException {
CaveatData caveatData = CaveatData.builder().caveatRaisedEmailNotificationRequested("Yes").caveatorEmailAddress("caveator@probate-test.com").build();
caveatDetails = new CaveatDetails(caveatData, LAST_MODIFIED, ID);
caveatCallbackRequest = new CaveatCallbackRequest(caveatDetails);
CaveatCallbackResponse caveatCallbackResponse = CaveatCallbackResponse.builder().errors(new ArrayList<>()).build();
Document document = Document.builder().build();
when(notificationService.sendCaveatEmail(eq(State.CAVEAT_WITHDRAW), eq(caveatDetails))).thenReturn(document);
when(eventValidationService.validateCaveatRequest(eq(caveatCallbackRequest), isA(List.class))).thenReturn(caveatCallbackResponse);
caveatNotificationService.withdraw(caveatCallbackRequest);
ArgumentCaptor<List<Document>> listArgumentCaptor = ArgumentCaptor.forClass(List.class);
verify(caveatCallbackResponseTransformer).withdrawn(eq(caveatCallbackRequest), listArgumentCaptor.capture(), isNull());
List<Document> passedDocument = listArgumentCaptor.getValue();
assertEquals("Document matched", passedDocument.get(0), document);
verify(notificationService).sendCaveatEmail(eq(State.CAVEAT_WITHDRAW), eq(caveatDetails));
verify(eventValidationService).validateCaveatRequest(eq(caveatCallbackRequest), isA(List.class));
}
use of uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatCallbackRequest in project probate-back-office by hmcts.
the class CaveatNotificationServiceTest method testCaveatExtendWithError.
@Test
public void testCaveatExtendWithError() throws NotificationClientException {
caveatData = CaveatData.builder().caveatRaisedEmailNotificationRequested("Yes").build();
documents.add(sentEmail);
responseCaveatData = ResponseCaveatData.builder().notificationsGenerated(DOCUMENTS_LIST).build();
caveatDetails = new CaveatDetails(caveatData, LAST_MODIFIED, ID);
caveatCallbackRequest = new CaveatCallbackRequest(caveatDetails);
caveatCallbackResponse = caveatCallbackResponse.builder().errors(new ArrayList<>(Arrays.asList("error1"))).build();
when(eventValidationService.validateCaveatRequest(any(CaveatCallbackRequest.class), any(List.class))).thenReturn(caveatCallbackResponse);
caveatNotificationService.caveatExtend(caveatCallbackRequest);
assertEquals(1, caveatCallbackResponse.getErrors().size());
}
Aggregations