From 25a4d2dfb72ea6b5782dc361f64e1ff3eb5054dc Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Mon, 26 May 2014 21:44:55 +0200 Subject: [PATCH] =?UTF-8?q?Podpora=20tisku.=20Implementace=20tisku=20dynam?= =?UTF-8?q?ick=C3=BDch=20sestav.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...InitListener.java => AppInitListener.java} | 23 +++- .../java/info/bukova/isspst/Constants.java | 7 ++ src/main/java/info/bukova/isspst/Module.java | 15 +++ .../isspst/reporting/DefinitionFiller.java | 44 ++++++++ .../isspst/reporting/DynamicGenerator.java | 101 ++++++++++++++++++ .../bukova/isspst/reporting/Generator.java | 7 ++ .../isspst/reporting/GeneratorFactory.java | 15 +++ .../info/bukova/isspst/reporting/Report.java | 44 ++++++++ .../isspst/reporting/ReportController.java | 63 +++++++++++ .../isspst/reporting/ReportDefinition.java | 101 ++++++++++++++++++ .../isspst/reporting/ReportMapping.java | 29 +++++ .../bukova/isspst/reporting/ReportType.java | 8 ++ .../isspst/services/AbstractService.java | 23 ++++ .../info/bukova/isspst/services/Service.java | 4 + .../java/info/bukova/isspst/ui/Check.java | 40 +++++++ .../info/bukova/isspst/ui/ListChecks.java | 21 ++++ .../info/bukova/isspst/ui/ListViewModel.java | 9 ++ .../info/bukova/isspst/ui/ReportDialogVM.java | 96 +++++++++++++++++ .../java/info/bukova/isspst/ui/ReportVM.java | 12 +++ .../webapp/WEB-INF/spring/root-context.xml | 9 ++ src/main/webapp/WEB-INF/web.xml | 8 +- src/main/webapp/WEB-INF/zk-label.properties | 6 ++ src/main/webapp/app/report.zul | 10 ++ src/main/webapp/app/reportDialog.zul | 32 ++++++ src/main/webapp/app/toolbar.zul | 1 + src/main/webapp/img/print.png | Bin 0 -> 3786 bytes src/main/webapp/img/send.png | Bin 0 -> 3781 bytes 27 files changed, 724 insertions(+), 4 deletions(-) rename src/main/java/info/bukova/isspst/{DbInitListener.java => AppInitListener.java} (79%) create mode 100644 src/main/java/info/bukova/isspst/reporting/DefinitionFiller.java create mode 100644 src/main/java/info/bukova/isspst/reporting/DynamicGenerator.java create mode 100644 src/main/java/info/bukova/isspst/reporting/Generator.java create mode 100644 src/main/java/info/bukova/isspst/reporting/GeneratorFactory.java create mode 100644 src/main/java/info/bukova/isspst/reporting/Report.java create mode 100644 src/main/java/info/bukova/isspst/reporting/ReportController.java create mode 100644 src/main/java/info/bukova/isspst/reporting/ReportDefinition.java create mode 100644 src/main/java/info/bukova/isspst/reporting/ReportMapping.java create mode 100644 src/main/java/info/bukova/isspst/reporting/ReportType.java create mode 100644 src/main/java/info/bukova/isspst/ui/Check.java create mode 100644 src/main/java/info/bukova/isspst/ui/ListChecks.java create mode 100644 src/main/java/info/bukova/isspst/ui/ReportDialogVM.java create mode 100644 src/main/java/info/bukova/isspst/ui/ReportVM.java create mode 100644 src/main/webapp/app/report.zul create mode 100644 src/main/webapp/app/reportDialog.zul create mode 100644 src/main/webapp/img/print.png create mode 100644 src/main/webapp/img/send.png diff --git a/src/main/java/info/bukova/isspst/DbInitListener.java b/src/main/java/info/bukova/isspst/AppInitListener.java similarity index 79% rename from src/main/java/info/bukova/isspst/DbInitListener.java rename to src/main/java/info/bukova/isspst/AppInitListener.java index 75f6fd23..d354ceed 100644 --- a/src/main/java/info/bukova/isspst/DbInitListener.java +++ b/src/main/java/info/bukova/isspst/AppInitListener.java @@ -3,6 +3,9 @@ package info.bukova.isspst; import info.bukova.isspst.data.Permission; import info.bukova.isspst.data.Role; import info.bukova.isspst.data.User; +import info.bukova.isspst.reporting.Report; +import info.bukova.isspst.reporting.ReportMapping; +import info.bukova.isspst.reporting.ReportType; import info.bukova.isspst.services.users.PermissionService; import info.bukova.isspst.services.users.RoleService; import info.bukova.isspst.services.users.UserService; @@ -16,7 +19,7 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; -public class DbInitListener implements ServletContextListener { +public class AppInitListener implements ServletContextListener { private RoleService roleService; private UserService userService; @@ -29,7 +32,7 @@ public class DbInitListener implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent evt) { - Logger logger = LoggerFactory.getLogger(DbInitListener.class); + Logger logger = LoggerFactory.getLogger(AppInitListener.class); logger.info("Initializing database"); WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(evt.getServletContext()); @@ -42,6 +45,8 @@ public class DbInitListener implements ServletContextListener { checkUsers(); checkPermissions(); userService.removeAccess(); + + loadModuleReports(); } private void checkRoles() { @@ -91,5 +96,19 @@ public class DbInitListener implements ServletContextListener { } } } + + private void loadModuleReports() { + for (Module m : Constants.MODULES) { + Report rep = new Report(); + rep.setType(ReportType.DYNAMIC); + rep.setName(Constants.DYNAMIC_REPORT_NAME); + m.addReport(rep); + for (ReportMapping r : Constants.REPORTS) { + if (m.getId().equals(r.getModule())) { + m.addReport(r.getReport()); + } + } + } + } } diff --git a/src/main/java/info/bukova/isspst/Constants.java b/src/main/java/info/bukova/isspst/Constants.java index 5fd8aba0..3c88315f 100644 --- a/src/main/java/info/bukova/isspst/Constants.java +++ b/src/main/java/info/bukova/isspst/Constants.java @@ -2,6 +2,8 @@ package info.bukova.isspst; import info.bukova.isspst.data.Permission; import info.bukova.isspst.data.Role; +import info.bukova.isspst.reporting.Report; +import info.bukova.isspst.reporting.ReportMapping; import info.bukova.isspst.services.addressbook.AdbService; import info.bukova.isspst.services.buildings.BuildingService; import info.bukova.isspst.services.users.RoleService; @@ -53,4 +55,9 @@ public class Constants { new Module(MOD_ADDRESSBOOK, "Dodavatelé", AdbService.class), new Module(MOD_BUILDINGS, "Budovy", BuildingService.class) }; + + public final static String DYNAMIC_REPORT_NAME = "Tabulková sestava"; + public final static ReportMapping REPORTS[] = { + new ReportMapping(MOD_ADDRESSBOOK, new Report("Pokusná sestava", "report")) + }; } diff --git a/src/main/java/info/bukova/isspst/Module.java b/src/main/java/info/bukova/isspst/Module.java index fd993384..86ee6d63 100644 --- a/src/main/java/info/bukova/isspst/Module.java +++ b/src/main/java/info/bukova/isspst/Module.java @@ -1,10 +1,16 @@ package info.bukova.isspst; +import info.bukova.isspst.reporting.Report; + +import java.util.ArrayList; +import java.util.List; + public class Module { private String id; private String name; private Class serviceClass; + private List reports; public Class getServiceClass() { return serviceClass; @@ -18,6 +24,7 @@ public class Module { this.id = id; this.name = name; this.serviceClass = serviceClass; + reports = new ArrayList(); } public String getId() { @@ -35,5 +42,13 @@ public class Module { public void setName(String name) { this.name = name; } + + public List getReports() { + return reports; + } + + public void addReport(Report report) { + this.reports.add(report); + } } diff --git a/src/main/java/info/bukova/isspst/reporting/DefinitionFiller.java b/src/main/java/info/bukova/isspst/reporting/DefinitionFiller.java new file mode 100644 index 00000000..9ab25c62 --- /dev/null +++ b/src/main/java/info/bukova/isspst/reporting/DefinitionFiller.java @@ -0,0 +1,44 @@ +package info.bukova.isspst.reporting; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; + +public class DefinitionFiller { + + @Autowired + ReportDefinition definition; + + @SuppressWarnings("unchecked") + private void setData(Object data) { + if (data instanceof List) { + definition.setDataSet((List)data); + } else { + definition.setSingleObject(data); + } + } + + public void fillDefinition(Report report, Object data) { + definition.clear(); + definition.setReport(report); + setData(data); + } + + public void fillDefinition(Report report, Object data, Map params) { + fillDefinition(report, data); + definition.setParams(params); + } + + public void fillDefinition(Report report, Object data, String[] columns) { + fillDefinition(report, data); + definition.setFieldsToPrint(Arrays.asList(columns)); + } + + public void fillDefinition(Report report, Object data, String[] columns, Map params) { + fillDefinition(report, data, params); + definition.setFieldsToPrint(Arrays.asList(columns)); + } + +} diff --git a/src/main/java/info/bukova/isspst/reporting/DynamicGenerator.java b/src/main/java/info/bukova/isspst/reporting/DynamicGenerator.java new file mode 100644 index 00000000..ee1bdaa0 --- /dev/null +++ b/src/main/java/info/bukova/isspst/reporting/DynamicGenerator.java @@ -0,0 +1,101 @@ +package info.bukova.isspst.reporting; + +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.sf.jasperreports.engine.JRDataSource; +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.JRProperties; + +import org.apache.commons.beanutils.PropertyUtils; + +import ar.com.fdvs.dj.core.DynamicJasperHelper; +import ar.com.fdvs.dj.core.layout.ClassicLayoutManager; +import ar.com.fdvs.dj.domain.DynamicReport; +import ar.com.fdvs.dj.domain.builders.ColumnBuilderException; +import ar.com.fdvs.dj.domain.builders.FastReportBuilder; + +@SuppressWarnings("deprecation") +public class DynamicGenerator implements Generator { + + private ReportDefinition definition; + private static Map,Class> primitiveMap = new HashMap,Class>(); + static { + primitiveMap.put(boolean.class, Boolean.class); + primitiveMap.put(byte.class, Byte.class); + primitiveMap.put(char.class, Character.class); + primitiveMap.put(short.class, Short.class); + primitiveMap.put(int.class, Integer.class); + primitiveMap.put(long.class, Long.class); + primitiveMap.put(float.class, Float.class); + primitiveMap.put(double.class, Double.class); + } + + public DynamicGenerator(ReportDefinition definition) { + this.definition = definition; + } + + @Override + public byte[] generate() { + FastReportBuilder rb = new FastReportBuilder(); + DynamicReport dr; + + for (String col : definition.getFieldsToPrint()) { + Class clazz = colClass(col); + if (clazz != null) { + try { + rb.addColumn(col, col, clazz, 30, false); + } catch (ColumnBuilderException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + rb.setTitle(definition.getReportTitle()); + rb.setUseFullPageWidth(true); + dr = rb.build(); + + JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "Cp1250"); + JRDataSource ds = new JRBeanCollectionDataSource(definition.getDataSet()); + try { + JasperReport report = DynamicJasperHelper.generateJasperReport(dr, new ClassicLayoutManager(), definition.getParams()); + return JasperRunManager.runReportToPdf(report, definition.getParams(), ds); + } catch (JRException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + } + + private Class colClass(String col) { + List data = definition.getDataSet(); + if (data != null && data.size() > 0) { + try { + Class clazz = PropertyUtils.getPropertyType(data.get(0), col); + if (clazz.isPrimitive()) { + clazz = primitiveMap.get(clazz); + } + return clazz; + } catch (IllegalAccessException e) { + return null; + } catch (InvocationTargetException e) { + return null; + } catch (NoSuchMethodException e) { + return null; + } + } + + return null; + } + +} diff --git a/src/main/java/info/bukova/isspst/reporting/Generator.java b/src/main/java/info/bukova/isspst/reporting/Generator.java new file mode 100644 index 00000000..b899c038 --- /dev/null +++ b/src/main/java/info/bukova/isspst/reporting/Generator.java @@ -0,0 +1,7 @@ +package info.bukova.isspst.reporting; + +public interface Generator { + + byte[] generate(); + +} diff --git a/src/main/java/info/bukova/isspst/reporting/GeneratorFactory.java b/src/main/java/info/bukova/isspst/reporting/GeneratorFactory.java new file mode 100644 index 00000000..40f6d227 --- /dev/null +++ b/src/main/java/info/bukova/isspst/reporting/GeneratorFactory.java @@ -0,0 +1,15 @@ +package info.bukova.isspst.reporting; + +public class GeneratorFactory { + + public Generator createGenerator(ReportDefinition definition) { + switch (definition.getReport().getType()) { + case DYNAMIC: + return new DynamicGenerator(definition); + + default: + return null; + } + } + +} diff --git a/src/main/java/info/bukova/isspst/reporting/Report.java b/src/main/java/info/bukova/isspst/reporting/Report.java new file mode 100644 index 00000000..061381f8 --- /dev/null +++ b/src/main/java/info/bukova/isspst/reporting/Report.java @@ -0,0 +1,44 @@ +package info.bukova.isspst.reporting; + + +public class Report { + + private ReportType type; + private String name; + private String jasperFile; + + public Report() { + + } + + public Report(String name, String jasperFile) { + this.type = ReportType.DEFINED; + this.name = name; + this.jasperFile = jasperFile; + } + + public ReportType getType() { + return type; + } + + public void setType(ReportType type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getJasperFile() { + return jasperFile; + } + + public void setJasperFile(String jasperFile) { + this.jasperFile = jasperFile; + } + +} diff --git a/src/main/java/info/bukova/isspst/reporting/ReportController.java b/src/main/java/info/bukova/isspst/reporting/ReportController.java new file mode 100644 index 00000000..bf86f0f8 --- /dev/null +++ b/src/main/java/info/bukova/isspst/reporting/ReportController.java @@ -0,0 +1,63 @@ +package info.bukova.isspst.reporting; + +import java.io.IOException; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +public class ReportController { + + @Autowired + private ReportDefinition reportDefinition; + @Autowired + private GeneratorFactory factory; + + @RequestMapping("report.pdf") + public void pdfReport(HttpServletResponse response) { + Generator gen = factory.createGenerator(reportDefinition); + byte[] data = gen.generate(); + String contentType = "application/pdf"; + + ServletOutputStream os = null; + + try { + os = response.getOutputStream(); + } catch (IOException e1) { + e1.printStackTrace(); + return; + } + +// if (reportDefinition.getReport() == null || reportDefinition.getDataSet() == null) { +// writeError(os, "Definition is null"); +// return; +// } + + response.setContentType(contentType); + response.setContentLength(data.length); + + try { + os.write(data, 0, data.length); + os.flush(); + os.close(); + } catch (IOException e) { + e.printStackTrace(); +// } catch (ReportException e) { +// writeError(os, e); + } finally { + if (os != null) { + try { + os.flush(); + os.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + +} diff --git a/src/main/java/info/bukova/isspst/reporting/ReportDefinition.java b/src/main/java/info/bukova/isspst/reporting/ReportDefinition.java new file mode 100644 index 00000000..1c813996 --- /dev/null +++ b/src/main/java/info/bukova/isspst/reporting/ReportDefinition.java @@ -0,0 +1,101 @@ +package info.bukova.isspst.reporting; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ReportDefinition implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 995511957163031085L; + private Report report; + private List dataSet; + private Map params; + private List fieldsToPrint; + private String reportTitle; + + public ReportDefinition() { + params = new HashMap(); + fieldsToPrint = new ArrayList(); + } + + public List getDataSet() { + return dataSet; + } + + public void setDataSet(List dataSet) { + this.dataSet = dataSet; + } + + public void setSingleObject(Object o) { + if (this.dataSet != null) { + dataSet.clear(); + } else { + dataSet = new ArrayList(); + } + + dataSet.add(o); + } + + public Map getParams() { + return params; + } + + public void setParams(Map params) { + this.params.clear(); + this.params.putAll(params); + } + + public void setParam(String key, Object value) { + this.params.put(key, value); + } + + public Object getParam(String key) { + return this.params.get(key); + } + + public List getFieldsToPrint() { + return fieldsToPrint; + } + + public void setFieldsToPrint(List fieldsToPrint) { + this.fieldsToPrint = fieldsToPrint; + } + + public Report getReport() { + return report; + } + + public void setReport(Report report) { + this.report = report; + } + + public Class gatDataClass() { + if (dataSet != null && dataSet.size() > 0) { + return dataSet.get(0).getClass(); + } + + return null; + } + + public void clear() { + report = null; + fieldsToPrint.clear(); + dataSet = null; + reportTitle = ""; + params.clear(); + } + + public String getReportTitle() { + return reportTitle; + } + + public void setReportTitle(String reportTitle) { + this.reportTitle = reportTitle; + } + +} diff --git a/src/main/java/info/bukova/isspst/reporting/ReportMapping.java b/src/main/java/info/bukova/isspst/reporting/ReportMapping.java new file mode 100644 index 00000000..11c1dc33 --- /dev/null +++ b/src/main/java/info/bukova/isspst/reporting/ReportMapping.java @@ -0,0 +1,29 @@ +package info.bukova.isspst.reporting; + +public class ReportMapping { + + private Report report; + private String module; + + public ReportMapping(String module, Report report) { + this.module = module; + this.report = report; + } + + public Report getReport() { + return report; + } + + public void setReport(Report report) { + this.report = report; + } + + public String getModule() { + return module; + } + + public void setModule(String module) { + this.module = module; + } + +} diff --git a/src/main/java/info/bukova/isspst/reporting/ReportType.java b/src/main/java/info/bukova/isspst/reporting/ReportType.java new file mode 100644 index 00000000..a7bd9961 --- /dev/null +++ b/src/main/java/info/bukova/isspst/reporting/ReportType.java @@ -0,0 +1,8 @@ +package info.bukova.isspst.reporting; + +public enum ReportType { + + DYNAMIC, + DEFINED + +} diff --git a/src/main/java/info/bukova/isspst/services/AbstractService.java b/src/main/java/info/bukova/isspst/services/AbstractService.java index 73888a53..b0fbb427 100644 --- a/src/main/java/info/bukova/isspst/services/AbstractService.java +++ b/src/main/java/info/bukova/isspst/services/AbstractService.java @@ -1,10 +1,14 @@ package info.bukova.isspst.services; import static ch.lambdaj.Lambda.filter; +import info.bukova.isspst.Constants; +import info.bukova.isspst.Module; import info.bukova.isspst.dao.BaseDao; import info.bukova.isspst.data.DataModel; import info.bukova.isspst.filters.Filter; +import info.bukova.isspst.reporting.Report; +import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Set; @@ -126,5 +130,24 @@ public abstract class AbstractService implements Service protected T createEntity() { return null; } + + @Override + public Module getModule() { + for (Module m : Constants.MODULES) { + if (Arrays.asList(this.getClass().getInterfaces()).contains(m.getServiceClass())) { + return m; + } + } + + return null; + } + + public List getReports() { + if (getModule() != null) { + return getModule().getReports(); + } else { + return null; + } + } } diff --git a/src/main/java/info/bukova/isspst/services/Service.java b/src/main/java/info/bukova/isspst/services/Service.java index 4fe6149a..b0f22709 100644 --- a/src/main/java/info/bukova/isspst/services/Service.java +++ b/src/main/java/info/bukova/isspst/services/Service.java @@ -1,6 +1,8 @@ package info.bukova.isspst.services; +import info.bukova.isspst.Module; import info.bukova.isspst.filters.Filter; +import info.bukova.isspst.reporting.Report; import java.util.List; @@ -16,5 +18,7 @@ public interface Service { public T selectSingle(String query); public T getById(int id); public List filterList(List sourceList, Filter filter); + public Module getModule(); + public List getReports(); } diff --git a/src/main/java/info/bukova/isspst/ui/Check.java b/src/main/java/info/bukova/isspst/ui/Check.java new file mode 100644 index 00000000..b84a0285 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/Check.java @@ -0,0 +1,40 @@ +package info.bukova.isspst.ui; + +import java.util.List; + +public class Check { + + private T member; + private List list; + private boolean checked; + + public Check(List list, T member) { + this.member = member; + this.list = list; + if (list.contains(member)) { + checked = true; + } else { + checked = false; + } + } + + public boolean isChecked() { + return checked; + } + + public void setChecked(boolean checked) { + if (checked && !list.contains(member)) { + list.add(member); + } else { + list.remove(member); + } + this.checked = checked; + } + + public T getMember() { + return member; + } + + + +} diff --git a/src/main/java/info/bukova/isspst/ui/ListChecks.java b/src/main/java/info/bukova/isspst/ui/ListChecks.java new file mode 100644 index 00000000..3761eb4b --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/ListChecks.java @@ -0,0 +1,21 @@ +package info.bukova.isspst.ui; + +import java.util.ArrayList; +import java.util.List; + +public class ListChecks { + + private List> checks; + + public ListChecks(List destList, List sourceList) { + checks = new ArrayList>(); + for (T member : sourceList) { + checks.add(new Check(destList, member)); + } + } + + public List> getChecks() { + return checks; + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/ListViewModel.java b/src/main/java/info/bukova/isspst/ui/ListViewModel.java index ca42ea03..ff5a7a34 100644 --- a/src/main/java/info/bukova/isspst/ui/ListViewModel.java +++ b/src/main/java/info/bukova/isspst/ui/ListViewModel.java @@ -295,6 +295,15 @@ public class ListViewModel { // fillThread.start(); // } + @Command + public void onPrint() { + Map params = new HashMap(); + params.put("reports", service.getReports()); + params.put("data", dataList); + Window win = (Window) Executions.createComponents("/app/reportDialog.zul", null, params); + win.doModal(); + } + private void loadFromDbSync() { dataList.addAll(service.getAll()); fullList = dataList; diff --git a/src/main/java/info/bukova/isspst/ui/ReportDialogVM.java b/src/main/java/info/bukova/isspst/ui/ReportDialogVM.java new file mode 100644 index 00000000..4072aa8f --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/ReportDialogVM.java @@ -0,0 +1,96 @@ +package info.bukova.isspst.ui; + +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.util.ArrayList; +import java.util.List; + +import info.bukova.isspst.reporting.Report; +import info.bukova.isspst.reporting.ReportDefinition; +import info.bukova.isspst.reporting.ReportType; + +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; + private List data; + @WireVariable + private ReportDefinition reportDefinition; + + @Init + public void init(@ExecutionArgParam("reports") List reports, + @ExecutionArgParam("data") List data) { + this.reports = reports; + this.data = data; + + if (data != null && data.size() > 0 && data.get(0).getClass() != reportDefinition.gatDataClass()) { + reportDefinition.clear(); + } + } + + public List getReports() { + return this.reports; + } + + public ReportDefinition getReportDefinition() { + return reportDefinition; + } + + public ListChecks getColumns() { + if (selected == null || selected.getType() != ReportType.DYNAMIC) { + return null; + } + if (data == null || data.size() == 0) { + return null; + } + + BeanInfo beanInfo; + try { + beanInfo = Introspector.getBeanInfo(data.get(0).getClass()); + } catch (IntrospectionException e) { + return null; + } + PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors(); + List properties = new ArrayList(); + for (PropertyDescriptor pd : pds) { + properties.add(pd.getName()); + } + ListChecks columns = new ListChecks(reportDefinition.getFieldsToPrint(), properties); + + return columns; + } + + public Report getSelected() { + return selected; + } + + @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(); + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/ReportVM.java b/src/main/java/info/bukova/isspst/ui/ReportVM.java new file mode 100644 index 00000000..29723ee2 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/ReportVM.java @@ -0,0 +1,12 @@ +package info.bukova.isspst.ui; + +import org.zkoss.bind.annotation.Init; + +public class ReportVM { + + @Init + public void init() { + + } + +} diff --git a/src/main/webapp/WEB-INF/spring/root-context.xml b/src/main/webapp/WEB-INF/spring/root-context.xml index fe183541..d49e645c 100644 --- a/src/main/webapp/WEB-INF/spring/root-context.xml +++ b/src/main/webapp/WEB-INF/spring/root-context.xml @@ -84,6 +84,15 @@ + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 45682012..da4c395b 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -19,7 +19,11 @@ - info.bukova.isspst.DbInitListener + org.springframework.web.context.request.RequestContextListener + + + + info.bukova.isspst.AppInitListener @@ -113,7 +117,7 @@ appServlet - /api/ + /api/* diff --git a/src/main/webapp/WEB-INF/zk-label.properties b/src/main/webapp/WEB-INF/zk-label.properties index 3a803204..57d14bfb 100644 --- a/src/main/webapp/WEB-INF/zk-label.properties +++ b/src/main/webapp/WEB-INF/zk-label.properties @@ -22,3 +22,9 @@ ToolbarRecNew=Nový záznam ToolbarRecEdit=Úprava aktuálního záznamu ToolbarRecDelete=Odstranit aktuální záznam ToolbarRecFilter=Filtr záznamů + +ReportReport=Sestava +ReportSend=Odeslat +ReportPrint=Tisk +ReportReports=Sestavy +ReportTitle=Nadpis sestavy: \ No newline at end of file diff --git a/src/main/webapp/app/report.zul b/src/main/webapp/app/report.zul new file mode 100644 index 00000000..5cef3420 --- /dev/null +++ b/src/main/webapp/app/report.zul @@ -0,0 +1,10 @@ + + + + + + +