Search in sources :

Example 1 with ReportRegion

use of io.jmix.reports.entity.wizard.ReportRegion in project jmix by jmix-framework.

the class ChartGenerator method generateSerialChart.

protected byte[] generateSerialChart(ReportData reportData) {
    if (CollectionUtils.isNotEmpty(reportData.getReportRegions())) {
        ReportRegion reportRegion = reportData.getReportRegions().get(0);
        SerialChartDescription serialChartDescription = metadata.create(SerialChartDescription.class);
        serialChartDescription.setBandName(reportRegion.getNameForBand());
        serialChartDescription.setValueAxisUnits("");
        serialChartDescription.setCategoryAxisCaption("");
        serialChartDescription.setValueAxisCaption("");
        List<RegionProperty> regionProperties = reportRegion.getRegionProperties();
        RegionProperty firstProperty = regionProperties.get(0);
        serialChartDescription.setCategoryField(firstProperty.getEntityTreeNode().getMetaPropertyName());
        serialChartDescription.setCategoryAxisCaption(firstProperty.getLocalizedName());
        if (regionProperties.size() > 1) {
            for (int i = 1; i < regionProperties.size(); i++) {
                RegionProperty regionProperty = regionProperties.get(i);
                MetaClass parentMetaClass = metadata.getClass(regionProperty.getEntityTreeNode().getParentMetaClassName());
                MetaProperty metaProperty = parentMetaClass.getProperty(regionProperty.getEntityTreeNode().getMetaPropertyName());
                Class<?> javaType = metaProperty.getJavaType();
                if (Number.class.isAssignableFrom(javaType)) {
                    ChartSeries chartSeries = metadata.create(ChartSeries.class);
                    chartSeries.setName(regionProperty.getLocalizedName());
                    chartSeries.setValueField(metaProperty.getName());
                    chartSeries.setType(SeriesType.COLUMN);
                    chartSeries.setOrder(serialChartDescription.getSeries().size() + 1);
                    serialChartDescription.getSeries().add(chartSeries);
                }
            }
        }
        return AbstractChartDescription.toJsonString(serialChartDescription).getBytes(StandardCharsets.UTF_8);
    }
    return new byte[0];
}
Also used : RegionProperty(io.jmix.reports.entity.wizard.RegionProperty) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) ReportRegion(io.jmix.reports.entity.wizard.ReportRegion)

Example 2 with ReportRegion

use of io.jmix.reports.entity.wizard.ReportRegion in project jmix by jmix-framework.

the class CsvGenerator method generateTemplate.

protected String generateTemplate(ReportData reportData) {
    List<String> headers = new ArrayList<>();
    List<String> aliases = new ArrayList<>();
    List<ReportRegion> reportRegions = reportData.getReportRegions();
    for (ReportRegion reportRegion : reportRegions) {
        List<String> propertyHeaders = new ArrayList<>();
        List<String> propertyAliases = new ArrayList<>();
        List<RegionProperty> regionProperties = reportRegion.getRegionProperties();
        for (RegionProperty regionProperty : regionProperties) {
            propertyHeaders.add(wrapField(regionProperty.getHierarchicalLocalizedNameExceptRoot()));
            String placeholderValue = reportTemplatePlaceholder.getPlaceholderValue(regionProperty.getHierarchicalNameExceptRoot(), reportRegion);
            propertyAliases.add(wrapField(placeholderValue));
        }
        headers.add(Joiner.on(SEPARATOR).join(propertyHeaders));
        aliases.add(Joiner.on(SEPARATOR).join(propertyAliases));
    }
    return Joiner.on(SEPARATOR).join(headers) + "\n" + Joiner.on(SEPARATOR).join(aliases);
}
Also used : RegionProperty(io.jmix.reports.entity.wizard.RegionProperty) ArrayList(java.util.ArrayList) ReportRegion(io.jmix.reports.entity.wizard.ReportRegion)

Example 3 with ReportRegion

use of io.jmix.reports.entity.wizard.ReportRegion in project jmix by jmix-framework.

the class DocxGenerator method generatePackage.

@Override
protected OpcPackage generatePackage(ReportData reportData) throws Docx4JException {
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    MainDocumentPart mainDocumentPart = wordMLPackage.getMainDocumentPart();
    org.docx4j.wml.ObjectFactory factory = org.docx4j.jaxb.Context.getWmlObjectFactory();
    for (ReportRegion reportRegion : reportData.getReportRegions()) {
        if (reportRegion.isTabulatedRegion()) {
            mainDocumentPart.addParagraphOfText("");
            int writableWidthTwips = wordMLPackage.getDocumentModel().getSections().get(0).getPageDimensions().getWritableWidthTwips();
            int cols = reportRegion.getRegionProperties().size();
            int cellWidthTwips = (int) Math.floor((writableWidthTwips / (double) cols));
            Tbl table = TblFactory.createTable(2, reportRegion.getRegionProperties().size(), cellWidthTwips);
            // for adding band name in table header row
            boolean isFirstHeaderCellFounded = false;
            List<String> tableHeaderRowData = new ArrayList<>(reportRegion.getRegionProperties().size());
            for (RegionProperty rp : reportRegion.getRegionProperties()) {
                if (!isFirstHeaderCellFounded) {
                    tableHeaderRowData.add("##band=" + reportRegion.getNameForBand() + " " + rp.getHierarchicalLocalizedNameExceptRoot());
                    isFirstHeaderCellFounded = true;
                } else {
                    tableHeaderRowData.add(rp.getHierarchicalLocalizedNameExceptRoot());
                }
            }
            fillWordTableRow(tableHeaderRowData, factory, (Tr) table.getContent().get(0));
            List<String> tablePlaceholdersRowData = new ArrayList<>(reportRegion.getRegionProperties().size());
            for (RegionProperty rp : reportRegion.getRegionProperties()) {
                tablePlaceholdersRowData.add(reportTemplatePlaceholder.getPlaceholderValue(rp.getHierarchicalNameExceptRoot(), reportRegion));
            }
            fillWordTableRow(tablePlaceholdersRowData, factory, (Tr) table.getContent().get(1));
            mainDocumentPart.addObject(table);
        } else {
            for (RegionProperty rp : reportRegion.getRegionProperties()) {
                mainDocumentPart.addParagraphOfText(rp.getHierarchicalLocalizedNameExceptRoot() + ": " + reportTemplatePlaceholder.getPlaceholderValueWithBandName(rp.getHierarchicalNameExceptRoot(), reportRegion));
            }
        }
    }
    return wordMLPackage;
}
Also used : RegionProperty(io.jmix.reports.entity.wizard.RegionProperty) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) ArrayList(java.util.ArrayList) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) ReportRegion(io.jmix.reports.entity.wizard.ReportRegion) Tbl(org.docx4j.wml.Tbl)

Example 4 with ReportRegion

use of io.jmix.reports.entity.wizard.ReportRegion in project jmix by jmix-framework.

the class HtmlGenerator method putBodyHtml.

protected void putBodyHtml(List<ReportRegion> reportRegions, Map<String, String> templateParameters) {
    StringBuilder templateBody = new StringBuilder();
    // Add #assign statements:
    for (ReportRegion reportRegion : reportRegions) {
        // header of table is filled here, so the three lines of code below is unused:
        appendHtmlFreeMarkerAssignments(templateBody, reportRegion.getNameForBand());
    }
    appendFreeMarkerSettings(templateBody);
    for (ReportRegion reportRegion : reportRegions) {
        if (reportRegion.isTabulatedRegion()) {
            // Are U ready for a String porn?
            // table def
            templateBody.append("\n\n<table class=\"report-table\" border=\"1\" cellspacing=\"0\" >\n");
            // table header
            templateBody.append("<thead>\n<tr>\n");
            for (RegionProperty regionProperty : reportRegion.getRegionProperties()) {
                templateBody.append("<th>").append(regionProperty.getHierarchicalLocalizedNameExceptRoot()).append("</th>\n");
            }
            // closing table header tags:
            templateBody.append("</tr>\n</thead>\n");
            // table body rows
            templateBody.append("<tbody>\n<#if ").append(reportRegion.getNameForBand()).append("?has_content>\n<#list ").append(reportRegion.getNameForBand()).append(" as row>\n<tr>");
            for (RegionProperty regionProperty : reportRegion.getRegionProperties()) {
                templateBody.append("\n<td> ").append(reportTemplatePlaceholder.getHtmlPlaceholderValue(reportRegion, regionProperty)).append(" </td>");
            }
            // closing table and table body tags:
            templateBody.append("\n</tr>\n</#list>\n</#if>\n</tbody>\n</table>\n\n");
        } else {
            for (RegionProperty regionProperty : reportRegion.getRegionProperties()) {
                templateBody.append("\n").append("<p>").append(regionProperty.getHierarchicalLocalizedNameExceptRoot()).append(": ").append(reportTemplatePlaceholder.getHtmlPlaceholderValue(reportRegion, regionProperty)).append("</p>");
            }
        }
    }
    templateParameters.put(HTML_TEMPLATE_PLACEHOLDER_BODY, templateBody.toString());
}
Also used : RegionProperty(io.jmix.reports.entity.wizard.RegionProperty) ReportRegion(io.jmix.reports.entity.wizard.ReportRegion)

Example 5 with ReportRegion

use of io.jmix.reports.entity.wizard.ReportRegion in project jmix by jmix-framework.

the class TableGenerator method generate.

@Override
public byte[] generate(ReportData reportData) {
    TemplateTableDescription templateTableDescription = dataManager.create(TemplateTableDescription.class);
    List<TemplateTableBand> bands = new LinkedList<>();
    for (int i = 0; i < reportData.getReportRegions().size(); i++) {
        ReportRegion reportRegion = reportData.getReportRegions().get(i);
        TemplateTableBand band = dataManager.create(TemplateTableBand.class);
        band.setPosition(i);
        band.setBandName(reportRegion.getNameForBand());
        List<TemplateTableColumn> columns = new LinkedList<>();
        for (int j = 0; j < reportRegion.getRegionProperties().size(); j++) {
            RegionProperty regionProperty = reportData.getReportRegions().get(i).getRegionProperties().get(j);
            String caption = regionProperty.getHierarchicalLocalizedNameExceptRoot().replace('.', ' ');
            TemplateTableColumn column = dataManager.create(TemplateTableColumn.class);
            column.setPosition(j);
            column.setKey(regionProperty.getHierarchicalNameExceptRoot());
            column.setCaption(caption);
            columns.add(column);
        }
        band.setColumns(columns);
        bands.add(band);
    }
    templateTableDescription.setTemplateTableBands(bands);
    return TemplateTableDescription.toJsonString(templateTableDescription).getBytes(StandardCharsets.UTF_8);
}
Also used : TemplateTableDescription(io.jmix.reports.entity.table.TemplateTableDescription) RegionProperty(io.jmix.reports.entity.wizard.RegionProperty) TemplateTableColumn(io.jmix.reports.entity.table.TemplateTableColumn) TemplateTableBand(io.jmix.reports.entity.table.TemplateTableBand) ReportRegion(io.jmix.reports.entity.wizard.ReportRegion) LinkedList(java.util.LinkedList)

Aggregations

ReportRegion (io.jmix.reports.entity.wizard.ReportRegion)8 RegionProperty (io.jmix.reports.entity.wizard.RegionProperty)7 MetaClass (io.jmix.core.metamodel.model.MetaClass)3 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)2 ArrayList (java.util.ArrayList)2 EntityTree (io.jmix.reports.app.EntityTree)1 TemplateTableBand (io.jmix.reports.entity.table.TemplateTableBand)1 TemplateTableColumn (io.jmix.reports.entity.table.TemplateTableColumn)1 TemplateTableDescription (io.jmix.reports.entity.table.TemplateTableDescription)1 ReportData (io.jmix.reports.entity.wizard.ReportData)1 RegionEditor (io.jmix.reportsui.screen.report.wizard.region.RegionEditor)1 MapScreenOptions (io.jmix.ui.screen.MapScreenOptions)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 SpreadsheetMLPackage (org.docx4j.openpackaging.packages.SpreadsheetMLPackage)1 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)1 Part (org.docx4j.openpackaging.parts.Part)1 PartName (org.docx4j.openpackaging.parts.PartName)1 Parts (org.docx4j.openpackaging.parts.Parts)1 Styles (org.docx4j.openpackaging.parts.SpreadsheetML.Styles)1