Search in sources :

Example 6 with Communication

use of org.incode.module.communications.dom.impl.comms.Communication 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 7 with Communication

use of org.incode.module.communications.dom.impl.comms.Communication in project estatio by estatio.

the class InvoiceForLease_sendAbstract method createEmailCommunication.

Communication createEmailCommunication(final Document document, final EmailAddress toChannel, final String cc, final String cc2, final String cc3, final String bcc, final String bcc2) throws IOException {
    // just delegate to Document_sendByEmail to do the work, then attach to buyer and seller
    final Communication communication = document_sendByEmail(document).act(toChannel, cc, cc2, cc3, bcc, bcc2);
    attachToBuyerAndSeller(document);
    return communication;
}
Also used : Communication(org.incode.module.communications.dom.impl.comms.Communication)

Example 8 with Communication

use of org.incode.module.communications.dom.impl.comms.Communication 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)

Example 9 with Communication

use of org.incode.module.communications.dom.impl.comms.Communication 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 10 with Communication

use of org.incode.module.communications.dom.impl.comms.Communication in project estatio by estatio.

the class InvoiceForLease_sendAbstract method createPostalCommunicationAsSent.

@Programmatic
public Communication createPostalCommunicationAsSent(final Document document, @ParameterLayout(named = "to:") final PostalAddress toChannel) throws IOException {
    // just delegate to document_sendByPost to do the work, then attach to buyer and seller
    final Communication communication = document_sendByPost(document).act(toChannel);
    attachToBuyerAndSeller(document);
    // and mark as sent
    communication.sent();
    return communication;
}
Also used : Communication(org.incode.module.communications.dom.impl.comms.Communication) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Aggregations

Communication (org.incode.module.communications.dom.impl.comms.Communication)11 Test (org.junit.Test)5 PostalAddress (org.incode.module.communications.dom.impl.commchannel.PostalAddress)4 Document (org.incode.module.document.dom.impl.docs.Document)4 DemoObjectWithNotes (org.incode.platform.dom.communications.integtests.demo.dom.demowithnotes.DemoObjectWithNotes)4 Action (org.apache.isis.applib.annotation.Action)3 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)2 CommunicationChannel (org.incode.module.communications.dom.impl.commchannel.CommunicationChannel)2 CommChannelRole (org.incode.module.communications.dom.impl.comms.CommChannelRole)2 DocumentAbstract (org.incode.module.document.dom.impl.docs.DocumentAbstract)2 Paperclip (org.incode.module.document.dom.impl.paperclips.Paperclip)2 DemoInvoice (org.incode.platform.dom.communications.integtests.demo.dom.invoice.DemoInvoice)2 Resources (com.google.common.io.Resources)1 IOException (java.io.IOException)1 URL (java.net.URL)1 List (java.util.List)1 Optional (java.util.Optional)1 Inject (javax.inject.Inject)1 Programmatic (org.apache.isis.applib.annotation.Programmatic)1 FixtureScript (org.apache.isis.applib.fixturescripts.FixtureScript)1