Search in sources :

Example 1 with LetterV3

use of uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3 in project sscs-evidence-share by hmcts.

the class SendLetterServiceConsumerTest method buildLetter.

private LetterV3 buildLetter() throws IOException, URISyntaxException {
    Path pdfPath = Paths.get(ClassLoader.getSystemResource("files/myPdf.pdf").toURI());
    byte[] pdf = Files.readAllBytes(pdfPath);
    String response = Base64.getEncoder().encodeToString(pdf);
    Map<String, Object> additionalData = new HashMap<>();
    additionalData.put(ADDITIONAL_DATA_CASE_REFERENCE, "123421323");
    return new LetterV3(XEROX_TYPE_PARAMETER, Arrays.asList(new Document(response, 2)), additionalData);
}
Also used : Path(java.nio.file.Path) LetterV3(uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3) HashMap(java.util.HashMap) Document(uk.gov.hmcts.reform.sendletter.api.model.v3.Document)

Example 2 with LetterV3

use of uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3 in project probate-back-office by hmcts.

the class BulkPrintService method sendToBulkPrint.

private SendLetterResponse sendToBulkPrint(CallbackRequest callbackRequest, Document grantDocument, Document coverSheet, boolean forReprint) {
    SendLetterResponse sendLetterResponse = null;
    try {
        String authHeaderValue = serviceAuthTokenGenerator.generate();
        Map<String, Object> additionalData = new HashMap<>();
        additionalData.put(ADDITIONAL_DATA_CASE_REFERENCE, callbackRequest.getCaseDetails().getId());
        additionalData = Collections.unmodifiableMap(additionalData);
        List<uk.gov.hmcts.reform.sendletter.api.model.v3.Document> pdfs;
        if (forReprint) {
            pdfs = arrangePdfDocumentsForReprint(callbackRequest, grantDocument, coverSheet, authHeaderValue);
        } else {
            pdfs = arrangePdfDocumentsForBulkPrinting(callbackRequest, grantDocument, coverSheet, authHeaderValue);
        }
        log.info(CASE_ID + callbackRequest.getCaseDetails().getId().toString() + "number of documents is: " + pdfs.size());
        sendLetterResponse = sendLetterApi.sendLetter(BEARER + authHeaderValue, new LetterV3(XEROX_TYPE_PARAMETER, pdfs, additionalData));
        log.info("Letter service produced the following letter Id {} for a pdf size {} for the case id {}", sendLetterResponse.letterId, pdfs.size(), callbackRequest.getCaseDetails().getId());
    } catch (HttpClientErrorException ex) {
        log.error("Error with Http Connection to Bulk Print with response body {} and message {} and code {}", ex.getResponseBodyAsString(), ex.getLocalizedMessage(), ex.getStatusCode());
    } catch (IOException ioe) {
        log.error("Error retrieving document from store with url {}", ioe);
    } catch (Exception e) {
        log.error("Error sending pdfs to bulk print {}", e.getMessage());
    }
    return sendLetterResponse;
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HashMap(java.util.HashMap) IOException(java.io.IOException) Document(uk.gov.hmcts.probate.model.ccd.raw.Document) SendLetterResponse(uk.gov.hmcts.reform.sendletter.api.SendLetterResponse) BulkPrintException(uk.gov.hmcts.probate.exception.BulkPrintException) IOException(java.io.IOException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) LetterV3(uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3)

Example 3 with LetterV3

use of uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3 in project probate-back-office by hmcts.

the class BulkPrintServiceTest method testSuccessfulSendToBulkPrintWithSixExtraCopies.

@Test
public void testSuccessfulSendToBulkPrintWithSixExtraCopies() {
    SolsAddress address = SolsAddress.builder().addressLine1("Address 1").addressLine2("Address 2").postCode("EC2").country("UK").build();
    CaseData caseData = CaseData.builder().primaryApplicantForenames("first").primaryApplicantSurname("last").primaryApplicantAddress(address).extraCopiesOfGrant(6L).build();
    CallbackRequest callbackRequest = new CallbackRequest(new CaseDetails(caseData, null, 0L));
    DocumentLink documentLink = DocumentLink.builder().documentUrl("http://localhost").build();
    Document document = Document.builder().documentFileName("test.pdf").documentGeneratedBy("test").documentType(DocumentType.DIGITAL_GRANT).documentDateAdded(LocalDate.now()).documentLink(documentLink).build();
    Document coverSheet = Document.builder().documentFileName("test.pdf").documentGeneratedBy("test").documentDateAdded(LocalDate.now()).documentLink(documentLink).build();
    UUID uuid = UUID.randomUUID();
    SendLetterResponse sendLetterResponse = new SendLetterResponse(uuid);
    when(sendLetterApiMock.sendLetter(anyString(), any(LetterV3.class))).thenReturn(sendLetterResponse);
    when(documentTransformer.hasDocumentWithType(Collections.singletonList(document), DocumentType.DIGITAL_GRANT)).thenReturn(true);
    SendLetterResponse response = bulkPrintService.sendToBulkPrintForGrant(callbackRequest, document, coverSheet);
    verify(sendLetterApiMock).sendLetter(anyString(), any(LetterV3.class));
    assertNotNull(response);
    assertThat(response.letterId, is(uuid));
}
Also used : LetterV3(uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3) CallbackRequest(uk.gov.hmcts.probate.model.ccd.raw.request.CallbackRequest) CaveatCallbackRequest(uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatCallbackRequest) ResponseCaseData(uk.gov.hmcts.probate.model.ccd.raw.response.ResponseCaseData) CaseData(uk.gov.hmcts.probate.model.ccd.raw.request.CaseData) SolsAddress(uk.gov.hmcts.probate.model.ccd.raw.SolsAddress) CaseDetails(uk.gov.hmcts.probate.model.ccd.raw.request.CaseDetails) Document(uk.gov.hmcts.probate.model.ccd.raw.Document) UUID(java.util.UUID) DocumentLink(uk.gov.hmcts.probate.model.ccd.raw.DocumentLink) SendLetterResponse(uk.gov.hmcts.reform.sendletter.api.SendLetterResponse) Test(org.junit.Test)

Example 4 with LetterV3

use of uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3 in project probate-back-office by hmcts.

the class BulkPrintServiceTest method sendToBulkPrintWith50ExtraCopiesWIG.

@Test
public void sendToBulkPrintWith50ExtraCopiesWIG() {
    SolsAddress address = SolsAddress.builder().addressLine1("Address 1").addressLine2("Address 2").postCode("EC2").country("UK").build();
    CaseData caseData = CaseData.builder().primaryApplicantForenames("first").primaryApplicantSurname("last").primaryApplicantAddress(address).extraCopiesOfGrant(50L).build();
    CallbackRequest callbackRequest = new CallbackRequest(new CaseDetails(caseData, null, 0L));
    DocumentLink documentLink = DocumentLink.builder().documentUrl("http://localhost").build();
    Document document = Document.builder().documentFileName("test.pdf").documentGeneratedBy("test").documentType(DocumentType.WELSH_INTESTACY_GRANT).documentDateAdded(LocalDate.now()).documentLink(documentLink).build();
    Document coverSheet = Document.builder().documentFileName("test.pdf").documentGeneratedBy("test").documentDateAdded(LocalDate.now()).documentLink(documentLink).build();
    UUID uuid = UUID.randomUUID();
    SendLetterResponse sendLetterResponse = new SendLetterResponse(uuid);
    when(sendLetterApiMock.sendLetter(anyString(), any(LetterV3.class))).thenReturn(sendLetterResponse);
    when(documentTransformer.hasDocumentWithType(Collections.singletonList(document), DocumentType.WELSH_INTESTACY_GRANT)).thenReturn(true);
    SendLetterResponse response = bulkPrintService.sendToBulkPrintForGrant(callbackRequest, document, coverSheet);
    verify(sendLetterApiMock).sendLetter(anyString(), any(LetterV3.class));
    assertNotNull(response);
    assertThat(response.letterId, is(uuid));
}
Also used : LetterV3(uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3) CallbackRequest(uk.gov.hmcts.probate.model.ccd.raw.request.CallbackRequest) CaveatCallbackRequest(uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatCallbackRequest) ResponseCaseData(uk.gov.hmcts.probate.model.ccd.raw.response.ResponseCaseData) CaseData(uk.gov.hmcts.probate.model.ccd.raw.request.CaseData) SolsAddress(uk.gov.hmcts.probate.model.ccd.raw.SolsAddress) CaseDetails(uk.gov.hmcts.probate.model.ccd.raw.request.CaseDetails) Document(uk.gov.hmcts.probate.model.ccd.raw.Document) UUID(java.util.UUID) DocumentLink(uk.gov.hmcts.probate.model.ccd.raw.DocumentLink) SendLetterResponse(uk.gov.hmcts.reform.sendletter.api.SendLetterResponse) Test(org.junit.Test)

Example 5 with LetterV3

use of uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3 in project probate-back-office by hmcts.

the class BulkPrintServiceTest method shouldSendToBulkPrintForReprint.

@Test
public void shouldSendToBulkPrintForReprint() {
    SolsAddress address = SolsAddress.builder().addressLine1("Address 1").addressLine2("Address 2").postCode("EC2").country("UK").build();
    CaseData caseData = CaseData.builder().primaryApplicantForenames("first").primaryApplicantSurname("last").primaryApplicantAddress(address).reprintNumberOfCopies("10").build();
    CallbackRequest callbackRequest = new CallbackRequest(new CaseDetails(caseData, null, 0L));
    DocumentLink documentLink = DocumentLink.builder().documentUrl("http://localhost").build();
    Document grant = Document.builder().documentFileName("test.pdf").documentGeneratedBy("test").documentType(DocumentType.DIGITAL_GRANT).documentDateAdded(LocalDate.now()).documentLink(documentLink).build();
    Document coverSheet = Document.builder().documentFileName("test.pdf").documentGeneratedBy("test").documentDateAdded(LocalDate.now()).documentLink(documentLink).build();
    UUID uuid = UUID.randomUUID();
    SendLetterResponse sendLetterResponse = new SendLetterResponse(uuid);
    List<String> errors = new ArrayList<>();
    CallbackResponse callbackResponse = CallbackResponse.builder().data(responseCaseData).errors(errors).build();
    when(sendLetterApiMock.sendLetter(anyString(), letterV3ArgumentCaptor.capture())).thenReturn(sendLetterResponse);
    when(eventValidationService.validateBulkPrintResponse(eq(uuid.toString()), any())).thenReturn(callbackResponse);
    SendLetterResponse response = bulkPrintService.sendDocumentsForReprint(callbackRequest, grant, coverSheet);
    assertEquals(sendLetterResponse, response);
    assertEquals(1, letterV3ArgumentCaptor.getValue().documents.get(0).copies);
    assertEquals(10, letterV3ArgumentCaptor.getValue().documents.get(1).copies);
    verify(sendLetterApiMock).sendLetter(anyString(), any(LetterV3.class));
}
Also used : CallbackRequest(uk.gov.hmcts.probate.model.ccd.raw.request.CallbackRequest) CaveatCallbackRequest(uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatCallbackRequest) ResponseCaseData(uk.gov.hmcts.probate.model.ccd.raw.response.ResponseCaseData) CaseData(uk.gov.hmcts.probate.model.ccd.raw.request.CaseData) SolsAddress(uk.gov.hmcts.probate.model.ccd.raw.SolsAddress) CallbackResponse(uk.gov.hmcts.probate.model.ccd.raw.response.CallbackResponse) CaseDetails(uk.gov.hmcts.probate.model.ccd.raw.request.CaseDetails) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Document(uk.gov.hmcts.probate.model.ccd.raw.Document) DocumentLink(uk.gov.hmcts.probate.model.ccd.raw.DocumentLink) SendLetterResponse(uk.gov.hmcts.reform.sendletter.api.SendLetterResponse) LetterV3(uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

LetterV3 (uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3)24 SendLetterResponse (uk.gov.hmcts.reform.sendletter.api.SendLetterResponse)21 Document (uk.gov.hmcts.probate.model.ccd.raw.Document)17 UUID (java.util.UUID)15 CaveatCallbackRequest (uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatCallbackRequest)15 DocumentLink (uk.gov.hmcts.probate.model.ccd.raw.DocumentLink)15 Test (org.junit.Test)14 SolsAddress (uk.gov.hmcts.probate.model.ccd.raw.SolsAddress)12 CallbackRequest (uk.gov.hmcts.probate.model.ccd.raw.request.CallbackRequest)12 CaseData (uk.gov.hmcts.probate.model.ccd.raw.request.CaseData)12 CaseDetails (uk.gov.hmcts.probate.model.ccd.raw.request.CaseDetails)12 ResponseCaseData (uk.gov.hmcts.probate.model.ccd.raw.response.ResponseCaseData)12 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Test (org.junit.jupiter.api.Test)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 ConfidentialDivorceDocument (uk.gov.hmcts.divorce.document.model.ConfidentialDivorceDocument)5 Letter (uk.gov.hmcts.divorce.document.print.model.Letter)5 Print (uk.gov.hmcts.divorce.document.print.model.Print)5 CallbackResponse (uk.gov.hmcts.probate.model.ccd.raw.response.CallbackResponse)5 User (uk.gov.hmcts.reform.idam.client.models.User)5