Search in sources :

Example 1 with Clob

use of org.apache.isis.applib.value.Clob 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 2 with Clob

use of org.apache.isis.applib.value.Clob 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 3 with Clob

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

the class DocumentType_and_DocumentTemplates_createSome method execute.

@Override
protected void execute(final ExecutionContext executionContext) {
    // these document types have no associated templates
    final DocumentType invoiceType = upsertType(DOC_TYPE_REF_INVOICE, "Demo invoice document type", executionContext);
    final DocumentType docType = upsertType(DOC_TYPE_REF_RECEIPT, "Receipt document type", executionContext);
    // doc type for rendering cover notes.
    final DocumentType docTypeForFreemarkerHtml = upsertType(DOC_TYPE_REF_FREEMARKER_HTML, "Demo Freemarker HTML (eg email Cover Note)", executionContext);
    final RenderingStrategy fmkRenderingStrategy = renderingStrategyRepository.findByReference(RenderingStrategy_create1.REF_FMK);
    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-${demoInvoice.num}", fmkRenderingStrategy, executionContext);
    mixin(DocumentTemplate._applicable.class, fmkTemplate).applicable(Document.class, RenderModelFactoryOfDocumentAttachedToDemoInvoice.class, null);
    executionContext.addResult(this, fmkTemplate);
}
Also used : 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 4 with Clob

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

the class DocumentTypeAndTemplatesFSForInvoicesUsingSsrs method upsertDocumentTemplateForTextHtmlWithApplicability.

private void upsertDocumentTemplateForTextHtmlWithApplicability(final DocumentType docType, final LocalDate templateDate, final String atPath, final String nameSuffixIfAny, final String contentText, final RenderingStrategy contentRenderingStrategy, final String nameText, final RenderingStrategy nameRenderingStrategy, final Class<?> domainClass, final Class<? extends RendererModelFactory> rendererModelFactoryClass, final Class<? extends AttachmentAdvisor> attachmentAdvisorClass, final ExecutionContext executionContext) {
    final Clob clob = new Clob(buildTemplateName(docType, nameSuffixIfAny, ".html"), "text/html", contentText);
    final DocumentTemplate documentTemplate = upsertDocumentClobTemplate(docType, templateDate, atPath, ".html", false, clob, contentRenderingStrategy, nameText, nameRenderingStrategy, executionContext);
    mixin(DocumentTemplate._applicable.class, documentTemplate).applicable(domainClass, rendererModelFactoryClass, attachmentAdvisorClass);
    // TODO: push down to incode document; for now this is a work-around that the 'DocumentTemplate#applicable' mixin isn't a full 'upsert'
    final Applicability applicability = existingApplicability(documentTemplate, domainClass.getName());
    applicability.setRendererModelFactoryClassName(rendererModelFactoryClass.getName());
    applicability.setAttachmentAdvisorClassName(attachmentAdvisorClass.getName());
    executionContext.addResult(this, documentTemplate);
}
Also used : DocumentTemplate(org.incode.module.document.dom.impl.docs.DocumentTemplate) Applicability(org.incode.module.document.dom.impl.applicability.Applicability) Clob(org.apache.isis.applib.value.Clob)

Aggregations

Clob (org.apache.isis.applib.value.Clob)4 Blob (org.apache.isis.applib.value.Blob)2 RenderingStrategy (org.incode.module.document.dom.impl.rendering.RenderingStrategy)2 DocumentType (org.incode.module.document.dom.impl.types.DocumentType)2 LocalDate (org.joda.time.LocalDate)2 IOException (java.io.IOException)1 ApplicationException (org.apache.isis.applib.ApplicationException)1 Programmatic (org.apache.isis.applib.annotation.Programmatic)1 TranslatableString (org.apache.isis.applib.services.i18n.TranslatableString)1 Applicability (org.incode.module.document.dom.impl.applicability.Applicability)1 DocumentTemplate (org.incode.module.document.dom.impl.docs.DocumentTemplate)1 Renderer (org.incode.module.document.dom.impl.renderers.Renderer)1 RendererFromBytesToBytes (org.incode.module.document.dom.impl.renderers.RendererFromBytesToBytes)1 RendererFromBytesToChars (org.incode.module.document.dom.impl.renderers.RendererFromBytesToChars)1 RendererFromCharsToBytes (org.incode.module.document.dom.impl.renderers.RendererFromCharsToBytes)1 RendererFromCharsToChars (org.incode.module.document.dom.impl.renderers.RendererFromCharsToChars)1