use of org.eevolution.model.MPPOrderWorkflow in project adempiere by adempiere.
the class CRPDatasetFactory method getTreeNodeRepresentation.
private String getTreeNodeRepresentation(Timestamp dateTime, DefaultMutableTreeNode node, MResource r) {
String name = null;
if (node.getUserObject() instanceof MResource) {
MResource res = (MResource) node.getUserObject();
name = res.getName();
} else if (node.getUserObject() instanceof Timestamp) {
Timestamp d = (Timestamp) node.getUserObject();
SimpleDateFormat df = Env.getLanguage(Env.getCtx()).getDateFormat();
name = df.format(d);
if (!isAvailable(r, d)) {
name = "{" + name + "}";
}
} else if (node.getUserObject() instanceof MPPOrder) {
MPPOrder o = (MPPOrder) node.getUserObject();
MProduct p = MProduct.get(Env.getCtx(), o.getM_Product_ID());
name = o.getDocumentNo() + " (" + p.getName() + ")";
} else if (node.getUserObject() instanceof MPPOrderNode) {
MPPOrderNode on = (MPPOrderNode) node.getUserObject();
MPPOrderWorkflow owf = on.getMPPOrderWorkflow();
MResourceType rt = MResourceType.get(Env.getCtx(), r.getS_ResourceType_ID());
// no function
//Env.getLanguage(Env.getCtx()).getTimeFormat();
SimpleDateFormat df = new SimpleDateFormat("HH:mm");
Timestamp[] interval = getDayBorders(dateTime, on, rt);
name = df.format(interval[0]) + " - " + df.format(interval[1]) + " " + on.getName() + " (" + owf.getName() + ")";
}
return name;
}
use of org.eevolution.model.MPPOrderWorkflow in project adempiere by adempiere.
the class CRP method runCRP.
public void runCRP(MPPOrder order) {
log.info("PP_Order DocumentNo:" + order.getDocumentNo());
MPPOrderWorkflow owf = order.getMPPOrderWorkflow();
if (owf == null) {
// TODO: generate notice
addLog("WARNING: No workflow found - " + order);
return;
}
log.info("PP_Order Workflow:" + owf.getName());
final ArrayList<Integer> visitedNodes = new ArrayList<Integer>();
// Schedule Fordward
if (p_ScheduleType.equals(FORWARD_SCHEDULING)) {
Timestamp date = order.getDateStartSchedule();
int nodeId = owf.getPP_Order_Node_ID();
MPPOrderNode node = null;
while (nodeId != 0) {
node = owf.getNode(nodeId);
if (visitedNodes.contains(nodeId)) {
throw new CRPException("Cyclic transition found").setPP_Order_Node(node);
}
visitedNodes.add(nodeId);
log.info("PP_Order Node:" + node.getName() != null ? node.getName() : "" + " Description:" + node.getDescription() != null ? node.getDescription() : "");
//
MResource resource = MResource.get(getCtx(), node.getS_Resource_ID());
// Skip this node if there is no resource
if (resource == null) {
nodeId = owf.getNext(nodeId, getAD_Client_ID());
continue;
}
if (!reasoner.isAvailable(resource)) {
throw new CRPException("@ResourceNotInSlotDay@").setS_Resource(resource);
}
long nodeMillis = calculateMillisFor(node, owf.getDurationBaseSec());
Timestamp dateFinish = scheduleForward(date, nodeMillis, resource);
node.setDateStartSchedule(date);
node.setDateFinishSchedule(dateFinish);
node.saveEx();
date = node.getDateFinishSchedule();
nodeId = owf.getNext(nodeId, getAD_Client_ID());
}
// Update order finish date
if (node != null && node.getDateFinishSchedule() != null) {
order.setDateFinishSchedule(node.getDateFinishSchedule());
}
} else // Schedule backward
if (p_ScheduleType.equals(BACKWARD_SCHEDULING)) {
Timestamp date = order.getDateFinishSchedule();
int nodeId = owf.getNodeLastID(getAD_Client_ID());
MPPOrderNode node = null;
while (nodeId != 0) {
node = owf.getNode(nodeId);
if (visitedNodes.contains(nodeId)) {
throw new CRPException("Cyclic transition found - ").setPP_Order_Node(node);
}
visitedNodes.add(nodeId);
log.info("PP_Order Node:" + node.getName() != null ? node.getName() : "" + " Description:" + node.getDescription() != null ? node.getDescription() : "");
//
MResource resource = MResource.get(getCtx(), node.getS_Resource_ID());
// Skip this node if there is no resource
if (resource == null) {
nodeId = owf.getPrevious(nodeId, getAD_Client_ID());
continue;
}
if (!reasoner.isAvailable(resource)) {
throw new CRPException("@ResourceNotInSlotDay@").setS_Resource(resource);
}
long nodeMillis = calculateMillisFor(node, owf.getDurationBaseSec());
Timestamp dateStart = scheduleBackward(date, nodeMillis, resource);
node.setDateStartSchedule(dateStart);
node.setDateFinishSchedule(date);
node.saveEx();
date = node.getDateStartSchedule();
nodeId = owf.getPrevious(nodeId, getAD_Client_ID());
}
// Update order start date
if (node != null && node.getDateStartSchedule() != null) {
order.setDateStartSchedule(node.getDateStartSchedule());
}
} else {
throw new CRPException("Unknown scheduling method - " + p_ScheduleType);
}
order.saveEx(get_TrxName());
}
Aggregations