Search in sources :

Example 1 with ProcessInfo

use of org.compiere.process.ProcessInfo 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)

Example 2 with ProcessInfo

use of org.compiere.process.ProcessInfo 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 3 with ProcessInfo

use of org.compiere.process.ProcessInfo in project adempiere by adempiere.

the class CostResult method createTrxAndInventoryValuationReport.

void createTrxAndInventoryValuationReport() {
    int AD_Process_ID = MProcess.getProcess_ID("Transaction Valuation", trxName);
    ProcessInfo pi = new ProcessInfo("Transaction Valuation", AD_Process_ID);
    MPInstance instance = new MPInstance(getCtx(), AD_Process_ID, 0);
    instance.saveEx();
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    pi.setAD_Client_ID(Env.getAD_Client_ID(getCtx()));
    //	Add Parameters
    MPInstancePara para = new MPInstancePara(instance, 10);
    para.setParameter(MCostDetail.COLUMNNAME_M_Product_ID, product.getM_Product_ID());
    para.saveEx();
    para = new MPInstancePara(instance, 20);
    para.setParameter(MCostDetail.COLUMNNAME_M_CostType_ID, 50000);
    para.saveEx();
    para = new MPInstancePara(instance, 30);
    para.setParameter(MCostDetail.COLUMNNAME_M_CostElement_ID, 100);
    para.saveEx();
    pi.setTransactionName(trxName);
    //ReportCtl.startStandardReport(pi);	
    ReportEngine re = ReportEngine.get(getCtx(), pi);
    File trxValuation = null;
    trxValuation = re.getPDF();
    AD_Process_ID = MProcess.getProcess_ID("Valuation Effective Date", trxName);
    pi = new ProcessInfo("Valuation Effective Date", AD_Process_ID);
    instance = new MPInstance(getCtx(), AD_Process_ID, 0);
    instance.saveEx();
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    pi.setAD_Client_ID(Env.getAD_Client_ID(getCtx()));
    para = new MPInstancePara(instance, 10);
    para.setParameter("DateValue", new Timestamp(System.currentTimeMillis()));
    para.saveEx();
    //	Add Parameters
    para = new MPInstancePara(instance, 20);
    para.setParameter(MCostDetail.COLUMNNAME_M_Product_ID, product.getM_Product_ID());
    para.saveEx();
    para = new MPInstancePara(instance, 30);
    para.setParameter(MCostDetail.COLUMNNAME_M_CostType_ID, 50000);
    para.saveEx();
    para = new MPInstancePara(instance, 40);
    para.setParameter(MCostDetail.COLUMNNAME_M_CostElement_ID, 100);
    para.saveEx();
    ValuationEffectiveDate process = new ValuationEffectiveDate();
    process.startProcess(getCtx(), pi, Trx.get(trxName, false));
    pi.setTransactionName(trxName);
    re = ReportEngine.get(getCtx(), pi);
    File report = null;
    report = re.getPDF();
    EMail email = new EMail(getCtx(), "smtp.gmail.com", "victor.perez@e-evolution.com", "victor.perez@e-evolution.com", "Transaction and Inventory Valuation Report Test", "Transaction and Inventory Valuation " + new Timestamp(System.currentTimeMillis()));
    email.addAttachment(trxValuation);
    email.addAttachment(report);
    email.createAuthenticator(Mail, MailPassword);
    String msg = email.send();
    System.out.println(msg);
}
Also used : ValuationEffectiveDate(org.eevolution.process.ValuationEffectiveDate) MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) ReportEngine(org.compiere.print.ReportEngine) ProcessInfo(org.compiere.process.ProcessInfo) EMail(org.compiere.util.EMail) File(java.io.File) Timestamp(java.sql.Timestamp)

Example 4 with ProcessInfo

use of org.compiere.process.ProcessInfo in project adempiere by adempiere.

the class CostResult method generateHistoryCost.

void generateHistoryCost() {
    int AD_Process_ID = MProcess.getProcess_ID("M_CostDetail Generate Cost Transaction", trxName);
    ProcessInfo pi = new ProcessInfo("Generate Cost Transaction", AD_Process_ID);
    MPInstance instance = new MPInstance(Env.getCtx(), AD_Process_ID, 0);
    instance.saveEx();
    pi.setAD_PInstance_ID(instance.getAD_PInstance_ID());
    pi.setAD_Client_ID(Env.getAD_Client_ID(Env.getCtx()));
    //	Add Parameters
    MPInstancePara para = new MPInstancePara(instance, 10);
    para.setParameter(MCostDetail.COLUMNNAME_C_AcctSchema_ID, Env.getContext(Env.getCtx(), "$C_AcctSchema_ID"));
    para.saveEx();
    para = new MPInstancePara(instance, 20);
    para.setParameter(MCostDetail.COLUMNNAME_M_CostType_ID, 50000);
    para.saveEx();
    para = new MPInstancePara(instance, 30);
    para.setParameter(MCostDetail.COLUMNNAME_M_CostElement_ID, 100);
    para.saveEx();
    //Add Parameters
    para = new MPInstancePara(instance, 40);
    para.setParameter(MCostDetail.COLUMNNAME_M_Product_ID, product.getM_Product_ID());
    para.saveEx();
    para = new MPInstancePara(instance, 50);
    para.setParameter(MCostDetail.COLUMNNAME_DateAcct, Timestamp.valueOf("2000-01-01 00:00:00.0"));
    para.saveEx();
    GenerateCostDetail process = new GenerateCostDetail();
    process.startProcess(Env.getCtx(), pi, Trx.get(trxName, false));
}
Also used : MPInstancePara(org.compiere.model.MPInstancePara) MPInstance(org.compiere.model.MPInstance) GenerateCostDetail(org.eevolution.process.GenerateCostDetail) ProcessInfo(org.compiere.process.ProcessInfo)

Example 5 with ProcessInfo

use of org.compiere.process.ProcessInfo in project adempiere by adempiere.

the class ModelImporter method main.

public static void main(String[] args) {
    CLogMgt.setLoggerLevel(Level.INFO, null);
    CLogMgt.setLevel(Level.INFO);
    Adempiere.startupEnvironment(false);
    ProcessInfo pi = new ProcessInfo("Test Import Model", 1000000);
    pi.setAD_Client_ID(11);
    pi.setAD_User_ID(100);
    ModelImporter modelImporter = new ModelImporter();
    modelImporter.startProcess(Env.getCtx(), pi, null);
    System.out.println("Process=" + pi.getTitle() + " Error=" + pi.isError() + " Summary=" + pi.getSummary());
}
Also used : ProcessInfo(org.compiere.process.ProcessInfo)

Aggregations

ProcessInfo (org.compiere.process.ProcessInfo)65 MPInstance (org.compiere.model.MPInstance)21 Trx (org.compiere.util.Trx)17 AdempiereException (org.adempiere.exceptions.AdempiereException)14 MPInstancePara (org.compiere.model.MPInstancePara)12 ReportEngine (org.compiere.print.ReportEngine)11 File (java.io.File)10 MProcess (org.compiere.model.MProcess)9 ProcessCtl (org.compiere.apps.ProcessCtl)8 SQLException (java.sql.SQLException)6 Timestamp (java.sql.Timestamp)6 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)5 ServletException (javax.servlet.ServletException)4 MBrowse (org.adempiere.model.MBrowse)4 PrintInfo (org.compiere.model.PrintInfo)4 ProcessInfoParameter (org.compiere.process.ProcessInfoParameter)4 Properties (java.util.Properties)3 MMovement (org.compiere.model.MMovement)3 PO (org.compiere.model.PO)3