Search in sources :

Example 1 with Blob

use of org.apache.isis.applib.value.Blob in project estatio by estatio.

the class PaymentLineDownloadManager method downloadToExcel.

@Action(semantics = SemanticsOf.SAFE)
public Blob downloadToExcel(final String fileName) {
    final List<PaymentLineExportV1> exportV1s = getPayments().stream().map(x -> new PaymentLineExportV1(x)).collect(Collectors.toList());
    WorksheetSpec spec = new WorksheetSpec(exportClass, "invoiceExport");
    WorksheetContent worksheetContent = new WorksheetContent(exportV1s, spec);
    return excelService.toExcel(worksheetContent, fileName);
}
Also used : Action(org.apache.isis.applib.annotation.Action) Nature(org.apache.isis.applib.annotation.Nature) Setter(lombok.Setter) Getter(lombok.Getter) PaymentLineRepository(org.estatio.module.capex.dom.payment.PaymentLineRepository) PromptStyle(org.apache.isis.applib.annotation.PromptStyle) Collectors(java.util.stream.Collectors) MemberOrder(org.apache.isis.applib.annotation.MemberOrder) Programmatic(org.apache.isis.applib.annotation.Programmatic) PropertyLayout(org.apache.isis.applib.annotation.PropertyLayout) LocalDate(org.joda.time.LocalDate) ActionLayout(org.apache.isis.applib.annotation.ActionLayout) CollectionLayout(org.apache.isis.applib.annotation.CollectionLayout) SemanticsOf(org.apache.isis.applib.annotation.SemanticsOf) PaymentLine(org.estatio.module.capex.dom.payment.PaymentLine) List(java.util.List) WorksheetContent(org.isisaddons.module.excel.dom.WorksheetContent) DomainObject(org.apache.isis.applib.annotation.DomainObject) WorksheetSpec(org.isisaddons.module.excel.dom.WorksheetSpec) Contributed(org.apache.isis.applib.annotation.Contributed) ExcelService(org.isisaddons.module.excel.dom.ExcelService) Blob(org.apache.isis.applib.value.Blob) NoArgsConstructor(lombok.NoArgsConstructor) WorksheetSpec(org.isisaddons.module.excel.dom.WorksheetSpec) WorksheetContent(org.isisaddons.module.excel.dom.WorksheetContent) Action(org.apache.isis.applib.annotation.Action)

Example 2 with Blob

use of org.apache.isis.applib.value.Blob in project estatio by estatio.

the class PaymentBatchManager method downloadExcelExportForCompletedBatches.

@Action(semantics = SemanticsOf.SAFE, commandPersistence = CommandPersistence.NOT_PERSISTED, publishing = Publishing.DISABLED)
public Blob downloadExcelExportForCompletedBatches(@Nullable final String documentName, final LocalDate startExecutionDate, final LocalDate endExecutionDate) {
    List<PaymentLineForExcelExportV1> lineVms = new ArrayList<>();
    List<PaymentBatch> batchesToExport = getCompletedBatches().stream().filter(x -> x.getRequestedExecutionDate().toLocalDate().isAfter(startExecutionDate.minusDays(1)) && x.getRequestedExecutionDate().toLocalDate().isBefore(endExecutionDate.plusDays(1))).collect(Collectors.toList());
    for (PaymentBatch batch : batchesToExport) {
        lineVms.addAll(batch.paymentLinesForExcelExport());
    }
    String name = documentName != null ? documentName.concat(".xlsx") : "export.xlsx";
    return excelService.toExcel(lineVms, PaymentLineForExcelExportV1.class, "export", name);
}
Also used : Clob(org.apache.isis.applib.value.Clob) Nature(org.apache.isis.applib.annotation.Nature) PaymentBatch_complete(org.estatio.module.capex.dom.payment.approval.triggers.PaymentBatch_complete) Setter(lombok.Setter) Getter(lombok.Getter) WrapperFactory(org.apache.isis.applib.services.wrapper.WrapperFactory) BankAccountRepository(org.estatio.module.financial.dom.BankAccountRepository) PaymentMethod(org.estatio.module.invoice.dom.PaymentMethod) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) BigDecimal(java.math.BigDecimal) CreditTransfer(org.estatio.module.capex.dom.payment.CreditTransfer) Lists(com.google.common.collect.Lists) AccessLevel(lombok.AccessLevel) BankAccount(org.estatio.module.financial.dom.BankAccount) FactoryService(org.apache.isis.applib.services.factory.FactoryService) Nullable(javax.annotation.Nullable) Blob(org.apache.isis.applib.value.Blob) IncomingInvoice(org.estatio.module.capex.dom.invoice.IncomingInvoice) Action(org.apache.isis.applib.annotation.Action) PaymentBatchRepository(org.estatio.module.capex.dom.payment.PaymentBatchRepository) IsisJdoSupport(org.apache.isis.applib.services.jdosupport.IsisJdoSupport) IncomingInvoiceRepository(org.estatio.module.capex.dom.invoice.IncomingInvoiceRepository) DebtorBankAccountService(org.estatio.module.capex.app.DebtorBankAccountService) ServiceRegistry2(org.apache.isis.applib.services.registry.ServiceRegistry2) Collection(java.util.Collection) DateTime(org.joda.time.DateTime) PaymentBatch(org.estatio.module.capex.dom.payment.PaymentBatch) IncomingInvoiceApprovalState(org.estatio.module.capex.dom.invoice.approval.IncomingInvoiceApprovalState) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) MemberOrder(org.apache.isis.applib.annotation.MemberOrder) LocalDate(org.joda.time.LocalDate) SemanticsOf(org.apache.isis.applib.annotation.SemanticsOf) PaymentLine(org.estatio.module.capex.dom.payment.PaymentLine) List(java.util.List) DomainObject(org.apache.isis.applib.annotation.DomainObject) CommandPersistence(org.apache.isis.applib.annotation.CommandPersistence) TransactionService(org.apache.isis.applib.services.xactn.TransactionService) ParameterLayout(org.apache.isis.applib.annotation.ParameterLayout) PaymentLineForExcelExportV1(org.estatio.module.capex.app.paymentline.PaymentLineForExcelExportV1) InvoicePageRange(org.estatio.module.capex.dom.util.InvoicePageRange) Collections(java.util.Collections) Publishing(org.apache.isis.applib.annotation.Publishing) ExcelService(org.isisaddons.module.excel.dom.ExcelService) ArrayList(java.util.ArrayList) PaymentLineForExcelExportV1(org.estatio.module.capex.app.paymentline.PaymentLineForExcelExportV1) PaymentBatch(org.estatio.module.capex.dom.payment.PaymentBatch) Action(org.apache.isis.applib.annotation.Action)

Example 3 with Blob

use of org.apache.isis.applib.value.Blob in project estatio by estatio.

the class DocumentTemplate method renderContent.

// endregion
// region > renderContent (programmatic)
@Programmatic
public void renderContent(final Document document, final Object contentDataModel) {
    final String variant = "content";
    final String documentName = document.getName();
    try {
        final DocumentNature inputNature = getContentRenderingStrategy().getInputNature();
        final DocumentNature outputNature = getContentRenderingStrategy().getOutputNature();
        final Renderer renderer = getContentRenderingStrategy().newRenderer();
        switch(inputNature) {
            case BYTES:
                switch(outputNature) {
                    case BYTES:
                        final byte[] renderedBytes = ((RendererFromBytesToBytes) renderer).renderBytesToBytes(getType(), variant, getAtPath(), getVersion(), asBytes(), contentDataModel);
                        final Blob blob = new Blob(documentName, getMimeType(), renderedBytes);
                        document.modifyBlob(blob);
                        return;
                    case CHARACTERS:
                        final String renderedChars = ((RendererFromBytesToChars) renderer).renderBytesToChars(getType(), variant, getAtPath(), getVersion(), asBytes(), contentDataModel);
                        if (renderedChars.length() <= TextType.Meta.MAX_LEN) {
                            document.setTextData(getName(), getMimeType(), renderedChars);
                        } else {
                            final Clob clob = new Clob(documentName, getMimeType(), renderedChars);
                            document.modifyClob(clob);
                        }
                        return;
                    default:
                        // shouldn't happen, above switch statement is complete
                        throw new IllegalArgumentException(String.format("Unknown output DocumentNature '%s'", outputNature));
                }
            case CHARACTERS:
                switch(outputNature) {
                    case BYTES:
                        final byte[] renderedBytes = ((RendererFromCharsToBytes) renderer).renderCharsToBytes(getType(), variant, getAtPath(), getVersion(), asChars(), contentDataModel);
                        final Blob blob = new Blob(documentName, getMimeType(), renderedBytes);
                        document.modifyBlob(blob);
                        return;
                    case CHARACTERS:
                        final String renderedChars = ((RendererFromCharsToChars) renderer).renderCharsToChars(getType(), variant, getAtPath(), getVersion(), asChars(), contentDataModel);
                        if (renderedChars.length() <= TextType.Meta.MAX_LEN) {
                            document.setTextData(getName(), getMimeType(), renderedChars);
                        } else {
                            final Clob clob = new Clob(documentName, getMimeType(), renderedChars);
                            document.modifyClob(clob);
                        }
                        return;
                    default:
                        // shouldn't happen, above switch statement is complete
                        throw new IllegalArgumentException(String.format("Unknown output DocumentNature '%s'", outputNature));
                }
            default:
                // shouldn't happen, above switch statement is complete
                throw new IllegalArgumentException(String.format("Unknown input DocumentNature '%s'", inputNature));
        }
    } catch (IOException e) {
        throw new ApplicationException("Unable to render document template", e);
    }
}
Also used : Blob(org.apache.isis.applib.value.Blob) RendererFromCharsToChars(org.incode.module.document.dom.impl.renderers.RendererFromCharsToChars) TranslatableString(org.apache.isis.applib.services.i18n.TranslatableString) RendererFromCharsToBytes(org.incode.module.document.dom.impl.renderers.RendererFromCharsToBytes) IOException(java.io.IOException) RendererFromBytesToChars(org.incode.module.document.dom.impl.renderers.RendererFromBytesToChars) RendererFromBytesToBytes(org.incode.module.document.dom.impl.renderers.RendererFromBytesToBytes) ApplicationException(org.apache.isis.applib.ApplicationException) Renderer(org.incode.module.document.dom.impl.renderers.Renderer) Clob(org.apache.isis.applib.value.Clob) Programmatic(org.apache.isis.applib.annotation.Programmatic)

Example 4 with Blob

use of org.apache.isis.applib.value.Blob in project estatio by estatio.

the class DocumentTypeAndTemplatesApplicableForDemoObjectFixture method execute.

@Override
protected void execute(final ExecutionContext executionContext) {
    // prereqs
    executionContext.executeChild(this, new RenderingStrategy_create6());
    // these document types have no associated templates (for attachPdf mixin)
    final DocumentType invoiceType = upsertType(DOC_TYPE_REF_TAX_RECEIPT, "Tax receipt", executionContext);
    final DocumentType docType = upsertType(DOC_TYPE_REF_SUPPLIER_RECEIPT, "Supplier receipt", executionContext);
    final DocumentType docTypeForFreemarkerHtml = upsertType(DOC_TYPE_REF_FREEMARKER_HTML, "Demo Freemarker HTML (eg email Cover Note)", executionContext);
    final RenderingStrategy fmkRenderingStrategy = renderingStrategyRepository.findByReference(RenderingStrategy_create6.REF_FMK);
    final RenderingStrategy sipcRenderingStrategy = renderingStrategyRepository.findByReference(RenderingStrategy_create6.REF_SIPC);
    final RenderingStrategy siRenderingStrategy = renderingStrategyRepository.findByReference(RenderingStrategy_create6.REF_SI);
    final RenderingStrategy xdpRenderingStrategy = renderingStrategyRepository.findByReference(RenderingStrategy_create6.REF_XDP);
    final RenderingStrategy xddRenderingStrategy = renderingStrategyRepository.findByReference(RenderingStrategy_create6.REF_XDD);
    final String atPath = "/";
    // 
    // freemarker template, with html
    // 
    final LocalDate now = clockService.now();
    final Clob clob = new Clob(docTypeForFreemarkerHtml.getName(), "text/html", loadResource("FreemarkerHtmlCoverNote.html"));
    fmkTemplate = upsertDocumentClobTemplate(docTypeForFreemarkerHtml, now, atPath, ".html", false, clob, fmkRenderingStrategy, "Freemarker-html-cover-note-for-${demoObject.name}", fmkRenderingStrategy, executionContext);
    mixin(DocumentTemplate._applicable.class, fmkTemplate).applicable(DemoObjectWithUrl.class, FreemarkerModelOfDemoObject.class, ForDemoObjectAttachToSame.class);
    executionContext.addResult(this, fmkTemplate);
    // 
    // template for string interpolator URL
    // 
    final DocumentType docTypeForStringInterpolatorUrl = upsertType(DOC_TYPE_REF_STRINGINTERPOLATOR_URL, "Demo String Interpolator to retrieve URL", executionContext);
    siTemplate = upsertDocumentTextTemplate(docTypeForStringInterpolatorUrl, now, atPath, ".pdf", false, docTypeForStringInterpolatorUrl.getName(), "application/pdf", "${demoObject.url}", sipcRenderingStrategy, "pdf-of-url-held-in-${demoObject.name}", siRenderingStrategy, executionContext);
    mixin(DocumentTemplate._applicable.class, siTemplate).applicable(DemoObjectWithUrl.class, StringInterpolatorRootOfDemoObject.class, ForDemoObjectAttachToSame.class);
    // 
    // template for xdocreport (PDF)
    // 
    final DocumentType docTypeForXDocReportPdf = upsertType(DOC_TYPE_REF_XDOCREPORT_PDF, "Demo XDocReport for PDF", executionContext);
    xdpTemplate = upsertDocumentBlobTemplate(docTypeForXDocReportPdf, now, atPath, ".pdf", false, new Blob(docTypeForXDocReportPdf.getName() + ".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", loadResourceBytes("demoObject-template.docx")), xdpRenderingStrategy, "${demoObject.name}", fmkRenderingStrategy, executionContext);
    mixin(DocumentTemplate._applicable.class, xdpTemplate).applicable(DemoObjectWithUrl.class, XDocReportModelOfDemoObject.class, ForDemoObjectAttachToSame.class);
    // 
    // template for xdocreport (DOCX)
    // 
    final DocumentType docTypeForXDocReportDocx = upsertType(DOC_TYPE_REF_XDOCREPORT_DOC, "Demo XDocReport for DOCX", executionContext);
    xddTemplate = upsertDocumentBlobTemplate(docTypeForXDocReportDocx, now, atPath, ".docx", false, new Blob(docTypeForXDocReportDocx.getName() + ".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", loadResourceBytes("demoObject-template.docx")), xddRenderingStrategy, "${demoObject.name}", fmkRenderingStrategy, executionContext);
    mixin(DocumentTemplate._applicable.class, xddTemplate).applicable(DemoObjectWithUrl.class, XDocReportModelOfDemoObject.class, ForDemoObjectAlsoAttachToFirstOtherObject.class);
}
Also used : Blob(org.apache.isis.applib.value.Blob) RenderingStrategy(org.incode.module.document.dom.impl.rendering.RenderingStrategy) DocumentType(org.incode.module.document.dom.impl.types.DocumentType) Clob(org.apache.isis.applib.value.Clob) LocalDate(org.joda.time.LocalDate)

Example 5 with Blob

use of org.apache.isis.applib.value.Blob in project estatio by estatio.

the class InvoiceSummaryForPropertyDueDateStatus_sendByPostAbstract method $$.

@Action(semantics = SemanticsOf.NON_IDEMPOTENT_ARE_YOU_SURE)
@ActionLayout(contributed = Contributed.AS_ACTION)
public Blob $$(final String fileName) throws IOException {
    final List<byte[]> pdfBytes = Lists.newArrayList();
    for (final InvoiceAndDocument invoiceAndDocument : invoiceAndDocumentsToSend()) {
        final Invoice invoice = invoiceAndDocument.getInvoice();
        final Document prelimLetterOrInvoiceNote = invoiceAndDocument.getDocument();
        final InvoiceForLease_sendByPost invoice_sendByPost = invoice_sendByPost(invoice);
        final PostalAddress postalAddress = invoice_sendByPost.default1$$(prelimLetterOrInvoiceNote);
        invoice_sendByPost.createPostalCommunicationAsSent(prelimLetterOrInvoiceNote, postalAddress);
        invoice_sendByPost.appendPdfBytes(prelimLetterOrInvoiceNote, pdfBytes);
    }
    final byte[] mergedBytes = pdfBoxService.merge(pdfBytes.toArray(new byte[][] {}));
    return new Blob(fileName, DocumentConstants.MIME_TYPE_APPLICATION_PDF, mergedBytes);
}
Also used : PostalAddress(org.incode.module.communications.dom.impl.commchannel.PostalAddress) Blob(org.apache.isis.applib.value.Blob) Invoice(org.estatio.module.invoice.dom.Invoice) Document(org.incode.module.document.dom.impl.docs.Document) InvoiceForLease_sendByPost(org.estatio.module.lease.dom.invoicing.comms.InvoiceForLease_sendByPost) Action(org.apache.isis.applib.annotation.Action) ActionLayout(org.apache.isis.applib.annotation.ActionLayout)

Aggregations

Blob (org.apache.isis.applib.value.Blob)19 Action (org.apache.isis.applib.annotation.Action)10 ActionLayout (org.apache.isis.applib.annotation.ActionLayout)8 Document (org.incode.module.document.dom.impl.docs.Document)7 List (java.util.List)4 SemanticsOf (org.apache.isis.applib.annotation.SemanticsOf)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 Inject (javax.inject.Inject)3 DomainObject (org.apache.isis.applib.annotation.DomainObject)3 MemberOrder (org.apache.isis.applib.annotation.MemberOrder)3 Nature (org.apache.isis.applib.annotation.Nature)3 Clob (org.apache.isis.applib.value.Clob)3 LocalDate (org.joda.time.LocalDate)3 URL (java.net.URL)2 Getter (lombok.Getter)2 Setter (lombok.Setter)2 CollectionLayout (org.apache.isis.applib.annotation.CollectionLayout)2 Contributed (org.apache.isis.applib.annotation.Contributed)2 Parameter (org.apache.isis.applib.annotation.Parameter)2