use of com.autentia.tnt.error.ReportException in project TNTConcept by autentia.
the class ReportGeneratorStandardImpl method generate.
public void generate(ReportInfo parameters, OutputStream outputStream) throws ReportException {
JasperReport report = null;
Session session = null;
Connection con = null;
try {
report = initReport(parameters.name, parameters.category);
debug("ReportGenerator - report: " + report);
debug("ReportGenerator - iniciando lista de parametros");
if (report == null) {
debug("ReportGenerator - SC_NOT_FOUND");
// response.sendError(HttpServletResponse.SC_NOT_FOUND);
this.throwError("Null report");
return;
}
Map args = getParametersAsMapAndSubReport(parameters.parameters, parameters.category);
// establecemos el resource bundle correspondiente al locale actual
// del usuario al JasperReport
final Principal principal = AuthenticationManager.getDefault().getCurrentPrincipal();
args.put(JRParameter.REPORT_RESOURCE_BUNDLE, ResourceBundle.getBundle("com.autentia.tnt.resources.report", principal.getLocale()));
debug("ReportGenerator - argc " + args.size());
debug("ReportGenerator - iniciando conexion and BD");
session = HibernateUtil.getSessionFactory().getCurrentSession();
con = session.connection();
debug("ReportGenerator - generación del informe en función del formato");
GeneratorFactory.getFactory().getGeneratorByFormat(parameters.format).generate(outputStream, report, args, con);
debug("ReportGenerator - finalización del informe");
} catch (Exception e) {
log.error("ReportGenerator - exception", e);
this.throwError("Exception");
/*
* try {
* response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
* e.getMessage()); } catch (IOException e1) { // TODO
* Auto-generated catch block e1.printStackTrace(); }
*/
} finally {
if (con != null) {
try {
con.close();
} catch (SQLException e1) {
log.error("ReportGenerator - exception cerrando conexion", e1);
}
con = null;
}
}
}
use of com.autentia.tnt.error.ReportException in project TNTConcept by autentia.
the class ReportGeneratorStandardImpl method getParametersAsMapAndSubReport.
private Map getParametersAsMapAndSubReport(Map<String, Object> parameters, String reportCategory) throws Exception, ReportException {
JasperReport subReport;
Map args = new HashMap();
Enumeration e = new IteratorEnumeration(parameters.keySet().iterator());
while (e.hasMoreElements()) {
String arg = (String) e.nextElement();
final String value = (String) parameters.get(arg);
Object obj = null;
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date value_date = sdf.parse(value);
java.sql.Timestamp ts = new Timestamp(value_date.getTime());
obj = ts;
} catch (Exception ex) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date value_date = sdf.parse(value);
obj = value_date;
} catch (Exception ex2) {
try {
Integer value_int = Integer.parseInt(value);
obj = value_int;
} catch (Exception ex3) {
if ("true".equals(value) || "false".equals(value)) {
obj = Boolean.parseBoolean(value);
} else {
obj = value;
}
}
}
}
if (arg.startsWith("SUBREPORT")) {
obj = loadSubreportByCategory(reportCategory, obj);
}
if (obj.equals("allItemsSelected")) {
obj = "%";
}
args.put(arg, obj);
}
return args;
}
use of com.autentia.tnt.error.ReportException in project TNTConcept by autentia.
the class ReportServlet method generateReport.
private void generateReport(HttpServletRequest request, HttpServletResponse response, String reportName, String ext, String reportCategory) throws IOException {
ReportInfoBuilder builder = new ReportInfoBuilder();
builder.name(reportName).in(ReportFormat.valueOf(ext)).withCategory(reportCategory);
Enumeration e = request.getParameterNames();
while (e.hasMoreElements()) {
String arg = (String) e.nextElement();
final String value = request.getParameter(arg);
builder.andParameter(arg, value);
}
ReportGeneratorStandardImpl generator = new ReportGeneratorStandardImpl();
try {
generator.generate(builder.build(), response.getOutputStream());
} catch (ReportException e1) {
log.error(e1);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e1.getMessage());
}
response.setContentType(ReportFormat.valueOf(ext).getResponseType());
}
use of com.autentia.tnt.error.ReportException in project TNTConcept by autentia.
the class ReportGeneratorStandardImpl method loadSubreportByCategory.
private Object loadSubreportByCategory(String reportCategory, Object obj) throws JRException, ReportException {
JasperReport subReport;
final String subreportPath = ConfigurationUtil.getDefault().getReportPath();
String targetFilePath;
String sourceFilePath;
if (reportCategory.equals("personal/")) {
sourceFilePath = subreportPath + ReportUtil.SUBREPORT_PREFIX + obj + ReportUtil.REPORT_DEFINITION_SUFFIX;
targetFilePath = subreportPath + ReportUtil.SUBREPORT_PREFIX + obj + ReportUtil.REPORT_SUFFIX;
} else {
sourceFilePath = ReportUtil.REPORT_PREFIX + reportCategory + ReportUtil.SUBREPORT_PREFIX + obj + ReportUtil.REPORT_DEFINITION_SUFFIX;
targetFilePath = ReportUtil.REPORT_PREFIX + reportCategory + ReportUtil.SUBREPORT_PREFIX + obj + ReportUtil.REPORT_SUFFIX;
}
if (null == getResourceAsURL(targetFilePath)) {
if (null != getResourceAsString(sourceFilePath))
JasperCompileManager.compileReportToFile(getResourceAsString(sourceFilePath));
}
int timeSpentWhile = 0;
while (isNotSubreportAvailable(getResourceAsURL(targetFilePath), timeSpentWhile)) {
try {
Thread.currentThread().sleep(SLEEP_TIME_IN_MILLIS_WHEN_CREATING_SUBREPORTS);
timeSpentWhile += SLEEP_TIME_IN_MILLIS_WHEN_CREATING_SUBREPORTS;
} catch (Exception ex) {
this.throwError("Subreport waiter sleep exception", ex);
}
}
subReport = (JasperReport) JRLoader.loadObject(getResourceAsURL(targetFilePath));
obj = targetFilePath;
return obj;
}
Aggregations