Search in sources :

Example 6 with Paperclip

use of org.incode.module.document.dom.impl.paperclips.Paperclip in project estatio by estatio.

the class RenderModelFactoryOfDocumentAttachedToDemoInvoice method doNewRendererModel.

@Override
protected Object doNewRendererModel(final DocumentTemplate documentTemplate, final Document document) {
    final List<Paperclip> paperclips = paperclipRepository.findByDocument(document);
    final DemoInvoice demoInvoice = paperclips.stream().map(Paperclip::getAttachedTo).filter(DemoInvoice.class::isInstance).map(DemoInvoice.class::cast).findFirst().get();
    return new DataModel(demoInvoice.getCustomer(), demoInvoice);
}
Also used : Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) DemoInvoice(org.incode.platform.dom.document.integtests.demo.dom.invoice.DemoInvoice)

Example 7 with Paperclip

use of org.incode.module.document.dom.impl.paperclips.Paperclip in project estatio by estatio.

the class BankAccount_attachPdfAsIbanProof method act.

@Action(semantics = SemanticsOf.IDEMPOTENT, commandDtoProcessor = DeriveBlobFromDummyPdfArg0.class)
public BankAccount act(@Parameter(fileAccept = "application/pdf") final Blob document) {
    final DocumentType ibanProofDocType = DocumentTypeData.IBAN_PROOF.findUsing(documentTypeRepository);
    final List<Paperclip> ibanProofPaperclips = paperclipRepository.findByAttachedToAndRoleName(bankAccount, ROLE_NAME_FOR_IBAN_PROOF);
    // delete all existing paperclips for this role whose type is also not IBAN_PROOF
    // (ie any incoming invoices that were automatically attached as candidate iban proofs)
    final Predicate<Paperclip> hasIbanProofDocType = paperclip -> Objects.equals(ibanProofDocType, paperclip.getDocument().getType());
    final Predicate<Paperclip> doesNotHaveIbanProofDocType = hasIbanProofDocType.negate();
    ibanProofPaperclips.stream().filter(doesNotHaveIbanProofDocType).forEach(paperclip -> paperclipRepository.delete(paperclip));
    final String name = document.getName();
    documentService.createAndAttachDocumentForBlob(ibanProofDocType, bankAccount.getAtPath(), name, document, ROLE_NAME_FOR_IBAN_PROOF, bankAccount);
    return bankAccount;
}
Also used : Action(org.apache.isis.applib.annotation.Action) DocumentType(org.incode.module.document.dom.impl.types.DocumentType) PaperclipRepository(org.incode.module.document.dom.impl.paperclips.PaperclipRepository) Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) Predicate(java.util.function.Predicate) DocumentTypeRepository(org.incode.module.document.dom.impl.types.DocumentTypeRepository) Objects(java.util.Objects) Inject(javax.inject.Inject) Mixin(org.apache.isis.applib.annotation.Mixin) SemanticsOf(org.apache.isis.applib.annotation.SemanticsOf) List(java.util.List) DocumentService(org.incode.module.document.dom.api.DocumentService) DeriveBlobFromDummyPdfArg0(org.incode.module.base.spi.DeriveBlobFromDummyPdfArg0) BankAccount(org.estatio.module.financial.dom.BankAccount) Parameter(org.apache.isis.applib.annotation.Parameter) Blob(org.apache.isis.applib.value.Blob) DocumentTypeData(org.estatio.module.invoice.dom.DocumentTypeData) Paperclip(org.incode.module.document.dom.impl.paperclips.Paperclip) DocumentType(org.incode.module.document.dom.impl.types.DocumentType) Action(org.apache.isis.applib.annotation.Action)

Example 8 with Paperclip

use of org.incode.module.document.dom.impl.paperclips.Paperclip 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 9 with Paperclip

use of org.incode.module.document.dom.impl.paperclips.Paperclip 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 10 with Paperclip

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

Aggregations

Paperclip (org.incode.module.document.dom.impl.paperclips.Paperclip)15 DocumentAbstract (org.incode.module.document.dom.impl.docs.DocumentAbstract)7 Document (org.incode.module.document.dom.impl.docs.Document)5 DemoInvoice (org.incode.platform.dom.communications.integtests.demo.dom.invoice.DemoInvoice)4 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 DocumentType (org.incode.module.document.dom.impl.types.DocumentType)2 DemoObjectWithNotes (org.incode.platform.dom.communications.integtests.demo.dom.demowithnotes.DemoObjectWithNotes)2 Test (org.junit.Test)2 List (java.util.List)1 Objects (java.util.Objects)1 Predicate (java.util.function.Predicate)1 Inject (javax.inject.Inject)1 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)1 Mixin (org.apache.isis.applib.annotation.Mixin)1