Search in sources :

Example 1 with MWFProcess

use of org.compiere.wf.MWFProcess in project adempiere by adempiere.

the class ProcessUtil method startWorkFlow.

public static MWFProcess startWorkFlow(Properties ctx, ProcessInfo pi, int AD_Workflow_ID) {
    MWorkflow wf = MWorkflow.get(ctx, AD_Workflow_ID);
    MWFProcess wfProcess = null;
    if (pi.isBatch())
        //	may return null
        wfProcess = wf.start(pi, pi.getTransactionName());
    else {
        //	may return null
        wfProcess = wf.startWait(pi);
    }
    log.fine(pi.toString());
    return wfProcess;
}
Also used : MWFProcess(org.compiere.wf.MWFProcess) MWorkflow(org.compiere.wf.MWorkflow)

Example 2 with MWFProcess

use of org.compiere.wf.MWFProcess 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 MWFProcess

use of org.compiere.wf.MWFProcess in project adempiere by adempiere.

the class WorkflowProcessor method sendEmail.

//	sendAlerts
/**
	 *  Send Alert EMail
	 *  @param activity activity
	 *  @param AD_Message message
	 *  @param toProcess true if to process owner
	 *  @param toSupervisor true if to Supervisor
	 * 	@return number of mails sent
	 */
private int sendEmail(MWFActivity activity, String AD_Message, boolean toProcess, boolean toSupervisor) {
    if (m_client == null || m_client.getAD_Client_ID() != activity.getAD_Client_ID())
        m_client = MClient.get(getCtx(), activity.getAD_Client_ID());
    MWFProcess process = new MWFProcess(getCtx(), activity.getAD_WF_Process_ID(), null);
    String subjectVar = activity.getNode().getName();
    String message = activity.getTextMsg();
    if (message == null || message.length() == 0)
        message = process.getTextMsg();
    File pdf = null;
    PO po = activity.getPO();
    if (po instanceof DocAction) {
        message = ((DocAction) po).getDocumentInfo() + "\n" + message;
        pdf = ((DocAction) po).createPDF();
    }
    //  Inactivity Alert: Workflow Activity {0}
    String subject = Msg.getMsg(m_client.getAD_Language(), AD_Message, new Object[] { subjectVar });
    //	Prevent duplicates
    ArrayList<Integer> list = new ArrayList<Integer>();
    int counter = 0;
    //	To Activity Owner
    if (m_client.sendEMail(activity.getAD_User_ID(), subject, message, pdf))
        counter++;
    list.add(new Integer(activity.getAD_User_ID()));
    //	To Process Owner
    if (toProcess && process.getAD_User_ID() != activity.getAD_User_ID()) {
        if (m_client.sendEMail(process.getAD_User_ID(), subject, message, pdf))
            counter++;
        list.add(new Integer(process.getAD_User_ID()));
    }
    //	To Activity Responsible
    MWFResponsible responsible = MWFResponsible.get(getCtx(), activity.getAD_WF_Responsible_ID());
    counter += sendAlertToResponsible(responsible, list, process, subject, message, pdf);
    //	To Process Responsible
    if (toProcess && process.getAD_WF_Responsible_ID() != activity.getAD_WF_Responsible_ID()) {
        responsible = MWFResponsible.get(getCtx(), process.getAD_WF_Responsible_ID());
        counter += sendAlertToResponsible(responsible, list, process, subject, message, pdf);
    }
    //	Processor SuperVisor
    if (toSupervisor && m_model.getSupervisor_ID() != 0 && !list.contains(new Integer(m_model.getSupervisor_ID()))) {
        if (m_client.sendEMail(m_model.getSupervisor_ID(), subject, message, pdf))
            counter++;
        list.add(new Integer(m_model.getSupervisor_ID()));
    }
    return counter;
}
Also used : MWFResponsible(org.compiere.wf.MWFResponsible) MWFProcess(org.compiere.wf.MWFProcess) DocAction(org.compiere.process.DocAction) ArrayList(java.util.ArrayList) File(java.io.File) PO(org.compiere.model.PO)

Example 4 with MWFProcess

use of org.compiere.wf.MWFProcess in project adempiere by adempiere.

the class ProcessCtl method startWorkflow.

//  unlock
/**************************************************************************
	 *  Start Workflow.
	 *
	 *  @param AD_Workflow_ID workflow
	 *  @return     true if started
	 */
private boolean startWorkflow(int AD_Workflow_ID) {
    log.fine(AD_Workflow_ID + " - " + processInstance);
    boolean started = false;
    if (isServerProcess) {
        Server server = CConnection.get().getServer();
        try {
            if (server != null) {
                //	See ServerBean
                processInstance = server.workflow(Env.getRemoteCallCtx(Env.getCtx()), processInstance, AD_Workflow_ID);
                log.finest("server => " + processInstance);
                started = true;
            }
        } catch (Exception ex) {
            log.log(Level.SEVERE, "AppsServer error", ex);
            started = false;
        }
    }
    //	Run locally
    if (!started && !isServerProcess) {
        if (m_trx != null)
            processInstance.setTransactionName(m_trx.getTrxName());
        MWFProcess wfProcess = ProcessUtil.startWorkFlow(Env.getCtx(), processInstance, AD_Workflow_ID);
        started = wfProcess != null;
    }
    return started;
}
Also used : MWFProcess(org.compiere.wf.MWFProcess) Server(org.compiere.interfaces.Server) InvalidClassException(java.io.InvalidClassException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 5 with MWFProcess

use of org.compiere.wf.MWFProcess in project adempiere by adempiere.

the class ServerProcessCtl method startWorkflow.

//  run
/**************************************************************************
	 *  Start Workflow.
	 *
	 *  @param AD_Workflow_ID workflow
	 *  @return     true if started
	 */
protected boolean startWorkflow(int AD_Workflow_ID) {
    log.fine(AD_Workflow_ID + " - " + processInfo);
    boolean started = false;
    if (isServerProcess) {
        Server server = CConnection.get().getServer();
        try {
            if (server != null) {
                //	See ServerBean
                processInfo = server.workflow(Env.getRemoteCallCtx(Env.getCtx()), processInfo, AD_Workflow_ID);
                log.finest("server => " + processInfo);
                started = true;
            }
        } catch (Exception ex) {
            log.log(Level.SEVERE, "AppsServer error", ex);
            started = false;
        }
    }
    //	Run locally
    if (!started && !isServerProcess) {
        if (trx != null)
            processInfo.setTransactionName(trx.getTrxName());
        MWFProcess wfProcess = ProcessUtil.startWorkFlow(Env.getCtx(), processInfo, AD_Workflow_ID);
        started = wfProcess != null;
    }
    return started;
}
Also used : MWFProcess(org.compiere.wf.MWFProcess) Server(org.compiere.interfaces.Server) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) InvalidClassException(java.io.InvalidClassException)

Aggregations

MWFProcess (org.compiere.wf.MWFProcess)6 MWorkflow (org.compiere.wf.MWorkflow)3 File (java.io.File)2 InvalidClassException (java.io.InvalidClassException)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 Server (org.compiere.interfaces.Server)2 PO (org.compiere.model.PO)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 CharArrayWriter (java.io.CharArrayWriter)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 JasperPrint (net.sf.jasperreports.engine.JasperPrint)1 MPInstance (org.compiere.model.MPInstance)1 MProcess (org.compiere.model.MProcess)1 MTable (org.compiere.model.MTable)1 Query (org.compiere.model.Query)1 MPrintFormat (org.compiere.print.MPrintFormat)1 ReportEngine (org.compiere.print.ReportEngine)1 DocAction (org.compiere.process.DocAction)1