Podpora pro sestavy definované přes JRXML soubory. Dynamické načítání

zul souborů pro nastavení sestavy.
closes #81
multitenant
Josef Rokos 11 years ago
parent b4a86ea5c2
commit cfb7e43173

@ -58,6 +58,6 @@ public class Constants {
public final static String DYNAMIC_REPORT_NAME = "Tabulková sestava"; public final static String DYNAMIC_REPORT_NAME = "Tabulková sestava";
public final static ReportMapping REPORTS[] = { public final static ReportMapping REPORTS[] = {
new ReportMapping(MOD_ADDRESSBOOK, new Report("Pokusná sestava", "report")) new ReportMapping(MOD_ADDRESSBOOK, new Report("Adresní karty", "address"))
}; };
} }

@ -1,11 +1,20 @@
package info.bukova.isspst.reporting; package info.bukova.isspst.reporting;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.annotation.Autowired;
public class GeneratorFactory { public class GeneratorFactory {
@Autowired
private ServletContext context;
public Generator createGenerator(ReportDefinition definition) { public Generator createGenerator(ReportDefinition definition) {
switch (definition.getReport().getType()) { switch (definition.getReport().getType()) {
case DYNAMIC: case DYNAMIC:
return new DynamicGenerator(definition); return new DynamicGenerator(definition);
case DEFINED:
return new PredefinedGenerator(definition, context);
default: default:
return null; return null;

@ -0,0 +1,45 @@
package info.bukova.isspst.reporting;
import java.io.File;
import javax.servlet.ServletContext;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.JasperRunManager;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.engine.util.JRProperties;
@SuppressWarnings("deprecation")
public class PredefinedGenerator implements Generator {
private ReportDefinition definition;
private ServletContext ctx;
public PredefinedGenerator(ReportDefinition definition, ServletContext ctx) {
this.definition = definition;
this.ctx = ctx;
}
@Override
public byte[] generate() {
byte[] bytes = null;
try {
JasperReport report = (JasperReport) JRLoader.loadObject(getReportFile());
JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "Cp1250");
bytes = JasperRunManager.runReportToPdf(report, definition.getParams(), new JRBeanCollectionDataSource(definition.getDataSet()));;
} catch (JRException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bytes;
}
protected File getReportFile() {
return new File(ctx.getRealPath("WEB-INF/reports") + "/" + definition.getReport().getJasperFile() + ".jasper");
}
}

@ -6,17 +6,24 @@ public class Report {
private ReportType type; private ReportType type;
private String name; private String name;
private String jasperFile; private String jasperFile;
private boolean hasSettings;
public Report() { public Report() {
hasSettings = false;
} }
public Report(String name, String jasperFile) { public Report(String name, String jasperFile) {
this();
this.type = ReportType.DEFINED; this.type = ReportType.DEFINED;
this.name = name; this.name = name;
this.jasperFile = jasperFile; this.jasperFile = jasperFile;
} }
public Report(String name, String jasperFile, boolean hasSettings) {
this(name, jasperFile);
this.hasSettings = hasSettings;
}
public ReportType getType() { public ReportType getType() {
return type; return type;
} }
@ -41,4 +48,12 @@ public class Report {
this.jasperFile = jasperFile; this.jasperFile = jasperFile;
} }
public boolean isHasSettings() {
return hasSettings;
}
public void setHasSettings(boolean hasSettings) {
this.hasSettings = hasSettings;
}
} }

@ -301,7 +301,7 @@ public class ListViewModel<T extends DataModel> {
Map<String, Object> params = new HashMap<String, Object>(); Map<String, Object> params = new HashMap<String, Object>();
params.put("reports", service.getReports()); params.put("reports", service.getReports());
params.put("data", dataList); params.put("data", dataList);
Window win = (Window) Executions.createComponents("/app/reportDialog.zul", null, params); Window win = (Window) Executions.createComponents("/app/reporting/reportDialog.zul", null, params);
win.doModal(); win.doModal();
} }

@ -1,4 +1,4 @@
package info.bukova.isspst.ui; package info.bukova.isspst.ui.reporting;
import java.beans.BeanInfo; import java.beans.BeanInfo;
import java.beans.IntrospectionException; import java.beans.IntrospectionException;
@ -10,50 +10,27 @@ import java.util.List;
import info.bukova.isspst.reporting.Report; import info.bukova.isspst.reporting.Report;
import info.bukova.isspst.reporting.ReportDefinition; import info.bukova.isspst.reporting.ReportDefinition;
import info.bukova.isspst.reporting.ReportType; import info.bukova.isspst.reporting.ReportType;
import info.bukova.isspst.ui.ListChecks;
import info.bukova.isspst.ui.LocaleConverter;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ExecutionArgParam;
import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zk.ui.select.annotation.WireVariable;
import org.zkoss.zul.Window;
public class ReportDialogVM { public class ColSelectVM {
private List<Report> reports;
private Report selected;
private List<Object> data;
@WireVariable @WireVariable
private ReportDefinition reportDefinition; private ReportDefinition reportDefinition;
private LocaleConverter locConverter; private LocaleConverter locConverter;
@Init @Init
public void init(@ExecutionArgParam("reports") List<Report> reports, public void init() {
@ExecutionArgParam("data") List<Object> data) {
this.reports = reports;
this.data = data;
locConverter = new LocaleConverter(); locConverter = new LocaleConverter();
if (data != null && data.size() > 0 && data.get(0).getClass() != reportDefinition.gatDataClass()) {
reportDefinition.clear();
}
}
public LocaleConverter getLocConverter() {
return locConverter;
}
public List<Report> getReports() {
return this.reports;
}
public ReportDefinition getReportDefinition() {
return reportDefinition;
} }
public ListChecks<String> getColumns() { public ListChecks<String> getColumns() {
Report selected = reportDefinition.getReport();
List<Object> data = reportDefinition.getDataSet();
if (selected == null || selected.getType() != ReportType.DYNAMIC) { if (selected == null || selected.getType() != ReportType.DYNAMIC) {
return null; return null;
} }
@ -79,26 +56,12 @@ public class ReportDialogVM {
return columns; return columns;
} }
public Report getSelected() { public LocaleConverter getLocConverter() {
return selected; return locConverter;
}
@NotifyChange("columns")
public void setSelected(Report selected) {
this.selected = selected;
}
@Command
public void print(@BindingParam("window") Window window) {
reportDefinition.setDataSet(data);
reportDefinition.setReport(selected);
if (window != null) {
window.detach();
} }
Window reportWin = (Window) Executions.createComponents("/app/report.zul", null, null); public ReportDefinition getReportDefinition() {
reportWin.doModal(); return reportDefinition;
} }
} }

@ -0,0 +1,75 @@
package info.bukova.isspst.ui.reporting;
import info.bukova.isspst.reporting.Report;
import info.bukova.isspst.reporting.ReportDefinition;
import info.bukova.isspst.reporting.ReportType;
import java.util.List;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ExecutionArgParam;
import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.select.annotation.WireVariable;
import org.zkoss.zul.Window;
public class ReportDialogVM {
private List<Report> reports;
private Report selected;
@WireVariable
private ReportDefinition reportDefinition;
@Init
public void init(@ExecutionArgParam("reports") List<Report> reports,
@ExecutionArgParam("data") List<Object> data) {
this.reports = reports;
if (data != null && data.size() > 0 && data.get(0).getClass() != reportDefinition.gatDataClass()) {
reportDefinition.clear();
}
reportDefinition.setDataSet(data);
}
public List<Report> getReports() {
return this.reports;
}
public ReportDefinition getReportDefinition() {
return reportDefinition;
}
public Report getSelected() {
return selected;
}
@NotifyChange("optionsForm")
public void setSelected(Report selected) {
this.selected = selected;
reportDefinition.setReport(selected);
}
@Command
public void print(@BindingParam("window") Window window) {
if (window != null) {
window.detach();
}
Window reportWin = (Window) Executions.createComponents("/app/reporting/report.zul", null, null);
reportWin.doModal();
}
public String getOptionsForm() {
if (selected != null && selected.getType() == ReportType.DYNAMIC) {
return "/app/reporting/colSelect.zul";
} else if (selected != null && selected.isHasSettings()) {
return "/app/reporting/" + selected.getJasperFile() + ".zul";
} else {
return "/app/reporting/noOptions.zul";
}
}
}

@ -1,4 +1,4 @@
package info.bukova.isspst.ui; package info.bukova.isspst.ui.reporting;
import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.Init;

@ -78,6 +78,7 @@ ReportPrint=Tisk
ReportReports=Sestavy ReportReports=Sestavy
ReportTitle=Nadpis sestavy: ReportTitle=Nadpis sestavy:
ReportOptions=Volby sestavy ReportOptions=Volby sestavy
ReportNoOptions=Žádná nestavení
Error=Chyba Error=Chyba
ErrorRights=K vykobání této operace nemáte dostatečná oprávnění ErrorRights=K vykobání této operace nemáte dostatečná oprávnění

@ -0,0 +1,173 @@
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="address" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2cacf86c-b3c7-40ea-97b1-bdf63b3abc19">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<field name="company" class="java.lang.String"/>
<field name="city" class="java.lang.String"/>
<field name="street" class="java.lang.String"/>
<field name="houseNumber" class="java.lang.String"/>
<field name="ic" class="java.lang.Long"/>
<field name="zipCode" class="java.lang.String"/>
<field name="dic" class="java.lang.String"/>
<field name="web" class="java.lang.String"/>
<field name="email" class="java.lang.String"/>
<field name="contactName" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="18" splitType="Stretch"/>
</title>
<pageHeader>
<band height="28" splitType="Stretch">
<staticText>
<reportElement uuid="f87bcea0-ca1b-494e-af40-25b7ecc257e3" x="247" y="0" width="113" height="26"/>
<textElement>
<font size="18" isBold="true" pdfFontName="Helvetica-Bold" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Adresy]]></text>
</staticText>
</band>
</pageHeader>
<columnHeader>
<band height="16" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="163" splitType="Stretch">
<line>
<reportElement uuid="878c0f64-8c89-4965-8f92-1fe06a5c568e" x="0" y="161" width="555" height="1"/>
<graphicElement>
<pen lineStyle="Double"/>
</graphicElement>
</line>
<textField>
<reportElement uuid="094bedd3-551d-42d4-8675-5711d960414e" x="0" y="5" width="555" height="20"/>
<textElement>
<font size="12" isBold="true" pdfFontName="Helvetica-BoldOblique" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{company}]]></textFieldExpression>
</textField>
<line>
<reportElement uuid="3e42046a-810f-423f-8134-6b71b4bd0c85" x="0" y="29" width="555" height="1"/>
</line>
<staticText>
<reportElement uuid="afa3900e-e487-4a09-a6f7-989a92a9f1ec" x="0" y="38" width="77" height="20"/>
<textElement>
<font isBold="true" pdfFontName="Helvetica-Bold" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[IČ]]></text>
</staticText>
<staticText>
<reportElement uuid="496d20e5-929b-4dfd-b770-70ab5c9341f3" x="0" y="58" width="77" height="20"/>
<textElement>
<font isBold="true" pdfFontName="Helvetica-Bold" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[DIČ]]></text>
</staticText>
<textField isBlankWhenNull="true">
<reportElement uuid="f2af95df-0b40-495b-8f54-0e53a1bbdcfb" x="77" y="58" width="128" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{dic}]]></textFieldExpression>
</textField>
<staticText>
<reportElement uuid="b88df725-f080-427b-b977-ca7d6c379f41" x="0" y="78" width="77" height="20"/>
<textElement>
<font isBold="true" pdfFontName="Helvetica-Bold" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Město]]></text>
</staticText>
<textField isBlankWhenNull="true">
<reportElement uuid="627a01de-a497-4654-bd3f-250006079b03" x="77" y="78" width="189" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>
</textField>
<staticText>
<reportElement uuid="93250d5f-6e5a-4bd3-860f-0778a1464ae2" x="0" y="98" width="77" height="20"/>
<textElement>
<font isBold="true" pdfFontName="Helvetica-Bold" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Ulice]]></text>
</staticText>
<textField isBlankWhenNull="true">
<reportElement uuid="8e4c5326-3905-450a-9ccd-e10b265c8769" x="77" y="98" width="189" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{street}]]></textFieldExpression>
</textField>
<staticText>
<reportElement uuid="a91717ea-dca2-43f9-bf8c-656f60f77f2a" x="0" y="118" width="77" height="20"/>
<textElement>
<font isBold="true" pdfFontName="Helvetica-Bold" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Číslo]]></text>
</staticText>
<textField isBlankWhenNull="true">
<reportElement uuid="6ee787ba-a11c-477f-a7b3-499bdb3206eb" x="77" y="118" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{houseNumber}]]></textFieldExpression>
</textField>
<staticText>
<reportElement uuid="b474f469-5635-48b7-ae02-7670081e1723" x="0" y="138" width="77" height="20"/>
<textElement>
<font isBold="true" pdfFontName="Helvetica-Bold" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[PSČ]]></text>
</staticText>
<textField isBlankWhenNull="true">
<reportElement uuid="bf63acbb-5367-4292-a3d3-863cce98b1a3" x="77" y="138" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{zipCode}]]></textFieldExpression>
</textField>
<staticText>
<reportElement uuid="f50e23b7-7daa-430b-bd18-290bdb839dc8" x="284" y="38" width="100" height="20"/>
<textElement>
<font isBold="true" pdfFontName="Helvetica-Bold" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Kontaktní osoba]]></text>
</staticText>
<staticText>
<reportElement uuid="ad4dcc95-d692-4dc5-acd1-b29aeb3f27f1" x="284" y="58" width="100" height="20"/>
<textElement>
<font isBold="true" pdfFontName="Helvetica-Bold" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[Web]]></text>
</staticText>
<textField isBlankWhenNull="true">
<reportElement uuid="a39b1341-2a2a-418b-beba-429521c24b77" x="384" y="58" width="171" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{web}]]></textFieldExpression>
</textField>
<staticText>
<reportElement uuid="20b19927-0028-4fa1-ae21-014546d2d1ee" x="284" y="78" width="100" height="20"/>
<textElement>
<font isBold="true" pdfFontName="Helvetica-Bold" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[E-mail]]></text>
</staticText>
<textField isBlankWhenNull="true">
<reportElement uuid="e9ab750f-9e93-4bb7-b450-0024bdd116c9" x="384" y="78" width="171" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{email}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement uuid="288a7d64-7aff-4358-aa3e-47988849915b" x="384" y="38" width="171" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{contactName}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement uuid="5bbc5045-e31c-40f1-8cdf-ad654441862b" x="77" y="38" width="125" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{ic}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="14" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="16" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="16" splitType="Stretch"/>
</summary>
</jasperReport>

@ -0,0 +1,15 @@
<?page title="Column Select" contentType="text/html;charset=UTF-8"?>
<zk>
<groupbox mold="3d" closable="false" width="270px" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vmOpt') @init('info.bukova.isspst.ui.reporting.ColSelectVM')">
<caption label="${labels.ReportOptions}"></caption>
<hbox>
<label value="${labels.ReportTitle}"/> <textbox value="@bind(vmOpt.reportDefinition.reportTitle)"/>
</hbox>
<vbox children="@load(vmOpt.columns.checks)">
<template name="children">
<checkbox label="@load(each.member) @converter(vmOpt.locConverter)" checked="@bind(each.checked)"/>
</template>
</vbox>
</groupbox>
</zk>

@ -0,0 +1,6 @@
<?page title="No Options" contentType="text/html;charset=UTF-8"?>
<zk>
<div>
<label value="${labels.ReportNoOptions}"/>
</div>
</zk>

@ -1,7 +1,7 @@
<?page title="${labels.ReportReport}" contentType="text/html;charset=UTF-8"?> <?page title="${labels.ReportReport}" contentType="text/html;charset=UTF-8"?>
<zk> <zk>
<window title="${labels.ReportReport}" border="normal" closable="true" apply="org.zkoss.bind.BindComposer" <window title="${labels.ReportReport}" border="normal" closable="true" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('info.bukova.isspst.ui.ReportVM')"> viewModel="@id('vm') @init('info.bukova.isspst.ui.reporting.ReportVM')">
<toolbar> <toolbar>
<toolbarbutton image="/img/send.png" tooltiptext="${labels.ReportSend}"/> <toolbarbutton image="/img/send.png" tooltiptext="${labels.ReportSend}"/>
</toolbar> </toolbar>

@ -1,7 +1,7 @@
<?page title="${labels.ReportReports}" contentType="text/html;charset=UTF-8"?> <?page title="${labels.ReportReports}" contentType="text/html;charset=UTF-8"?>
<zk> <zk>
<window id="reportDialog" title="${labels.ReportReports}" border="normal" apply="org.zkoss.bind.BindComposer" <window id="reportDialog" title="${labels.ReportReports}" border="normal" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('info.bukova.isspst.ui.ReportDialogVM')" viewModel="@id('vm') @init('info.bukova.isspst.ui.reporting.ReportDialogVM')"
closable="true" width="550px"> closable="true" width="550px">
<hbox> <hbox>
@ -12,17 +12,7 @@
</listitem> </listitem>
</template> </template>
</listbox> </listbox>
<groupbox mold="3d" closable="false" width="270px"> <include src="@load(vm.optionsForm)"/>
<caption label="${labels.ReportOptions}"></caption>
<hbox>
<label value="${labels.ReportTitle}"/> <textbox value="@bind(vm.reportDefinition.reportTitle)"/>
</hbox>
<vbox children="@load(vm.columns.checks)">
<template name="children">
<checkbox label="@load(each.member) @converter(vm.locConverter)" checked="@bind(each.checked)"/>
</template>
</vbox>
</groupbox>
</hbox> </hbox>
<hbox> <hbox>
<button label="${labels.ReportPrint}" onClick="@command('print', window=reportDialog)"/> <button label="${labels.ButtonStorno}" onClick="reportDialog.detach()"/> <button label="${labels.ReportPrint}" onClick="@command('print', window=reportDialog)"/> <button label="${labels.ButtonStorno}" onClick="reportDialog.detach()"/>
Loading…
Cancel
Save