Java Code Examples for org.mvel2.MVEL#eval()
The following examples show how to use
org.mvel2.MVEL#eval() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SurveyPage.java From JDeSurvey with GNU Affero General Public License v3.0 | 6 votes |
public Boolean getSatisfiesConditions(PageLogic pageLogic,String dateFormat) { try { Map map = new HashMap(); map.put("page", this); String mvelExpression = computeMvelExpression(pageLogic,dateFormat); System.out.println("---------------------------"); System.out.println(mvelExpression); System.out.println("---------------------------"); Boolean satisfied = (Boolean) MVEL.eval(mvelExpression, map); if (satisfied !=null) { return satisfied; } return false; } catch (Exception e) { throw (new RuntimeException(e)); } }
Example 2
Source File: RawMVELEvaluator.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Override public <T> T eval(final String expression, final Class<T> toType) { return MVEL.eval(expression, toType); }
Example 3
Source File: RawMVELEvaluator.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public <T> T eval(final String expression, final VariableResolverFactory vars, final Class<T> toType) { return MVEL.eval(expression, vars, toType); }
Example 4
Source File: ClassTests.java From javatech with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
@Test public void testEval() { String expression = "foobar > 99"; Map vars = new HashMap(); vars.put("foobar", new Integer(100)); Boolean result = (Boolean) MVEL.eval(expression, vars); Assertions.assertEquals(true, result); }
Example 5
Source File: MvelRule.java From javatech with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
/** * 判断条件是否匹配 */ @Override public boolean evaluate(RuleContext ruleContext) { try { return (Boolean) MVEL.eval(getCondition(), ruleContext); } catch (Exception e) { throw new RuntimeException(String.format("条件[%s]匹配发生异常:", getCondition()), e); } }
Example 6
Source File: RawMVELEvaluator.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public <T> T eval(final String expression, final Object ctx, final VariableResolverFactory vars, final Class<T> toType) { return MVEL.eval(expression, ctx, vars, toType); }
Example 7
Source File: ELFunction.java From baymax with Apache License 2.0 | 5 votes |
public Integer execute(String columnValue, Map<String, Object> extension) { Map<String, Object> vrs = new HashMap<String, Object>(); //, Map<String, ElFunction<?,?>> functionMap //vrs.putAll(functionMap);// 拓展函数 Map<String, Object> params = new HashMap<String, Object>(); params.put("value", columnValue); vrs.put("$ROOT", params); VariableResolverFactory vrfactory = new MapVariableResolverFactory(vrs); return MVEL.eval(expression, params, vrfactory, Integer.class); }
Example 8
Source File: MvelEL.java From osmanthus with Apache License 2.0 | 5 votes |
@Override public Object executeStrExp(String strExp, Event event) { Object obj = MVEL.eval(strExp, event.getVariables()); logger.info("{}, expression[{}], its result is [{}]", event.getId(), strExp, obj); return obj; }
Example 9
Source File: ParseHelper.java From zealot with Apache License 2.0 | 5 votes |
/** * 通过MVEL来解析表达式的值,如果出错则抛出异常. * @param exp 待解析表达式 * @param paramObj 参数对象 * @return 返回解析后的值 */ public static Object parseExpressWithException(String exp, Object paramObj) { Object obj; try { obj = MVEL.eval(exp, paramObj); } catch (Exception e) { throw new ParseExpressionException("解析Mvel表达式异常,解析出错的表达式为:" + exp, e); } return obj; }
Example 10
Source File: ParseHelper.java From zealot with Apache License 2.0 | 5 votes |
/** * 通过MVEL来解析表达式的值,如果出错不抛出异常. * @param exp 待解析表达式 * @param paramObj 参数对象 * @return 返回解析后的值 */ public static Object parseExpress(String exp, Object paramObj) { try { return MVEL.eval(exp, paramObj); } catch (Exception e) { log.error("解析表达式出错,表达式为:" + exp, e); return null; } }
Example 11
Source File: ScriptUtils.java From nimble-orm with GNU General Public License v2.0 | 5 votes |
/** * 执行mvel脚本,返回脚本执行返回的值 * @param ignoreScriptError * @param script * @return */ public static Object getValueFromScript(Boolean ignoreScriptError, String script) { try { return MVEL.eval(script); } catch (Throwable e) { LOGGER.error("execute script fail: {}", script, e); if(!ignoreScriptError) { throw new ScriptErrorException(e); } return null; } }
Example 12
Source File: RawMVELEvaluator.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public Object eval(final String expression, final Object ctx, final VariableResolverFactory resolverFactory) { return MVEL.eval(expression, ctx, resolverFactory); }
Example 13
Source File: RawMVELEvaluator.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public Object eval(final String expression, final VariableResolverFactory resolverFactory) { return MVEL.eval(expression, resolverFactory); }
Example 14
Source File: RawMVELEvaluator.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public Object eval(final String expression, final Object ctx) { return MVEL.eval(expression, ctx); }
Example 15
Source File: BasePremiumCalculationRule.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
boolean applies(Calculation calculation) { return applyIfFormula == null || applyIfFormula.isEmpty() ? true : MVEL.eval(applyIfFormula, calculation.toMap(), Boolean.class); }
Example 16
Source File: BasePremiumCalculationRule.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
BigDecimal calculateBasePrice(Calculation calculation) { return MVEL.eval(basePriceFormula, calculation.toMap(), BigDecimal.class); }
Example 17
Source File: DiscountMarkupRule.java From micronaut-microservices-poc with Apache License 2.0 | 4 votes |
boolean applies(Calculation calculation) { return applyIfFormula == null || applyIfFormula.isEmpty() ? true : MVEL.eval(applyIfFormula, calculation.toMap(), Boolean.class); }
Example 18
Source File: CommonActions.java From sailfish-core with Apache License 2.0 | 4 votes |
/** * Check message tags with mvel expressions * * @param actionContext - an implementation of {@link IActionContext} * @param filterData - hash map of mvel expressions against it is required to check message <br /> * @throws Exception - throws an exception */ @Description( "Check message tags with mvel expressions.<br>" + "For every field that contains value this action " + "will try to evaluate that value and return boolean result.<br>" + "Logical and equality operators are following:<br>" + "'==' Equal to<br>" + "'!=' Not equal to<br>" + "'>' Greater than<br>" + "'>=' Greater than or equal to<br>" + "'<' Less than<br>" + "'<=' Less than or equal to<br>" + "'&&' AND<br>" + "'||' OR<br>" + "'^' exclusive OR<br>" + "Example: ${Logon1.HeartBtInt} + \" != 10 && \" + ${Logon1.HeartBtInt} + \" < 1000 && \" + ${Logon1.HeartBtInt} + \" > 200\"" ) @ActionMethod public void CheckMessage(IActionContext actionContext, HashMap<?, ?> filterData) throws Exception { ComparisonResult compResult = new ComparisonResult("CheckMessage"); compResult.setStatus(StatusType.PASSED); Exception problem = null; for(Entry<?, ?> entry : filterData.entrySet()) { ComparisonResult curResult = new ComparisonResult(entry.getKey().toString()); Object value = unwrapFilters(entry.getValue()); curResult.setExpected("True"); curResult.setActual(value); try { Boolean result = (Boolean)MVEL.eval(value.toString()); if(result) { curResult.setStatus(StatusType.PASSED); } else { curResult.setStatus(StatusType.FAILED); compResult.setStatus(StatusType.FAILED); } } catch ( Exception e ) { curResult.setStatus(StatusType.FAILED); compResult.setStatus(StatusType.FAILED); problem = e; actionContext.getLogger().error("CheckMessage problem", e); } compResult.addResult(curResult); } boolean addToReport = actionContext.isAddToReport(); if (addToReport) { int countPassed = ComparisonUtil.getResultCount(compResult, StatusType.PASSED); countPassed += ComparisonUtil.getResultCount(compResult, StatusType.CONDITIONALLY_PASSED); int countFailed = ComparisonUtil.getResultCount(compResult, StatusType.FAILED); countFailed += ComparisonUtil.getResultCount(compResult, StatusType.CONDITIONALLY_FAILED); int countNA = ComparisonUtil.getResultCount(compResult, StatusType.NA); IActionReport report = actionContext.getReport(); report.createVerification(compResult.getStatus(), "CheckMessage. Failed/Passed/NA: " + countFailed + "/" + countPassed + "/" + countNA, "", "", compResult, problem); if ( compResult.getStatus() == StatusType.FAILED) { throw new EPSCommonException("Verification failed"); } } }
Example 19
Source File: JBRULESTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Test public void testJBRULES3111() { final String str = "package org.drools.compiler\n" + "declare Bool123\n" + " bool1 : boolean\n" + " bool2 : boolean\n" + " bool3 : boolean\n" + "end\n" + "declare Thing\n" + " name : String\n" + " bool123 : Bool123\n" + "end\n" + "rule kickOff\n" + "when\n" + "then\n" + " insert( new Thing( \"one\", new Bool123( true, false, false ) ) );\n" + " insert( new Thing( \"two\", new Bool123( false, false, false ) ) );\n" + " insert( new Thing( \"three\", new Bool123( false, false, false ) ) );\n" + "end\n" + "rule r1\n" + "when\n" + " $t: Thing( bool123.bool1 == true )\n" + "then\n" + "end\n" + "rule r2\n" + "when\n" + " $t: Thing( bool123.bool2 == true )\n" + "then\n" + "end\n" + "rule r3\n" + "when\n" + " $t: Thing( bool123.bool3 == true )\n" + "then\n" + "end"; final KieBase kbase = loadKnowledgeBaseFromString(str); final KieSession ksession = createKnowledgeSession(kbase); final org.kie.api.event.rule.AgendaEventListener ael = mock(org.kie.api.event.rule.AgendaEventListener.class); ksession.addEventListener(ael); final int rulesFired = ksession.fireAllRules(); assertEquals(2, rulesFired); final ArgumentCaptor<AfterMatchFiredEvent> captor = ArgumentCaptor.forClass(org.kie.api.event.rule.AfterMatchFiredEvent.class); verify(ael, times(2)).afterMatchFired(captor.capture()); final List<org.kie.api.event.rule.AfterMatchFiredEvent> aafe = captor.getAllValues(); assertThat(aafe.get(0).getMatch().getRule().getName()).isEqualTo("kickOff"); assertThat(aafe.get(1).getMatch().getRule().getName()).isEqualTo("r1"); final Object value = aafe.get(1).getMatch().getDeclarationValue("$t"); final String name = (String) MVEL.eval("$t.name", Collections.singletonMap("$t", value)); assertThat(name).isEqualTo("one"); }
Example 20
Source File: MvelUtils.java From bulbasaur with Apache License 2.0 | 2 votes |
/** * 脚本和上下文对比。eg:脚本里面 goto==2 ,上下文里面 map("goto",2) * * @return void * @author: [email protected] * @since 2012-12-13 下午02:15:49 */ public static Object eval(String script, Map<String, Object> context) { return MVEL.eval(script, context); }