use of com.googlecode.aviator.exception.ExpressionRuntimeException in project aviatorscript by killme2008.
the class StringReplaceAllFunction method call.
@Override
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2, AviatorObject arg3) {
String target = FunctionUtils.getStringValue(arg1, env);
if (target == null)
throw new ExpressionRuntimeException("Could not replace with null string");
String regex = FunctionUtils.getStringValue(arg2, env);
String replacement = FunctionUtils.getStringValue(arg3, env);
return new AviatorString(target.replaceAll(regex, replacement));
}
use of com.googlecode.aviator.exception.ExpressionRuntimeException in project aviatorscript by killme2008.
the class AviatorJavaTypeUnitTest method testNot.
@Test
public void testNot() {
AviatorJavaType intType = new AviatorJavaType("intType");
AviatorJavaType boolType = new AviatorJavaType("boolType");
AviatorJavaType stringType = new AviatorJavaType("stringType");
AviatorJavaType charType = new AviatorJavaType("charType");
AviatorJavaType dateType = new AviatorJavaType("dateType");
Map<String, Object> env = new HashMap<String, Object>();
env.put("intType", 3);
env.put("boolType", Boolean.FALSE);
env.put("stringType", "hello");
env.put("charType", 'c');
env.put("dateType", new Date());
assertEquals(Boolean.TRUE, boolType.not(env).getValue(env));
try {
intType.not(env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
stringType.not(env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
charType.not(env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
dateType.not(env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
}
use of com.googlecode.aviator.exception.ExpressionRuntimeException in project aviatorscript by killme2008.
the class AviatorJavaTypeUnitTest method compareWithJavaType.
@Test
public void compareWithJavaType() {
AviatorJavaType intType = new AviatorJavaType("intType");
AviatorJavaType boolType = new AviatorJavaType("boolType");
AviatorJavaType stringType = new AviatorJavaType("stringType");
AviatorJavaType charType = new AviatorJavaType("charType");
AviatorJavaType dateType = new AviatorJavaType("dateType");
Map<String, Object> env = new HashMap<String, Object>();
env.put("intType", 3);
env.put("boolType", Boolean.FALSE);
env.put("stringType", "hello");
env.put("charType", 'c');
env.put("dateType", new Date());
assertEquals(0, intType.innerCompare(intType, env));
assertEquals(1, intType.innerCompare(new AviatorJavaType("unknow"), env));
try {
intType.innerCompare(boolType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
intType.innerCompare(stringType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
intType.innerCompare(charType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
intType.innerCompare(dateType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
boolType.innerCompare(intType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
assertEquals(0, boolType.innerCompare(boolType, env));
try {
boolType.innerCompare(stringType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
boolType.innerCompare(charType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
boolType.innerCompare(dateType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
stringType.innerCompare(intType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
stringType.innerCompare(boolType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
assertEquals(0, stringType.innerCompare(stringType, env));
try {
stringType.innerCompare(dateType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
assertTrue(stringType.innerCompare(charType, env) > 0);
try {
charType.innerCompare(intType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
charType.innerCompare(boolType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
assertTrue(charType.innerCompare(stringType, env) < 0);
assertEquals(0, charType.innerCompare(charType, env));
try {
charType.innerCompare(dateType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
dateType.innerCompare(intType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
dateType.innerCompare(boolType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
dateType.innerCompare(stringType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
try {
dateType.innerCompare(charType, env);
Assert.fail();
} catch (ExpressionRuntimeException e) {
}
assertEquals(0, dateType.innerCompare(dateType, env));
}
use of com.googlecode.aviator.exception.ExpressionRuntimeException in project rebuild by getrebuild.
the class RobotTriggerObserver method execAction.
/**
* 执行触发内容
*
* @param context
* @param when
*/
protected void execAction(OperatingContext context, TriggerWhen when) {
final ID primaryId = context.getAnyRecord().getPrimary();
final String sourceName = primaryId + ":" + when.name().charAt(0);
TriggerAction[] beExecuted = when == TriggerWhen.DELETE ? DELETE_ACTION_HOLDS.get(primaryId) : RobotTriggerManager.instance.getActions(getEffectedId(context), when);
if (beExecuted == null || beExecuted.length == 0) {
return;
}
final boolean originTriggerSource = getTriggerSource() == null;
// 设置原始触发源
if (originTriggerSource) {
TRIGGER_SOURCE.set(context);
} else {
// 自己触发自己,避免无限执行
boolean x = primaryId.equals(getTriggerSource().getAnyRecord().getPrimary());
boolean xor = x || sourceName.equals(TRIGGER_SOURCE_LAST.get());
if (x || xor) {
if (Application.devMode())
log.warn("Self trigger, ignore : {}", sourceName);
return;
}
}
TRIGGER_SOURCE_LAST.set(sourceName);
try {
for (TriggerAction action : beExecuted) {
log.info("Trigger [ {} ] executing on record ({}) : {}", action.getType(), when.name(), primaryId);
try {
action.execute(context);
CommonsLog.createLog(TYPE_TRIGGER, context.getOperator(), action.getActionContext().getConfigId());
} catch (Throwable ex) {
// DataValidate 直接抛出
if (ex instanceof DataValidateException)
throw ex;
log.error("Trigger execution failed : {} << {}", action, context, ex);
CommonsLog.createLog(TYPE_TRIGGER, context.getOperator(), action.getActionContext().getConfigId(), ex);
// FIXME 触发器执行失败是否抛出
if (ex instanceof MissingMetaExcetion || ex instanceof ExpressionRuntimeException || ex instanceof RepeatedRecordsException) {
throw new TriggerException(Language.L("触发器执行失败 : %s", ex.getLocalizedMessage()));
} else if (ex instanceof TriggerException) {
throw (TriggerException) ex;
} else {
throw new RebuildException(ex);
}
} finally {
if (originTriggerSource) {
action.clean();
}
}
}
} finally {
if (originTriggerSource) {
TRIGGER_SOURCE.remove();
TRIGGER_SOURCE_LAST.remove();
}
}
}
use of com.googlecode.aviator.exception.ExpressionRuntimeException in project aviatorscript by killme2008.
the class String2DateFunction method call.
@Override
public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
String source = FunctionUtils.getStringValue(arg1, env);
String format = FunctionUtils.getStringValue(arg2, env);
SimpleDateFormat dateFormat = DateFormatCache.getOrCreateDateFormat(format);
try {
return AviatorRuntimeJavaType.valueOf(dateFormat.parse(source));
} catch (ParseException e) {
throw new ExpressionRuntimeException("Cast string to date failed", e);
}
}
Aggregations