Search in sources :

Example 46 with Document

use of org.incode.module.document.dom.impl.docs.Document 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 47 with Document

use of org.incode.module.document.dom.impl.docs.Document 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)

Example 48 with Document

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

the class Document_sendByEmail method act.

@Action(semantics = SemanticsOf.NON_IDEMPOTENT, domainEvent = ActionDomainEvent.class)
@ActionLayout(cssClassFa = "at", contributed = Contributed.AS_ACTION)
public Communication act(@ParameterLayout(named = "to:") final EmailAddress toChannel, @Parameter(optionality = Optionality.OPTIONAL, maxLength = CommunicationChannel.EmailType.Meta.MAX_LEN, regexPattern = CommunicationChannel.EmailType.Meta.REGEX, regexPatternReplacement = CommunicationChannel.EmailType.Meta.REGEX_DESC) @ParameterLayout(named = "cc:") final String cc, @Parameter(optionality = Optionality.OPTIONAL, maxLength = CommunicationChannel.EmailType.Meta.MAX_LEN, regexPattern = CommunicationChannel.EmailType.Meta.REGEX, regexPatternReplacement = CommunicationChannel.EmailType.Meta.REGEX_DESC) @ParameterLayout(named = "cc (2):") final String cc2, @Parameter(optionality = Optionality.OPTIONAL, maxLength = CommunicationChannel.EmailType.Meta.MAX_LEN, regexPattern = CommunicationChannel.EmailType.Meta.REGEX, regexPatternReplacement = CommunicationChannel.EmailType.Meta.REGEX_DESC) @ParameterLayout(named = "cc (3):") final String cc3, @Parameter(optionality = Optionality.OPTIONAL, maxLength = CommunicationChannel.EmailType.Meta.MAX_LEN, regexPattern = CommunicationChannel.EmailType.Meta.REGEX, regexPatternReplacement = CommunicationChannel.EmailType.Meta.REGEX_DESC) @ParameterLayout(named = "bcc:") final String bcc, @Parameter(optionality = Optionality.OPTIONAL, maxLength = CommunicationChannel.EmailType.Meta.MAX_LEN, regexPattern = CommunicationChannel.EmailType.Meta.REGEX, regexPatternReplacement = CommunicationChannel.EmailType.Meta.REGEX_DESC) @ParameterLayout(named = "bcc (2):") final String bcc2) 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 cover note
    // 
    // nb: there is a presumption is that the cover note will not be automatically attached to any other objects,
    // ie its AttachmentAdvisor should be AttachToNone.
    final DocumentTemplate coverNoteTemplate = determineEmailCoverNoteTemplate();
    final Document coverNoteDoc = documentCreatorService.createDocumentAndAttachPaperclips(this.document, coverNoteTemplate);
    coverNoteDoc.render(coverNoteTemplate, this.document);
    // create comm and correspondents
    final String atPath = document.getAtPath();
    final String subject = stripFileExtensionIfAny(coverNoteDoc.getName());
    final Communication communication = communicationRepository.createEmail(subject, atPath, toChannel, cc, cc2, cc3, bcc, bcc2);
    transactionService.flushTransaction();
    // manually attach the cover note to the comm
    paperclipRepository.attach(coverNoteDoc, DocumentConstants.PAPERCLIP_ROLE_COVER, communication);
    // also 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 primary document
    final List<Document> communicationAttachments = attachmentProvider.attachmentsFor(document);
    for (Document communicationAttachment : communicationAttachments) {
        paperclipRepository.attach(communicationAttachment, DocumentConstants.PAPERCLIP_ROLE_ATTACHMENT, communication);
    }
    transactionService.flushTransaction();
    // finally, schedule the email to be sent
    communication.scheduleSend();
    return communication;
}
Also used : DocumentTemplate(org.incode.module.document.dom.impl.docs.DocumentTemplate) 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 49 with Document

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

the class DocumentTemplateForAtPathService method documentTemplatesForCreateAndAttach.

@Programmatic
public List<DocumentTemplate> documentTemplatesForCreateAndAttach(final Object domainObject) {
    final List<DocumentTemplate> templates = Lists.newArrayList();
    final String atPath = atPathFor(domainObject);
    if (atPath == null) {
        return templates;
    }
    final List<DocumentTemplate> templatesForPath = documentTemplateRepository.findByApplicableToAtPath(atPath);
    return Lists.newArrayList(templatesForPath.stream().filter(template -> {
        final AttachmentAdvisor advisor = template.newAttachmentAdvisor(domainObject);
        if (advisor == null) {
            return false;
        }
        // at this stage we are asking the advisor if it would be able to attach a document
        // if created.  We don't yet have that document, so it is null.
        final Document document = null;
        final List<AttachmentAdvisor.PaperclipSpec> paperclipSpecs = advisor.advise(template, domainObject, document);
        return canCreate(template, paperclipSpecs);
    }).collect(Collectors.toList()));
}
Also used : AttachmentAdvisor(org.incode.module.document.dom.impl.applicability.AttachmentAdvisor) DocumentTemplate(org.incode.module.document.dom.impl.docs.DocumentTemplate) Document(org.incode.module.document.dom.impl.docs.Document) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 50 with Document

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

the class T_createAndAttachDocumentAndRender method $$.

@Action(domainEvent = ActionDomainEvent.class, semantics = SemanticsOf.NON_IDEMPOTENT)
@ActionLayout(contributed = Contributed.AS_ACTION)
@MemberOrder(name = "documents", sequence = "3.1")
public Object $$(final DocumentTemplate template) throws IOException {
    final Document document = documentCreatorService.createDocumentAndAttachPaperclips(domainObject, template);
    render(template, document);
    return document;
}
Also used : Document(org.incode.module.document.dom.impl.docs.Document) Action(org.apache.isis.applib.annotation.Action) MemberOrder(org.apache.isis.applib.annotation.MemberOrder) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

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