Search in sources :

Example 6 with MProcess

use of org.compiere.model.MProcess in project adempiere by adempiere.

the class ReportStarter method downloadAttachment.

/**
	 * Download db attachment
	 * @param reportPath must of syntax attachment:filename
	 * @return File
	 */
private File downloadAttachment(String reportPath) {
    File reportFile = null;
    String name = reportPath.substring("attachment:".length()).trim();
    MProcess process = new MProcess(Env.getCtx(), processInfo.getAD_Process_ID(), processInfo.getTransactionName());
    attachment = process.getAttachment();
    if (attachment != null) {
        MAttachmentEntry[] entries = attachment.getEntries();
        MAttachmentEntry entry = null;
        for (int i = 0; i < entries.length; i++) {
            if (entries[i].getName().equals(name)) {
                entry = entries[i];
                break;
            }
        }
        if (entry != null) {
            reportFile = getAttachmentEntryFile(entry);
        }
    }
    return reportFile;
}
Also used : MProcess(org.compiere.model.MProcess) MAttachmentEntry(org.compiere.model.MAttachmentEntry) DigestOfFile(org.compiere.util.DigestOfFile) File(java.io.File) JasperPrint(net.sf.jasperreports.engine.JasperPrint)

Example 7 with MProcess

use of org.compiere.model.MProcess in project adempiere by adempiere.

the class ASPGenerateFields method generateProcess.

//	doIt
private void generateProcess(int p_AD_Process_ID) {
    // Add Process and Parameters
    MProcess process = new MProcess(getCtx(), p_AD_Process_ID, get_TrxName());
    int asp_process_id = DB.getSQLValueEx(get_TrxName(), "SELECT COUNT(*) FROM ASP_Process WHERE ASP_Level_ID = ? AND AD_Process_ID = ?", p_ASP_Level_ID, process.getAD_Process_ID());
    X_ASP_Process aspProcess = null;
    if (asp_process_id < 1) {
        aspProcess = new X_ASP_Process(getCtx(), 0, get_TrxName());
        aspProcess.setASP_Level_ID(p_ASP_Level_ID);
        aspProcess.setAD_Process_ID(process.getAD_Process_ID());
        aspProcess.setASP_Status(p_ASP_Status);
        if (aspProcess.save()) {
            noProcesses++;
            asp_process_id = aspProcess.getASP_Process_ID();
        }
    } else {
        aspProcess = new X_ASP_Process(getCtx(), asp_process_id, get_TrxName());
    }
    // parameters
    for (MProcessPara processpara : process.getParameters()) {
        if (DB.getSQLValueEx(get_TrxName(), "SELECT COUNT(*) FROM ASP_Process_Para WHERE ASP_Process_ID = ? AND AD_Process_Para_ID = ?", asp_process_id, processpara.getAD_Process_Para_ID()) < 1) {
            X_ASP_Process_Para aspProcess_Para = new X_ASP_Process_Para(getCtx(), 0, get_TrxName());
            aspProcess_Para.setASP_Process_ID(asp_process_id);
            aspProcess_Para.setAD_Process_Para_ID(processpara.getAD_Process_Para_ID());
            aspProcess_Para.setASP_Status(p_ASP_Status);
            if (aspProcess_Para.save())
                noParameters++;
        }
    }
    if (process.getAD_Workflow_ID() > 0) {
        generateWorkflow(process.getAD_Workflow_ID());
    }
}
Also used : MProcess(org.compiere.model.MProcess) X_ASP_Process(org.compiere.model.X_ASP_Process) MProcessPara(org.compiere.model.MProcessPara) X_ASP_Process_Para(org.compiere.model.X_ASP_Process_Para)

Example 8 with MProcess

use of org.compiere.model.MProcess in project adempiere by adempiere.

the class CopyReportProcess method doIt.

@Override
protected String doIt() throws Exception {
    //	Instance current process
    MProcess process = MProcess.get(getCtx(), getRecord_ID());
    //	
    List<Integer> keys = getSelectionKeys();
    for (Integer key : keys) {
        copyFrom(process, key);
    }
    //	Default Ok
    return "@OK@";
}
Also used : MProcess(org.compiere.model.MProcess)

Example 9 with MProcess

use of org.compiere.model.MProcess 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 10 with MProcess

use of org.compiere.model.MProcess in project adempiere by adempiere.

the class ProcessInfoHandler method init.

private void init(int processID) {
    process = new MProcess(Env.getCtx(), processID, null);
    if (process != null) {
        pi = getProcessInfo(Msg.translate(Env.getCtx(), process.getName()), process.get_ID());
        pinstance = getProcessInstance(pi);
        pi.setAD_PInstance_ID(pinstance.getAD_PInstance_ID());
    }
}
Also used : MProcess(org.compiere.model.MProcess)

Aggregations

MProcess (org.compiere.model.MProcess)25 ProcessInfo (org.compiere.process.ProcessInfo)9 MProcessPara (org.compiere.model.MProcessPara)8 MPInstance (org.compiere.model.MPInstance)7 File (java.io.File)6 Timestamp (java.sql.Timestamp)6 SQLException (java.sql.SQLException)5 Trx (org.compiere.util.Trx)5 IOException (java.io.IOException)4 org.apache.ecs.xhtml.i (org.apache.ecs.xhtml.i)4 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)4 org.apache.ecs.xhtml.p (org.apache.ecs.xhtml.p)4 org.apache.ecs.xhtml.td (org.apache.ecs.xhtml.td)4 ReportEngine (org.compiere.print.ReportEngine)4 JasperPrint (net.sf.jasperreports.engine.JasperPrint)3 org.apache.ecs.xhtml.div (org.apache.ecs.xhtml.div)3 org.apache.ecs.xhtml.fieldset (org.apache.ecs.xhtml.fieldset)3 org.apache.ecs.xhtml.form (org.apache.ecs.xhtml.form)3 org.apache.ecs.xhtml.tr (org.apache.ecs.xhtml.tr)3 MPInstancePara (org.compiere.model.MPInstancePara)3