public static Object eval(String str, Map<String, Object> vars) { ParserConfiguration pconf = new ParserConfiguration(); pconf.addPackageImport("org.kie.internal.task.api.model"); pconf.addPackageImport("org.jbpm.services.task"); pconf.addPackageImport("org.jbpm.services.task.impl.model"); pconf.addPackageImport("org.jbpm.services.task.query"); pconf.addPackageImport("org.jbpm.services.task.internals.lifecycle"); pconf.addImport(Status.class); pconf.addImport(Allowed.class); pconf.addPackageImport("java.util"); ParserContext context = new ParserContext(pconf); Serializable s = MVEL.compileExpression(str.trim(), context); if (vars != null) { return MVELSafeHelper.getEvaluator().executeExpression(s, vars); } else { return MVELSafeHelper.getEvaluator().executeExpression(s); } }
private String resolveVariable(String s) { if (s == null) { return null; } // cannot parse delay, trying to interpret it Map<String, String> replacements = new HashMap<String, String>(); Matcher matcher = PARAMETER_MATCHER.matcher(s); while (matcher.find()) { String paramName = matcher.group(1); if (replacements.get(paramName) == null) { VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, paramName); if (variableScopeInstance != null) { Object variableValue = variableScopeInstance.getVariable(paramName); String variableValueString = variableValue == null ? "" : variableValue.toString(); replacements.put(paramName, variableValueString); } else { try { Object variableValue = MVELSafeHelper.getEvaluator() .eval(paramName, new NodeInstanceResolverFactory(this)); String variableValueString = variableValue == null ? "" : variableValue.toString(); replacements.put(paramName, variableValueString); } catch (Throwable t) { logger.error("Could not find variable scope for variable {}", paramName); logger.error( "when trying to replace variable in processId for sub process {}", getNodeName()); logger.error("Continuing without setting process id."); } } } } for (Map.Entry<String, String> replacement : replacements.entrySet()) { s = s.replace("#{" + replacement.getKey() + "}", replacement.getValue()); } return s; }