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);
}
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;
}
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));
}
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));
}
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));
}
Aggregations