Search in sources :

Example 1 with CaveatCallbackRequest

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());
    }
}
Also used : ResponseCaveatDetails(uk.gov.hmcts.probate.model.exceptionrecord.ResponseCaveatDetails) CaveatDetails(uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatDetails) ExceptionRecordCaveatDetails(uk.gov.hmcts.probate.model.ccd.caveat.request.ExceptionRecordCaveatDetails) ExceptionRecordRequest(uk.gov.hmcts.probate.model.exceptionrecord.ExceptionRecordRequest) HashMap(java.util.HashMap) OCRMappingException(uk.gov.hmcts.probate.exception.OCRMappingException) ArrayList(java.util.ArrayList) OCRField(uk.gov.hmcts.probate.model.ocr.OCRField) LocalDate(java.time.LocalDate) OCRMappingException(uk.gov.hmcts.probate.exception.OCRMappingException) CaveatCallbackResponse(uk.gov.hmcts.probate.model.ccd.caveat.response.CaveatCallbackResponse) CaveatCallbackRequest(uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatCallbackRequest) ExceptionRecordCaveatDetails(uk.gov.hmcts.probate.model.ccd.caveat.request.ExceptionRecordCaveatDetails)

Example 2 with CaveatCallbackRequest

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());
}
Also used : CaveatDetails(uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatDetails) CaveatCallbackRequest(uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatCallbackRequest) ArrayList(java.util.ArrayList) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) Test(org.junit.Test)

Example 3 with CaveatCallbackRequest

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());
}
Also used : CaveatDetails(uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatDetails) CaveatCallbackRequest(uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatCallbackRequest) ArrayList(java.util.ArrayList) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) SendLetterResponse(uk.gov.hmcts.reform.sendletter.api.SendLetterResponse) Test(org.junit.Test)

Example 4 with CaveatCallbackRequest

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));
}
Also used : CaveatDetails(uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatDetails) CaveatData(uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatData) ResponseCaveatData(uk.gov.hmcts.probate.model.ccd.caveat.response.ResponseCaveatData) CaveatCallbackRequest(uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatCallbackRequest) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) Document(uk.gov.hmcts.probate.model.ccd.raw.Document) CaveatCallbackResponse(uk.gov.hmcts.probate.model.ccd.caveat.response.CaveatCallbackResponse) Test(org.junit.Test)

Example 5 with CaveatCallbackRequest

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());
}
Also used : CaveatDetails(uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatDetails) CaveatCallbackRequest(uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatCallbackRequest) ArrayList(java.util.ArrayList) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) Test(org.junit.Test)

Aggregations

CaveatCallbackRequest (uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatCallbackRequest)25 CaveatDetails (uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatDetails)25 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)17 List (java.util.List)16 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)15 CaveatData (uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatData)10 Document (uk.gov.hmcts.probate.model.ccd.raw.Document)10 CaveatCallbackResponse (uk.gov.hmcts.probate.model.ccd.caveat.response.CaveatCallbackResponse)8 SendLetterResponse (uk.gov.hmcts.reform.sendletter.api.SendLetterResponse)7 ResponseCaveatData (uk.gov.hmcts.probate.model.ccd.caveat.response.ResponseCaveatData)6 ProbateAddress (uk.gov.hmcts.probate.model.ccd.ProbateAddress)4 DocumentLink (uk.gov.hmcts.probate.model.ccd.raw.DocumentLink)4 LocalDate (java.time.LocalDate)2 LetterV3 (uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3)2 IOException (java.io.IOException)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 Optional.ofNullable (java.util.Optional.ofNullable)1