Search in sources :

Example 1 with MProcess

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

the class ProcessCtl method run.

/**
	 *	Execute Process Instance and Lock UI.
	 *  Calls lockUI and unlockUI if parent is a ASyncProcess
	 *  <pre>
	 *		- Get Process Information
	 *      - Call Class
	 *		- Submit SQL Procedure
	 *		- Run SQL Procedure
	 *	</pre>
	 */
public void run() {
    log.fine("AD_PInstance_ID=" + processInstance.getAD_PInstance_ID() + ", Record_ID=" + processInstance.getRecord_ID());
    //  Lock
    lock();
    //	Get Process Information: Name, Procedure Name, ClassName, IsReport, IsDirectPrint
    String procedureName = "";
    boolean isDirectPrint = false;
    boolean isPrintPreview = processInstance.isPrintPreview();
    //	Get Process data
    MProcess process = null;
    //	
    if (processInstance.getAD_Process_ID() != 0) {
        process = MProcess.get(Env.getCtx(), processInstance.getAD_Process_ID());
    } else {
        process = MProcess.getFromInstance(Env.getCtx(), processInstance.getAD_PInstance_ID());
        processInstance.setAD_Process_ID(process.getAD_Process_ID());
    }
    //	
    if (process.getAD_Process_ID() <= 0) {
        processInstance.setSummary(Msg.parseTranslation(Env.getCtx(), "@AD_Process_ID@ @NotFound@"), true);
        unlock();
        log.log(Level.SEVERE, "run", "AD_Process_ID=" + processInstance.getAD_Process_ID() + " Not Found");
        return;
    }
    //	Set values from process
    processInstance.setTitle(process.get_Translation(I_AD_Process.COLUMNNAME_Name));
    if (waiting != null)
        waiting.setTitle(processInstance.getTitle());
    procedureName = process.getProcedureName();
    processInstance.setClassName(process.getClassname());
    //	Report
    if (process.isReport()) {
        if (process.isDirectPrint() && !Ini.isPropertyBool(Ini.P_PRINTPREVIEW) && !isPrintPreview)
            isDirectPrint = true;
    }
    //
    int estimate = process.getEstimatedSeconds();
    if (estimate != 0) {
        //  admin overhead
        processInstance.setEstSeconds(estimate + 1);
        if (waiting != null)
            waiting.setTimerEstimate(processInstance.getEstSeconds());
    }
    isServerProcess = process.isServerProcess();
    //  No PL/SQL Procedure
    if (procedureName == null)
        procedureName = "";
    /**********************************************************************
		 *	Workflow
		 */
    if (process.isWorkflow()) {
        startWorkflow(process.getAD_Workflow_ID());
        unlock();
        return;
    }
    // Clear Jasper Report class if default - to be executed later
    if (process.isJasper()) {
        if (ProcessUtil.JASPER_STARTER_CLASS.equals(processInstance.getClassName())) {
            processInstance.setClassName(null);
        }
    }
    //	Save selection
    //	FR [ 352 ]
    //	if is from a selection then save all record in DB
    saveSelection();
    /**********************************************************************
		 *	Start Optional Class
		 */
    if (processInstance.getClassName() != null) {
        if (process.isJasper()) {
            processInstance.setReportingProcess(true);
        }
        //	Run Class
        if (!startProcess()) {
            unlock();
            return;
        }
        //  No Optional SQL procedure ... done
        if (!process.isReport() && procedureName.length() == 0) {
            unlock();
            return;
        }
        //  No Optional Report ... done
        if (process.isReport() && process.getAD_ReportView_ID() == 0 && !process.isJasper()) {
            unlock();
            return;
        }
    }
    //	Optional Pre-Report Process
    if (process.isReport() && procedureName.length() > 0) {
        processInstance.setReportingProcess(true);
        if (!startDBProcess(procedureName)) {
            unlock();
            return;
        }
    }
    if (process.isJasper()) {
        processInstance.setReportingProcess(true);
        processInstance.setClassName(ProcessUtil.JASPER_STARTER_CLASS);
        startProcess();
        unlock();
        return;
    }
    if (process.isReport()) {
        processInstance.setReportingProcess(true);
        if (!m_IsOnlyProcess) {
            //	Start Report	-----------------------------------------------
            boolean ok = ReportCtl.start(m_parent, windowno, processInstance, isDirectPrint);
            processInstance.setSummary("Report", !ok);
        }
        //	
        unlock();
    } else /**********************************************************************
		 * 	Process submission
		 */
    {
        if (procedureName.length() > 0 && !startDBProcess(procedureName)) {
            unlock();
            return;
        }
        //	Success - getResult
        ProcessInfoUtil.setSummaryFromDB(processInstance);
        unlock();
    }
//	*** Process submission ***
//	log.fine(Log.l3_Util, "ProcessCtl.run - done");
}
Also used : MProcess(org.compiere.model.MProcess)

Example 2 with MProcess

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

the class ProcessUtil method startJavaProcess.

/**
	 * @param ctx
	 * @param pi
	 * @param trx
	 * @param managedTrx false if trx is managed by caller
	 * @return boolean
	 */
public static boolean startJavaProcess(Properties ctx, ProcessInfo pi, Trx trx, boolean managedTrx) {
    String className = pi.getClassName();
    if (className == null) {
        MProcess proc = new MProcess(ctx, pi.getAD_Process_ID(), trx.getTrxName());
        if (proc.getJasperReport() != null)
            className = JASPER_STARTER_CLASS;
    }
    //Get Class
    Class<?> processClass = null;
    //use context classloader if available
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    if (classLoader == null)
        classLoader = ProcessUtil.class.getClassLoader();
    try {
        processClass = classLoader.loadClass(className);
    } catch (ClassNotFoundException ex) {
        log.log(Level.WARNING, className, ex);
        pi.setSummary("ClassNotFound", true);
        return false;
    }
    //Get Process
    ProcessCall process = null;
    try {
        process = (ProcessCall) processClass.newInstance();
    } catch (Exception ex) {
        log.log(Level.WARNING, "Instance for " + className, ex);
        pi.setSummary("InstanceError", true);
        return false;
    }
    if (processClass == null) {
        pi.setSummary("No Instance for " + pi.getClassName(), true);
        return false;
    }
    boolean success = false;
    try {
        success = process.startProcess(ctx, pi, trx);
        if (success && trx != null && managedTrx) {
            trx.commit(true);
        }
    } catch (Exception e) {
        pi.setSummary(Msg.getMsg(Env.getCtx(), "ProcessError") + " " + e.getLocalizedMessage(), true);
        log.log(Level.SEVERE, pi.getClassName(), e);
        return false;
    } finally {
        if (trx != null && managedTrx) {
            if (!success)
                trx.rollback();
            trx.close();
            trx = null;
        }
    }
    return success;
}
Also used : MProcess(org.compiere.model.MProcess) ProcessCall(org.compiere.process.ProcessCall)

Example 3 with MProcess

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

the class CalloutParameter method element.

/**
	 * Set the default values from Element
	 * 
	 * @param ctx
	 * @param WindowNo
	 * @param mTab
	 * @param mField
	 * @param value
	 * @return
	 */
public String element(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) {
    Integer AD_Element_ID = (Integer) value;
    if (AD_Element_ID == null || AD_Element_ID <= 0)
        return "";
    I_AD_Process_Para para = GridTabWrapper.create(mTab, I_AD_Process_Para.class);
    MTable table = MTable.get(ctx, para.Table_ID);
    MProcess process = MProcess.get(ctx, para.getAD_Process_ID());
    para.setEntityType(process.getEntityType());
    M_Element element = new M_Element(ctx, AD_Element_ID, null);
    if (element.getAD_Reference_ID() == DisplayType.ID) {
        String columnName = table.get_TableName() + "_ID";
        if (!columnName.equals(element.getColumnName())) {
            para.setAD_Reference_ID(DisplayType.TableDir);
        }
    }
    if (para.getColumnName() == null || para.getColumnName().length() <= 0)
        para.setColumnName(element.getColumnName());
    if (para.getFieldLength() <= 0)
        para.setFieldLength(element.getFieldLength());
    if (para.getAD_Reference_ID() <= 0)
        para.setAD_Reference_ID(element.getAD_Reference_ID());
    if (para.getAD_Reference_Value_ID() <= 0)
        para.setAD_Reference_Value_ID(element.getAD_Reference_Value_ID());
    if (para.getName() == null || para.getName().length() <= 0)
        para.setName(element.getName());
    if (para.getDescription() == null || para.getDescription().length() <= 0)
        para.setDescription(element.getDescription());
    if (para.getHelp() == null || para.getHelp().length() <= 0)
        para.setHelp(element.getHelp());
    return "";
}
Also used : MProcess(org.compiere.model.MProcess) MTable(org.compiere.model.MTable) I_AD_Process_Para(org.compiere.model.I_AD_Process_Para) M_Element(org.compiere.model.M_Element)

Example 4 with MProcess

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

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

the class Process method getProcessParams.

public static ProcessParamsDocument getProcessParams(CompiereService cs, GetProcessParamsDocument req) throws XFireFault {
    ProcessParamsDocument res = ProcessParamsDocument.Factory.newInstance();
    ProcessParams params = res.addNewProcessParams();
    ProcessParamList PL = params.addNewParams();
    int AD_Menu_ID = req.getGetProcessParams().getADMenuID();
    int AD_Process_ID = req.getGetProcessParams().getADProcessID();
    MProcess process = null;
    if (AD_Menu_ID > 0 && AD_Process_ID == 0)
        process = MProcess.getFromMenu(cs.getM_ctx(), AD_Menu_ID);
    else if (AD_Menu_ID == 0 && AD_Process_ID > 0)
        process = new MProcess(cs.getM_ctx(), AD_Process_ID, null);
    if (process != null) {
        params.setDescription(process.getDescription());
        params.setHelp(process.getHelp());
        params.setName(process.getName());
        params.setADProcessID(process.getAD_Process_ID());
        MProcessPara[] parameter = process.getParameters();
        for (int i = 0; i < parameter.length; i++) {
            MProcessPara para = parameter[i];
            ProcessParam p = PL.addNewParam();
            p.setName(para.getName());
            p.setDescription(para.getDescription());
            p.setDisplayType(para.getAD_Reference_ID());
            p.setIsMandatory(para.isMandatory());
            p.setFieldLength(para.getFieldLength());
            p.setIsRange(para.isRange());
            p.setColumnName(para.getColumnName());
            p.setDefaultValue(para.getDefaultValue());
            p.setDefaultValue2(para.getDefaultValue2());
            if (para.getDefaultValue() != null) {
                if (DisplayType.isDate(para.getAD_Reference_ID())) {
                    if (para.getDefaultValue().indexOf("@#Date@") >= 0) {
                        //Object t = Env.getContextAsDate( cs.getM_ctx(), "#Date" );
                        //String t = Env.getContext( cs.getM_ctx(), "#Date" );
                        String t = cs.dateFormat.format(Env.getContextAsDate(cs.getM_ctx(), "#Date"));
                        //cs.dateFormat.format( t ));
                        p.setDefaultValue(t);
                    }
                } else if (DisplayType.YesNo == para.getAD_Reference_ID()) {
                    if ("Y".equalsIgnoreCase(para.getDefaultValue()))
                        p.setDefaultValue("true");
                    else
                        p.setDefaultValue("false");
                }
            } else {
                if (DisplayType.YesNo == para.getAD_Reference_ID())
                    p.setDefaultValue("false");
            }
            if (para.getDefaultValue2() != null) {
                if (DisplayType.isDate(para.getAD_Reference_ID())) {
                    if (para.getDefaultValue2().indexOf("@#Date@") >= 0) {
                        //Object t = Env.getContextAsDate( cs.getM_ctx(), "#Date" );
                        //String t = Env.getContext( cs.getM_ctx(), "#Date" );
                        String t = cs.dateFormat.format(Env.getContextAsDate(cs.getM_ctx(), "#Date"));
                        //cs.dateFormat.format( t ) );
                        p.setDefaultValue2(t);
                    }
                }
            }
            if (para.isLookup()) {
                LookupValues lvs = p.addNewLookup();
                Lookup lookup = para.getLookup();
                try {
                    ADLookup.fillLookupValues(lvs, lookup, para.isMandatory(), false);
                } catch (Exception ex) {
                    System.out.println("getProcessParams exception: " + ex.getMessage());
                    ex.printStackTrace();
                }
            }
        }
    }
    return res;
}
Also used : MProcess(org.compiere.model.MProcess) ProcessParams(pl.x3E.adInterface.ProcessParams) GetProcessParamsDocument(pl.x3E.adInterface.GetProcessParamsDocument) ProcessParamsDocument(pl.x3E.adInterface.ProcessParamsDocument) ProcessParamList(pl.x3E.adInterface.ProcessParamList) MProcessPara(org.compiere.model.MProcessPara) Lookup(org.compiere.model.Lookup) LookupValues(pl.x3E.adInterface.LookupValues) JasperPrint(net.sf.jasperreports.engine.JasperPrint) ProcessParam(pl.x3E.adInterface.ProcessParam) SQLException(java.sql.SQLException) IOException(java.io.IOException)

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