Search in sources :

Example 21 with Document

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

the class Communication method sendByEmail.

// so can invoke via BackgroundService
@Action(hidden = Where.EVERYWHERE)
public Communication sendByEmail() {
    // body...
    final Document coverNoteDoc = findDocument(DocumentConstants.PAPERCLIP_ROLE_COVER);
    final String emailBody = coverNoteDoc.asChars();
    // (email) attachments..
    // this corresponds to the primary document and any attachments
    final List<DataSource> attachments = Lists.newArrayList();
    final Document primaryDocument = getPrimaryDocument();
    if (primaryDocument != null) {
        // should be the case
        attachments.add(primaryDocument.asDataSource());
    }
    attachments.addAll(findDocumentsInRoleAsStream(DocumentConstants.PAPERCLIP_ROLE_ATTACHMENT).map(DocumentAbstract::asDataSource).collect(Collectors.toList()));
    // cc..
    final List<String> toList = findCorrespondents(CommChannelRoleType.TO);
    final List<String> ccList = findCorrespondents(CommChannelRoleType.CC);
    final List<String> bccList = findCorrespondents(CommChannelRoleType.BCC);
    // subject ...
    final String subject = getSubject();
    // finally, we send
    final boolean send = emailService.send(toList, ccList, bccList, subject, emailBody, attachments.toArray(new DataSource[] {}));
    if (!send) {
        throw new ApplicationException("Failed to send email; see system logs for details.");
    }
    // mark this comm as having been sent.
    sent();
    return this;
}
Also used : DocumentAbstract(org.incode.module.document.dom.impl.docs.DocumentAbstract) ApplicationException(org.apache.isis.applib.ApplicationException) Document(org.incode.module.document.dom.impl.docs.Document) DataSource(javax.activation.DataSource) Action(org.apache.isis.applib.annotation.Action)

Example 22 with Document

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

the class Communication_downloadPdfForPosting method act.

@Action(semantics = SemanticsOf.IDEMPOTENT)
@ActionLayout(named = "Download PDF for posting", cssClassFa = "download")
public Blob act(@ParameterLayout(named = "File name") final String fileName) throws IOException {
    // the act of downloading implicitly sends the communication
    if (communication.getState() == CommunicationState.PENDING) {
        communication.sent();
    }
    final List<byte[]> pdfBytes = Lists.newArrayList();
    final Document primaryDoc = communication.getPrimaryDocument();
    appendBytes(primaryDoc, pdfBytes);
    // merge any and all attachments
    final List<Document> attachedDocuments = findAttachedPdfDocuments();
    attachedDocuments.sort(Ordering.natural().onResultOf(Document::getCreatedAt));
    for (final Document attachedDoc : attachedDocuments) {
        appendBytes(attachedDoc, pdfBytes);
    }
    final byte[] mergedBytes = pdfBoxService.merge(pdfBytes.toArray(new byte[][] {}));
    return new Blob(fileName, DocumentConstants.MIME_TYPE_APPLICATION_PDF, mergedBytes);
}
Also used : Document_downloadExternalUrlAsBlob(org.incode.module.document.dom.impl.docs.Document_downloadExternalUrlAsBlob) Blob(org.apache.isis.applib.value.Blob) Document(org.incode.module.document.dom.impl.docs.Document) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Example 23 with Document

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

the class SuppressContributionsForCoverNoteDocument method hideIfCoverNote.

private void hideIfCoverNote(final org.apache.isis.applib.services.eventbus.ActionDomainEvent<?> ev) {
    if (ev.getEventPhase() != AbstractDomainEvent.Phase.HIDE) {
        return;
    }
    final Object mixedIn = ev.getMixedIn();
    if (!(mixedIn instanceof Document)) {
        return;
    }
    final Document document = (Document) mixedIn;
    final Communication communication = evaluator.coverNoteFor(document);
    if (communication != null) {
        ev.hide();
    }
}
Also used : Document(org.incode.module.document.dom.impl.docs.Document) Communication(org.incode.module.communications.dom.impl.comms.Communication)

Example 24 with Document

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

the class Document_sendByPost method act.

@Action(semantics = SemanticsOf.NON_IDEMPOTENT, domainEvent = ActionDomainEvent.class)
@ActionLayout(cssClassFa = "envelope-o", contributed = Contributed.AS_ACTION)
public Communication act(@ParameterLayout(named = "to:") final PostalAddress toChannel) throws IOException {
    if (this.document.getState() == DocumentState.NOT_RENDERED) {
        // this shouldn't happen, but want to fail-fast in case a future programmer calls this directly
        throw new IllegalArgumentException("Document is not yet rendered");
    }
    // create comm and correspondents
    final String atPath = document.getAtPath();
    final String subject = document.getName();
    final Communication communication = communicationRepository.createPostal(subject, atPath, toChannel);
    transactionService.flushTransaction();
    // attach this "primary" document to the comm
    paperclipRepository.attach(this.document, DocumentConstants.PAPERCLIP_ROLE_PRIMARY, communication);
    // also copy over as attachments to the comm anything else also attached to original document
    final List<Document> communicationAttachments = attachmentProvider.attachmentsFor(document);
    for (Document communicationAttachment : communicationAttachments) {
        paperclipRepository.attach(communicationAttachment, DocumentConstants.PAPERCLIP_ROLE_ATTACHMENT, communication);
    }
    transactionService.flushTransaction();
    return communication;
}
Also used : Document(org.incode.module.document.dom.impl.docs.Document) Communication(org.incode.module.communications.dom.impl.comms.Communication) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Example 25 with Document

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

the class DocumentService method createAndAttachDocumentForBlob.

/**
 * @param documentName - override the name of the blob (if null, then uses the blob's name)
 */
@Programmatic
public Document createAndAttachDocumentForBlob(final DocumentType documentType, final String documentAtPath, String documentName, final Blob blob, final String paperclipRoleName, final Object paperclipAttachTo) {
    final Document document = createForBlob(documentType, documentAtPath, documentName, blob);
    paperclipRepository.attach(document, paperclipRoleName, paperclipAttachTo);
    return document;
}
Also used : Document(org.incode.module.document.dom.impl.docs.Document) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Aggregations

Document (org.incode.module.document.dom.impl.docs.Document)57 Action (org.apache.isis.applib.annotation.Action)23 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)22 Programmatic (org.apache.isis.applib.annotation.Programmatic)8 Blob (org.apache.isis.applib.value.Blob)7 IncomingInvoice (org.estatio.module.capex.dom.invoice.IncomingInvoice)7 DocumentAbstract (org.incode.module.document.dom.impl.docs.DocumentAbstract)7 MemberOrder (org.apache.isis.applib.annotation.MemberOrder)5 Paperclip (org.incode.module.document.dom.impl.paperclips.Paperclip)5 IncomingDocumentCategorisationStateTransition (org.estatio.module.capex.dom.documents.categorisation.IncomingDocumentCategorisationStateTransition)4 Bookmark (org.apache.isis.applib.services.bookmark.Bookmark)3 BuyerFinder (org.estatio.module.capex.dom.documents.BuyerFinder)3 Communication (org.incode.module.communications.dom.impl.comms.Communication)3 DocumentTemplate (org.incode.module.document.dom.impl.docs.DocumentTemplate)3 Expectations (org.jmock.Expectations)3 TitleBuffer (org.apache.isis.applib.util.TitleBuffer)2 IncomingDocAsOrderViewModel (org.estatio.module.capex.app.order.IncomingDocAsOrderViewModel)2 Order (org.estatio.module.capex.dom.order.Order)2 BankAccount (org.estatio.module.financial.dom.BankAccount)2 DocumentTypeData (org.estatio.module.invoice.dom.DocumentTypeData)2