Search in sources :

Example 1 with DocumentAbstract

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

the class Paperclip method getDocumentDate.

/**
 * Either the {@link Document#getCreatedAt()} or {@link Document#getRenderedAt()}, depending upon the
 * {@link Document#getState()} of the {@link Document}.  Returns <tt>null</tt> for {@link DocumentTemplate}s.
 */
@NotPersistent
@Property(domainEvent = DocumentDateDomainEvent.class, editing = Editing.DISABLED)
public DateTime getDocumentDate() {
    final DocumentAbstract documentAbstract = getDocument();
    if (documentAbstract instanceof Document) {
        final Document document = (Document) documentAbstract;
        DocumentState state = document.getState();
        return state.dateOf(document);
    }
    return null;
}
Also used : DocumentAbstract(org.incode.module.document.dom.impl.docs.DocumentAbstract) DocumentState(org.incode.module.document.dom.impl.docs.DocumentState) Document(org.incode.module.document.dom.impl.docs.Document) NotPersistent(javax.jdo.annotations.NotPersistent) Property(org.apache.isis.applib.annotation.Property)

Example 2 with DocumentAbstract

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

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

the class InvoiceForLease_sendByEmail 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_sendByEmail document_email = document_sendByEmail(document);
        if (document_email.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(org.incode.module.document.dom.impl.docs.Document) Document_sendByEmail(org.incode.module.communications.dom.mixins.Document_sendByEmail)

Example 4 with DocumentAbstract

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

the class InvoiceSummaryForPropertyDueDateStatus_actionAbstract method findMostRecentAttachedTo.

Document findMostRecentAttachedTo(final Invoice invoice, final DocumentType documentType) {
    final List<Paperclip> paperclips = paperclipRepository.findByAttachedTo(invoice);
    for (Paperclip paperclip : paperclips) {
        final DocumentAbstract documentAbstract = paperclip.getDocument();
        if (!(documentAbstract instanceof Document)) {
            continue;
        }
        final Document document = (Document) documentAbstract;
        if (document.getType() == documentType) {
            return document;
        }
    }
    return null;
}
Also used : Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) DocumentAbstract(org.incode.module.document.dom.impl.docs.DocumentAbstract) Document(org.incode.module.document.dom.impl.docs.Document)

Example 5 with DocumentAbstract

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

the class Smoke_IntegTest method can_send_email.

@Test
public void can_send_email() throws Exception {
    // given
    fixtureScripts.runFixtureScript(new CommandDomModule().getTeardownFixtureWillDelete(), null);
    fixtureScripts.runFixtureScript(new DemoObjectWithNotes_and_DemoInvoice_and_docs_and_comms_create(), null);
    transactionService.nextTransaction();
    // and so given customer with an email
    final DemoObjectWithNotes fred = customerMenu.findDemoObjectsWithNotesByName(DemoObjectWithNote_and_DemoInvoice_create3.FRED_HAS_EMAIL_AND_PHONE).get(0);
    final EmailAddress fredEmail = (EmailAddress) linkRepository.findByOwnerAndCommunicationChannelType(fred, CommunicationChannelType.EMAIL_ADDRESS).get(0).getCommunicationChannel();
    // and with an invoice
    final DemoInvoice fredInvoice = invoiceRepository.findByCustomer(fred).get(0);
    // that has an attached document
    final Paperclip paperclip = paperclipRepository.findByAttachedTo(fredInvoice).get(0);
    final DocumentAbstract document = paperclip.getDocument();
    // when
    final Document_sendByEmail documentEmail = mixin(Document_sendByEmail.class, document);
    final Set<EmailAddress> emailAddresses = documentEmail.choices0Act();
    // then
    assertThat(emailAddresses).contains(fredEmail);
    // and when
    // REVIEW: should be wrapped, however the DocumentCommunicationSupportForDocumentsAttachedToInvoiceForLease
    // vetoes this, and there is current no way to exclude classes that are not part of the "effective" module
    // final Communication comm = wrap(documentEmail).act(fredEmail, null, null, null, null, null);
    final Communication comm = documentEmail.act(fredEmail, null, null, null, null, null);
    // then
    assertThat(comm).isNotNull();
    assertThat(comm.getState()).isEqualTo(CommunicationState.PENDING);
    assertThat(comm.getCreatedAt()).isNotNull();
    assertThat(comm.getType()).isEqualTo(CommunicationChannelType.EMAIL_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(fredEmail);
    List<EmailMessage> emailMessages = fakeEmailService.listSentEmails();
    assertThat(emailMessages).isEmpty();
    List<CommandJdo> commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
    assertThat(commands.size()).isEqualTo(1);
    // when
    fakeScheduler.runBackgroundCommands(5000);
    // then
    assertThat(comm.getState()).isEqualTo(CommunicationState.SENT);
    assertThat(comm.getSentAt()).isNotNull();
    emailMessages = fakeEmailService.listSentEmails();
    assertThat(emailMessages).isNotEmpty();
}
Also used : Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) DocumentAbstract(org.incode.module.document.dom.impl.docs.DocumentAbstract) EmailMessage(org.incode.platform.dom.communications.integtests.app.services.fakeemail.EmailMessage) CommandJdo(org.isisaddons.module.command.dom.CommandJdo) DemoInvoice(org.incode.platform.dom.communications.integtests.demo.dom.invoice.DemoInvoice) CommChannelRole(org.incode.module.communications.dom.impl.comms.CommChannelRole) EmailAddress(org.incode.module.communications.dom.impl.commchannel.EmailAddress) CommunicationChannel(org.incode.module.communications.dom.impl.commchannel.CommunicationChannel) DemoObjectWithNotes(org.incode.platform.dom.communications.integtests.demo.dom.demowithnotes.DemoObjectWithNotes) Document_sendByEmail(org.incode.module.communications.dom.mixins.Document_sendByEmail) CommandDomModule(org.isisaddons.module.command.dom.CommandDomModule) DemoObjectWithNotes_and_DemoInvoice_and_docs_and_comms_create(org.incode.platform.dom.communications.integtests.dom.communications.fixture.DemoObjectWithNotes_and_DemoInvoice_and_docs_and_comms_create) Communication(org.incode.module.communications.dom.impl.comms.Communication) Test(org.junit.Test)

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