use of org.compiere.wf.MWorkflow in project adempiere by adempiere.
the class DefaultRoutingServiceImplTest method assertEstimateWorkingTime.
/**
* @see RoutingService#estimateWorkingTime(I_AD_WF_Node)
*/
protected void assertEstimateWorkingTime(double expectedDuration, int duration, int unitsCycles) {
// not relevant
int qtyBatchSize = 1;
// not relevant
int setupTime = 0;
// not relevant
int overlapUnits = 0;
MWorkflow wf = createWorkflow(qtyBatchSize);
I_AD_WF_Node node = createNode(wf, "10", setupTime, duration, unitsCycles, overlapUnits);
BigDecimal durationActual = routingService.estimateWorkingTime(node);
assertEquals(expectedDuration, durationActual.doubleValue());
}
use of org.compiere.wf.MWorkflow in project adempiere by adempiere.
the class DefaultRoutingServiceImplTest method createWorkflow.
private MWorkflow createWorkflow(int qtyBatchSize) {
String value = "JUnit_Test_" + System.currentTimeMillis();
MWorkflow wf = new MWorkflow(getCtx(), 0, getTrxName());
wf.setWorkflowType(MWorkflow.WORKFLOWTYPE_Manufacturing);
wf.setProcessType(MWorkflow.PROCESSTYPE_DedicateRepetititiveFlow);
wf.setValue(value);
wf.setName(value);
wf.setDescription("Generated by " + getClass());
wf.setAuthor("JUnit");
wf.setQtyBatchSize(BigDecimal.valueOf(qtyBatchSize));
//
wf.saveEx();
return wf;
}
use of org.compiere.wf.MWorkflow in project adempiere by adempiere.
the class WorkflowElementHandler method startElement.
public void startElement(Properties ctx, Element element) throws SAXException {
Attributes atts = element.attributes;
String elementValue = element.getElementValue();
log.info(elementValue + " " + atts.getValue("Name"));
String entitytype = atts.getValue("EntityType");
log.info("entitytype " + atts.getValue("EntityType"));
if (isProcessElement(ctx, entitytype)) {
String workflowName = atts.getValue("Name");
int id = get_IDWithColumn(ctx, "AD_Workflow", "name", workflowName);
if (id > 0 && workflows.contains(id)) {
element.skip = true;
return;
}
MWorkflow m_Workflow = new MWorkflow(ctx, id, getTrxName(ctx));
int AD_Backup_ID = -1;
String Object_Status = null;
if (id <= 0 && atts.getValue("AD_Workflow_ID") != null && Integer.parseInt(atts.getValue("AD_Workflow_ID")) <= PackOut.MAX_OFFICIAL_ID)
m_Workflow.setAD_Workflow_ID(Integer.parseInt(atts.getValue("AD_Workflow_ID")));
if (id > 0) {
AD_Backup_ID = copyRecord(ctx, "AD_Workflow", m_Workflow);
Object_Status = "Update";
} else {
Object_Status = "New";
AD_Backup_ID = 0;
}
String name = atts.getValue("ADTableNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_Table", "TableName", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_Table: " + name;
return;
}
m_Workflow.setAD_Table_ID(id);
}
name = atts.getValue("ADWorkflowResponsibleNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_WF_Responsible", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_WF_Responsible: " + name;
return;
}
m_Workflow.setAD_WF_Responsible_ID(id);
}
name = atts.getValue("ADWorkflowProcessorNameID");
if (name != null && name.trim().length() > 0) {
id = get_IDWithColumn(ctx, "AD_WorkflowProcessor", "Name", name);
if (id <= 0) {
element.defer = true;
element.unresolved = "AD_WorkflowProcessor: " + name;
return;
}
m_Workflow.setAD_WorkflowProcessor_ID(id);
}
m_Workflow.setValue(atts.getValue("Value"));
m_Workflow.setName(workflowName);
m_Workflow.setIsBetaFunctionality(Boolean.valueOf(atts.getValue("isBetaFunctionality")).booleanValue());
m_Workflow.setAccessLevel(atts.getValue("AccessLevel"));
m_Workflow.setDescription(getStringValue(atts, "Description"));
m_Workflow.setHelp(getStringValue(atts, "Help"));
m_Workflow.setDurationUnit(getStringValue(atts, "DurationUnit"));
m_Workflow.setAuthor(getStringValue(atts, "Author"));
if (getStringValue(atts, "Version") != null)
m_Workflow.setVersion(Integer.valueOf(atts.getValue("Version")));
if (getStringValue(atts, "Priority") != null)
m_Workflow.setPriority(Integer.valueOf(atts.getValue("Priority")));
if (getStringValue(atts, "Limit") != null)
m_Workflow.setLimit(Integer.valueOf(atts.getValue("Limit")));
if (getStringValue(atts, "Duration") != null)
m_Workflow.setDuration(Integer.valueOf(atts.getValue("Duration")));
if (getStringValue(atts, "Cost") != null)
m_Workflow.setCost(new BigDecimal(atts.getValue("Cost")));
m_Workflow.setWorkingTime(Integer.valueOf(atts.getValue("WorkingTime")));
m_Workflow.setWaitingTime(Integer.valueOf(atts.getValue("WaitingTime")));
m_Workflow.setPublishStatus(atts.getValue("PublishStatus"));
m_Workflow.setWorkflowType(atts.getValue("WorkflowType"));
m_Workflow.setDocValueLogic(getStringValue(atts, "DocValueLogic"));
m_Workflow.setIsValid(atts.getValue("isValid") != null ? Boolean.valueOf(atts.getValue("isValid")).booleanValue() : true);
m_Workflow.setEntityType(atts.getValue("EntityType"));
m_Workflow.setAD_WF_Node_ID(-1);
log.info("about to execute m_Workflow.save");
if (m_Workflow.save(getTrxName(ctx)) == true) {
log.info("m_Workflow save success");
record_log(ctx, 1, m_Workflow.getName(), "Workflow", m_Workflow.get_ID(), AD_Backup_ID, Object_Status, "AD_Workflow", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Workflow"));
workflows.add(m_Workflow.getAD_Workflow_ID());
element.recordId = m_Workflow.getAD_Workflow_ID();
} else {
log.info("m_Workflow save failure");
record_log(ctx, 0, m_Workflow.getName(), "Workflow", m_Workflow.get_ID(), AD_Backup_ID, Object_Status, "AD_Workflow", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Workflow"));
throw new POSaveFailedException("MWorkflow");
}
} else {
element.skip = true;
}
}
use of org.compiere.wf.MWorkflow in project adempiere by adempiere.
the class WorkflowElementHandler method endElement.
/**
* @param ctx
* @param element
*/
public void endElement(Properties ctx, Element element) throws SAXException {
if (!element.defer && !element.skip && element.recordId > 0) {
Attributes atts = element.attributes;
//set start node
String name = atts.getValue("ADWorkflowNodeNameID");
if (name != null && name.trim().length() > 0) {
MWorkflow m_Workflow = new MWorkflow(ctx, element.recordId, getTrxName(ctx));
int id = get_IDWithMasterAndColumn(ctx, "AD_WF_Node", "Name", name, "AD_Workflow", m_Workflow.getAD_Workflow_ID());
if (id <= 0) {
log.warning("Failed to resolve start node reference for workflow element. Workflow=" + m_Workflow.getName() + " StartNode=" + name);
return;
}
m_Workflow.setAD_WF_Node_ID(id);
if (m_Workflow.save(getTrxName(ctx)) == true) {
log.info("m_Workflow update success");
record_log(ctx, 1, m_Workflow.getName(), "Workflow", m_Workflow.get_ID(), 0, "Update", "AD_Workflow", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Workflow"));
workflows.add(m_Workflow.getAD_Workflow_ID());
element.recordId = m_Workflow.getAD_Workflow_ID();
} else {
log.info("m_Workflow update fail");
record_log(ctx, 0, m_Workflow.getName(), "Workflow", m_Workflow.get_ID(), 0, "Update", "AD_Workflow", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_Workflow"));
throw new POSaveFailedException("MWorkflow");
}
}
}
}
use of org.compiere.wf.MWorkflow in project adempiere by adempiere.
the class MPPOrder method explotion.
/**
* Create PP_Order_BOM from PP_Product_BOM.
* Create PP_Order_Workflow from AD_Workflow.
*/
private void explotion() {
// Create BOM Head
final MPPProductBOM PP_Product_BOM = MPPProductBOM.get(getCtx(), getPP_Product_BOM_ID());
// Product from Order should be same as product from BOM - teo_sarca [ 2817870 ]
if (getM_Product_ID() != PP_Product_BOM.getM_Product_ID()) {
throw new AdempiereException("@NotMatch@ @PP_Product_BOM_ID@ , @M_Product_ID@");
}
// Product BOM Configuration should be verified - teo_sarca [ 2817870 ]
final MProduct product = MProduct.get(getCtx(), PP_Product_BOM.getM_Product_ID());
if (!product.isVerified()) {
// TODO: translate
throw new AdempiereException("Product BOM Configuration not verified. Please verify the product first - " + product.getValue());
}
if (PP_Product_BOM.isValidFromTo(getDateStartSchedule())) {
MPPOrderBOM PP_Order_BOM = new MPPOrderBOM(PP_Product_BOM, getPP_Order_ID(), get_TrxName());
PP_Order_BOM.setAD_Org_ID(getAD_Org_ID());
PP_Order_BOM.saveEx();
for (MPPProductBOMLine PP_Product_BOMline : PP_Product_BOM.getLines(true)) {
if (PP_Product_BOMline.isValidFromTo(getDateStartSchedule())) {
MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(PP_Product_BOMline, getPP_Order_ID(), PP_Order_BOM.get_ID(), getM_Warehouse_ID(), get_TrxName());
PP_Order_BOMLine.setAD_Org_ID(getAD_Org_ID());
PP_Order_BOMLine.setM_Warehouse_ID(getM_Warehouse_ID());
PP_Order_BOMLine.setM_Locator_ID(getM_Locator_ID());
PP_Order_BOMLine.setQtyOrdered(getQtyOrdered());
PP_Order_BOMLine.saveEx();
} else // end if valid From / To
{
log.fine("BOM Line skiped - " + PP_Product_BOMline);
}
}
// end Create Order BOM
} else // end if From / To parent
{
throw new BOMExpiredException(PP_Product_BOM, getDateStartSchedule());
}
// Create Workflow (Routing & Process)
final MWorkflow AD_Workflow = MWorkflow.get(getCtx(), getAD_Workflow_ID());
// Workflow should be validated first - teo_sarca [ 2817870 ]
if (!AD_Workflow.isValid()) {
// TODO: translate
throw new AdempiereException("Routing is not valid. Please validate it first - " + AD_Workflow.getValue());
}
if (AD_Workflow.isValidFromTo(getDateStartSchedule())) {
MPPOrderWorkflow PP_Order_Workflow = new MPPOrderWorkflow(AD_Workflow, get_ID(), get_TrxName());
PP_Order_Workflow.setAD_Org_ID(getAD_Org_ID());
PP_Order_Workflow.saveEx();
for (MWFNode AD_WF_Node : AD_Workflow.getNodes(false, getAD_Client_ID())) {
if (AD_WF_Node.isValidFromTo(getDateStartSchedule())) {
MPPOrderNode PP_Order_Node = new MPPOrderNode(AD_WF_Node, PP_Order_Workflow, getQtyOrdered(), get_TrxName());
PP_Order_Node.setAD_Org_ID(getAD_Org_ID());
PP_Order_Node.saveEx();
for (MWFNodeNext AD_WF_NodeNext : AD_WF_Node.getTransitions(getAD_Client_ID())) {
MPPOrderNodeNext nodenext = new MPPOrderNodeNext(AD_WF_NodeNext, PP_Order_Node);
nodenext.setAD_Org_ID(getAD_Org_ID());
nodenext.saveEx();
}
for (MPPWFNodeProduct wfnp : MPPWFNodeProduct.forAD_WF_Node_ID(getCtx(), AD_WF_Node.get_ID())) {
MPPOrderNodeProduct nodeOrderProduct = new MPPOrderNodeProduct(wfnp, PP_Order_Node);
nodeOrderProduct.setAD_Org_ID(getAD_Org_ID());
nodeOrderProduct.saveEx();
}
for (MPPWFNodeAsset wfna : MPPWFNodeAsset.forAD_WF_Node_ID(getCtx(), AD_WF_Node.get_ID())) {
MPPOrderNodeAsset nodeorderasset = new MPPOrderNodeAsset(wfna, PP_Order_Node);
nodeorderasset.setAD_Org_ID(getAD_Org_ID());
nodeorderasset.saveEx();
}
}
// for node
}
// Update transitions nexts and set first node
// requery
PP_Order_Workflow.getNodes(true);
for (MPPOrderNode orderNode : PP_Order_Workflow.getNodes(false, getAD_Client_ID())) {
// set workflow start node
if (PP_Order_Workflow.getAD_WF_Node_ID() == orderNode.getAD_WF_Node_ID()) {
PP_Order_Workflow.setPP_Order_Node_ID(orderNode.getPP_Order_Node_ID());
}
// set node next
for (MPPOrderNodeNext next : orderNode.getTransitions(getAD_Client_ID())) {
next.setPP_Order_Next_ID();
next.saveEx();
}
}
PP_Order_Workflow.saveEx();
} else // workflow valid from/to
{
throw new RoutingExpiredException(AD_Workflow, getDateStartSchedule());
}
}
Aggregations