Search in sources :

Example 11 with MWFNode

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

Example 12 with MWFNode

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

the class RollupWorkflow method rollup.

/**
     * Execute rollup process
     * @param accountSchema
     * @param costType
     * @param costElement
     * @param product
     * @param workflow
     * @param trxName
     */
protected void rollup(MAcctSchema accountSchema, MCostType costType, MCostElement costElement, MProduct product, MWorkflow workflow, String trxName) {
    log.info("Workflow: " + workflow);
    workflow.setCost(Env.ZERO);
    double yield = 1;
    int queuingTime = 0;
    int setupTime = 0;
    int duration = 0;
    int waitingTime = 0;
    int movingTime = 0;
    int workingTime = 0;
    MWFNode[] nodes = workflow.getNodes(false, getAD_Client_ID());
    for (MWFNode node : nodes) {
        node.setCost(Env.ZERO);
        if (node.getYield() != 0) {
            yield = yield * ((double) node.getYield() / 100);
        }
        // We use node.getDuration() instead of m_routingService.estimateWorkingTime(node) because
        // this will be the minimum duration of this node. So even if the node have defined units/cycle
        // we consider entire duration of the node.
        long nodeDuration = node.getDuration();
        queuingTime += node.getQueuingTime();
        setupTime += node.getSetupTime();
        duration += nodeDuration;
        waitingTime += node.getWaitingTime();
        movingTime += node.getMovingTime();
        workingTime += node.getWorkingTime();
    }
    workflow.setCost(Env.ZERO);
    workflow.setYield((int) (yield * 100));
    workflow.setQueuingTime(queuingTime);
    workflow.setSetupTime(setupTime);
    workflow.setDuration(duration);
    workflow.setWaitingTime(waitingTime);
    workflow.setMovingTime(movingTime);
    workflow.setWorkingTime(workingTime);
    final CostDimension costDimension = new CostDimension(product, accountSchema, costType.getM_CostType_ID(), getOrganizationId(), getWarehouseId(), 0, costElement.get_ID());
    MCost cost = MCost.getOrCreate(product, 0, accountSchema, getOrganizationId(), getWarehouseId(), costType.getM_CostType_ID(), costElement.getM_CostElement_ID());
    cost.setFutureCostPrice(BigDecimal.ZERO);
    if (!cost.isCostFrozen())
        cost.setCurrentCostPrice(BigDecimal.ZERO);
    AtomicReference<BigDecimal> segmentCost = new AtomicReference<>(Env.ZERO);
    Arrays.stream(nodes).filter(node -> node != null).forEach(node -> {
        final CostEngine costEngine = CostEngineFactory.getCostEngine(node.getAD_Client_ID());
        final BigDecimal rate = StandardCostingMethod.getResourceActualCostRate(node.getS_Resource_ID(), costDimension, trxName);
        final BigDecimal baseValue = routingService.getResourceBaseValue(node.getS_Resource_ID(), node);
        BigDecimal nodeCostPrecision = baseValue.multiply(rate);
        BigDecimal nodeCost;
        if (nodeCostPrecision.scale() > accountSchema.getCostingPrecision())
            nodeCost = nodeCostPrecision.setScale(accountSchema.getCostingPrecision(), RoundingMode.HALF_UP);
        else
            nodeCost = nodeCostPrecision;
        segmentCost.updateAndGet(costAmt -> costAmt.add(nodeCost));
        log.info(Msg.parseTranslation(getCtx(), " @M_CostElement_ID@ : ") + costElement.getName() + ", Node=" + node + ", BaseValue=" + baseValue + ", rate=" + rate + ", nodeCost=" + nodeCost + " => Cost=" + segmentCost);
        node.setCost(node.getCost().add(nodeCost));
    });
    cost.setFutureCostPrice(segmentCost.get());
    if (!cost.isCostFrozen())
        cost.setCurrentCostPrice(segmentCost.get());
    cost.saveEx();
    // Update Workflow cost
    workflow.setCost(workflow.getCost().add(segmentCost.get()));
    // Save Workflow & Nodes
    Arrays.stream(nodes).filter(node -> node != null).forEach(node -> node.saveEx());
    workflow.saveEx();
    log.info("Product: " + product.getName() + " WFCost: " + workflow.getCost());
}
Also used : MPPProductPlanning(org.eevolution.model.MPPProductPlanning) Arrays(java.util.Arrays) Env(org.compiere.util.Env) MCostType(org.compiere.model.MCostType) AtomicReference(java.util.concurrent.atomic.AtomicReference) MAcctSchema(org.compiere.model.MAcctSchema) ArrayList(java.util.ArrayList) RoutingService(org.eevolution.model.RoutingService) MCost(org.compiere.model.MCost) BigDecimal(java.math.BigDecimal) Query(org.compiere.model.Query) Msg(org.compiere.util.Msg) Trx(org.compiere.util.Trx) CostEngine(org.adempiere.engine.CostEngine) RoundingMode(java.math.RoundingMode) CostEngineFactory(org.adempiere.engine.CostEngineFactory) CostDimension(org.adempiere.engine.CostDimension) MWorkflow(org.compiere.wf.MWorkflow) StandardCostingMethod(org.adempiere.engine.StandardCostingMethod) RoutingServiceFactory(org.eevolution.model.RoutingServiceFactory) List(java.util.List) MWFNode(org.compiere.wf.MWFNode) MCostElement(org.compiere.model.MCostElement) TrxRunnable(org.compiere.util.TrxRunnable) MProduct(org.compiere.model.MProduct) CostEngine(org.adempiere.engine.CostEngine) MCost(org.compiere.model.MCost) MWFNode(org.compiere.wf.MWFNode) AtomicReference(java.util.concurrent.atomic.AtomicReference) CostDimension(org.adempiere.engine.CostDimension) BigDecimal(java.math.BigDecimal)

Example 13 with MWFNode

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

the class DefaultRoutingServiceImplTest method createNode.

private MWFNode createNode(MWorkflow wf, String value, int setupTime, int duration, int unitsCycles, int overlapUnits) {
    if (value == null) {
        value = "" + System.currentTimeMillis();
    }
    MWFNode node = new MWFNode(wf, value, value);
    node.setSetupTime(setupTime);
    node.setDuration(duration);
    node.setUnitsCycles(BigDecimal.valueOf(unitsCycles));
    node.setOverlapUnits(overlapUnits);
    //
    node.saveEx();
    return node;
}
Also used : MWFNode(org.compiere.wf.MWFNode)

Example 14 with MWFNode

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

the class PackInHandler method endElement.

/**
     *	Receive notification of the end of an element.
     * 	@param uri namespace
     * 	@param localName simple name
     * 	@param qName qualified name
     * 	@throws SAXException
     */
public void endElement(String uri, String localName, String qName) throws SAXException {
    // Check namespace.
    String elementValue = null;
    if ("".equals(uri))
        elementValue = qName;
    else
        elementValue = uri + localName;
    if (elementValue.equals("adempiereAD")) {
        processDeferElements();
        processMenuElements();
        if (!PK_Status.equals("Completed with errors"))
            PK_Status = "Completed successfully";
        //Update package history log with package status
        StringBuffer sqlB = new StringBuffer("UPDATE AD_Package_Imp " + "SET PK_Status = '" + PK_Status + "' WHERE AD_Package_Imp_ID = " + AD_Package_Imp_ID);
        int no = DB.executeUpdate(sqlB.toString(), m_trxName);
        if (no == -1)
            log.info("Update to package summary failed");
        //Update package list with package status		
        sqlB = new StringBuffer("UPDATE AD_Package_Imp_Inst " + "SET PK_Status = '" + PK_Status + "' WHERE AD_Package_Imp_Inst_ID = " + AD_Package_Imp_Inst_ID);
        no = DB.executeUpdate(sqlB.toString(), m_trxName);
        if (no == -1)
            log.info("Update to package list failed");
        if (workflow.size() > 0) {
            for (Element e : workflow) {
                Attributes atts = e.attributes;
                String workflowName = atts.getValue("Name");
                MWorkflow wf = null;
                int workflow_id = IDFinder.get_IDWithColumn("AD_Workflow", "Name", workflowName, m_AD_Client_ID, m_trxName);
                if (workflow_id > 0) {
                    wf = new MWorkflow(m_ctx, workflow_id, m_trxName);
                    int node_id = 0;
                    String name = atts.getValue("ADWorkflowNodeNameID");
                    if (name != null && name.trim().length() > 0) {
                        MWFNode[] nodes = wf.getNodes(false, m_AD_Client_ID);
                        for (MWFNode node : nodes) {
                            if (node.getName().trim().equals(name.trim())) {
                                node_id = node.getAD_WF_Node_ID();
                                wf.setAD_WF_Node_ID(node_id);
                                if (!wf.save())
                                    System.out.println("Can not save Start Node " + name + "to Workflow " + workflowName + " do not exist ");
                                break;
                            }
                        }
                        if (node_id == 0)
                            System.out.println("Unresolved: Start Node to Workflow " + workflowName + " do not exist ");
                        else
                            break;
                    }
                }
            }
        }
        if (nodes.size() > 0) {
            for (Element e : nodes) {
                Attributes atts = e.attributes;
                String nodeName = atts.getValue("Name");
                MWFNode node = null;
                int id = IDFinder.get_IDWithColumn("AD_WF_Node", "Name", nodeName, m_AD_Client_ID, false, m_trxName);
                if (id > 0) {
                    node = new MWFNode(m_ctx, id, m_trxName);
                    String workflowNodeName = atts.getValue("WorkflowNameID").trim();
                    if (workflowNodeName != null && workflowNodeName.trim().length() > 0) {
                        int workflow_id = IDFinder.get_IDWithColumn("AD_Workflow", "Name", workflowNodeName, m_AD_Client_ID, m_trxName);
                        if (workflow_id > 0) {
                            node.setWorkflow_ID(workflow_id);
                            if (!node.save()) {
                                System.out.println("can not save Workflow " + workflowNodeName);
                            }
                        } else
                            System.out.println("Unresolved: Workflow " + workflowNodeName + " do not exist ");
                    }
                }
            }
        }
        logDocument.endElement("", "", "adempiereDocument");
        logDocument.endDocument();
        try {
            fw_document.close();
        } catch (Exception e) {
        }
        //reset
        setupHandlers();
    } else {
        Element e = stack.pop();
        if (e.defer) {
            defer.add(new DeferEntry(e, false));
        } else {
            ElementHandler handler = handlers.get(elementValue);
            if (handler != null)
                handler.endElement(m_ctx, e);
            if (e.defer || e.deferEnd)
                defer.add(new DeferEntry(e, false));
            else if (!e.skip) {
                if (log.isLoggable(Level.INFO))
                    log.info("Processed: " + e.getElementValue() + " - " + e.attributes.getValue(0));
            }
        }
    }
}
Also used : MWorkflow(org.compiere.wf.MWorkflow) Attributes(org.xml.sax.Attributes) MWFNode(org.compiere.wf.MWFNode) ProcessElementHandler(org.adempiere.pipo.handler.ProcessElementHandler) UserRoleElementHandler(org.adempiere.pipo.handler.UserRoleElementHandler) PrintFormatItemElementHandler(org.adempiere.pipo.handler.PrintFormatItemElementHandler) WindowElementHandler(org.adempiere.pipo.handler.WindowElementHandler) RoleElementHandler(org.adempiere.pipo.handler.RoleElementHandler) FormElementHandler(org.adempiere.pipo.handler.FormElementHandler) TabElementHandler(org.adempiere.pipo.handler.TabElementHandler) FieldElementHandler(org.adempiere.pipo.handler.FieldElementHandler) ModelValidatorElementHandler(org.adempiere.pipo.handler.ModelValidatorElementHandler) ReportViewColElementHandler(org.adempiere.pipo.handler.ReportViewColElementHandler) ViewColumnElementHandler(org.adempiere.pipo.handler.ViewColumnElementHandler) DataElementHandler(org.adempiere.pipo.handler.DataElementHandler) PreferenceElementHandler(org.adempiere.pipo.handler.PreferenceElementHandler) ReportViewElementHandler(org.adempiere.pipo.handler.ReportViewElementHandler) WorkflowNodeNextElementHandler(org.adempiere.pipo.handler.WorkflowNodeNextElementHandler) ViewDefinitionElementHandler(org.adempiere.pipo.handler.ViewDefinitionElementHandler) DistFileElementHandler(org.adempiere.pipo.handler.DistFileElementHandler) ImpFormatRowElementHandler(org.adempiere.pipo.handler.ImpFormatRowElementHandler) EntityTypeElementHandler(org.adempiere.pipo.handler.EntityTypeElementHandler) MenuElementHandler(org.adempiere.pipo.handler.MenuElementHandler) WorkflowElementHandler(org.adempiere.pipo.handler.WorkflowElementHandler) WorkflowNodeElementHandler(org.adempiere.pipo.handler.WorkflowNodeElementHandler) WindowAccessElementHandler(org.adempiere.pipo.handler.WindowAccessElementHandler) ImpFormatElementHandler(org.adempiere.pipo.handler.ImpFormatElementHandler) ReferenceTableElementHandler(org.adempiere.pipo.handler.ReferenceTableElementHandler) ReferenceListElementHandler(org.adempiere.pipo.handler.ReferenceListElementHandler) AdElementHandler(org.adempiere.pipo.handler.AdElementHandler) PrintFormatElementHandler(org.adempiere.pipo.handler.PrintFormatElementHandler) TaskAccessElementHandler(org.adempiere.pipo.handler.TaskAccessElementHandler) ViewElementHandler(org.adempiere.pipo.handler.ViewElementHandler) ProcessAccessElementHandler(org.adempiere.pipo.handler.ProcessAccessElementHandler) BrowseFieldElementHandler(org.adempiere.pipo.handler.BrowseFieldElementHandler) TableElementHandler(org.adempiere.pipo.handler.TableElementHandler) MessageElementHandler(org.adempiere.pipo.handler.MessageElementHandler) OrgRoleElementHandler(org.adempiere.pipo.handler.OrgRoleElementHandler) FormAccessElementHandler(org.adempiere.pipo.handler.FormAccessElementHandler) SQLStatementElementHandler(org.adempiere.pipo.handler.SQLStatementElementHandler) WorkflowAccessElementHandler(org.adempiere.pipo.handler.WorkflowAccessElementHandler) ColumnElementHandler(org.adempiere.pipo.handler.ColumnElementHandler) DynValRuleElementHandler(org.adempiere.pipo.handler.DynValRuleElementHandler) TaskElementHandler(org.adempiere.pipo.handler.TaskElementHandler) PrintPaperElementHandler(org.adempiere.pipo.handler.PrintPaperElementHandler) ReferenceElementHandler(org.adempiere.pipo.handler.ReferenceElementHandler) BrowseElementHandler(org.adempiere.pipo.handler.BrowseElementHandler) WorkflowNodeNextConditionElementHandler(org.adempiere.pipo.handler.WorkflowNodeNextConditionElementHandler) FieldGroupElementHandler(org.adempiere.pipo.handler.FieldGroupElementHandler) CodeSnipitElementHandler(org.adempiere.pipo.handler.CodeSnipitElementHandler) ProcessParaElementHandler(org.adempiere.pipo.handler.ProcessParaElementHandler) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) SQLException(java.sql.SQLException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException)

Example 15 with MWFNode

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

the class WFContentPanel method actionPerformed.

//	addMenuItem
/**
	 * 	Action Listener
	 *	@param e event
	 */
public void actionPerformed(ActionEvent e) {
    log.info(e.toString());
    //	Add new Node
    if (e.getSource() == m_NewMenuNode) {
        log.info("Create New Node");
        String nameLabel = Util.cleanAmp(Msg.getMsg(Env.getCtx(), "Name"));
        String name = JOptionPane.showInputDialog(this, //	message
        nameLabel, //	title
        Msg.getMsg(Env.getCtx(), "CreateNewNode"), JOptionPane.QUESTION_MESSAGE);
        if (name != null && name.length() > 0) {
            int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
            MWFNode node = new MWFNode(m_wf, name, name);
            node.setClientOrg(AD_Client_ID, 0);
            node.saveEx();
            m_parent.load(m_wf.getAD_Workflow_ID(), true);
        }
    } else //	Add/Delete Line
    if (e.getSource() instanceof WFPopupItem) {
        WFPopupItem item = (WFPopupItem) e.getSource();
        item.execute();
    }
}
Also used : MWFNode(org.compiere.wf.MWFNode) Point(java.awt.Point)

Aggregations

MWFNode (org.compiere.wf.MWFNode)29 MWorkflow (org.compiere.wf.MWorkflow)17 MWFNodeNext (org.compiere.wf.MWFNodeNext)8 ArrayList (java.util.ArrayList)7 Point (java.awt.Point)4 HttpSession (javax.servlet.http.HttpSession)4 BufferedImage (java.awt.image.BufferedImage)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Properties (java.util.Properties)3 WFLine (org.compiere.apps.wf.WFLine)3 Trx (org.compiere.util.Trx)3 ValueNamePair (org.compiere.util.ValueNamePair)3 Dimension (java.awt.Dimension)2 BigDecimal (java.math.BigDecimal)2 SQLException (java.sql.SQLException)2 MProduct (org.compiere.model.MProduct)2 Query (org.compiere.model.Query)2 WebDoc (org.compiere.util.WebDoc)2 WebSessionCtx (org.compiere.util.WebSessionCtx)2 AImage (org.zkoss.image.AImage)2