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();
}
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());
}
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;
}
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));
}
}
}
}
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();
}
}
Aggregations