diff --git a/src/main/java/info/bukova/isspst/Constants.java b/src/main/java/info/bukova/isspst/Constants.java index e1f6f665..ab906aac 100644 --- a/src/main/java/info/bukova/isspst/Constants.java +++ b/src/main/java/info/bukova/isspst/Constants.java @@ -61,6 +61,7 @@ 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")), + new ReportMapping(MOD_ADDRESSBOOK, new Report("Adresna", "address", false, true)) }; } diff --git a/src/main/java/info/bukova/isspst/StringUtils.java b/src/main/java/info/bukova/isspst/StringUtils.java index cf352fc3..d3b8bcf2 100644 --- a/src/main/java/info/bukova/isspst/StringUtils.java +++ b/src/main/java/info/bukova/isspst/StringUtils.java @@ -28,7 +28,7 @@ public class StringUtils { } public static String localize(String key) { - return Labels.getLabel(key); + return Labels.getLabel(key) == null ? key : Labels.getLabel(key); } private static String getLocalized(String str) { diff --git a/src/main/java/info/bukova/isspst/reporting/DynamicGenerator.java b/src/main/java/info/bukova/isspst/reporting/DynamicGenerator.java index ee1bdaa0..b2117879 100644 --- a/src/main/java/info/bukova/isspst/reporting/DynamicGenerator.java +++ b/src/main/java/info/bukova/isspst/reporting/DynamicGenerator.java @@ -1,5 +1,7 @@ package info.bukova.isspst.reporting; +import info.bukova.isspst.StringUtils; + import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.List; @@ -49,13 +51,11 @@ public class DynamicGenerator implements Generator { Class clazz = colClass(col); if (clazz != null) { try { - rb.addColumn(col, col, clazz, 30, false); + rb.addColumn(StringUtils.localize(col), col, clazz, 30, false); } catch (ColumnBuilderException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + throw new ReportException(e); } catch (ClassNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + throw new ReportException(e); } } } @@ -70,11 +70,8 @@ public class DynamicGenerator implements Generator { 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(); + throw new ReportException(e); } - - return null; } private Class colClass(String col) { 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..81a1f5f6 --- /dev/null +++ b/src/main/java/info/bukova/isspst/reporting/PredefinedGenerator.java @@ -0,0 +1,44 @@ +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) { + throw new ReportException(e); + } + + 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..19b2a757 100644 --- a/src/main/java/info/bukova/isspst/reporting/Report.java +++ b/src/main/java/info/bukova/isspst/reporting/Report.java @@ -6,16 +6,45 @@ public class Report { private ReportType type; private String name; private String jasperFile; + private boolean hasSettings; + private boolean singleRecord; public Report() { - + hasSettings = false; + singleRecord = false; } + /** + * @param name + * @param jasperFile + */ public Report(String name, String jasperFile) { + this(); this.type = ReportType.DEFINED; this.name = name; this.jasperFile = jasperFile; } + + /** + * @param name + * @param jasperFile + * @param hasSettings + */ + public Report(String name, String jasperFile, boolean hasSettings) { + this(name, jasperFile); + this.hasSettings = hasSettings; + } + + /** + * @param name + * @param jasperFile + * @param hasSettings + * @param singleRecord + */ + public Report(String name, String jasperFile, boolean hasSettings, boolean singleRecord) { + this(name, jasperFile, hasSettings); + this.singleRecord = singleRecord; + } public ReportType getType() { return type; @@ -41,4 +70,20 @@ public class Report { this.jasperFile = jasperFile; } + public boolean isHasSettings() { + return hasSettings; + } + + public void setHasSettings(boolean hasSettings) { + this.hasSettings = hasSettings; + } + + public boolean isSingleRecord() { + return singleRecord; + } + + public void setSingleRecord(boolean singleRecord) { + this.singleRecord = singleRecord; + } + } diff --git a/src/main/java/info/bukova/isspst/reporting/ReportController.java b/src/main/java/info/bukova/isspst/reporting/ReportController.java index bf86f0f8..18888238 100644 --- a/src/main/java/info/bukova/isspst/reporting/ReportController.java +++ b/src/main/java/info/bukova/isspst/reporting/ReportController.java @@ -1,6 +1,7 @@ package info.bukova.isspst.reporting; import java.io.IOException; +import java.io.OutputStream; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; @@ -16,38 +17,46 @@ public class ReportController { private ReportDefinition reportDefinition; @Autowired private GeneratorFactory factory; + private static final String ERROR_MESSAGE = "Generator returned no data!
%s"; - @RequestMapping("report.pdf") - public void pdfReport(HttpServletResponse response) { - Generator gen = factory.createGenerator(reportDefinition); - byte[] data = gen.generate(); - String contentType = "application/pdf"; - - ServletOutputStream os = null; - + private void writeError(OutputStream stream, Throwable e) { + writeError(stream, e.toString()); + } + + private void writeError(OutputStream stream, String message) { + String err = String.format(ERROR_MESSAGE, message); try { - os = response.getOutputStream(); + stream.write(err.getBytes(), 0, err.getBytes().length); } catch (IOException e1) { e1.printStackTrace(); - return; } + } + + @RequestMapping("report.pdf") + public void pdfReport(HttpServletResponse response) { + final String contentType = "application/pdf"; -// if (reportDefinition.getReport() == null || reportDefinition.getDataSet() == null) { -// writeError(os, "Definition is null"); -// return; -// } + ServletOutputStream os = null; - response.setContentType(contentType); - response.setContentLength(data.length); - try { + os = response.getOutputStream(); + + if (reportDefinition.getReport() == null || reportDefinition.getDataSet() == null) { + throw new ReportException("Definition is null"); + } + + Generator gen = factory.createGenerator(reportDefinition); + byte[] data = gen.generate(); + response.setContentType(contentType); + response.setContentLength(data.length); + os.write(data, 0, data.length); os.flush(); os.close(); } catch (IOException e) { e.printStackTrace(); -// } catch (ReportException e) { -// writeError(os, e); + } catch (ReportException e) { + writeError(os, e); } finally { if (os != null) { try { diff --git a/src/main/java/info/bukova/isspst/reporting/ReportException.java b/src/main/java/info/bukova/isspst/reporting/ReportException.java new file mode 100644 index 00000000..1f82b317 --- /dev/null +++ b/src/main/java/info/bukova/isspst/reporting/ReportException.java @@ -0,0 +1,20 @@ +package info.bukova.isspst.reporting; + +import info.bukova.isspst.services.IsspstException; + +public class ReportException extends IsspstException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public ReportException(Throwable cause) { + super("Reporting exception: ", cause); + } + + public ReportException(String message) { + super(message); + } + +} diff --git a/src/main/java/info/bukova/isspst/services/IsspstException.java b/src/main/java/info/bukova/isspst/services/IsspstException.java index b0a89439..449f45c2 100644 --- a/src/main/java/info/bukova/isspst/services/IsspstException.java +++ b/src/main/java/info/bukova/isspst/services/IsspstException.java @@ -4,7 +4,7 @@ public class IsspstException extends RuntimeException { private static final long serialVersionUID = 1L; - private final static String MSG = "RsFaktura Exception. "; + private final static String MSG = "IS Exception. "; public IsspstException() { super(MSG); diff --git a/src/main/java/info/bukova/isspst/ui/ListViewModel.java b/src/main/java/info/bukova/isspst/ui/ListViewModel.java index d0fd12ba..ccafe836 100644 --- a/src/main/java/info/bukova/isspst/ui/ListViewModel.java +++ b/src/main/java/info/bukova/isspst/ui/ListViewModel.java @@ -301,7 +301,8 @@ 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); + params.put("singleObject", dataBean); + Window win = (Window) Executions.createComponents("/app/reporting/reportDialog.zul", null, params); win.doModal(); } diff --git a/src/main/java/info/bukova/isspst/ui/LocaleConverter.java b/src/main/java/info/bukova/isspst/ui/LocaleConverter.java new file mode 100644 index 00000000..e6efbcfb --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/LocaleConverter.java @@ -0,0 +1,21 @@ +package info.bukova.isspst.ui; + +import info.bukova.isspst.StringUtils; + +import org.zkoss.bind.BindContext; +import org.zkoss.bind.Converter; +import org.zkoss.zk.ui.Component; + +public class LocaleConverter implements Converter { + + @Override + public String coerceToBean(String str, Component component, BindContext ctx) { + return str; + } + + @Override + public String coerceToUi(String str, Component component, BindContext ctx) { + return StringUtils.localize(str); + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/reporting/ColSelectVM.java b/src/main/java/info/bukova/isspst/ui/reporting/ColSelectVM.java new file mode 100644 index 00000000..6036514c --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/reporting/ColSelectVM.java @@ -0,0 +1,67 @@ +package info.bukova.isspst.ui.reporting; + +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 info.bukova.isspst.ui.ListChecks; +import info.bukova.isspst.ui.LocaleConverter; + +import org.zkoss.bind.annotation.Init; +import org.zkoss.zk.ui.select.annotation.WireVariable; + +public class ColSelectVM { + + @WireVariable + private ReportDefinition reportDefinition; + private LocaleConverter locConverter; + + @Init + public void init() { + locConverter = new LocaleConverter(); + } + + public ListChecks getColumns() { + Report selected = reportDefinition.getReport(); + List data = reportDefinition.getDataSet(); + + 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) { + if (!(pd.getName().equals("password") || pd.getName().equals("class") || pd.getName().equals("id") || pd.getName().equals("valid"))) { + properties.add(pd.getName()); + } + } + ListChecks columns = new ListChecks(reportDefinition.getFieldsToPrint(), properties); + + return columns; + } + + public LocaleConverter getLocConverter() { + return locConverter; + } + + public ReportDefinition getReportDefinition() { + return reportDefinition; + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/ReportDialogVM.java b/src/main/java/info/bukova/isspst/ui/reporting/ReportDialogVM.java similarity index 58% rename from src/main/java/info/bukova/isspst/ui/ReportDialogVM.java rename to src/main/java/info/bukova/isspst/ui/reporting/ReportDialogVM.java index 4072aa8f..98873a23 100644 --- a/src/main/java/info/bukova/isspst/ui/ReportDialogVM.java +++ b/src/main/java/info/bukova/isspst/ui/reporting/ReportDialogVM.java @@ -1,16 +1,11 @@ -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; +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; @@ -24,19 +19,23 @@ public class ReportDialogVM { private List reports; private Report selected; - private List data; @WireVariable private ReportDefinition reportDefinition; + private List dataList; + private Object singleObject; @Init public void init(@ExecutionArgParam("reports") List reports, - @ExecutionArgParam("data") List data) { + @ExecutionArgParam("data") List data, + @ExecutionArgParam("singleObject") Object singleObject) { this.reports = reports; - this.data = data; if (data != null && data.size() > 0 && data.get(0).getClass() != reportDefinition.gatDataClass()) { reportDefinition.clear(); } + + dataList = data; + this.singleObject = singleObject; } public List getReports() { @@ -47,50 +46,47 @@ public class ReportDialogVM { 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") + @NotifyChange({"optionsForm", "selected"}) public void setSelected(Report selected) { this.selected = selected; + reportDefinition.setReport(selected); + if (selected.isSingleRecord()) { + reportDefinition.setSingleObject(singleObject); + } else { + reportDefinition.setDataSet(dataList); + } } @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); + 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"; + } + } + + public Object getSingleObject() { + return singleObject; + } + + public void setReportDefinition(ReportDefinition reportDefinition) { + this.reportDefinition = reportDefinition; + } } 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/columns.properties b/src/main/webapp/WEB-INF/locales/columns.properties new file mode 100644 index 00000000..31df501b --- /dev/null +++ b/src/main/webapp/WEB-INF/locales/columns.properties @@ -0,0 +1,38 @@ +#Obecné +created=Vytvořeno +ownedBy=Vytvořil +modified=Změněno +modifiedBy=Změnil + +#Adresa +city=Město +company=Firma +contactName=Kontaktní osoba +department=Oddělení +description=Poznámka +dic=DIČ +email=E-mail +houseNumber=Číslo domu +ic=IČ +phone=Telefon +state=Stát +street=Ulice +web=Webová adresa +zipCode=PSČ + +#Budova +code=Kód +name=Název + +#Uživatel +accountNonExpired=Platný +accountNonLocked=Odemknutý +authorities=Role +credentialsNonExpired=Heslo je platné +enabled=Povolený +firstName=Jméno +fullName=Plné jméno +lastName=Příjmení +notify=Posílat oznámení +personalNumber=Osobní číslo +username=Uživatelské jméno \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties similarity index 97% rename from src/main/webapp/WEB-INF/zk-label.properties rename to src/main/webapp/WEB-INF/locales/zk-label.properties index a7461dcf..ec91fb37 100644 --- a/src/main/webapp/WEB-INF/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -86,6 +86,8 @@ ReportSend=Odeslat 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/WEB-INF/zk.xml b/src/main/webapp/WEB-INF/zk.xml index 1f1e39fb..009fe9fc 100644 --- a/src/main/webapp/WEB-INF/zk.xml +++ b/src/main/webapp/WEB-INF/zk.xml @@ -17,6 +17,11 @@ org.zkoss.web.classWebResource.cache false + + + /WEB-INF/locales/zk-label.properties + /WEB-INF/locales/columns.properties + /WEB-INF/lang-addons/mapa-lang-addon.xml diff --git a/src/main/webapp/app/report.zul b/src/main/webapp/app/report.zul deleted file mode 100644 index 5cef3420..00000000 --- a/src/main/webapp/app/report.zul +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - -