|
|
@ -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 {
|
|
|
|