Fix bug [ 1854603 ] Prepare method is being called twice
great team work on IRC between tobi42, MCalderon, hengsin and me :-) Thanks
This commit is contained in:
parent
a1cc40c5b6
commit
9667f26ad9
|
@ -41,7 +41,7 @@ import org.compiere.util.*;
|
||||||
public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Get Activities for table/tecord
|
* Get Activities for table/record
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
* @param AD_Table_ID table
|
* @param AD_Table_ID table
|
||||||
* @param Record_ID record
|
* @param Record_ID record
|
||||||
|
@ -182,6 +182,22 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
||||||
m_process = process;
|
m_process = process;
|
||||||
} // MWFActivity
|
} // MWFActivity
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parent Contructor
|
||||||
|
* @param process process
|
||||||
|
* @param AD_WF_Node_ID start node
|
||||||
|
* @param lastPO PO from the previously executed node
|
||||||
|
*/
|
||||||
|
public MWFActivity(MWFProcess process, int next_ID, PO lastPO) {
|
||||||
|
this(process, next_ID);
|
||||||
|
if (lastPO != null) {
|
||||||
|
// Compare if the last PO is the same type and record needed here, if yes, use it
|
||||||
|
if (lastPO.get_Table_ID() == getAD_Table_ID() && lastPO.get_ID() == getRecord_ID()) {
|
||||||
|
m_po = lastPO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** State Machine */
|
/** State Machine */
|
||||||
private StateEngine m_state = null;
|
private StateEngine m_state = null;
|
||||||
/** Workflow Node */
|
/** Workflow Node */
|
||||||
|
@ -238,7 +254,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
||||||
if (m_process == null)
|
if (m_process == null)
|
||||||
m_process = new MWFProcess (getCtx(), getAD_WF_Process_ID(),
|
m_process = new MWFProcess (getCtx(), getAD_WF_Process_ID(),
|
||||||
m_trx == null ? null : m_trx.getTrxName());
|
m_trx == null ? null : m_trx.getTrxName());
|
||||||
m_process.checkActivities(m_trx == null ? null : m_trx.getTrxName());
|
m_process.checkActivities(m_trx == null ? null : m_trx.getTrxName(), m_po);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -307,8 +323,9 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
|
||||||
*/
|
*/
|
||||||
public PO getPO (Trx trx)
|
public PO getPO (Trx trx)
|
||||||
{
|
{
|
||||||
if (m_po != null)
|
if (m_po != null) {
|
||||||
return m_po;
|
return m_po;
|
||||||
|
}
|
||||||
|
|
||||||
MTable table = MTable.get (getCtx(), getAD_Table_ID());
|
MTable table = MTable.get (getCtx(), getAD_Table_ID());
|
||||||
if (trx != null)
|
if (trx != null)
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class MWFProcess extends X_AD_WF_Process
|
||||||
// Lock Entity
|
// Lock Entity
|
||||||
getPO();
|
getPO();
|
||||||
if (m_po != null)
|
if (m_po != null)
|
||||||
m_po.lock();
|
m_po.lock();
|
||||||
} // MWFProcess
|
} // MWFProcess
|
||||||
|
|
||||||
/** State Machine */
|
/** State Machine */
|
||||||
|
@ -227,7 +227,7 @@ public class MWFProcess extends X_AD_WF_Process
|
||||||
* - start new activity
|
* - start new activity
|
||||||
* @param trxName transaction
|
* @param trxName transaction
|
||||||
*/
|
*/
|
||||||
public void checkActivities(String trxName)
|
public void checkActivities(String trxName, PO lastPO)
|
||||||
{
|
{
|
||||||
log.info("(" + getAD_Workflow_ID() + ") - " + getWFState()
|
log.info("(" + getAD_Workflow_ID() + ") - " + getWFState()
|
||||||
+ (trxName == null ? "" : "[" + trxName + "]"));
|
+ (trxName == null ? "" : "[" + trxName + "]"));
|
||||||
|
@ -246,7 +246,7 @@ public class MWFProcess extends X_AD_WF_Process
|
||||||
// Completed - Start Next
|
// Completed - Start Next
|
||||||
if (activityState.isCompleted())
|
if (activityState.isCompleted())
|
||||||
{
|
{
|
||||||
if (startNext (activity, activities))
|
if (startNext (activity, activities, lastPO))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
@ -303,7 +303,7 @@ public class MWFProcess extends X_AD_WF_Process
|
||||||
* @param activities all activities
|
* @param activities all activities
|
||||||
* @return true if there is a next activity
|
* @return true if there is a next activity
|
||||||
*/
|
*/
|
||||||
private boolean startNext (MWFActivity last, MWFActivity[] activities)
|
private boolean startNext (MWFActivity last, MWFActivity[] activities, PO lastPO)
|
||||||
{
|
{
|
||||||
log.fine("Last=" + last);
|
log.fine("Last=" + last);
|
||||||
// transitions from the last processed node
|
// transitions from the last processed node
|
||||||
|
@ -331,9 +331,11 @@ public class MWFProcess extends X_AD_WF_Process
|
||||||
if (!transitions[i].isValidFor(last))
|
if (!transitions[i].isValidFor(last))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Start new Activity
|
// Start new Activity...
|
||||||
MWFActivity activity = new MWFActivity (this, transitions[i].getAD_WF_Next_ID());
|
MWFActivity activity = new MWFActivity (this, transitions[i].getAD_WF_Next_ID(), lastPO);
|
||||||
new Thread(activity).start();
|
//new Thread(activity).start();
|
||||||
|
//..but not in another thread
|
||||||
|
activity.run();
|
||||||
|
|
||||||
// only the first valid if XOR
|
// only the first valid if XOR
|
||||||
if (MWFNode.SPLITELEMENT_XOR.equals(split))
|
if (MWFNode.SPLITELEMENT_XOR.equals(split))
|
||||||
|
|
Loading…
Reference in New Issue