use of uk.gov.hmcts.probate.model.ccd.raw.DocumentLink in project probate-back-office by hmcts.
the class PDFManagementService method uploadDocument.
private Document uploadDocument(DocumentType documentType, EvidenceManagementFileUpload fileUpload) {
try {
log.info("Uploading pdf for template {}", documentType.getTemplateName());
EvidenceManagementFile store = uploadService.store(fileUpload);
Optional<Link> binaryOptionalLink = store.getLink("binary");
Optional<Link> selfOptionalLink = store.getLink(IanaLinkRelations.SELF);
if (!binaryOptionalLink.isPresent()) {
throw new IOException("binary link is not present");
}
if (!selfOptionalLink.isPresent()) {
throw new IOException("self link is not present");
}
DocumentLink documentLink = DocumentLink.builder().documentBinaryUrl(((Link) binaryOptionalLink.get()).getHref()).documentUrl(((Link) selfOptionalLink.get()).getHref()).documentFilename(documentType.getTemplateName() + ".pdf").build();
return Document.builder().documentFileName(fileUpload.getFileName()).documentLink(documentLink).documentType(documentType).documentDateAdded(LocalDate.now()).documentGeneratedBy(httpServletRequest.getHeader("user-id")).build();
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new ConnectionException(e.getMessage());
}
}
use of uk.gov.hmcts.probate.model.ccd.raw.DocumentLink 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.probate.model.ccd.raw.DocumentLink 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.probate.model.ccd.raw.DocumentLink 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));
}
use of uk.gov.hmcts.probate.model.ccd.raw.DocumentLink in project probate-back-office by hmcts.
the class BulkPrintServiceTest method testSuccessfulSendToBulkPrintForDocumentType.
private void testSuccessfulSendToBulkPrintForDocumentType(DocumentType documentType) {
SolsAddress address = SolsAddress.builder().addressLine1("Address 1").addressLine2("Address 2").postCode("EC2").country("UK").build();
CaseData caseData = CaseData.builder().primaryApplicantEmailAddress("primary@probate-test.com").primaryApplicantForenames("firstname").primaryApplicantSurname("surname").primaryApplicantAddress(address).extraCopiesOfGrant(1L).build();
final CallbackRequest callbackRequest = new CallbackRequest(new CaseDetails(caseData, null, 0L));
DocumentLink documentLink = DocumentLink.builder().documentUrl("http://localhost").build();
final Document document = Document.builder().documentFileName("test.pdf").documentGeneratedBy("test").documentType(documentType).documentDateAdded(LocalDate.now()).documentLink(documentLink).build();
final Document coverSheet = Document.builder().documentFileName("test.pdf").documentGeneratedBy("test").documentDateAdded(LocalDate.now()).documentLink(documentLink).build();
responseCaseData = ResponseCaseData.builder().registryLocation("leeds").deceasedForenames("name").deceasedSurname("name").build();
final CallbackResponse callbackResponse = CallbackResponse.builder().errors(new ArrayList<>()).data(responseCaseData).build();
UUID uuid = UUID.randomUUID();
SendLetterResponse sendLetterResponse = new SendLetterResponse(uuid);
when(sendLetterApiMock.sendLetter(anyString(), any(LetterV3.class))).thenReturn(sendLetterResponse);
when(eventValidationService.validateBulkPrintResponse(eq(uuid.toString()), any())).thenReturn(callbackResponse);
when(documentTransformer.hasDocumentWithType(Collections.singletonList(document), documentType)).thenReturn(true);
final String letterId = bulkPrintService.optionallySendToBulkPrint(callbackRequest, coverSheet, document, true);
verify(sendLetterApiMock).sendLetter(anyString(), letterV3ArgumentCaptor.capture());
assertEquals(1, letterV3ArgumentCaptor.getValue().documents.get(0).copies);
assertEquals(2, letterV3ArgumentCaptor.getValue().documents.get(1).copies);
assertNotNull(letterId);
assertThat(letterId, is(uuid.toString()));
}
Aggregations