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];
}
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);
}
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;
}
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());
}
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);
}
Aggregations