Search in sources :

Example 1 with JasperPrint

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;
}
Also used : JasperPrint(net.sf.jasperreports.engine.JasperPrint) Connection(java.sql.Connection) JasperReport(net.sf.jasperreports.engine.JasperReport)

Example 2 with 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;
}
Also used : MProcess(org.compiere.model.MProcess) MWFProcess(org.compiere.wf.MWFProcess) MWorkflow(org.compiere.wf.MWorkflow) JasperPrint(net.sf.jasperreports.engine.JasperPrint) ProcessInfo(org.compiere.process.ProcessInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RunProcessResponse(pl.x3E.adInterface.RunProcessResponse) JasperPrint(net.sf.jasperreports.engine.JasperPrint) SQLException(java.sql.SQLException) IOException(java.io.IOException) CharArrayWriter(java.io.CharArrayWriter) MPInstance(org.compiere.model.MPInstance) ReportEngine(org.compiere.print.ReportEngine) MPrintFormat(org.compiere.print.MPrintFormat) MTable(org.compiere.model.MTable) RunProcess(pl.x3E.adInterface.RunProcess) Trx(org.compiere.util.Trx) File(java.io.File) RunProcessResponseDocument(pl.x3E.adInterface.RunProcessResponseDocument) PO(org.compiere.model.PO)

Example 3 with JasperPrint

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();
    }
}
Also used : JasperPrint(net.sf.jasperreports.engine.JasperPrint) ReportProcessor(net.sf.compilo.report.ReportProcessor) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 4 with JasperPrint

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();
    }
}
Also used : HashMap(java.util.HashMap) JasperPrint(net.sf.jasperreports.engine.JasperPrint) JasperReport(net.sf.jasperreports.engine.JasperReport) JRException(net.sf.jasperreports.engine.JRException) SQLException(java.sql.SQLException)

Example 5 with JasperPrint

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"));
            }
        }
    }
}
Also used : JRSingleSheetXlsSaveContributor(net.sf.jasperreports.view.save.JRSingleSheetXlsSaveContributor) JFileChooser(javax.swing.JFileChooser) JRException(net.sf.jasperreports.engine.JRException) JasperPrint(net.sf.jasperreports.engine.JasperPrint) JRSaveContributor(net.sf.jasperreports.view.JRSaveContributor) Preferences(java.util.prefs.Preferences) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) JasperPrint(net.sf.jasperreports.engine.JasperPrint) JRCsvSaveContributor(net.sf.jasperreports.view.save.JRCsvSaveContributor)

Aggregations

JasperPrint (net.sf.jasperreports.engine.JasperPrint)30 JasperReport (net.sf.jasperreports.engine.JasperReport)13 JRException (net.sf.jasperreports.engine.JRException)11 HashMap (java.util.HashMap)10 Connection (java.sql.Connection)8 File (java.io.File)7 IOException (java.io.IOException)6 SQLException (java.sql.SQLException)5 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)4 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)3 Map (java.util.Map)3 SimpleExporterInput (net.sf.jasperreports.export.SimpleExporterInput)3 SimpleOutputStreamExporterOutput (net.sf.jasperreports.export.SimpleOutputStreamExporterOutput)3 Address (eu.ggnet.dwoss.redtape.ee.entity.Address)2 DocumentHistory (eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory)2 Guardian (eu.ggnet.saft.core.auth.Guardian)2 PrinterJob (java.awt.print.PrinterJob)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 MalformedURLException (java.net.MalformedURLException)2