Search in sources :

Example 1 with MWorkflow

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

the class ASPGenerateLevel method generateWorkflow.

private void generateWorkflow(int p_AD_Workflow_ID) {
    // Add Workflow and Nodes
    MWorkflow workflow = new MWorkflow(getCtx(), p_AD_Workflow_ID, get_TrxName());
    if (DB.getSQLValueEx(get_TrxName(), "SELECT COUNT(*) FROM ASP_Workflow WHERE ASP_Level_ID = ? AND AD_Workflow_ID = ?", p_ASP_Level_ID, workflow.getAD_Workflow_ID()) < 1) {
        X_ASP_Workflow aspWorkflow = new X_ASP_Workflow(getCtx(), 0, get_TrxName());
        aspWorkflow.setASP_Level_ID(p_ASP_Level_ID);
        aspWorkflow.setAD_Workflow_ID(workflow.getAD_Workflow_ID());
        aspWorkflow.setASP_Status(p_ASP_Status);
        if (aspWorkflow.save())
            noWorkflows++;
    }
}
Also used : MWorkflow(org.compiere.wf.MWorkflow) X_ASP_Workflow(org.compiere.model.X_ASP_Workflow)

Example 2 with MWorkflow

use of org.compiere.wf.MWorkflow 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 3 with MWorkflow

use of org.compiere.wf.MWorkflow 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 4 with MWorkflow

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

the class ReleaseInOutBound method createManufacturingOrder.

/**
	 * Create Manufacturing Order when the Is create supply is define as yes
	 * @param outBoundOrderLine Bound Line
	 * @param product Product
	 * @param qtySupply Quantity to Supply
	 */
public void createManufacturingOrder(MWMInOutBoundLine outBoundOrderLine, MProduct product, BigDecimal qtySupply) {
    MPPOrder order = MPPOrder.forC_OrderLine_ID(outBoundOrderLine.getCtx(), outBoundOrderLine.getC_OrderLine_ID(), product.get_ID(), outBoundOrderLine.get_TrxName());
    if (order == null) {
        MPPProductBOM bom = MPPProductBOM.getDefault(product, get_TrxName());
        if (bom != null) {
            MPPProductPlanning productPlanning = null;
            //Validate the BOM based in planning data 
            if (bom == null) {
                productPlanning = MPPProductPlanning.find(getCtx(), outBoundOrderLine.getAD_Org_ID(), 0, 0, product.getM_Product_ID(), null);
                if (productPlanning != null) {
                    bom = (MPPProductBOM) productPlanning.getPP_Product_BOM();
                }
            }
            if (bom != null) {
                final int plant_id = MPPProductPlanning.getPlantForWarehouse(outBoundOrderLine.getM_Warehouse_ID());
                if (plant_id <= 0) {
                    throw new NoPlantForWarehouseException(outBoundOrderLine.getM_Warehouse_ID());
                }
                MWorkflow workflow = MWorkflow.get(getCtx(), MWorkflow.getWorkflowSearchKey(product));
                //Validate the workflow based in planning data 						
                if (workflow == null && productPlanning != null) {
                    workflow = productPlanning.getAD_Workflow();
                }
                if (plant_id > 0 && workflow != null) {
                    String description = Msg.translate(getCtx(), MWMInOutBound.COLUMNNAME_WM_InOutBound_ID) + " : " + outBoundOrderLine.getParent().getDocumentNo();
                    //Create temporary Product Planning to Create Manufacturing Order 
                    productPlanning = new MPPProductPlanning(getCtx(), 0, get_TrxName());
                    productPlanning.setAD_Org_ID(outBoundOrderLine.getAD_Org_ID());
                    productPlanning.setM_Product_ID(product.getM_Product_ID());
                    productPlanning.setPlanner_ID(outBoundOrderLine.getParent().getSalesRep_ID());
                    productPlanning.setPP_Product_BOM_ID(bom.getPP_Product_BOM_ID());
                    productPlanning.setAD_Workflow_ID(workflow.getAD_Workflow_ID());
                    productPlanning.setM_Warehouse_ID(outBoundOrderLine.getM_Warehouse_ID());
                    productPlanning.setS_Resource_ID(plant_id);
                    order = MPPMRP.createMO(productPlanning, outBoundOrderLine.getC_OrderLine_ID(), outBoundOrderLine.getM_AttributeSetInstance_ID(), qtySupply, outBoundOrderLine.getPickDate(), outBoundOrderLine.getShipDate(), description);
                    MOrderLine orderLine = new MOrderLine(getCtx(), outBoundOrderLine.getC_OrderLine_ID(), get_TrxName());
                    description = "";
                    if (orderLine.getDescription() != null)
                        description = orderLine.getDescription();
                    description = description + " " + Msg.translate(orderLine.getCtx(), MPPOrder.COLUMNNAME_PP_Order_ID) + " : " + order.getDocumentNo();
                    orderLine.setDescription(description);
                    orderLine.saveEx();
                    String boundDescription = "";
                    if (outBoundOrderLine.getDescription() != null)
                        boundDescription = outBoundOrderLine.getDescription();
                    boundDescription = boundDescription + " " + Msg.translate(getCtx(), MPPOrder.COLUMNNAME_PP_Order_ID) + " : " + order.getDocumentNo();
                    outBoundOrderLine.setDescription(boundDescription);
                }
            }
        }
    }
    if (order != null) {
        outBoundOrderLine.setProcessed(true);
        outBoundOrderLine.saveEx();
    }
}
Also used : MPPProductPlanning(org.eevolution.model.MPPProductPlanning) MWorkflow(org.compiere.wf.MWorkflow) MOrderLine(org.compiere.model.MOrderLine) MPPProductBOM(org.eevolution.model.MPPProductBOM) NoPlantForWarehouseException(org.eevolution.exceptions.NoPlantForWarehouseException) MPPOrder(org.eevolution.model.MPPOrder)

Example 5 with MWorkflow

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

the class WFPanel method load.

//	load
/**
	 * 	Load Workflow & Nodes
	 * 	@param AD_Workflow_ID ID
	 * 	@param readWrite if true nodes can be moved
	 */
public void load(int AD_Workflow_ID, boolean readWrite) {
    log.fine("RW=" + readWrite + " - AD_Workflow_ID=" + AD_Workflow_ID);
    if (AD_Workflow_ID == 0)
        return;
    int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
    //	Get Workflow
    m_wf = new MWorkflow(Env.getCtx(), AD_Workflow_ID, null);
    centerPanel.removeAll();
    centerPanel.setReadWrite(readWrite);
    if (readWrite)
        centerPanel.setWorkflow(m_wf);
    //	Add Nodes for Paint
    MWFNode[] nodes = m_wf.getNodes(true, AD_Client_ID);
    for (int i = 0; i < nodes.length; i++) {
        WFNode wfn = new WFNode(nodes[i]);
        wfn.addPropertyChangeListener(WFNode.PROPERTY_SELECTED, this);
        boolean rw = //	in editor mode & owned
        readWrite && (AD_Client_ID == nodes[i].getAD_Client_ID());
        centerPanel.add(wfn, rw);
        //	Add Lines
        MWFNodeNext[] nexts = nodes[i].getTransitions(AD_Client_ID);
        for (int j = 0; j < nexts.length; j++) centerPanel.add(new WFLine(nexts[j]), false);
    }
    //	Info Text
    StringBuffer msg = new StringBuffer("<HTML>");
    msg.append("<H2>").append(m_wf.getName(true)).append("</H2>");
    String s = m_wf.getDescription(true);
    if (s != null && s.length() > 0)
        msg.append("<B>").append(s).append("</B>");
    s = m_wf.getHelp(true);
    if (s != null && s.length() > 0)
        msg.append("<BR>").append(s);
    msg.append("</HTML>");
    infoTextPane.setText(msg.toString());
    infoTextPane.setCaretPosition(0);
    //	Layout
    centerPanel.validate();
    centerPanel.repaint();
    validate();
}
Also used : MWFNode(org.compiere.wf.MWFNode) MWorkflow(org.compiere.wf.MWorkflow) MWFNode(org.compiere.wf.MWFNode) MWFNodeNext(org.compiere.wf.MWFNodeNext) Point(java.awt.Point)

Aggregations

MWorkflow (org.compiere.wf.MWorkflow)36 MWFNode (org.compiere.wf.MWFNode)18 BigDecimal (java.math.BigDecimal)9 ArrayList (java.util.ArrayList)8 MWFNodeNext (org.compiere.wf.MWFNodeNext)7 Query (org.compiere.model.Query)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 HttpSession (javax.servlet.http.HttpSession)4 AdempiereException (org.adempiere.exceptions.AdempiereException)4 BufferedImage (java.awt.image.BufferedImage)3 Properties (java.util.Properties)3 MProduct (org.compiere.model.MProduct)3 Trx (org.compiere.util.Trx)3 MPPProductPlanning (org.eevolution.model.MPPProductPlanning)3 Dimension (java.awt.Dimension)2 RoundingMode (java.math.RoundingMode)2 Arrays (java.util.Arrays)2 List (java.util.List)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 CostDimension (org.adempiere.engine.CostDimension)2