Umožněn tisk sestavy aktuálně vybraného záznamu. Ošetření možných

výjimek při generování sestavy. 
closes #89
multitenant
Josef Rokos 11 years ago
parent 452ea9c698
commit e304e25872

@ -58,6 +58,7 @@ 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("Adresní karty", "address")) new ReportMapping(MOD_ADDRESSBOOK, new Report("Adresní karty", "address")),
new ReportMapping(MOD_ADDRESSBOOK, new Report("Adresna", "address", false, true))
}; };
} }

@ -53,11 +53,9 @@ public class DynamicGenerator implements Generator {
try { try {
rb.addColumn(StringUtils.localize(col), col, clazz, 30, false); rb.addColumn(StringUtils.localize(col), col, clazz, 30, false);
} catch (ColumnBuilderException e) { } catch (ColumnBuilderException e) {
// TODO Auto-generated catch block throw new ReportException(e);
e.printStackTrace();
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
// TODO Auto-generated catch block throw new ReportException(e);
e.printStackTrace();
} }
} }
} }
@ -72,11 +70,8 @@ public class DynamicGenerator implements Generator {
JasperReport report = DynamicJasperHelper.generateJasperReport(dr, new ClassicLayoutManager(), definition.getParams()); JasperReport report = DynamicJasperHelper.generateJasperReport(dr, new ClassicLayoutManager(), definition.getParams());
return JasperRunManager.runReportToPdf(report, definition.getParams(), ds); return JasperRunManager.runReportToPdf(report, definition.getParams(), ds);
} catch (JRException e) { } catch (JRException e) {
// TODO Auto-generated catch block throw new ReportException(e);
e.printStackTrace();
} }
return null;
} }
private Class<?> colClass(String col) { private Class<?> colClass(String col) {

@ -31,8 +31,7 @@ public class PredefinedGenerator implements Generator {
JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "Cp1250"); JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "Cp1250");
bytes = JasperRunManager.runReportToPdf(report, definition.getParams(), new JRBeanCollectionDataSource(definition.getDataSet()));; bytes = JasperRunManager.runReportToPdf(report, definition.getParams(), new JRBeanCollectionDataSource(definition.getDataSet()));;
} catch (JRException e) { } catch (JRException e) {
// TODO Auto-generated catch block throw new ReportException(e);
e.printStackTrace();
} }
return bytes; return bytes;

@ -7,11 +7,17 @@ public class Report {
private String name; private String name;
private String jasperFile; private String jasperFile;
private boolean hasSettings; private boolean hasSettings;
private boolean singleRecord;
public Report() { public Report() {
hasSettings = false; hasSettings = false;
singleRecord = false;
} }
/**
* @param name
* @param jasperFile
*/
public Report(String name, String jasperFile) { public Report(String name, String jasperFile) {
this(); this();
this.type = ReportType.DEFINED; this.type = ReportType.DEFINED;
@ -19,10 +25,26 @@ public class Report {
this.jasperFile = jasperFile; this.jasperFile = jasperFile;
} }
/**
* @param name
* @param jasperFile
* @param hasSettings
*/
public Report(String name, String jasperFile, boolean hasSettings) { public Report(String name, String jasperFile, boolean hasSettings) {
this(name, jasperFile); this(name, jasperFile);
this.hasSettings = hasSettings; 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() { public ReportType getType() {
return type; return type;
@ -56,4 +78,12 @@ public class Report {
this.hasSettings = hasSettings; this.hasSettings = hasSettings;
} }
public boolean isSingleRecord() {
return singleRecord;
}
public void setSingleRecord(boolean singleRecord) {
this.singleRecord = singleRecord;
}
} }

@ -1,6 +1,7 @@
package info.bukova.isspst.reporting; package info.bukova.isspst.reporting;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -16,38 +17,46 @@ public class ReportController {
private ReportDefinition reportDefinition; private ReportDefinition reportDefinition;
@Autowired @Autowired
private GeneratorFactory factory; private GeneratorFactory factory;
private static final String ERROR_MESSAGE = "<html><body><b>Generator returned no data!</b><br/>%s</body></html>";
@RequestMapping("report.pdf") private void writeError(OutputStream stream, Throwable e) {
public void pdfReport(HttpServletResponse response) { writeError(stream, e.toString());
Generator gen = factory.createGenerator(reportDefinition); }
byte[] data = gen.generate();
String contentType = "application/pdf"; private void writeError(OutputStream stream, String message) {
String err = String.format(ERROR_MESSAGE, message);
ServletOutputStream os = null;
try { try {
os = response.getOutputStream(); stream.write(err.getBytes(), 0, err.getBytes().length);
} catch (IOException e1) { } catch (IOException e1) {
e1.printStackTrace(); e1.printStackTrace();
return;
} }
}
@RequestMapping("report.pdf")
public void pdfReport(HttpServletResponse response) {
final String contentType = "application/pdf";
// if (reportDefinition.getReport() == null || reportDefinition.getDataSet() == null) { ServletOutputStream os = null;
// writeError(os, "Definition is null");
// return;
// }
response.setContentType(contentType);
response.setContentLength(data.length);
try { 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.write(data, 0, data.length);
os.flush(); os.flush();
os.close(); os.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
// } catch (ReportException e) { } catch (ReportException e) {
// writeError(os, e); writeError(os, e);
} finally { } finally {
if (os != null) { if (os != null) {
try { try {

@ -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);
}
}

@ -4,7 +4,7 @@ public class IsspstException extends RuntimeException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final static String MSG = "RsFaktura Exception. "; private final static String MSG = "IS Exception. ";
public IsspstException() { public IsspstException() {
super(MSG); super(MSG);

@ -301,6 +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);
params.put("singleObject", dataBean);
Window win = (Window) Executions.createComponents("/app/reporting/reportDialog.zul", null, params); Window win = (Window) Executions.createComponents("/app/reporting/reportDialog.zul", null, params);
win.doModal(); win.doModal();
} }

@ -21,17 +21,21 @@ public class ReportDialogVM {
private Report selected; private Report selected;
@WireVariable @WireVariable
private ReportDefinition reportDefinition; private ReportDefinition reportDefinition;
private List<Object> dataList;
private Object singleObject;
@Init @Init
public void init(@ExecutionArgParam("reports") List<Report> reports, public void init(@ExecutionArgParam("reports") List<Report> reports,
@ExecutionArgParam("data") List<Object> data) { @ExecutionArgParam("data") List<Object> data,
@ExecutionArgParam("singleObject") Object singleObject) {
this.reports = reports; this.reports = reports;
if (data != null && data.size() > 0 && data.get(0).getClass() != reportDefinition.gatDataClass()) { if (data != null && data.size() > 0 && data.get(0).getClass() != reportDefinition.gatDataClass()) {
reportDefinition.clear(); reportDefinition.clear();
} }
reportDefinition.setDataSet(data); dataList = data;
this.singleObject = singleObject;
} }
public List<Report> getReports() { public List<Report> getReports() {
@ -50,6 +54,11 @@ public class ReportDialogVM {
public void setSelected(Report selected) { public void setSelected(Report selected) {
this.selected = selected; this.selected = selected;
reportDefinition.setReport(selected); reportDefinition.setReport(selected);
if (selected.isSingleRecord()) {
reportDefinition.setSingleObject(singleObject);
} else {
reportDefinition.setDataSet(dataList);
}
} }
@Command @Command
@ -72,4 +81,12 @@ public class ReportDialogVM {
} }
} }
public Object getSingleObject() {
return singleObject;
}
public void setReportDefinition(ReportDefinition reportDefinition) {
this.reportDefinition = reportDefinition;
}
} }

@ -8,7 +8,7 @@
<hbox> <hbox>
<listbox model="@load(vm.reports)" width="250px" height="350px" selectedItem="@bind(vm.selected)"> <listbox model="@load(vm.reports)" width="250px" height="350px" selectedItem="@bind(vm.selected)">
<template name="model"> <template name="model">
<listitem> <listitem disabled="@load(each.singleRecord and empty vm.singleObject)">
<listcell><label value="@load(each.name)"/></listcell> <listcell><label value="@load(each.name)"/></listcell>
</listitem> </listitem>
</template> </template>

Loading…
Cancel
Save