diff --git a/org.adempiere.base/src/org/compiere/wf/MWFActivity.java b/org.adempiere.base/src/org/compiere/wf/MWFActivity.java index d6d8498d5f..2924a72e26 100644 --- a/org.adempiere.base/src/org/compiere/wf/MWFActivity.java +++ b/org.adempiere.base/src/org/compiere/wf/MWFActivity.java @@ -66,6 +66,7 @@ import org.compiere.util.Env; import org.compiere.util.Msg; import org.compiere.util.Trace; import org.compiere.util.Trx; +import org.compiere.util.TrxEventListener; import org.compiere.util.Util; /** @@ -1007,6 +1008,8 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, m_node.getWaitTime()); setEndWaitTime(new Timestamp(cal.getTimeInMillis())); + if (m_node.getWaitTime() == -1) + prepareCommitEvent(); return false; // not done } @@ -1979,5 +1982,44 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable } return sb.toString(); } // getSummary + + private void prepareCommitEvent() + { + Trx trx = null; + if (get_TrxName() == null) + { + return; // no transaction, nothing to commit + } + MWFActivity activity = new MWFActivity (getCtx(), get_ID(), get_TrxName()); + trx = Trx.get(get_TrxName(), true); + trx.addTrxEventListener(new TrxListener(activity)); + } + + + static class TrxListener implements TrxEventListener { + + private MWFActivity activity; + + protected TrxListener(MWFActivity activity) { + this.activity = activity; + } + + @Override + public void afterRollback(Trx trx, boolean success) { + } + + @Override + public void afterCommit(Trx trx, boolean success) { + if (success) { + trx.removeTrxEventListener(this); + activity.setWFState (StateEngine.STATE_Completed); + } + } + + @Override + public void afterClose(Trx trx) { + trx.removeTrxEventListener(this); + } + } } // MWFActivity