Search in sources :

Example 1 with IncomingDocumentCategorisationStateTransition

use of org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition in project estatio by estatio.

the class TaskIncomingDocumentPdfService method doLookupPdfFor.

private Blob doLookupPdfFor(final Task task) {
    StateTransition<?, ?, ?, ?> stateTransition = stateTransitionService.findFor(task);
    if (stateTransition == null) {
        return null;
    }
    if (stateTransition instanceof IncomingDocumentCategorisationStateTransition) {
        IncomingDocumentCategorisationStateTransition idcst = (IncomingDocumentCategorisationStateTransition) stateTransition;
        final Document document = idcst.getDocument();
        if (document == null) {
            return null;
        }
        if (!Objects.equals(document.getMimeType(), "application/pdf")) {
            return null;
        }
        return document.getBlob();
    }
    if (stateTransition instanceof OrderApprovalStateTransition) {
        final OrderApprovalStateTransition oast = (OrderApprovalStateTransition) stateTransition;
        final Order order = oast.getOrdr();
        final Optional<Document> documentIfAny = lookupAttachedPdfService.lookupOrderPdfFrom(order);
        return documentIfAny.map(DocumentAbstract::getBlob).orElse(null);
    }
    if (stateTransition instanceof IncomingInvoiceApprovalStateTransition) {
        final IncomingInvoiceApprovalStateTransition iiast = (IncomingInvoiceApprovalStateTransition) stateTransition;
        final IncomingInvoice invoice = iiast.getInvoice();
        final Optional<Document> documentIfAny = lookupAttachedPdfService.lookupIncomingInvoicePdfFrom(invoice);
        return documentIfAny.map(DocumentAbstract::getBlob).orElse(null);
    }
    if (stateTransition instanceof BankAccountVerificationStateTransition) {
        final BankAccountVerificationStateTransition bavst = (BankAccountVerificationStateTransition) stateTransition;
        final BankAccount bankAccount = bavst.getBankAccount();
        final Optional<Document> documentIfAny = lookupAttachedPdfService.lookupIbanProofPdfFrom(bankAccount);
        return documentIfAny.map(DocumentAbstract::getBlob).orElse(null);
    }
    return null;
}
Also used : Order(org.estatio.module.capex.dom.order.Order) IncomingInvoiceApprovalStateTransition(org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition) IncomingDocumentCategorisationStateTransition(org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) BankAccount(org.estatio.module.financial.dom.BankAccount) Document(org.incode.module.document.dom.impl.docs.Document) OrderApprovalStateTransition(org.estatio.module.capex.dom.order.approval.OrderApprovalStateTransition) BankAccountVerificationStateTransition(org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationStateTransition)

Example 2 with IncomingDocumentCategorisationStateTransition

use of org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition in project estatio by estatio.

the class IncomingDocViewModel_viewTask method pendingTask.

private Object pendingTask() {
    final Document document = viewModel.getDocument();
    final IncomingDocumentCategorisationStateTransition pendingTransition = repository.findByDomainObjectAndCompleted(document, false);
    return pendingTransition != null ? pendingTransition.getTask() : null;
}
Also used : IncomingDocumentCategorisationStateTransition(org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition) Document(org.incode.module.document.dom.impl.docs.Document)

Example 3 with IncomingDocumentCategorisationStateTransition

use of org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition in project estatio by estatio.

the class Order_2_IntegTest method orderFixtureLoadedProperly.

@Test
public void orderFixtureLoadedProperly() throws Exception {
    assertThat(orderRepository.listAll().size()).isEqualTo(1);
    List<Document> unclassifiedIncomingOrders = incomingDocumentRepository.findUnclassifiedIncomingOrders();
    assertThat(unclassifiedIncomingOrders.size()).isEqualTo(0);
    final String documentName = Order_enum.fakeOrder2Pdf.getDocument_d().findUsing(serviceRegistry).getName();
    Document document = incomingDocumentRepository.findAllIncomingDocumentsByName(documentName).get(0);
    List<IncomingDocumentCategorisationStateTransition> transitions = mixin(Document_categorisationTransitions.class, document).coll();
    assertThat(transitions.size()).isEqualTo(2);
}
Also used : Document_categorisationTransitions(org.estatio.module.capex.dom.documents.categorisation.transitions.Document_categorisationTransitions) IncomingDocumentCategorisationStateTransition(org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition) Document(org.incode.module.document.dom.impl.docs.Document) Test(org.junit.Test)

Example 4 with IncomingDocumentCategorisationStateTransition

use of org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition in project estatio by estatio.

the class DocumentMenu_Upload_IntegTest method happy_case.

@Test
public void happy_case() throws Exception {
    // given
    List<Document> incomingDocumentsBefore = repository.findIncomingDocuments();
    assertThat(incomingDocumentsBefore).isEmpty();
    // when
    final String fileName = "1020100123.pdf";
    final byte[] pdfBytes = Resources.toByteArray(Resources.getResource(DocumentMenu_Upload_IntegTest.class, fileName));
    final Blob blob = new Blob(fileName, "application/pdf", pdfBytes);
    wrap(documentMenu).upload(blob);
    transactionService.nextTransaction();
    // then
    List<Document> incomingDocumentsAfter = repository.findAllIncomingDocuments();
    assertThat(incomingDocumentsAfter).hasSize(1);
    final Document document = incomingDocumentsAfter.get(0);
    final Blob documentBlob = document.getBlob();
    assertThat(documentBlob.getName()).isEqualTo(blob.getName());
    assertThat(documentBlob.getMimeType().getBaseType()).isEqualTo(blob.getMimeType().getBaseType());
    assertThat(documentBlob.getBytes()).isEqualTo(blob.getBytes());
    assertThat(JDOHelper.getVersion(document)).isEqualTo(1L);
    assertThat(paperclipRepository.findByDocument(document).size()).isEqualTo(0);
    // and then also
    final List<IncomingDocumentCategorisationStateTransition> transitions = stateTransitionRepository.findByDomainObject(document);
    assertThat(transitions).hasSize(2);
    assertTransition(transitions.get(0), NEW, CATEGORISE, null);
    assertTransition(transitions.get(1), null, INSTANTIATE, NEW);
    // and when
    final String fileName2 = "1020100123-altered.pdf";
    final byte[] pdfBytes2 = Resources.toByteArray(Resources.getResource(DocumentMenu_Upload_IntegTest.class, fileName2));
    final Blob similarNamedBlob = new Blob(fileName, "application/pdf", pdfBytes2);
    wrap(documentMenu).upload(similarNamedBlob);
    transactionService.nextTransaction();
    // then
    incomingDocumentsAfter = repository.findAllIncomingDocuments();
    assertThat(incomingDocumentsAfter).hasSize(2);
    assertThat(incomingDocumentsAfter.get(0).getName()).isEqualTo(fileName);
    assertThat(incomingDocumentsAfter.get(0).getBlobBytes()).isEqualTo(similarNamedBlob.getBytes());
    assertThat(JDOHelper.getVersion(incomingDocumentsAfter.get(0))).isEqualTo(2L);
    assertThat(paperclipRepository.findByDocument(incomingDocumentsAfter.get(0)).size()).isEqualTo(1);
    // has prefix arch-[date time indication]-
    assertThat(incomingDocumentsAfter.get(1).getName()).contains(fileName);
    assertThat(incomingDocumentsAfter.get(1).getBlobBytes()).isEqualTo(documentBlob.getBytes());
    assertThat(JDOHelper.getVersion(incomingDocumentsAfter.get(1))).isEqualTo(1L);
    assertThat(paperclipRepository.findByDocument(incomingDocumentsAfter.get(1)).size()).isEqualTo(0);
}
Also used : Blob(org.apache.isis.applib.value.Blob) IncomingDocumentCategorisationStateTransition(org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition) Document(org.incode.module.document.dom.impl.docs.Document) Test(org.junit.Test)

Aggregations

IncomingDocumentCategorisationStateTransition (org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition)4 Document (org.incode.module.document.dom.impl.docs.Document)4 Test (org.junit.Test)2 Blob (org.apache.isis.applib.value.Blob)1 BankAccountVerificationStateTransition (org.estatio.module.capex.dom.bankaccount.verification.BankAccountVerificationStateTransition)1 Document_categorisationTransitions (org.estatio.module.capex.dom.documents.categorisation.transitions.Document_categorisationTransitions)1 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)1 IncomingInvoiceApprovalStateTransition (org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalStateTransition)1 Order (org.estatio.module.capex.dom.order.Order)1 OrderApprovalStateTransition (org.estatio.module.capex.dom.order.approval.OrderApprovalStateTransition)1 BankAccount (org.estatio.module.financial.dom.BankAccount)1