[ 1879395 ] Implement Process script JSR 223
- Implement G_, W_, A_ and P_ prefix for variables.
This commit is contained in:
parent
5fc29bd7ad
commit
17321afafb
|
@ -155,22 +155,22 @@ public final class ProcessUtil {
|
|||
|
||||
ScriptEngine engine = rule.getScriptEngine();
|
||||
|
||||
// Window context are _
|
||||
// Login context are __
|
||||
// Parameter context are ___
|
||||
// Window context are W_
|
||||
// Login context are G_
|
||||
// Method arguments context are A_
|
||||
// Parameter context are P_
|
||||
MRule.setContext(engine, ctx, 0); // no window
|
||||
// now add the process parameters to the engine
|
||||
// Parameter context are ___
|
||||
engine.put("$$$Ctx", ctx);
|
||||
// now add the method arguments to the engine
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "Ctx", ctx);
|
||||
if (trx == null)
|
||||
trx = Trx.get(pi.getTitle()+"_"+pi.getAD_PInstance_ID(), true);
|
||||
engine.put("$$$Trx", trx);
|
||||
engine.put("$$$TrxName", trx.getTrxName());
|
||||
engine.put("$$$Record_ID", pi.getRecord_ID());
|
||||
engine.put("$$$AD_Client_ID", pi.getAD_Client_ID());
|
||||
engine.put("$$$AD_User_ID", pi.getAD_User_ID());
|
||||
engine.put("$$$AD_PInstance_ID", pi.getAD_PInstance_ID());
|
||||
engine.put("$$$Table_ID", pi.getTable_ID());
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "Trx", trx);
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "TrxName", trx.getTrxName());
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "Record_ID", pi.getRecord_ID());
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "AD_Client_ID", pi.getAD_Client_ID());
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "AD_User_ID", pi.getAD_User_ID());
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "AD_PInstance_ID", pi.getAD_PInstance_ID());
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "Table_ID", pi.getTable_ID());
|
||||
// Add process parameters
|
||||
ProcessInfoParameter[] para = pi.getParameter();
|
||||
if (para == null) {
|
||||
|
@ -178,31 +178,31 @@ public final class ProcessUtil {
|
|||
para = pi.getParameter();
|
||||
}
|
||||
if (para != null) {
|
||||
engine.put("$$$Parameter", pi.getParameter());
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "Parameter", pi.getParameter());
|
||||
for (int i = 0; i < para.length; i++)
|
||||
{
|
||||
String name = para[i].getParameterName();
|
||||
if (para[i].getParameter_To() == null) {
|
||||
Object value = para[i].getParameter();
|
||||
if (name.endsWith("_ID") && (value instanceof BigDecimal))
|
||||
engine.put("$$$" + name, ((BigDecimal)value).intValue());
|
||||
engine.put(MRule.PARAMETERS_PREFIX + name, ((BigDecimal)value).intValue());
|
||||
else
|
||||
engine.put("$$$" + name, value);
|
||||
engine.put(MRule.PARAMETERS_PREFIX + name, value);
|
||||
} else {
|
||||
Object value1 = para[i].getParameter();
|
||||
Object value2 = para[i].getParameter_To();
|
||||
if (name.endsWith("_ID") && (value1 instanceof BigDecimal))
|
||||
engine.put("$$$" + name + "1", ((BigDecimal)value1).intValue());
|
||||
engine.put(MRule.PARAMETERS_PREFIX + name + "1", ((BigDecimal)value1).intValue());
|
||||
else
|
||||
engine.put("$$$" + name + "1", value1);
|
||||
engine.put(MRule.PARAMETERS_PREFIX + name + "1", value1);
|
||||
if (name.endsWith("_ID") && (value2 instanceof BigDecimal))
|
||||
engine.put("$$$" + name + "2", ((BigDecimal)value2).intValue());
|
||||
engine.put(MRule.PARAMETERS_PREFIX + name + "2", ((BigDecimal)value2).intValue());
|
||||
else
|
||||
engine.put("$$$" + name + "2", value2);
|
||||
engine.put(MRule.PARAMETERS_PREFIX + name + "2", value2);
|
||||
}
|
||||
}
|
||||
}
|
||||
engine.put("$$$ProcessInfo", pi);
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "ProcessInfo", pi);
|
||||
|
||||
msg = engine.eval(rule.getScript()).toString();
|
||||
//transaction should rollback if there are error in process
|
||||
|
|
|
@ -2466,16 +2466,17 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
|
|||
|
||||
ScriptEngine engine = rule.getScriptEngine();
|
||||
|
||||
// Window context are _
|
||||
// Login context are __
|
||||
// Window context are W_
|
||||
// Login context are G_
|
||||
MRule.setContext(engine, m_vo.ctx, m_vo.WindowNo);
|
||||
// now add the callout parameters windowNo, tab, field, value, oldValue to the engine
|
||||
// Parameter context are ___
|
||||
engine.put("$$$WindowNo", m_vo.WindowNo);
|
||||
engine.put("$$$Tab", this);
|
||||
engine.put("$$$Field", field);
|
||||
engine.put("$$$Value", value);
|
||||
engine.put("$$$OldValue", oldValue);
|
||||
// Method arguments context are A_
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "WindowNo", m_vo.WindowNo);
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "Tab", this);
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "Field", field);
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "Value", value);
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "OldValue", oldValue);
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "Ctx", m_vo.ctx);
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -33,6 +33,15 @@ import org.compiere.util.*;
|
|||
*/
|
||||
public class MRule extends X_AD_Rule
|
||||
{
|
||||
//global or login context variable prefix
|
||||
public final static String GLOBAL_CONTEXT_PREFIX = "G_";
|
||||
//window context variable prefix
|
||||
public final static String WINDOW_CONTEXT_PREFIX = "W_";
|
||||
//method call arguments prefix
|
||||
public final static String ARGUMENTS_PREFIX = "A_";
|
||||
//process parameters prefix
|
||||
public final static String PARAMETERS_PREFIX = "P_";
|
||||
|
||||
/**
|
||||
* Get Rule from Cache
|
||||
* @param ctx context
|
||||
|
@ -267,13 +276,18 @@ public class MRule extends X_AD_Rule
|
|||
String k = m_windowNo + "|";
|
||||
if (key.startsWith(k))
|
||||
{
|
||||
String retValue = "$" + key.substring(k.length());
|
||||
retValue = Util.replace(retValue, "|", "$");
|
||||
String retValue = WINDOW_CONTEXT_PREFIX + key.substring(k.length());
|
||||
retValue = Util.replace(retValue, "|", "_");
|
||||
return retValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
String retValue = Util.replace(key, "#", "$$");
|
||||
String retValue = null;
|
||||
if (key.startsWith("#"))
|
||||
retValue = GLOBAL_CONTEXT_PREFIX + key.substring(1);
|
||||
else
|
||||
retValue = key;
|
||||
retValue = Util.replace(retValue, "#", "_");
|
||||
return retValue;
|
||||
}
|
||||
} // convertKey
|
||||
|
|
|
@ -206,13 +206,12 @@ public class ModelValidationEngine
|
|||
ScriptEngine engine = loginRule.getScriptEngine();
|
||||
|
||||
MRule.setContext(engine, Env.getCtx(), 0); // no window
|
||||
// now add the process parameters to the engine
|
||||
// Parameter context are ___
|
||||
engine.put("$$$Ctx", Env.getCtx());
|
||||
engine.put("$$$AD_Client_ID", AD_Client_ID);
|
||||
engine.put("$$$AD_Org_ID", AD_Org_ID);
|
||||
engine.put("$$$AD_Role_ID", AD_Role_ID);
|
||||
engine.put("$$$AD_User_ID", AD_User_ID);
|
||||
// now add the method arguments to the engine
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "Ctx", Env.getCtx());
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "AD_Client_ID", AD_Client_ID);
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "AD_Org_ID", AD_Org_ID);
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "AD_Role_ID", AD_Role_ID);
|
||||
engine.put(MRule.ARGUMENTS_PREFIX + "AD_User_ID", AD_User_ID);
|
||||
|
||||
error = engine.eval(loginRule.getScript()).toString();
|
||||
} catch (Exception e) {
|
||||
|
|
Loading…
Reference in New Issue