/** * Evaluate the expression against this context if needed * * @param obj * @return the resolved value * @since 9.1 */ public Object resolve(Object obj) { if (!(obj instanceof Expression)) { return obj; } return ((Expression) obj).eval(this); }
@OperationMethod public BlobList run() throws CompileException, RuntimeException { if (expr == null) { String text = script.replaceAll("<", "<"); text = text.replaceAll(">", ">"); text = text.replaceAll("&", "&"); expr = Scripting.newExpression(text); } return (BlobList) expr.eval(ctx); }
@OperationMethod public DocumentModel run() throws CompileException, RuntimeException { if (expr == null) { String text = script.replaceAll("<", "<"); text = text.replaceAll(">", ">"); text = text.replaceAll("&", "&"); expr = Scripting.newExpression(text); } return (DocumentModel) expr.eval(ctx); }
@OperationMethod public Blob run() throws CompileException, RuntimeException { if (expr == null) { String text = script.replaceAll("<", "<"); text = text.replaceAll(">", ">"); text = text.replaceAll("&", "&"); expr = Scripting.newExpression(text); } return (Blob) expr.eval(ctx); }
@OperationMethod public DocumentModelList run() throws CompileException, RuntimeException { if (expr == null) { String text = script.replaceAll("<", "<"); text = text.replaceAll(">", ">"); text = text.replaceAll("&", "&"); expr = Scripting.newExpression(text); } return (DocumentModelList) expr.eval(ctx); }
@OperationMethod public void run() throws CompileException, RuntimeException { if (expr == null) { String text = script.replaceAll("<", "<"); text = text.replaceAll(">", ">"); text = text.replaceAll("&", "&"); expr = Scripting.newExpression(text); } expr.eval(ctx); }
protected void inject(String key, Object value) { if (!(value instanceof Expression)) { parameters.put(key, value); return; } Expression exp = (Expression) value; for (String mvelExpr : MVEL_BLACK_LIST_EXPR) { if (exp.getExpr().contains(mvelExpr)) { parameters.put(key, new ExpressionParameter(key, String.format("Cannot be evaluated in traces when using '%s' expression", mvelExpr))); return; } } try { parameters.put(key, new ExpressionParameter(key, exp.eval(context))); return; } catch (RuntimeException e) { log.warn("Cannot evaluate mvel expression for parameter: " + key, e); } } }
/** * Create a document reference from its path * * @param ctx the operation context * @param value the document path * @return the document reference */ public static DocumentRef createDocumentRef(OperationContext ctx, String value) throws TypeAdaptException { Object obj = createDocumentRefOrExpression(value); if (obj instanceof DocumentRef) { return (DocumentRef) obj; } else if (obj instanceof Expression) { obj = ((Expression) obj).eval(ctx); if (obj instanceof DocumentModel) { return ((DocumentModel) obj).getRef(); } else if (obj instanceof DocumentRef) { return (DocumentRef) obj; } throw new TypeAdaptException(String.format("Cannot adapt value '%s' to a DocumentRef instance", value)); } else { throw new RuntimeException(String.format("Unhandled value: %s", value)); } }
protected <T> T valueOrExpression(Class<T> klass, String v, OperationContext context, String kind) throws DocumentRouteException { if (!v.startsWith(EXPR_PREFIX)) { return (T) v; } v = v.substring(EXPR_PREFIX.length()).trim(); Expression expr; if (v.contains(TEMPLATE_START)) { expr = Scripting.newTemplate(v); } else { expr = Scripting.newExpression(v); } Object res = null; try { res = expr.eval(context); // stupid eval() method throws generic Exception } catch (RuntimeException e) { throw new DocumentRouteException("Error evaluating expression: " + v, e); } if (!(klass.isAssignableFrom(res.getClass()))) { throw new DocumentRouteException( kind + " of node '" + getId() + "' of graph '" + graph.getName() + "' does not evaluate to " + klass.getSimpleName() + " but " + res.getClass().getName() + ": " + v); } return (T) res; }
Object res = expr.eval(context);
if (!(Boolean) expr.eval(ctx)) { return false;
protected Date evaluateDueDate() throws DocumentRouteException { String taskDueDateExpr = getTaskDueDateExpr(); if (StringUtils.isEmpty(taskDueDateExpr)) { return new Date(); } try (OperationContext context = getExecutionContext(getSession())) { Expression expr = Scripting.newExpression(taskDueDateExpr); Object res = expr.eval(context); if (res instanceof DateWrapper) { return ((DateWrapper) res).getDate(); } else if (res instanceof Date) { return (Date) res; } else if (res instanceof Calendar) { return ((Calendar) res).getTime(); } else if (res instanceof String) { return DateParser.parseW3CDateTime((String) res); } else { throw new DocumentRouteException( "The following expression can not be evaluated to a date: " + taskDueDateExpr); } } catch (DocumentRouteException e) { throw e; } catch (RuntimeException e) { throw new DocumentRouteException("Error evaluating task due date: " + taskDueDateExpr, e); } }
Expression expr = Scripting.newExpression(condition); try { if (!Boolean.TRUE.equals(expr.eval(ctx))) { return false;
@Override public List<EscalationRule> evaluateEscalationRules() { List<EscalationRule> rulesToExecute = new ArrayList<>(); // add specific helpers for escalation for (EscalationRule rule : getEscalationRules()) { try (OperationContext context = getExecutionContext(getSession())) { Expression expr = new RoutingScriptingExpression(rule.condition, new RoutingScriptingFunctions(context, rule)); Object res = expr.eval(context); if (!(res instanceof Boolean)) { throw new DocumentRouteException("Condition for rule " + rule + " of node '" + getId() + "' of graph '" + graph.getName() + "' does not evaluate to a boolean: " + rule.condition); } boolean bool = Boolean.TRUE.equals(res); if ((!rule.isExecuted() || rule.isMultipleExecution()) && bool) { rulesToExecute.add(rule); } } catch (DocumentRouteException e) { throw e; } catch (RuntimeException e) { throw new DocumentRouteException("Error evaluating condition: " + rule.condition, e); } } saveDocument(); return rulesToExecute; }
protected Object invoke(OperationContext context) throws OperationException { context.getCallback().onOperationEnter(context, typeof, method, params.map()); Object output = method.invoke(context, params.map()); if (output instanceof Expression) { output = ((Expression) output).eval(context); } context.getCallback().onOperationExit(output); context.setInput(output); if (next != null) { return next.invoke(context); } return output; }
context.put("transition", t.id); Expression expr = new RoutingScriptingExpression(t.condition, new RoutingScriptingFunctions(context)); Object res = expr.eval(context);
AutomationFilter filter = getAutomationFilter(catchChainExceptionItem.getFilterId()); try { String filterValue = (String) filter.getValue().eval(ctx);