diff --git a/src/main/java/info/bukova/isspst/Constants.java b/src/main/java/info/bukova/isspst/Constants.java index 3c88315f..039d67cb 100644 --- a/src/main/java/info/bukova/isspst/Constants.java +++ b/src/main/java/info/bukova/isspst/Constants.java @@ -58,6 +58,6 @@ public class Constants { public final static String DYNAMIC_REPORT_NAME = "Tabulková sestava"; public final static ReportMapping REPORTS[] = { - new ReportMapping(MOD_ADDRESSBOOK, new Report("Pokusná sestava", "report")) + new ReportMapping(MOD_ADDRESSBOOK, new Report("Adresní karty", "address")) }; } diff --git a/src/main/java/info/bukova/isspst/reporting/GeneratorFactory.java b/src/main/java/info/bukova/isspst/reporting/GeneratorFactory.java index 40f6d227..0b45414a 100644 --- a/src/main/java/info/bukova/isspst/reporting/GeneratorFactory.java +++ b/src/main/java/info/bukova/isspst/reporting/GeneratorFactory.java @@ -1,11 +1,20 @@ package info.bukova.isspst.reporting; +import javax.servlet.ServletContext; + +import org.springframework.beans.factory.annotation.Autowired; + public class GeneratorFactory { + @Autowired + private ServletContext context; + public Generator createGenerator(ReportDefinition definition) { switch (definition.getReport().getType()) { case DYNAMIC: return new DynamicGenerator(definition); + case DEFINED: + return new PredefinedGenerator(definition, context); default: return null; diff --git a/src/main/java/info/bukova/isspst/reporting/PredefinedGenerator.java b/src/main/java/info/bukova/isspst/reporting/PredefinedGenerator.java new file mode 100644 index 00000000..d50fd5c6 --- /dev/null +++ b/src/main/java/info/bukova/isspst/reporting/PredefinedGenerator.java @@ -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"); + } + +} diff --git a/src/main/java/info/bukova/isspst/reporting/Report.java b/src/main/java/info/bukova/isspst/reporting/Report.java index 061381f8..93dd580c 100644 --- a/src/main/java/info/bukova/isspst/reporting/Report.java +++ b/src/main/java/info/bukova/isspst/reporting/Report.java @@ -6,16 +6,23 @@ public class Report { private ReportType type; private String name; private String jasperFile; + private boolean hasSettings; public Report() { - + hasSettings = false; } public Report(String name, String jasperFile) { + this(); this.type = ReportType.DEFINED; this.name = name; this.jasperFile = jasperFile; } + + public Report(String name, String jasperFile, boolean hasSettings) { + this(name, jasperFile); + this.hasSettings = hasSettings; + } public ReportType getType() { return type; @@ -41,4 +48,12 @@ public class Report { this.jasperFile = jasperFile; } + public boolean isHasSettings() { + return hasSettings; + } + + public void setHasSettings(boolean hasSettings) { + this.hasSettings = hasSettings; + } + } diff --git a/src/main/java/info/bukova/isspst/ui/ListViewModel.java b/src/main/java/info/bukova/isspst/ui/ListViewModel.java index d0fd12ba..f739efd9 100644 --- a/src/main/java/info/bukova/isspst/ui/ListViewModel.java +++ b/src/main/java/info/bukova/isspst/ui/ListViewModel.java @@ -301,7 +301,7 @@ public class ListViewModel { Map params = new HashMap(); params.put("reports", service.getReports()); 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(); } diff --git a/src/main/java/info/bukova/isspst/ui/ReportDialogVM.java b/src/main/java/info/bukova/isspst/ui/reporting/ColSelectVM.java similarity index 56% rename from src/main/java/info/bukova/isspst/ui/ReportDialogVM.java rename to src/main/java/info/bukova/isspst/ui/reporting/ColSelectVM.java index 66bec2f7..6036514c 100644 --- a/src/main/java/info/bukova/isspst/ui/ReportDialogVM.java +++ b/src/main/java/info/bukova/isspst/ui/reporting/ColSelectVM.java @@ -1,4 +1,4 @@ -package info.bukova.isspst.ui; +package info.bukova.isspst.ui.reporting; import java.beans.BeanInfo; import java.beans.IntrospectionException; @@ -10,50 +10,27 @@ import java.util.List; import info.bukova.isspst.reporting.Report; import info.bukova.isspst.reporting.ReportDefinition; 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.NotifyChange; -import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.select.annotation.WireVariable; -import org.zkoss.zul.Window; -public class ReportDialogVM { +public class ColSelectVM { - private List reports; - private Report selected; - private List data; @WireVariable private ReportDefinition reportDefinition; private LocaleConverter locConverter; @Init - public void init(@ExecutionArgParam("reports") List reports, - @ExecutionArgParam("data") List data) { - this.reports = reports; - this.data = data; + public void init() { locConverter = new LocaleConverter(); - - if (data != null && data.size() > 0 && data.get(0).getClass() != reportDefinition.gatDataClass()) { - reportDefinition.clear(); - } - } - - public LocaleConverter getLocConverter() { - return locConverter; } - public List getReports() { - return this.reports; - } - - public ReportDefinition getReportDefinition() { - return reportDefinition; - } - public ListChecks getColumns() { + Report selected = reportDefinition.getReport(); + List data = reportDefinition.getDataSet(); + if (selected == null || selected.getType() != ReportType.DYNAMIC) { return null; } @@ -79,26 +56,12 @@ public class ReportDialogVM { return columns; } - public Report getSelected() { - return selected; + public LocaleConverter getLocConverter() { + 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); - reportWin.doModal(); + public ReportDefinition getReportDefinition() { + return reportDefinition; } } diff --git a/src/main/java/info/bukova/isspst/ui/reporting/ReportDialogVM.java b/src/main/java/info/bukova/isspst/ui/reporting/ReportDialogVM.java new file mode 100644 index 00000000..ba37c19a --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/reporting/ReportDialogVM.java @@ -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 reports; + private Report selected; + @WireVariable + private ReportDefinition reportDefinition; + + @Init + public void init(@ExecutionArgParam("reports") List reports, + @ExecutionArgParam("data") List data) { + this.reports = reports; + + if (data != null && data.size() > 0 && data.get(0).getClass() != reportDefinition.gatDataClass()) { + reportDefinition.clear(); + } + + reportDefinition.setDataSet(data); + } + + public List 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"; + } + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/ReportVM.java b/src/main/java/info/bukova/isspst/ui/reporting/ReportVM.java similarity index 71% rename from src/main/java/info/bukova/isspst/ui/ReportVM.java rename to src/main/java/info/bukova/isspst/ui/reporting/ReportVM.java index 29723ee2..5fda96d7 100644 --- a/src/main/java/info/bukova/isspst/ui/ReportVM.java +++ b/src/main/java/info/bukova/isspst/ui/reporting/ReportVM.java @@ -1,4 +1,4 @@ -package info.bukova.isspst.ui; +package info.bukova.isspst.ui.reporting; import org.zkoss.bind.annotation.Init; diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 51e3507f..a7df6ea1 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -78,6 +78,7 @@ ReportPrint=Tisk ReportReports=Sestavy ReportTitle=Nadpis sestavy: ReportOptions=Volby sestavy +ReportNoOptions=Žádná nestavení Error=Chyba ErrorRights=K vykobání této operace nemáte dostatečná oprávnění diff --git a/src/main/webapp/WEB-INF/reports/address.jasper b/src/main/webapp/WEB-INF/reports/address.jasper new file mode 100644 index 00000000..78f658e9 Binary files /dev/null and b/src/main/webapp/WEB-INF/reports/address.jasper differ diff --git a/src/main/webapp/WEB-INF/reports/address.jrxml b/src/main/webapp/WEB-INF/reports/address.jrxml new file mode 100644 index 00000000..a03e1260 --- /dev/null +++ b/src/main/webapp/WEB-INF/reports/address.jrxml @@ -0,0 +1,173 @@ + + + + + + + + + + + + + + + + + + + + <band height="18" splitType="Stretch"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/app/reporting/colSelect.zul b/src/main/webapp/app/reporting/colSelect.zul new file mode 100644 index 00000000..4ad9fdee --- /dev/null +++ b/src/main/webapp/app/reporting/colSelect.zul @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/app/reporting/noOptions.zul b/src/main/webapp/app/reporting/noOptions.zul new file mode 100644 index 00000000..e2401f1c --- /dev/null +++ b/src/main/webapp/app/reporting/noOptions.zul @@ -0,0 +1,6 @@ + + +
+
+
\ No newline at end of file diff --git a/src/main/webapp/app/report.zul b/src/main/webapp/app/reporting/report.zul similarity index 82% rename from src/main/webapp/app/report.zul rename to src/main/webapp/app/reporting/report.zul index 5cef3420..b8710f9e 100644 --- a/src/main/webapp/app/report.zul +++ b/src/main/webapp/app/reporting/report.zul @@ -1,7 +1,7 @@ + viewModel="@id('vm') @init('info.bukova.isspst.ui.reporting.ReportVM')"> diff --git a/src/main/webapp/app/reportDialog.zul b/src/main/webapp/app/reporting/reportDialog.zul similarity index 56% rename from src/main/webapp/app/reportDialog.zul rename to src/main/webapp/app/reporting/reportDialog.zul index b71ab691..6017a6b2 100644 --- a/src/main/webapp/app/reportDialog.zul +++ b/src/main/webapp/app/reporting/reportDialog.zul @@ -1,7 +1,7 @@ @@ -12,17 +12,7 @@ - - - - - - - - +