Search in sources :

Example 1 with DocumentLink

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());
    }
}
Also used : EvidenceManagementFile(uk.gov.hmcts.probate.model.evidencemanagement.EvidenceManagementFile) IOException(java.io.IOException) DocumentLink(uk.gov.hmcts.probate.model.ccd.raw.DocumentLink) DocumentLink(uk.gov.hmcts.probate.model.ccd.raw.DocumentLink) Link(org.springframework.hateoas.Link) ConnectionException(uk.gov.hmcts.probate.exception.ConnectionException)

Example 2 with DocumentLink

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));
}
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 3 with DocumentLink

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

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

Example 5 with DocumentLink

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()));
}
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) CallbackResponse(uk.gov.hmcts.probate.model.ccd.raw.response.CallbackResponse) CaseDetails(uk.gov.hmcts.probate.model.ccd.raw.request.CaseDetails) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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)

Aggregations

DocumentLink (uk.gov.hmcts.probate.model.ccd.raw.DocumentLink)25 Document (uk.gov.hmcts.probate.model.ccd.raw.Document)19 Test (org.junit.Test)18 CaveatCallbackRequest (uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatCallbackRequest)17 LetterV3 (uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3)15 SendLetterResponse (uk.gov.hmcts.reform.sendletter.api.SendLetterResponse)14 SolsAddress (uk.gov.hmcts.probate.model.ccd.raw.SolsAddress)13 CallbackRequest (uk.gov.hmcts.probate.model.ccd.raw.request.CallbackRequest)13 CaseData (uk.gov.hmcts.probate.model.ccd.raw.request.CaseData)13 CaseDetails (uk.gov.hmcts.probate.model.ccd.raw.request.CaseDetails)13 ResponseCaseData (uk.gov.hmcts.probate.model.ccd.raw.response.ResponseCaseData)13 UUID (java.util.UUID)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 CollectionMember (uk.gov.hmcts.probate.model.ccd.raw.CollectionMember)5 UploadDocument (uk.gov.hmcts.probate.model.ccd.raw.UploadDocument)5 CallbackResponse (uk.gov.hmcts.probate.model.ccd.raw.response.CallbackResponse)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ProbateAddress (uk.gov.hmcts.probate.model.ccd.ProbateAddress)4 CaveatData (uk.gov.hmcts.probate.model.ccd.caveat.request.CaveatData)4