use of org.compiere.wf.MWFNode in project adempiere by adempiere.
the class DefaultRoutingServiceImpl method calculateDuration.
public BigDecimal calculateDuration(I_AD_Workflow wf, I_S_Resource plant, BigDecimal qty) {
if (plant == null)
return Env.ZERO;
final Properties ctx = ((PO) wf).getCtx();
final MResourceType S_ResourceType = MResourceType.get(ctx, plant.getS_ResourceType_ID());
BigDecimal AvailableDayTime = new BigDecimal(S_ResourceType.getTimeSlotHours());
int AvailableDays = S_ResourceType.getAvailableDaysWeek();
double durationBaseSec = getDurationBaseSec(wf.getDurationUnit());
double durationTotal = 0.0;
MWFNode[] nodes = ((MWorkflow) wf).getNodes(false, Env.getAD_Client_ID(ctx));
for (I_AD_WF_Node node : nodes) {
// Qty independent times:
durationTotal += node.getQueuingTime();
durationTotal += node.getSetupTime();
durationTotal += node.getWaitingTime();
durationTotal += node.getMovingTime();
// Get OverlapUnits - number of units that must be completed before they are moved the next activity
double overlapUnits = qty.doubleValue();
if (node.getOverlapUnits() > 0 && node.getOverlapUnits() < overlapUnits) {
overlapUnits = node.getOverlapUnits();
}
double durationBeforeOverlap = node.getDuration() * overlapUnits;
durationTotal += durationBeforeOverlap;
}
BigDecimal requiredTime = BigDecimal.valueOf(durationTotal * durationBaseSec / 60 / 60);
// TODO: implement here, Victor's suggestion - https://sourceforge.net/forum/message.php?msg_id=5179460
// Weekly Factor
BigDecimal WeeklyFactor = new BigDecimal(7).divide(new BigDecimal(AvailableDays), 8, RoundingMode.UP);
return (requiredTime.multiply(WeeklyFactor)).divide(AvailableDayTime, 0, RoundingMode.UP);
}
use of org.compiere.wf.MWFNode in project adempiere by adempiere.
the class WorkflowProcessor method dynamicPriority.
// wakeup
/**
* Set/Increase Priority dynamically
*/
private void dynamicPriority() {
// suspend activities with dynamic priority node
String sql = "SELECT * " + "FROM AD_WF_Activity a " + // suspended
"WHERE Processed='N' AND WFState='OS'" + " AND EXISTS (SELECT * FROM AD_Workflow wf" + " INNER JOIN AD_WF_Node wfn ON (wf.AD_Workflow_ID=wfn.AD_Workflow_ID) " + "WHERE a.AD_WF_Node_ID=wfn.AD_WF_Node_ID AND wf.AD_WorkflowProcessor_ID=?" + " AND wfn.DynPriorityUnit IS NOT NULL AND wfn.DynPriorityChange IS NOT NULL)";
PreparedStatement pstmt = null;
int count = 0;
int countEMails = 0;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_model.getAD_WorkflowProcessor_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
MWFActivity activity = new MWFActivity(getCtx(), rs, null);
if (activity.getDynPriorityStart() == 0)
activity.setDynPriorityStart(activity.getPriority());
long ms = System.currentTimeMillis() - activity.getCreated().getTime();
MWFNode node = activity.getNode();
int prioDiff = node.calculateDynamicPriority((int) (ms / 1000));
activity.setPriority(activity.getDynPriorityStart() + prioDiff);
activity.saveEx();
count++;
}
rs.close();
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(pstmt);
}
m_summary.append("DynPriority #").append(count).append(" - ");
}
use of org.compiere.wf.MWFNode in project adempiere by adempiere.
the class WWFActivity method cmd_button.
// cmd_zoom
/**
* Answer Button
*/
private void cmd_button() {
log.config("Activity=" + m_activity);
if (m_activity == null)
return;
//
MWFNode node = m_activity.getNode();
if (MWFNode.ACTION_UserWindow.equals(node.getAction())) {
// Explicit Window
int AD_Window_ID = node.getAD_Window_ID();
String ColumnName = m_activity.getPO().get_TableName() + "_ID";
int Record_ID = m_activity.getRecord_ID();
MQuery query = MQuery.getEqualQuery(ColumnName, Record_ID);
boolean IsSOTrx = m_activity.isSOTrx();
//
log.info("Zoom to AD_Window_ID=" + AD_Window_ID + " - " + query + " (IsSOTrx=" + IsSOTrx + ")");
AEnv.zoom(AD_Window_ID, query);
} else if (MWFNode.ACTION_UserForm.equals(node.getAction())) {
int AD_Form_ID = node.getAD_Form_ID();
Window form = ADForm.openForm(AD_Form_ID);
AEnv.showWindow(form);
} else if (MWFNode.ACTION_SmartBrowse.equals(node.getAction())) {
int AD_Browse_ID = node.getAD_Browse_ID();
Window browse = WBrowser.openBrowse(0, AD_Browse_ID, "", m_activity.isSOTrx());
AEnv.showWindow(browse);
} else
log.log(Level.SEVERE, "No User Action:" + node.getAction());
}
use of org.compiere.wf.MWFNode in project adempiere by adempiere.
the class WFEditor method load.
private void load(int workflowId) {
// Get Workflow
MWorkflow wf = new MWorkflow(Env.getCtx(), workflowId, null);
WFNodeContainer nodeContainer = new WFNodeContainer();
nodeContainer.setWorkflow(wf);
// Add Nodes for Paint
MWFNode[] nodes = wf.getNodes(true, Env.getAD_Client_ID(Env.getCtx()));
for (int i = 0; i < nodes.length; i++) {
WFNode wfn = new WFNode(nodes[i]);
nodeContainer.add(wfn);
// Add Lines
MWFNodeNext[] nexts = nodes[i].getTransitions(Env.getAD_Client_ID(Env.getCtx()));
for (int j = 0; j < nexts.length; j++) nodeContainer.add(new WFLine(nexts[j]));
}
Dimension dimension = nodeContainer.getDimension();
BufferedImage bi = new BufferedImage(dimension.width + 2, dimension.height + 2, BufferedImage.TYPE_INT_ARGB);
nodeContainer.paint(bi.createGraphics());
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
ImageIO.write(bi, "png", os);
AImage imageContent = new AImage("workflow.png", os.toByteArray());
imageMap.setWidth(dimension.width + "px");
imageMap.setHeight(dimension.height + "px");
imageMap.setContent(imageContent);
} catch (Exception e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
use of org.compiere.wf.MWFNode in project adempiere by adempiere.
the class WWFPanelManufacturing method load.
private void load(int workflowId) {
// Get Workflow
MWorkflow wf = new MWorkflow(Env.getCtx(), workflowId, null);
WFNodeContainer nodeContainer = new WFNodeContainer();
nodeContainer.setWorkflow(wf);
// Add Nodes for Paint
MWFNode[] nodes = wf.getNodes(true, Env.getAD_Client_ID(Env.getCtx()));
for (int i = 0; i < nodes.length; i++) {
WFNode wfn = new WFNode(nodes[i]);
nodeContainer.add(wfn);
// Add Lines
MWFNodeNext[] nexts = nodes[i].getTransitions(Env.getAD_Client_ID(Env.getCtx()));
for (int j = 0; j < nexts.length; j++) nodeContainer.add(new WFLine(nexts[j]));
}
Dimension dimension = nodeContainer.getDimension();
BufferedImage bi = new BufferedImage(dimension.width + 2, dimension.height + 2, BufferedImage.TYPE_INT_ARGB);
nodeContainer.paint(bi.createGraphics());
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
ImageIO.write(bi, "png", os);
AImage imageContent = new AImage("workflow.png", os.toByteArray());
imageMap.setWidth(dimension.width + "px");
imageMap.setHeight(dimension.height + "px");
imageMap.setContent(imageContent);
} catch (Exception e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
Aggregations