From 20b1cb08fadb8e42c59fd2977f467cb6652989ab Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Mon, 26 Sep 2011 10:41:31 -0500 Subject: [PATCH] Fix IDEMPIERE-73 Workflow Node with Action = Wait/Sleep does not wait for entered Wait Time --- .../oracle/807_EnableWorkflowProcessClient.sql | 9 +++++++++ .../postgresql/807_EnableWorkflowProcessClient.sql | 9 +++++++++ .../src/org/compiere/process/StateEngine.java | 2 +- .../src/org/compiere/wf/MWFActivity.java | 12 ++++++------ .../src/org/compiere/wf/MWFProcess.java | 5 +++-- .../org/compiere/server/WorkflowProcessor.java | 10 ++++------ 6 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 migration/360lts-release/oracle/807_EnableWorkflowProcessClient.sql create mode 100644 migration/360lts-release/postgresql/807_EnableWorkflowProcessClient.sql diff --git a/migration/360lts-release/oracle/807_EnableWorkflowProcessClient.sql b/migration/360lts-release/oracle/807_EnableWorkflowProcessClient.sql new file mode 100644 index 0000000000..3ae9d52f4d --- /dev/null +++ b/migration/360lts-release/oracle/807_EnableWorkflowProcessClient.sql @@ -0,0 +1,9 @@ +-- Sep 25, 2011 10:42:55 AM COT +-- IDEMPIERE-73 Enable Workflow Process window for Client +UPDATE AD_Table SET AccessLevel='6',Updated=TO_DATE('2011-09-25 10:42:55','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=697 +; + +-- Sep 25, 2011 10:43:00 AM COT +UPDATE AD_Table SET AccessLevel='6',Updated=TO_DATE('2011-09-25 10:43:00','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=696 +; + diff --git a/migration/360lts-release/postgresql/807_EnableWorkflowProcessClient.sql b/migration/360lts-release/postgresql/807_EnableWorkflowProcessClient.sql new file mode 100644 index 0000000000..b444cfc796 --- /dev/null +++ b/migration/360lts-release/postgresql/807_EnableWorkflowProcessClient.sql @@ -0,0 +1,9 @@ +-- Sep 25, 2011 10:42:55 AM COT +-- IDEMPIERE-73 Enable Workflow Process window for Client +UPDATE AD_Table SET AccessLevel='6',Updated=TO_TIMESTAMP('2011-09-25 10:42:55','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=697 +; + +-- Sep 25, 2011 10:43:00 AM COT +UPDATE AD_Table SET AccessLevel='6',Updated=TO_TIMESTAMP('2011-09-25 10:43:00','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Table_ID=696 +; + diff --git a/org.adempiere.base/src/org/compiere/process/StateEngine.java b/org.adempiere.base/src/org/compiere/process/StateEngine.java index 4c07013a9a..cc6e94505d 100644 --- a/org.adempiere.base/src/org/compiere/process/StateEngine.java +++ b/org.adempiere.base/src/org/compiere/process/StateEngine.java @@ -365,7 +365,7 @@ public class StateEngine if (isRunning()) return new String[] {STATE_Suspended, STATE_Completed, STATE_Aborted, STATE_Terminated}; if (isSuspended()) - return new String[] {STATE_Running, STATE_Aborted, STATE_Terminated}; + return new String[] {STATE_Running, STATE_Aborted, STATE_Terminated, STATE_Completed}; // return new String[] {}; } // getNewStateOptions diff --git a/org.adempiere.base/src/org/compiere/wf/MWFActivity.java b/org.adempiere.base/src/org/compiere/wf/MWFActivity.java index afa7eb058b..ecb04c4660 100644 --- a/org.adempiere.base/src/org/compiere/wf/MWFActivity.java +++ b/org.adempiere.base/src/org/compiere/wf/MWFActivity.java @@ -192,7 +192,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable setEndWaitTime(new Timestamp(limitMS + System.currentTimeMillis())); // Responsible setResponsible(process); - save(); + saveEx(); // m_audit = new MWFEventAudit(this); m_audit.saveEx(); @@ -266,7 +266,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable log.fine(oldState + "->"+ WFState + ", Msg=" + getTextMsg()); super.setWFState (WFState); m_state = new StateEngine (getWFState()); - save(); // closed in MWFProcess.checkActivities() + saveEx(); // closed in MWFProcess.checkActivities() updateEventAudit(); // Inform Process @@ -282,7 +282,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable log.log(Level.SEVERE, msg); Trace.printStack(); setTextMsg(msg); - save(); + saveEx(); // TODO: teo_sarca: throw exception ? please analyze the call hierarchy first } } // setWFState @@ -958,10 +958,10 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable if (MWFNode.ACTION_WaitSleep.equals(action)) { log.fine("Sleep:WaitTime=" + m_node.getWaitTime()); - if (m_node.getWaitingTime() == 0) + if (m_node.getWaitTime() == 0) // IDEMPIERE-73 Carlos Ruiz - globalqss return true; // done Calendar cal = Calendar.getInstance(); - cal.add(m_node.getDurationCalendarField(), m_node.getWaitTime()); + cal.add(Calendar.MINUTE, m_node.getWaitTime()); setEndWaitTime(new Timestamp(cal.getTimeInMillis())); return false; // not done } @@ -1434,7 +1434,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable // Update setAD_User_ID (user.getAD_User_ID()); setTextMsg(textMsg); - save(); + saveEx(); // Close up Old Event getEventAudit(); m_audit.setAD_User_ID(oldUser.getAD_User_ID()); diff --git a/org.adempiere.base/src/org/compiere/wf/MWFProcess.java b/org.adempiere.base/src/org/compiere/wf/MWFProcess.java index f4b75d2205..500ffe95ac 100644 --- a/org.adempiere.base/src/org/compiere/wf/MWFProcess.java +++ b/org.adempiere.base/src/org/compiere/wf/MWFProcess.java @@ -47,7 +47,7 @@ public class MWFProcess extends X_AD_WF_Process /** * */ - private static final long serialVersionUID = -8992222567597358696L; + private static final long serialVersionUID = -4447369291008183913L; /** * Standard Constructor @@ -256,6 +256,7 @@ public class MWFProcess extends X_AD_WF_Process */ public void checkActivities(String trxName, PO lastPO) { + this.set_TrxName(trxName); // ensure process is working on the same transaction log.info("(" + getAD_Workflow_ID() + ") - " + getWFState() + (trxName == null ? "" : "[" + trxName + "]")); if (m_state.isClosed()) @@ -319,7 +320,7 @@ public class MWFProcess extends X_AD_WF_Process { setWFState(closedState); getPO(); - //hengsin: remmove lock/unlock in workflow which is causing deadlock in many place + //hengsin: remove lock/unlock in workflow which is causing deadlock in many place //if (m_po != null) //m_po.unlock(null); } diff --git a/org.adempiere.server/src/main/server/org/compiere/server/WorkflowProcessor.java b/org.adempiere.server/src/main/server/org/compiere/server/WorkflowProcessor.java index 605e5dd03a..77b3b187ec 100644 --- a/org.adempiere.server/src/main/server/org/compiere/server/WorkflowProcessor.java +++ b/org.adempiere.server/src/main/server/org/compiere/server/WorkflowProcessor.java @@ -55,7 +55,7 @@ public class WorkflowProcessor extends AdempiereServer */ public WorkflowProcessor (MWorkflowProcessor model) { - super (model, 120); // 2 minute dalay + super (model, 120); // 2 minute delay m_model = model; m_client = MClient.get(model.getCtx(), model.getAD_Client_ID()); } // WorkflowProcessor @@ -95,7 +95,7 @@ public class WorkflowProcessor extends AdempiereServer String sql = "SELECT * " + "FROM AD_WF_Activity a " + "WHERE Processed='N' AND WFState='OS'" // suspended - + " AND EndWaitTime > SysDate" + + " AND EndWaitTime <= SysDate" + " AND AD_Client_ID=?" + " AND EXISTS (SELECT * FROM AD_Workflow wf " + " INNER JOIN AD_WF_Node wfn ON (wf.AD_Workflow_ID=wfn.AD_Workflow_ID) " @@ -104,7 +104,6 @@ public class WorkflowProcessor extends AdempiereServer + " AND (wf.AD_WorkflowProcessor_ID IS NULL OR wf.AD_WorkflowProcessor_ID=?))"; PreparedStatement pstmt = null; int count = 0; - int countEMails = 0; try { pstmt = DB.prepareStatement (sql, null); @@ -114,11 +113,11 @@ public class WorkflowProcessor extends AdempiereServer while (rs.next ()) { MWFActivity activity = new MWFActivity (getCtx(), rs, null); - activity.setWFState (StateEngine.STATE_Completed); + activity.setWFState (StateEngine.STATE_Completed); // saves and calls MWFProcess.checkActivities(); count++; } - rs.close (); + rs.close (); } catch (Exception e) { @@ -146,7 +145,6 @@ public class WorkflowProcessor extends AdempiereServer + " 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);