use of net.sf.jasperreports.engine.JRException in project adempiere by adempiere.
the class ReportInfo method processReport.
protected File processReport(String reportFile) {
log.finest("ReportInfo.processReport - " + reportFile);
File JasperDesignFile = new File(reportFile);
String JasperReportFile = reportFile.replaceAll(".jrxml", ".jasper").replaceAll(".xml", ".jasper");
File jasperFile = new File(JasperReportFile);
// Marco LOMBARDO: this is the local one, there is the same
// field at class level. There was a bug on it about subreports.
JasperReport jasperReport = null;
if (jasperFile.exists()) {
// test time
if (JasperDesignFile.lastModified() <= jasperFile.lastModified()) {
try {
// Marco LOMBARDO: should refer to local.
jasperReport = (JasperReport) JRLoader.loadObject(jasperFile.getAbsolutePath());
} catch (JRException e) {
// Marco LOMBARDO: on error reset global report.
this.jasperReport = null;
log.saveError("ReportServer.processReport: Can not load report - ", e);
}
} else {
// Marco LOMBARDO: should refer to local.
jasperReport = compileReport(JasperDesignFile, jasperFile);
}
} else {
// create new jasper file
// Marco LOMBARDO: should refer to local.
jasperReport = compileReport(JasperDesignFile, jasperFile);
}
if (hasError)
return null;
// Marco LOMBARDO: this should happen only after compile the main report.
if (this.jasperReport == null)
this.jasperReport = jasperReport;
if (// Marco LOMBARDO: should refer to local.
jasperReport != null) {
String[] extension = { ".xml", "jrxml" };
File[] subreports = JasperDesignFile.getParentFile().listFiles(new FileFilter(JasperReportFile.replaceAll(".jasper", "") + "Subreport", JasperDesignFile.getParentFile(), extension));
for (int i = 0; i < subreports.length; i++) {
log.finest("The subreport file @ " + subreports[i].getAbsolutePath());
File sub = processReport(subreports[i].getAbsolutePath());
String subName = sub.getName();
int pos = sub.getName().indexOf('.');
if (pos != -1)
subName = subName.substring(0, pos);
subReport.put(subName, sub.getAbsolutePath());
this.hasSubReport = true;
}
}
if (hasError)
return null;
return jasperFile;
}
use of net.sf.jasperreports.engine.JRException in project adempiere by adempiere.
the class ReportStarter method processReport.
/**
* @author rlemeill
* @param reportFile
* @return
*/
protected JasperData processReport(File reportFile) {
log.info("reportFile.getAbsolutePath() = " + reportFile.getAbsolutePath());
JasperReport jasperReport = null;
String jasperName = reportFile.getName();
int pos = jasperName.indexOf('.');
if (pos != -1)
jasperName = jasperName.substring(0, pos);
File reportDir = reportFile.getParentFile();
//test if the compiled report exists
File jasperFile = new File(reportDir.getAbsolutePath(), jasperName + ".jasper");
if (jasperFile.exists()) {
// test time
if (reportFile.lastModified() == jasperFile.lastModified()) {
log.info(" no need to compile use " + jasperFile.getAbsolutePath());
try {
jasperReport = (JasperReport) JRLoader.loadObject(jasperFile.getAbsolutePath());
} catch (JRException e) {
jasperReport = null;
log.severe("Can not load report - " + e.getMessage());
}
} else {
jasperReport = compileReport(reportFile, jasperFile);
}
} else {
// create new jasper file
jasperReport = compileReport(reportFile, jasperFile);
}
return new JasperData(jasperReport, reportDir, jasperName, jasperFile);
}
use of net.sf.jasperreports.engine.JRException in project midpoint by Evolveum.
the class MidPointAbstractDataSource method getFieldValue.
@Override
public Object getFieldValue(JRField jrField) throws JRException {
// TODO Auto-generated method stub
String fieldName = jrField.getName();
if (fieldName.equals("oid")) {
return currentObject.getOid();
}
Item i = currentObject.findItem(new QName(fieldName));
if (i == null) {
return null;
}
if (i instanceof PrismProperty) {
if (i.isSingleValue()) {
return ((PrismProperty) i).getRealValue();
}
return ((PrismProperty) i).getRealValues();
} else if (i instanceof PrismReference) {
if (i.isSingleValue()) {
return ((PrismReference) i).getValue().asReferencable();
}
List<Referencable> refs = new ArrayList<Referencable>();
for (PrismReferenceValue refVal : ((PrismReference) i).getValues()) {
refs.add(refVal.asReferencable());
}
return refs;
} else if (i instanceof PrismContainer) {
if (i.isSingleValue()) {
return ((PrismContainer) i).getValue().asContainerable();
}
List<Containerable> containers = new ArrayList<Containerable>();
for (Object pcv : i.getValues()) {
if (pcv instanceof PrismContainerValue) {
containers.add(((PrismContainerValue) pcv).asContainerable());
}
}
return containers;
} else
throw new JRException("Could not get value of the fileld: " + fieldName);
}
use of net.sf.jasperreports.engine.JRException in project midpoint by Evolveum.
the class ReportCreateTaskHandler method prepareReportParameters.
// private JasperReport loadJasperReport(ReportType reportType) throws SchemaException{
//
// if (reportType.getTemplate() == null) {
// throw new IllegalStateException("Could not create report. No jasper template defined.");
// }
// try {
// byte[] reportTemplate = Base64.decodeBase64(reportType.getTemplate());
//
// InputStream inputStreamJRXML = new ByteArrayInputStream(reportTemplate);
// JasperDesign jasperDesign = JRXmlLoader.load(inputStreamJRXML);
// LOGGER.trace("load jasper design : {}", jasperDesign);
//
// if (reportType.getTemplateStyle() != null){
// JRDesignReportTemplate templateStyle = new JRDesignReportTemplate(new JRDesignExpression("$P{" + PARAMETER_TEMPLATE_STYLES + "}"));
// jasperDesign.addTemplate(templateStyle);
// JRDesignParameter parameter = new JRDesignParameter();
// parameter.setName(PARAMETER_TEMPLATE_STYLES);
// parameter.setValueClass(JRTemplate.class);
// parameter.setForPrompting(false);
// jasperDesign.addParameter(parameter);
// }
// JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
// return jasperReport;
// } catch (JRException ex){
// LOGGER.error("Couldn't create jasper report design {}", ex.getMessage());
// throw new SchemaException(ex.getMessage(), ex.getCause());
// }
//
//
// }
private Map<String, Object> prepareReportParameters(ReportType reportType, OperationResult parentResult) {
Map<String, Object> params = new HashMap<String, Object>();
if (reportType.getTemplateStyle() != null) {
byte[] reportTemplateStyleBase64 = reportType.getTemplateStyle();
byte[] reportTemplateStyle = Base64.decodeBase64(reportTemplateStyleBase64);
try {
LOGGER.trace("Style template string {}", new String(reportTemplateStyle));
InputStream inputStreamJRTX = new ByteArrayInputStream(reportTemplateStyle);
JRTemplate templateStyle = JRXmlTemplateLoader.load(inputStreamJRTX);
params.put(PARAMETER_TEMPLATE_STYLES, templateStyle);
LOGGER.trace("Style template parameter {}", templateStyle);
} catch (Exception ex) {
LOGGER.error("Error create style template parameter {}", ex.getMessage());
throw new SystemException(ex);
}
}
// for our special datasource
params.put(PARAMETER_REPORT_OID, reportType.getOid());
params.put(PARAMETER_OPERATION_RESULT, parentResult);
params.put(ReportService.PARAMETER_REPORT_SERVICE, reportService);
return params;
}
use of net.sf.jasperreports.engine.JRException in project bamboobsc by billchen198318.
the class JReportUtils method deployReport.
public static void deployReport(TbSysJreport report) throws Exception {
String reportDeployDirName = Constants.getDeployJasperReportDir() + "/";
File reportDeployDir = new File(reportDeployDirName);
try {
if (!reportDeployDir.exists()) {
logger.warn("no exists dir, force mkdir " + reportDeployDirName);
FileUtils.forceMkdir(reportDeployDir);
}
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage().toString());
}
logger.info("REPORT-ID : " + report.getReportId());
File reportFile = null;
File reportZipFile = null;
OutputStream os = null;
try {
String reportFileFullPath = reportDeployDirName + report.getReportId() + "/" + report.getFile();
String reportZipFileFullPath = reportDeployDirName + report.getReportId() + ".zip";
reportZipFile = new File(reportZipFileFullPath);
if (reportZipFile.exists()) {
logger.warn("delete " + reportZipFileFullPath);
FileUtils.forceDelete(reportZipFile);
}
os = new FileOutputStream(reportZipFile);
IOUtils.write(report.getContent(), os);
os.flush();
ZipFile zipFile = new ZipFile(reportZipFileFullPath);
zipFile.extractAll(reportDeployDirName);
reportFile = new File(reportFileFullPath);
if (!reportFile.exists()) {
logger.warn("report file is missing : " + reportFileFullPath);
return;
}
if (YesNo.YES.equals(report.getIsCompile()) && report.getFile().endsWith("jrxml")) {
logger.info("compile report...");
File d = new File(reportDeployDirName + report.getReportId());
String outJasper = compileReportToJasperFile(d.listFiles(), reportDeployDirName + report.getReportId() + "/");
logger.info("out first : " + outJasper);
}
} catch (JRException re) {
re.printStackTrace();
logger.error(re.getMessage().toString());
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage().toString());
} finally {
if (os != null) {
os.close();
}
os = null;
reportFile = null;
reportZipFile = null;
}
reportDeployDir = null;
}
Aggregations