From 52cf63414bdacd9d1af5684b194a103d73215aa7 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Fri, 27 Nov 2015 15:11:23 +0100 Subject: [PATCH] =?UTF-8?q?Oprevena=20sestava=20=C5=BD=C3=A1dost=20o=20SC-?= =?UTF-8?q?=20tisk=20z=20agend=20Cestovn=C3=AD=20p=C5=99=C3=ADkazy=20a=20P?= =?UTF-8?q?o=C5=BEadavky=20na=20SC=20odkazuje=20na=20stejnou=20sestavu.=20?= =?UTF-8?q?Byla=20p=C5=99id=C3=A1na=20mo=C5=BEnost=20pou=C5=BE=C3=ADt=20pr?= =?UTF-8?q?operty=20hlavn=C3=AD=20entity=20jako=20zdroje=20dat=20pro=20ses?= =?UTF-8?q?tavu-=20roz=C5=A1=C3=AD=C5=99en=20constructor=20t=C5=99=C3=ADdy?= =?UTF-8?q?=20Report=20o=20parametr=20property.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/info/bukova/isspst/Constants.java | 2 +- .../info/bukova/isspst/reporting/Report.java | 14 +++++++ .../isspst/ui/reporting/ReportDialogVM.java | 39 ++++++++++++++++++- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/main/java/info/bukova/isspst/Constants.java b/src/main/java/info/bukova/isspst/Constants.java index 9a10d6fc..fe13529a 100644 --- a/src/main/java/info/bukova/isspst/Constants.java +++ b/src/main/java/info/bukova/isspst/Constants.java @@ -143,7 +143,7 @@ public class Constants { public final static ReportMapping REPORTS[] = { new ReportMapping(MOD_ADDRESSBOOK, new Report(1, false, "Adresní karty", "address")), new ReportMapping(MOD_ADDRESSBOOK, new Report(2, false, "Adresa", "address", false, true)), - new ReportMapping(MOD_TRIPBILL, new Report(3, false, "Žádost", "tripRequirement", false, true)), + new ReportMapping(MOD_TRIPBILL, new Report(7, true, "Žádost o SC", "tripRequirementApp", false, true, "requirement")), new ReportMapping(MOD_TRIPBILL, new Report(4, true, "Vyúčtování", "tripBill", false, true, true)), new ReportMapping(MOD_ORDER, new Report(5, false, "Objednávka", "order", true, true)), new ReportMapping(MOD_REQUIREMENTS, new Report(6, false, "Požadavky", "requirements")), diff --git a/src/main/java/info/bukova/isspst/reporting/Report.java b/src/main/java/info/bukova/isspst/reporting/Report.java index 89875d6d..a2f0cf80 100644 --- a/src/main/java/info/bukova/isspst/reporting/Report.java +++ b/src/main/java/info/bukova/isspst/reporting/Report.java @@ -11,6 +11,7 @@ public class Report { private boolean hasSettings; private boolean singleRecord; private boolean hasCondition; + private String property; public Report() { this.reportId = 0; @@ -60,6 +61,11 @@ public class Report { this.singleRecord = singleRecord; } + public Report(long reportId, boolean signable, String name, String jasperFile, boolean hasSettings, boolean singleRecord, String property) { + this(reportId, signable, name, jasperFile, hasSettings, singleRecord); + this.property = property; + } + /** * * @param reportId @@ -138,4 +144,12 @@ public class Report { public void setSignable(boolean signable) { this.signable = signable; } + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } } diff --git a/src/main/java/info/bukova/isspst/ui/reporting/ReportDialogVM.java b/src/main/java/info/bukova/isspst/ui/reporting/ReportDialogVM.java index 0fd9a4b3..00c55650 100644 --- a/src/main/java/info/bukova/isspst/ui/reporting/ReportDialogVM.java +++ b/src/main/java/info/bukova/isspst/ui/reporting/ReportDialogVM.java @@ -1,9 +1,13 @@ package info.bukova.isspst.ui.reporting; +import info.bukova.isspst.Module; +import info.bukova.isspst.ModuleUtils; +import info.bukova.isspst.data.DataModel; import info.bukova.isspst.reporting.Report; import info.bukova.isspst.reporting.ReportDefinition; import info.bukova.isspst.reporting.ReportType; import info.bukova.isspst.services.Service; +import info.bukova.isspst.sort.ReflectionTools; import info.bukova.isspst.ui.DocumentViewModel; import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; @@ -11,9 +15,12 @@ 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.Sessions; import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zul.Window; +import javax.servlet.ServletContext; +import java.lang.reflect.InvocationTargetException; import java.util.List; public class ReportDialogVM extends DocumentViewModel @@ -24,7 +31,8 @@ public class ReportDialogVM extends DocumentViewModel @WireVariable private ReportDefinition reportDefinition; private List dataList; - private Object singleObject; + private Object singleObject; + private ServletContext ctx; @Init(superclass = true) public void init(@ExecutionArgParam("reports") List reports, @@ -40,6 +48,8 @@ public class ReportDialogVM extends DocumentViewModel dataList = data; this.singleObject = singleObject; reportDefinition.setService(service); + + ctx = Sessions.getCurrent().getWebApp().getServletContext(); } public List getReports() { @@ -59,11 +69,36 @@ public class ReportDialogVM extends DocumentViewModel this.selected = selected; reportDefinition.setReport(selected); if (selected.isSingleRecord()) { - reportDefinition.setSingleObject(singleObject); + setObject(selected); } else { reportDefinition.setDataSet(dataList); } } + + private void setObject(Report report) { + if (report.getProperty() == null) { + reportDefinition.setSingleObject(singleObject); + } else { + try { + Object o = ReflectionTools.getGetterMethod(singleObject, report.getProperty()).invoke(singleObject); + reportDefinition.setSingleObject(o); + + if (!(o instanceof DataModel)) { + return; + } + + Module m = ModuleUtils.getModule((DataModel)o, ctx); + + if (m != null) { + reportDefinition.setService((Service) ModuleUtils.getServiceInstance(m, ctx)); + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + } @Command public void print(@BindingParam("window") Window window) {