Search in sources :

Example 1 with WebSessionCtx

use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.

the class WReport method launchReport.

//	launchReport
/**
	 * 	Launch Report
	 * 	@param pf print format
	 */
private File launchReport(MPrintFormat pf, HttpServletRequest request, GridTab m_curTab, MQuery m_query) {
    int Record_ID = 0;
    WebSessionCtx wsc = WebSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);
    //Instance pInstance = new MPInstance (wsc.ctx, 0, 0);
    File fileName = null;
    if (m_query.getRestrictionCount() == 1 && m_query.getCode(0) instanceof Integer) {
        Record_ID = ((Integer) m_query.getCode(0)).intValue();
    }
    PrintInfo info = new PrintInfo(pf.getName(), pf.getAD_Table_ID(), Record_ID);
    info.setDescription(m_query.getInfo());
    if (pf != null && pf.getJasperProcess_ID() > 0) {
        // It's a report using the JasperReports engine
        ProcessInfo pi = new ProcessInfo("", pf.getJasperProcess_ID());
        Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
        //	Execute Process
        WProcessCtl.process(this, m_curTab.getAD_Window_ID(), pi, trx, request);
    } else {
        // It's a default report using the standard printing engine
        ReportEngine re = new ReportEngine(wsc.ctx, pf, m_query, info);
        if (re == null) {
            log.info("Could not start ReportEngine");
        } else {
            try {
                File file = File.createTempFile("WProcess", ".pdf");
                boolean ok = re.createPDF(file);
                if (ok) {
                    fileName = file;
                } else {
                    log.info("Could not create Report");
                }
            } catch (Exception e) {
                log.info(e.toString());
            }
        }
    }
    return fileName;
}
Also used : ReportEngine(org.compiere.print.ReportEngine) PrintInfo(org.compiere.model.PrintInfo) ProcessInfo(org.compiere.process.ProcessInfo) Trx(org.compiere.util.Trx) WebSessionCtx(org.compiere.util.WebSessionCtx) File(java.io.File) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 2 with WebSessionCtx

use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.

the class WReport method launchReport.

//	copyFormatFromClient
/**
	 * 	Launch Report
	 * 	@param pp Key=AD_PrintFormat_ID
	 */
private File launchReport(KeyNamePair pp, HttpServletRequest request, GridTab m_curTab, MQuery m_query) {
    WebSessionCtx wsc = WebSessionCtx.get(request);
    MPrintFormat pf = MPrintFormat.get(wsc.ctx, pp.getKey(), false);
    File file = launchReport(pf, request, m_curTab, m_query);
    return file;
}
Also used : MPrintFormat(org.compiere.print.MPrintFormat) WebSessionCtx(org.compiere.util.WebSessionCtx) File(java.io.File)

Example 3 with WebSessionCtx

use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.

the class WProcess method doGet.

//  init
/**
	 *	Process the HTTP Get request.
	 *	Initial Call
	 *	@param request 
	 *	@param response 
	 *	@throws ServletException 
	 *	@throws IOException 
	 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //  Get Session attributes
    WebSessionCtx wsc = WebSessionCtx.get(request);
    //Modified by Rob Klein 4/29/07
    WWindowStatus ws = WWindowStatus.get(request);
    if (wsc == null) {
        WebUtil.createTimeoutPage(request, response, this, null);
        return;
    }
    WebDoc doc = null;
    //  Get Parameter: Menu_ID
    //Modified by Rob Klein 4/29/07
    int AD_Menu_ID = WebUtil.getParameterAsInt(request, "AD_Menu_ID");
    String fileName = WebUtil.getParameter(request, "File");
    if (AD_Menu_ID > 0) {
        doc = createParameterPage(wsc, AD_Menu_ID, 0, 0, 0, 0, null, null);
    } else //else if (fileName!=null)
    //{			
    //	int AD_PInstance_ID = WebUtil.getParameterAsInt(request, "AD_PInstance_ID");
    //	
    //	String error = streamResult (request, response, AD_PInstance_ID, fileName);
    //	if (error == null)
    //		return;
    //	doc = WebDoc.createWindow(error);
    //}
    {
        int AD_Process_ID = WebUtil.getParameterAsInt(request, "AD_Process_ID");
        int AD_Window_ID = WebUtil.getParameterAsInt(request, "AD_Window_ID");
        int AD_Table_ID = WebUtil.getParameterAsInt(request, "AD_Table_ID");
        int AD_Record_ID = WebUtil.getParameterAsInt(request, "AD_Record_ID");
        String columnName = WebUtil.getParameter(request, "columnName");
        int AD_Tab_ID = WebUtil.getParameterAsInt(request, "AD_Tab_ID");
        if (AD_Process_ID == 0) {
            WebUtil.createErrorPage(request, response, this, "No Process");
            return;
        }
        doc = createParameterPage(wsc, AD_Process_ID, AD_Window_ID, AD_Table_ID, AD_Record_ID, 1, columnName, ws.curTab);
    }
    if (doc == null)
        doc = WebDoc.createWindow("Process Not Found");
    //
    WebUtil.createResponse(request, response, this, null, doc, true);
}
Also used : WebDoc(org.compiere.util.WebDoc) WebSessionCtx(org.compiere.util.WebSessionCtx)

Example 4 with WebSessionCtx

use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.

the class WProcess method streamResult.

//	fillParameter
/**
	 * 	Stream Result
	 *	@param request request
	 *	@param response response
	 *	@param AD_PInstance_ID instance id
	 *	@param fileName file to stream
	 *	@return message
	 */
private String streamResult(HttpServletRequest request, HttpServletResponse response, int AD_PInstance_ID, File file) {
    if (AD_PInstance_ID == 0)
        return "Your process not found";
    WebSessionCtx wsc = WebSessionCtx.get(request);
    Object value = wsc.ctx.get("AD_PInstance_ID=" + AD_PInstance_ID);
    if (value == null || !value.equals("ok"))
        return "Process Instance not found";
    //
    if (file == null || file.length() == 0)
        return "No Process Result";
    //File file = new File (fileName);
    if (!file.exists())
        return "Process Result not found: " + file;
    //	OK
    return WebUtil.streamFile(response, file);
}
Also used : WebSessionCtx(org.compiere.util.WebSessionCtx)

Example 5 with WebSessionCtx

use of org.compiere.util.WebSessionCtx in project adempiere by adempiere.

the class WProcess method createProcessPage.

//	createParameterPage
//Modified by Rob klein 4/29/07	
/**************************************************************************
	 * 	Create Parocess Page
	 * 	@param request request
	 *	@param AD_Process_ID Process
	 *	@return Page
	 */
public void createProcessPage(HttpServletRequest request, HttpServletResponse response, int AD_Process_ID, int AD_Window_ID) {
    WebSessionCtx wsc = WebSessionCtx.get(request);
    MProcess process = MProcess.get(wsc.ctx, AD_Process_ID);
    log.info("PI table id " + process.get_Table_ID());
    log.info("PI table name id " + process.get_TableName());
    log.info("PI table client id " + process.getAD_Client_ID());
    log.info("PI table process id " + process.getAD_Process_ID());
    log.info("PI  process class name " + process.getClassname());
    //	need to check if Role can access
    WebDoc doc = null;
    if (process == null) {
        doc = WebDoc.createWindow("Process Not Found");
    } else {
        doc = WebDoc.createWindow(process.getName());
        td center = doc.addWindowCenter(false);
        if (process.getDescription() != null)
            center.addElement(new p(new i(process.getDescription())));
        if (process.getHelp() != null)
            center.addElement(new p(process.getHelp(), AlignType.LEFT));
        //	Create Process Instance
        MPInstance pInstance = fillParameter(request, process);
        //		
        int AD_Table_ID = WebUtil.getParameterAsInt(request, "AD_Table_ID");
        int AD_Record_ID = WebUtil.getParameterAsInt(request, "AD_Record_ID");
        ProcessInfo pi = new ProcessInfo(process.getName(), process.getAD_Process_ID(), AD_Table_ID, AD_Record_ID);
        pi.setAD_User_ID(Env.getAD_User_ID(wsc.ctx));
        pi.setAD_Client_ID(Env.getAD_Client_ID(wsc.ctx));
        pi.setClassName(process.getClassname());
        log.info("PI client id " + pi.getAD_Client_ID());
        pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
        //	Info
        p p = new p();
        p.addElement(Msg.translate(wsc.ctx, "AD_PInstance_ID") + ": " + pInstance.getAD_PInstance_ID());
        center.addElement(p);
        //	Start
        boolean processOK = false;
        if (process.isWorkflow()) {
            Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true);
            try {
                WProcessCtl.process(this, AD_Window_ID, pi, trx, request);
                //processOK = process.processIt(pi, trx);			
                trx.commit();
                trx.close();
            } catch (Throwable t) {
                trx.rollback();
                trx.close();
            }
            if (pi.isError()) {
                center.addElement(new p("Error:" + pi.getSummary(), AlignType.LEFT).setClass("Cerror"));
                processOK = false;
            } else {
                center.addElement(new p("OK: Workflow Started", AlignType.LEFT));
                processOK = true;
            }
            center.addElement(new p().addElement(pi.getSummary()));
            center.addElement(pi.getLogInfo(true));
        }
        String jasper = process.getJasperReport();
        if (process.isJavaProcess()) {
            if (jasper != null) {
                pi.setPrintPreview(false);
                pi.setIsBatch(true);
            }
            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()) {
                center.addElement(new p("Error:" + pi.getSummary(), AlignType.LEFT).setClass("Cerror"));
                processOK = false;
            } else {
                if (jasper != null) {
                    String error = WebUtil.streamFile(response, pi.getPDFReport());
                    //String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file);
                    if (error == null)
                        return;
                    doc = WebDoc.create(error);
                    wsc.ctx.put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
                } else {
                    center.addElement(new p().addElement(pi.getSummary()));
                    center.addElement(pi.getLogInfo(true));
                }
            }
        }
        //	Report
        if (process.isReport()) //if (processOK && process.isReport())
        {
            if (jasper == null) {
                log.info(response.toString());
                ReportEngine re = ReportEngine.get(wsc.ctx, pi);
                if (re == null) {
                    center.addElement(new p("Could not start ReportEngine", AlignType.LEFT).setClass("Cerror"));
                } else {
                    try {
                        File file = File.createTempFile("WProcess", ".pdf");
                        boolean ok = re.createPDF(file);
                        if (ok) {
                            String error = WebUtil.streamFile(response, file);
                            //String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file);
                            if (error == null)
                                return;
                            doc = WebDoc.create(error);
                            //Modified by Rob Klein 6/1/07
                            /**
							String url = "WProcess?AD_PInstance_ID=" 
								+ pInstance.getAD_PInstance_ID()
								+ "&File=" 
								+ URLEncoder.encode(file.getAbsolutePath(), WebEnv.ENCODING);
							a link = new a (url, null, a.TARGET_BLANK, process.getName());
							center
								.addElement(new p()
									.addElement("Report created: ")
									.addElement(link));
							//	Marker that Process is OK
							 * */
                            wsc.ctx.put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok");
                        } else
                            center.addElement(new p("Could not create Report", AlignType.LEFT).setClass("Cerror"));
                    } catch (Exception e) {
                        center.addElement(new p("Could not create Report:", AlignType.LEFT).setClass("Cerror"));
                        center.addElement(e.toString());
                    }
                }
            }
        }
    }
    doc.addPopupClose(wsc.ctx);
    try {
        WebUtil.createResponse(request, response, this, null, doc, false);
    } catch (IOException e) {
        log.info(e.toString());
    }
}
Also used : MProcess(org.compiere.model.MProcess) org.apache.ecs.xhtml.i(org.apache.ecs.xhtml.i) ProcessInfo(org.compiere.process.ProcessInfo) IOException(java.io.IOException) WebSessionCtx(org.compiere.util.WebSessionCtx) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) IOException(java.io.IOException) org.apache.ecs.xhtml.td(org.apache.ecs.xhtml.td) org.apache.ecs.xhtml.p(org.apache.ecs.xhtml.p) Timestamp(java.sql.Timestamp) MPInstance(org.compiere.model.MPInstance) ReportEngine(org.compiere.print.ReportEngine) WebDoc(org.compiere.util.WebDoc) Trx(org.compiere.util.Trx) File(java.io.File)

Aggregations

WebSessionCtx (org.compiere.util.WebSessionCtx)38 WebDoc (org.compiere.util.WebDoc)21 File (java.io.File)13 HttpSession (javax.servlet.http.HttpSession)11 SQLException (java.sql.SQLException)8 Properties (java.util.Properties)6 MPrintFormat (org.compiere.print.MPrintFormat)6 IOException (java.io.IOException)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ServletException (javax.servlet.ServletException)4 GridField (org.compiere.model.GridField)4 org.apache.ecs.xhtml.body (org.apache.ecs.xhtml.body)3 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)3 org.apache.ecs.xhtml.p (org.apache.ecs.xhtml.p)3 org.apache.ecs.xhtml.td (org.apache.ecs.xhtml.td)3 ReportEngine (org.compiere.print.ReportEngine)3 ProcessInfo (org.compiere.process.ProcessInfo)3 KeyNamePair (org.compiere.util.KeyNamePair)3 Trx (org.compiere.util.Trx)3