use of net.sf.jasperreports.engine.JasperPrint in project opennms by OpenNMS.
the class DefaultReportService method runAndRender.
private JasperPrint runAndRender(Report report) throws Exception, JRException {
JasperPrint jasperPrint = new JasperPrint();
JasperReport jasperReport = JasperCompileManager.compileReport(System.getProperty("opennms.home") + File.separator + "etc" + File.separator + "report-templates" + File.separator + report.getReportTemplate());
if (report.getReportEngine().equals("jdbc")) {
Connection connection = DataSourceFactory.getInstance().getConnection();
jasperPrint = JasperFillManager.fillReport(jasperReport, paramListToMap(report.getParameters()), connection);
connection.close();
} else if (report.getReportEngine().equals("opennms")) {
LOG.error("Sorry the OpenNMS Data source engine is not yet available");
jasperPrint = null;
} else {
LOG.error("Unknown report engine: {} ", report.getReportEngine());
jasperPrint = null;
}
return jasperPrint;
}
use of net.sf.jasperreports.engine.JasperPrint in project adempiere by adempiere.
the class Process method runProcess.
/**************************************************************************
* Create Process Page
* @param AD_Process_ID Process
* @return Page
*/
public static RunProcessResponseDocument runProcess(CompiereService m_cs, RunProcessDocument req) {
RunProcessResponseDocument res = RunProcessResponseDocument.Factory.newInstance();
RunProcessResponse r = res.addNewRunProcessResponse();
RunProcess rp = req.getRunProcess();
int AD_Process_ID = rp.getADProcessID();
int m_record_id = rp.getADRecordID();
//WebSessionCtx wsc = WebSessionCtx.get (request);
MProcess process = MProcess.get(m_cs.getM_ctx(), AD_Process_ID);
// need to check if Role can access
if (process == null) {
// WebDoc doc = WebDoc.createWindow("Process not found");
r.setError("Process not found");
r.setIsError(true);
return res;
}
//process.getDescription()
//process.getHelp()
// Evaluate DocAction, if call have DocAction parameter, then try to set DocAction before calling workflow process
String docAction = rp.getDocAction();
if (docAction != null && docAction.length() > 0) {
// - the process must be a workflow document
if (process.getAD_Workflow_ID() > 0) {
MWorkflow wf = MWorkflow.get(m_cs.getM_ctx(), process.getAD_Workflow_ID());
if (wf.getWorkflowType().equals(MWorkflow.WORKFLOWTYPE_DocumentProcess)) {
// - get the table associated with the workflow document
// - set DocAction in such table
// get the PO for the tablename and record ID
MTable table = MTable.get(m_cs.getM_ctx(), wf.getAD_Table_ID());
if (table != null) {
PO po = table.getPO(m_record_id, null);
if (po != null) {
po.set_ValueOfColumn("DocAction", docAction);
po.save();
}
}
}
}
}
// Create Process Instance
MPInstance pInstance = null;
try {
pInstance = fillParameter(m_cs, rp.getParamValues(), process);
} catch (Exception ex) {
//center.addElement(new p("B��d: " + ex.getMessage(), AlignType.LEFT).setClass("ProcesResultError"));
r.setError(ex.getMessage());
r.setIsError(true);
return res;
}
if (m_record_id > 0) {
pInstance.setRecord_ID(m_record_id);
pInstance.save();
}
//
ProcessInfo pi = new ProcessInfo(process.getName(), process.getAD_Process_ID());
pi.setAD_User_ID(Env.getAD_User_ID(m_cs.getM_ctx()));
pi.setAD_Client_ID(Env.getAD_Client_ID(m_cs.getM_ctx()));
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
if (m_record_id > 0)
pi.setRecord_ID(m_record_id);
// Info
//p p = new p();
//p.addElement(Msg.translate(wsc.ctx, "AD_PInstance_ID") + ": " + pInstance.getAD_PInstance_ID());
//center.addElement(p);
boolean processOK = false;
boolean jasperreport = (process != null && process.getClassname() != null && process.getClassname().indexOf("net.sf.compilo.report.ReportStarter") >= 0);
if (jasperreport) {
//this.jasperReport( request, response, wsc.ctx, pi);
processOK = true;
}
// Start
if (process.isWorkflow()) {
try {
int AD_Workflow_ID = process.getAD_Workflow_ID();
MWorkflow wf = MWorkflow.get(Env.getCtx(), AD_Workflow_ID);
// may return null
MWFProcess wfProcess = wf.startWait(pi);
if (wfProcess != null) {
//wynik
r.setSummary(pi.getSummary());
r.setLogInfo(pi.getLogInfo(true));
r.setIsError(false);
return res;
}
} catch (Exception ex) {
r.setError(ex.getMessage());
r.setLogInfo(pi.getLogInfo(true));
r.setIsError(true);
return res;
//Wyj�tek: pi.getLogInfo(true) pi.getLogInfo(true)
}
//started = wfProcess != null;
}
if (process.isJavaProcess() && !jasperreport) {
Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
try {
processOK = process.processIt(pi, trx);
trx.commit();
trx.close();
} catch (Throwable t) {
trx.rollback();
trx.close();
}
if (!processOK || pi.isError()) {
// b��d: pi.getSummary()
r.setSummary(pi.getSummary());
r.setLogInfo(pi.getLogInfo(true));
r.setIsError(true);
processOK = false;
} else {
r.setSummary(pi.getSummary());
r.setLogInfo(pi.getLogInfo(true));
r.setIsError(false);
//return res;
// wynik - String summary = pi.getSummary();
}
}
// Report
if (//&& !m_jasperreport)
(process.isReport() || jasperreport)) /*processOK &&*/
{
r.setIsReport(true);
//if (m_jasperreport)
//{
// center.addElement(new p("JASPER REPORT", AlignType.LEFT).setClass("Cerror"));
//}
//else
{
ReportEngine re = null;
if (!jasperreport)
re = start(pi);
//ReportEngine.get(m_cs.getM_ctx(), pi);
if (re == null && !jasperreport) {
//b��d: "Nie uda�o si� uruchomi� silnika raport�w (ReportEngine)",
} else {
try {
boolean ok = false;
File file;
String file_type = "pdf";
if (!jasperreport) {
//file = File.createTempFile("WProcess", ".pdf");
//ok = re.createPDF(file);
MPrintFormat pf = re.getPrintFormat();
if (pf.isTableBased()) {
CharArrayWriter wr = new CharArrayWriter();
//file = File.createTempFile("WProcess", ".xls");
ok = ReportEngineEx.createEXCEL_HTML_wr(re, m_cs.getM_ctx(), wr, false, re.getPrintFormat().getLanguage());
//ok = re.createXML( file );
file_type = "xls";
String data = wr.toString();
if (data != null)
r.setData(data.getBytes());
r.setReportFormat(file_type);
} else {
byte[] dat = re.createPDFData();
file_type = "pdf";
r.setData(dat);
r.setReportFormat(file_type);
}
//r.setReportFormat("xls");
ok = true;
} else {
JasperPrint jp = getJasperReportPrint(m_cs.getM_ctx(), pi);
//file = File.createTempFile("WProcess", ".pdf");
ByteArrayOutputStream wr = new ByteArrayOutputStream();
net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(jp, wr);
//exportReportToPdfFile( jp, file.getAbsolutePath() );
file_type = "pdf";
r.setData(wr.toByteArray());
r.setReportFormat(file_type);
ok = true;
}
if (ok) {
//pInstance.getAD_PInstance_ID()
//file.getAbsolutePath()
// Marker that Process is OK
m_cs.getM_ctx().put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
} else {
r.setError("Cannot create report");
r.setLogInfo(pi.getLogInfo(true));
r.setIsError(true);
return res;
//"Cannot create report:",
}
} catch (Exception e) {
r.setError("Cannot create report:" + e.getMessage());
r.setLogInfo(pi.getLogInfo(true));
r.setIsError(true);
return res;
// ,
}
}
}
}
return res;
}
use of net.sf.jasperreports.engine.JasperPrint in project adempiere by adempiere.
the class Process method getJasperReportPrint.
// fillParameter
/*
static ReportServer server = null;
private void jasperReport(HttpServletRequest request, HttpServletResponse response, Properties ctx, int AD_Process_ID, int AD_Instance_ID) throws Exception
{
MProcess process = MProcess.get (ctx, AD_Process_ID);
// need to check if Role can access
if (process == null)
throw new Exception( "Brak procesu" );
MPInstance pInstance = new MPInstance( ctx, AD_Instance_ID, null );
if (pInstance == null)
throw new Exception( "Brak intancji procesu" );
ProcessInfo pi = new ProcessInfo (process.getName(), process.getAD_Process_ID());
pi.setAD_User_ID(pInstance.getAD_User_ID());
pi.setAD_Client_ID(pInstance.getAD_Client_ID());
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
pi.setRecord_ID( pInstance.getRecord_ID() );
jasperReport( request, response, ctx, pi);
}
*/
/**
* Procedura obsluguje raporty jasper - przekazuje wynik raportu w postaci PDF
* @param request
* @param response
* @param ctx
* @param pi
*/
/*
private void jasperReport(HttpServletRequest request, HttpServletResponse response, Properties ctx, ProcessInfo pi)
{
try
{
JasperPrint jasperPrint = getJasperReportPrint( ctx, pi );
ServletOutputStream output = response.getOutputStream();
net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfStream(jasperPrint, output);
int bufferSize = 2048; // 2k Buffer
//response.setContentType(mimeType.getMimeType());
response.setBufferSize(bufferSize);
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
response.setContentType( "application/pdf" );
//response.setHeader("Content-disposition","inline;filename=generated.pdf");
// response.setHeader("Pragma","no-cache");
// response.setHeader("Cache-Control", "no-cache");
// response.setHeader("Cache-Control","no-store" );
// response.setDateHeader("Expires", -1);
// response.setHeader("Content-Type","application/pdf" );
//response.setContentType( "application/pdf" );
//response.setHeader("Content-Type","application/pdf" );
output.flush();
output.close();
}
catch (JRException e)
{
log.saveError("ReportStarter.startProcess: Can not run report - ", e);
return;
//return e.getMessage();
}
catch (Exception ex)
{
log.saveError("ReportStarter.startProcess: Can not run report - ", ex);
return;
// return ex.getMessage();
}
}
*/
private static JasperPrint getJasperReportPrint(Properties ctx, ProcessInfo pi) {
// lokalnie czy zdalnie
boolean local = true;
try {
Env.setContext(ctx, "#AD_Language", "pl_PL");
Env.setContext(Env.getCtx(), "#AD_Language", "pl_PL");
JasperPrint jasperPrint;
ReportProcessor rp = new ReportProcessor(ctx, pi);
jasperPrint = rp.runReport();
if (jasperPrint == null) {
log.finer("ReportStarter.startProcess Cannot process JasperPrint Object");
return null;
} else
return jasperPrint;
} catch (Exception ex) {
log.saveError("ReportStarter.startProcess: Can not run report - ", ex);
return null;
// return ex.getMessage();
}
}
use of net.sf.jasperreports.engine.JasperPrint in project adempiere by adempiere.
the class JasperViewer method main.
// End of variables declaration//GEN-END:variables
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
JasperReport myjasperReport = (JasperReport) JasperCompileManager.compileReport(args[0]);
JasperPrint myjasperPrint = JasperFillManager.fillReport(myjasperReport, new HashMap(), getConnection());
JasperViewer.viewReport(myjasperPrint);
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.sf.jasperreports.engine.JasperPrint in project jgnash by ccavanaugh.
the class DynamicJasperReportPanel method saveAction.
private void saveAction() {
Preferences p = Preferences.userNodeForPackage(DynamicJasperReportPanel.class);
JFileChooser fileChooser = new JFileChooser();
fileChooser.setMultiSelectionEnabled(false);
saveContributors.forEach(fileChooser::addChoosableFileFilter);
// restore the last save format
if (p.get(LAST_CONTRIBUTOR, null) != null) {
String last = p.get(LAST_CONTRIBUTOR, null);
for (JRSaveContributor saveContributor : saveContributors) {
if (saveContributor.getDescription().equals(last)) {
fileChooser.setFileFilter(saveContributor);
break;
}
}
} else if (!saveContributors.isEmpty()) {
fileChooser.setFileFilter(saveContributors.get(0));
}
if (p.get(LAST_DIRECTORY, null) != null) {
fileChooser.setCurrentDirectory(new File(p.get(LAST_DIRECTORY, null)));
}
int retValue = fileChooser.showSaveDialog(this);
if (retValue == JFileChooser.APPROVE_OPTION) {
FileFilter fileFilter = fileChooser.getFileFilter();
File file = fileChooser.getSelectedFile();
p.put(LAST_DIRECTORY, file.getParent());
JRSaveContributor contributor = null;
if (fileFilter instanceof JRSaveContributor) {
// save format chosen from the list
contributor = (JRSaveContributor) fileFilter;
} else {
for (JRSaveContributor saveContributor : saveContributors) {
// need to determine the best match
if (saveContributor.accept(file)) {
contributor = saveContributor;
break;
}
}
if (contributor == null) {
JOptionPane.showMessageDialog(this, resourceBundle.getString("error.saving"));
}
}
if (contributor != null) {
p.put(LAST_CONTRIBUTOR, contributor.getDescription());
try {
if (contributor instanceof JRSingleSheetXlsSaveContributor) {
LOG.info("Formatting for xls file");
JasperPrint print = report.createJasperPrint(true);
contributor.save(print, file);
} else if (contributor instanceof JRCsvSaveContributor) {
LOG.info("Formatting for csv file");
JasperPrint print = report.createJasperPrint(true);
contributor.save(print, file);
} else {
contributor.save(jasperPrint, file);
}
} catch (final JRException ex) {
LOG.log(Level.SEVERE, ex.getMessage(), ex);
JOptionPane.showMessageDialog(this, resourceBundle.getString("error.saving"));
}
}
}
}
Aggregations