Search in sources :

Example 6 with DocumentAbstract

use of org.incode.module.document.dom.impl.docs.DocumentAbstract in project estatio by estatio.

the class Smoke_IntegTest method can_create_postal_address.

@Test
public void can_create_postal_address() throws Exception {
    // given
    fixtureScripts.runFixtureScript(new DemoObjectWithNotes_and_DemoInvoice_and_docs_and_comms_recreate(), null);
    transactionService.nextTransaction();
    // and so given customer with an email
    final DemoObjectWithNotes mary = customerMenu.findDemoObjectsWithNotesByName(DemoObjectWithNote_and_DemoInvoice_create3.MARY_HAS_PHONE_AND_POST).get(0);
    final PostalAddress maryPost = (PostalAddress) linkRepository.findByOwnerAndCommunicationChannelType(mary, CommunicationChannelType.POSTAL_ADDRESS).get(0).getCommunicationChannel();
    // and with an invoice
    final DemoInvoice fredInvoice = invoiceRepository.findByCustomer(mary).get(0);
    // that has an attached document
    final Paperclip paperclip = paperclipRepository.findByAttachedTo(fredInvoice).get(0);
    final DocumentAbstract document = paperclip.getDocument();
    // when
    final Document_sendByPost documentPrint = mixin(Document_sendByPost.class, document);
    final Set<PostalAddress> postalAddresses = documentPrint.choices0Act();
    // then
    assertThat(postalAddresses).contains(maryPost);
    // and when
    final Communication comm = wrap(documentPrint).act(maryPost);
    // then
    assertThat(comm).isNotNull();
    assertThat(comm.getState()).isEqualTo(CommunicationState.PENDING);
    // same as emails
    assertThat(comm.getCreatedAt()).isNotNull();
    assertThat(comm.getType()).isEqualTo(CommunicationChannelType.POSTAL_ADDRESS);
    assertThat(comm.getSubject()).isNotNull();
    assertThat(comm.getSentAt()).isNull();
    final List<CommunicationChannel> correspondentChannels = Lists.newArrayList(comm.getCorrespondents()).stream().map(CommChannelRole::getChannel).filter(Objects::nonNull).collect(Collectors.toList());
    assertThat(correspondentChannels).contains(maryPost);
    // when
    final Communication_downloadPdfForPosting mixin = mixin(Communication_downloadPdfForPosting.class, comm);
    wrap(mixin).act(mixin.default0Act());
    // then
    assertThat(comm.getState()).isEqualTo(CommunicationState.SENT);
    assertThat(comm.getSentAt()).isNotNull();
}
Also used : Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) DocumentAbstract(org.incode.module.document.dom.impl.docs.DocumentAbstract) DemoInvoice(org.incode.platform.dom.communications.integtests.demo.dom.invoice.DemoInvoice) CommChannelRole(org.incode.module.communications.dom.impl.comms.CommChannelRole) CommunicationChannel(org.incode.module.communications.dom.impl.commchannel.CommunicationChannel) DemoObjectWithNotes(org.incode.platform.dom.communications.integtests.demo.dom.demowithnotes.DemoObjectWithNotes) Communication_downloadPdfForPosting(org.incode.module.communications.dom.impl.comms.Communication_downloadPdfForPosting) PostalAddress(org.incode.module.communications.dom.impl.commchannel.PostalAddress) Document_sendByPost(org.incode.module.communications.dom.mixins.Document_sendByPost) DemoObjectWithNotes_and_DemoInvoice_and_docs_and_comms_recreate(org.incode.platform.dom.communications.integtests.dom.communications.fixture.DemoObjectWithNotes_and_DemoInvoice_and_docs_and_comms_recreate) Communication(org.incode.module.communications.dom.impl.comms.Communication) Test(org.junit.Test)

Example 7 with DocumentAbstract

use of org.incode.module.document.dom.impl.docs.DocumentAbstract in project estatio by estatio.

the class ForPrimaryDocOfInvoiceAttachToInvoiceAndAnyRelevantSupportingDocuments method doAdvise.

@Override
protected List<AttachmentAdvisor.PaperclipSpec> doAdvise(final DocumentTemplate documentTemplate, final Invoice invoice, final Document createdDocument) {
    final List<PaperclipSpec> paperclipSpecs = Lists.newArrayList();
    paperclipSpecs.add(new PaperclipSpec(null, invoice, createdDocument));
    // not every supporting doc type supports each type of primary document
    // for example, TAX_REGISTER supports invoices (but not PLs), whereas CALCULATION is other way around.
    // we therefore need to filter the supporting documents that we find attached to the invoice.
    // 
    // to start with, we get hold of the set of doc type (data)s that _do_ support the primary doc just created
    DocumentTypeData primaryDocTypeData = DocumentTypeData.docTypeDataFor(createdDocument);
    List<DocumentTypeData> supportingDocTypeDatasForThisPrimaryDoc = DocumentTypeData.supports(primaryDocTypeData);
    // copy over all relevant supporting attached to this primary document (invoice or prelim letter)
    final List<Paperclip> paperclips = paperclipRepository.findByAttachedTo(invoice);
    for (Paperclip paperclip : paperclips) {
        if (PaperclipRoleNames.SUPPORTING_DOCUMENT.equals(paperclip.getRoleName())) {
            final DocumentAbstract supportingDocAbs = paperclip.getDocument();
            if (supportingDocAbs instanceof Document) {
                final Document supportingDoc = (Document) supportingDocAbs;
                final DocumentTypeData supportingDocTypeData = DocumentTypeData.docTypeDataFor(supportingDoc);
                // (and here is where filter out to only attach those that are relevant)
                if (supportingDocTypeDatasForThisPrimaryDoc.contains(supportingDocTypeData)) {
                    // note that the supporting documents point to the primary doc, rather than the other way around
                    paperclipSpecs.add(new PaperclipSpec(PaperclipRoleNames.INVOICE_DOCUMENT_SUPPORTED_BY, createdDocument, supportingDoc));
                }
            }
        }
    }
    return paperclipSpecs;
}
Also used : Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) DocumentAbstract(org.incode.module.document.dom.impl.docs.DocumentAbstract) DocumentTypeData(org.estatio.module.invoice.dom.DocumentTypeData) Document(org.incode.module.document.dom.impl.docs.Document)

Example 8 with DocumentAbstract

use of org.incode.module.document.dom.impl.docs.DocumentAbstract in project estatio by estatio.

the class InvoiceForLease_attachSupportingDocument method $$.

@Action(semantics = SemanticsOf.NON_IDEMPOTENT, commandDtoProcessor = DeriveBlobFromDummyPdfArg1.class)
@ActionLayout(contributed = Contributed.AS_ACTION, cssClassFa = "paperclip")
public Invoice $$(final DocumentType supportingDocumentType, @Parameter(fileAccept = "application/pdf") @ParameterLayout(named = "Receipt (PDF)") final Blob blob, @Parameter(optionality = Optionality.OPTIONAL) final String fileName, final String roleName) throws IOException {
    // 
    // if appropriate, we will automatically attach the supporting doc (once created)
    // to any unsent documents for this Invoice
    // before we do anything, therefore, we get hold of those invoice documents.
    // 
    DocumentTypeData supportedBy = DocumentTypeData.supportedBy(supportingDocumentType);
    final List<DocumentAbstract> unsentDocuments = findUnsentDocumentsFor(invoiceForLease, supportedBy);
    // 
    // now we create the receiptDoc, and attach to the invoice
    // 
    String documentName = determineName(blob, fileName);
    // unlike documents that are generated from a template (where we call documentTemplate#render), in this case
    // we have the actual bytes; so we just set up the remaining state of the document manually.
    final Document supportingDoc = documentService.createAndAttachDocumentForBlob(supportingDocumentType, this.invoiceForLease.getAtPath(), documentName, blob, PaperclipRoleNames.SUPPORTING_DOCUMENT, this.invoiceForLease);
    // 
    for (DocumentAbstract unsentDocument : unsentDocuments) {
        paperclipRepository.attach(supportingDoc, roleName, unsentDocument);
    }
    return this.invoiceForLease;
}
Also used : DocumentAbstract(org.incode.module.document.dom.impl.docs.DocumentAbstract) DocumentTypeData(org.estatio.module.invoice.dom.DocumentTypeData) Document(org.incode.module.document.dom.impl.docs.Document) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Example 9 with DocumentAbstract

use of org.incode.module.document.dom.impl.docs.DocumentAbstract in project estatio by estatio.

the class InvoiceForLease_attachSupportingDocument method findUnsentDocumentsFor.

private List<DocumentAbstract> findUnsentDocumentsFor(final InvoiceForLease invoice, final DocumentTypeData docTypeData) {
    final DocumentType documentType = docTypeData.findUsing(documentTypeRepository, queryResultsCache);
    final List<DocumentAbstract> unsentDocuments = Lists.newArrayList();
    final List<Paperclip> existingInvoicePaperclips = paperclipRepository.findByAttachedTo(invoice);
    for (Paperclip paperclip : existingInvoicePaperclips) {
        final DocumentAbstract document = paperclip.getDocument();
        if (document.getType() == documentType) {
            boolean sent = whetherSent(document);
            if (!sent) {
                unsentDocuments.add(document);
            }
        }
    }
    return unsentDocuments;
}
Also used : DocumentAbstract(org.incode.module.document.dom.impl.docs.DocumentAbstract) Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) DocumentType(org.incode.module.document.dom.impl.types.DocumentType)

Example 10 with DocumentAbstract

use of org.incode.module.document.dom.impl.docs.DocumentAbstract in project estatio by estatio.

the class InvoiceForLease_sendByPost method choices0$$.

public List<Document> choices0$$() {
    final List<Paperclip> paperclips = paperclipRepository.findByAttachedTo(invoice);
    final List<Document> documents = Lists.newArrayList();
    for (Paperclip paperclip : paperclips) {
        final DocumentAbstract documentAbs = paperclip.getDocument();
        if (!(documentAbs instanceof Document)) {
            continue;
        }
        final Document document = (Document) documentAbs;
        if (document.getState() != DocumentState.RENDERED) {
            continue;
        }
        if (!DocumentTypeData.isPrimaryType(document)) {
            continue;
        }
        final Document_sendByPost document_sendByPost = document_sendByPost(document);
        if (document_sendByPost.disableAct() != null) {
            continue;
        }
        documents.add(document);
    }
    return documents;
}
Also used : Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) DocumentAbstract(org.incode.module.document.dom.impl.docs.DocumentAbstract) Document_sendByPost(org.incode.module.communications.dom.mixins.Document_sendByPost) Document(org.incode.module.document.dom.impl.docs.Document)

Aggregations

DocumentAbstract (org.incode.module.document.dom.impl.docs.DocumentAbstract)10 Document (org.incode.module.document.dom.impl.docs.Document)7 Paperclip (org.incode.module.document.dom.impl.paperclips.Paperclip)7 Action (org.apache.isis.applib.annotation.Action)2 DocumentTypeData (org.estatio.module.invoice.dom.DocumentTypeData)2 CommunicationChannel (org.incode.module.communications.dom.impl.commchannel.CommunicationChannel)2 CommChannelRole (org.incode.module.communications.dom.impl.comms.CommChannelRole)2 Communication (org.incode.module.communications.dom.impl.comms.Communication)2 Document_sendByEmail (org.incode.module.communications.dom.mixins.Document_sendByEmail)2 Document_sendByPost (org.incode.module.communications.dom.mixins.Document_sendByPost)2 DemoObjectWithNotes (org.incode.platform.dom.communications.integtests.demo.dom.demowithnotes.DemoObjectWithNotes)2 DemoInvoice (org.incode.platform.dom.communications.integtests.demo.dom.invoice.DemoInvoice)2 Test (org.junit.Test)2 DataSource (javax.activation.DataSource)1 NotPersistent (javax.jdo.annotations.NotPersistent)1 ApplicationException (org.apache.isis.applib.ApplicationException)1 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)1 Property (org.apache.isis.applib.annotation.Property)1 EmailAddress (org.incode.module.communications.dom.impl.commchannel.EmailAddress)1 PostalAddress (org.incode.module.communications.dom.impl.commchannel.PostalAddress)1