IDEMPIERE-2756 Background threads losing context when user log out - fix validation / integrate fix from hengsin: Improve handling of context lost ( due to user close browser ) exception for document workflow.

This commit is contained in:
Carlos Ruiz 2015-10-14 20:29:42 -05:00
parent 6522a64289
commit 8e193dad3d
2 changed files with 43 additions and 18 deletions

View File

@ -916,19 +916,41 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
processMsg = e.getMessage(); processMsg = e.getMessage();
setTextMsg(processMsg); setTextMsg(processMsg);
// addTextMsg(e); // do not add the exception text // addTextMsg(e); // do not add the exception text
setWFState (StateEngine.STATE_Terminated); // unlocks boolean contextLost = false;
// Set Document Status if (e instanceof AdempiereException && "Context lost".equals(e.getMessage()))
if (m_po != null && m_po instanceof DocAction && m_docStatus != null)
{ {
m_po.load(get_TrxName()); contextLost = true;
DocAction doc = (DocAction)m_po; m_docStatus = DocAction.STATUS_Invalid;
doc.setDocStatus(m_docStatus); }
m_po.saveEx(); try {
} if (contextLost)
if (m_process != null) {
{ Env.getCtx().setProperty("#AD_Client_ID", (m_po != null ? Integer.toString(m_po.getAD_Client_ID()) : "0") );
m_process.setProcessMsg(this.getTextMsg()); m_state = new StateEngine(WFSTATE_Running);
m_process.saveEx(); setProcessed(true);
setWFState (StateEngine.STATE_Aborted);
}
else
{
setWFState (StateEngine.STATE_Terminated); // unlocks
}
// Set Document Status
if (m_po != null && m_po instanceof DocAction && m_docStatus != null)
{
m_po.load(get_TrxName());
DocAction doc = (DocAction)m_po;
doc.setDocStatus(m_docStatus);
m_po.saveEx();
}
if (m_process != null)
{
m_process.setProcessMsg(this.getTextMsg());
m_process.saveEx();
}
} finally {
if (contextLost)
Env.getCtx().remove("#AD_Client_ID");
} }
} }
finally finally

View File

@ -462,13 +462,16 @@ public abstract class AbstractProcessDialog extends Window implements IProcessUI
if (Executions.getCurrent() == null) if (Executions.getCurrent() == null)
{ {
Executions.schedule(getDesktop(), new EventListener<Event>() if (getDesktop() != null)
{ {
@Override Executions.schedule(getDesktop(), new EventListener<Event>()
public void onEvent(Event event) throws Exception { {
doUnlockUI(); @Override
} public void onEvent(Event event) throws Exception {
}, new Event("onUnLockUI")); doUnlockUI();
}
}, new Event("onUnLockUI"));
}
} else { } else {
doUnlockUI(); doUnlockUI();
} }