- add debug message for workflow related exceptions
This commit is contained in:
Heng Sin Low 2009-11-03 08:25:30 +00:00
parent 5eaa185cc3
commit bc5972eea6
3 changed files with 96 additions and 6 deletions

View File

@ -22,6 +22,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.logging.Level;
import javax.script.ScriptEngine;
@ -386,11 +387,19 @@ public class ModelValidationEngine
{
String error = validator.modelChange(po, changeType);
if (error != null && error.length() > 0)
{
if (log.isLoggable(Level.FINE))
{
log.log(Level.FINE, "po="+po+" validator="+validator+" changeType="+changeType);
}
return error;
}
}
}
catch (Exception e)
{
//log the exception
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
String error = e.getLocalizedMessage();
if (error == null)
error = e.toString();
@ -533,13 +542,20 @@ public class ModelValidationEngine
{
String error = validator.docValidate(po, docTiming);
if (error != null && error.length() > 0)
{
if (log.isLoggable(Level.FINE))
{
log.log(Level.FINE, "po="+po+" validator="+validator+" timing="+docTiming);
}
return error;
}
}
}
catch (Exception e)
{
//log the stack trace
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
// Exeptions are errors and should stop the document processing - teo_sarca [ 1679692 ]
// log.log(Level.SEVERE, validator.toString(), e);
String error = e.getLocalizedMessage();
if (error == null)
error = e.toString();
@ -666,13 +682,20 @@ public class ModelValidationEngine
{
String error = validator.factsValidate(schema, facts, po);
if (error != null && error.length() > 0)
{
if (log.isLoggable(Level.FINE))
{
log.log(Level.FINE, "po="+po+" schema="+schema+" validator="+validator);
}
return error;
}
}
}
catch (Exception e)
{
// Exeptions are errors and should stop the document processing - teo_sarca [ 1679692 ]
// log.log(Level.SEVERE, validator.toString(), e);
//log the stack trace
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
// Exeptions are errors and should stop the document processing - teo_sarca [ 1679692 ]
String error = e.getLocalizedMessage();
if (error == null)
error = e.toString();

View File

@ -542,17 +542,25 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
if (obj == null)
return;
//
StringBuffer TextMsg = new StringBuffer (obj.toString());
StringBuffer TextMsg = new StringBuffer ();
if (obj instanceof Exception)
{
Exception ex = (Exception)obj;
if (ex.getMessage() != null && ex.getMessage().trim().length() > 0)
{
TextMsg.append(ex.toString());
}
else if (ex instanceof NullPointerException)
{
TextMsg.append(ex.getClass().getName());
}
while (ex != null)
{
StackTraceElement[] st = ex.getStackTrace();
for (int i = 0; i < st.length; i++)
{
StackTraceElement ste = st[i];
if (i == 0 || ste.getClassName().startsWith("org.compiere"))
if (i == 0 || ste.getClassName().startsWith("org.compiere") || ste.getClassName().startsWith("org.adempiere"))
TextMsg.append(" (").append(i).append("): ")
.append(ste.toString())
.append("\n");
@ -563,6 +571,10 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
ex = null;
}
}
else
{
TextMsg.append(obj.toString());
}
//
String oldText = getTextMsg();
if (oldText == null || oldText.length() == 0)
@ -759,6 +771,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
if (!m_state.isValidAction(StateEngine.ACTION_Start))
{
setTextMsg("State=" + getWFState() + " - cannot start");
addTextMsg(new Exception(""));
setWFState(StateEngine.STATE_Terminated);
return;
}
@ -1283,6 +1296,7 @@ public class MWFActivity extends X_AD_WF_Activity implements Runnable
{
newState = StateEngine.STATE_Terminated;
setTextMsg ("User Choice: " + e.toString());
addTextMsg(e);
log.log(Level.WARNING, "", e);
}
// Send Approval Notification

View File

@ -33,6 +33,7 @@ import org.compiere.process.StateEngine;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.TimeUtil;
import org.compiere.util.Util;
/**
@ -110,6 +111,7 @@ public class MWFProcess extends X_AD_WF_Process
if (getPO() == null)
{
setTextMsg("No PO with ID=" + pi.getRecord_ID());
addTextMsg(new Exception(""));
super.setWFState (WFSTATE_Terminated);
}
else
@ -310,6 +312,7 @@ public class MWFProcess extends X_AD_WF_Process
if (activities.length == 0)
{
setTextMsg("No Active Processed found");
addTextMsg(new Exception(""));
closedState = WFSTATE_Terminated;
}
if (closedState != null)
@ -503,6 +506,7 @@ public class MWFProcess extends X_AD_WF_Process
{
log.log(Level.SEVERE, "AD_WF_Node_ID=" + AD_WF_Node_ID, e);
setTextMsg(e.toString());
addTextMsg(e);
setWFState(StateEngine.STATE_Terminated);
return false;
}
@ -549,7 +553,56 @@ public class MWFProcess extends X_AD_WF_Process
super.setTextMsg (oldText + "\n - " + TextMsg);
} // setTextMsg
/**
* Add to Text Msg
* @param obj some object
*/
public void addTextMsg (Object obj)
{
if (obj == null)
return;
//
StringBuffer TextMsg = new StringBuffer ();
if (obj instanceof Exception)
{
Exception ex = (Exception)obj;
if (ex.getMessage() != null && ex.getMessage().trim().length() > 0)
{
TextMsg.append(ex.toString());
}
else if (ex instanceof NullPointerException)
{
TextMsg.append(ex.getClass().getName());
}
while (ex != null)
{
StackTraceElement[] st = ex.getStackTrace();
for (int i = 0; i < st.length; i++)
{
StackTraceElement ste = st[i];
if (i == 0 || ste.getClassName().startsWith("org.compiere") || ste.getClassName().startsWith("org.adempiere"))
TextMsg.append(" (").append(i).append("): ")
.append(ste.toString())
.append("\n");
}
if (ex.getCause() instanceof Exception)
ex = (Exception)ex.getCause();
else
ex = null;
}
}
else
{
TextMsg.append(obj.toString());
}
//
String oldText = getTextMsg();
if (oldText == null || oldText.length() == 0)
super.setTextMsg(Util.trimSize(TextMsg.toString(),1000));
else if (TextMsg != null && TextMsg.length() > 0)
super.setTextMsg(Util.trimSize(oldText + "\n - " + TextMsg.toString(),1000));
} // addTextMsg
/**
* Set Runtime (Error) Message
* @param msg message