public static int getMatchingIndex(String spelExpression, ListMultimap<String, String> values) throws NoSuchElementException { // Compile the expression final ExpressionParser parser = new SpelExpressionParser(); final Expression exp = parser.parseExpression(spelExpression); // Recursively check all levels, defaulting to the first element return getMatchingIndex(exp, values, 0); }
final ListMultimap<String, String> elementValues = ResponseHandlingUtils.toMultiMap(node); LOG.debug("Element values: {}", elementValues); if (attrib.getFilter() != null && !ResponseHandlingUtils.matchesFilter(attrib.getFilter(), elementValues)) { continue; if (attributeValues.size() > 1 && attrib.getIndexOf() != null) { try { int index = ResponseHandlingUtils.getMatchingIndex(attrib.getIndexOf(), elementValues); valueAsString = attributeValues.get(index); } catch (NoSuchElementException e) {
final ListMultimap<String, String> elementValues = ResponseHandlingUtils.toMultiMap(node); try { ResponseHandlingUtils.getMatchingIndex(rule, elementValues);
final ListMultimap<String, String> elementValues = ResponseHandlingUtils.toMultiMap(node); LOG.debug("Element values: {}", elementValues); if (attrib.getFilter() != null && !ResponseHandlingUtils.matchesFilter(attrib.getFilter(), elementValues)) { continue; if (attributeValues.size() > 1 && attrib.getIndexOf() != null) { try { int index = ResponseHandlingUtils.getMatchingIndex(attrib.getIndexOf(), elementValues); valueAsString = attributeValues.get(index); } catch (NoSuchElementException e) {
final ListMultimap<String, String> elementValues = ResponseHandlingUtils.toMultiMap(node); try { ResponseHandlingUtils.getMatchingIndex(rule, elementValues);
public static int getMatchingIndex(String spelExpression, ListMultimap<String, String> values) throws NoSuchElementException { // Compile the expression final ExpressionParser parser = new SpelExpressionParser(); final Expression exp = parser.parseExpression(spelExpression); // Recursively check all levels, defaulting to the first element return getMatchingIndex(exp, values, 0); }
private static int getMatchingIndex(Expression exp, ListMultimap<String, String> valuesByName, int depth) throws NoSuchElementException { // Build the context with values from all the attributes at the current depth final StandardEvaluationContext context = new StandardEvaluationContext(); int maxDepth = 0; for (String name : valuesByName.keySet()) { List<String> values = valuesByName.get(name); // Keep track of the largest depth maxDepth = Math.max(maxDepth, values.size()); // Skip the variable if there are no values are the current depth if (values.size() < depth + 1) { continue; } // Store the value for the current depth in the context context.setVariable(name, values.get(depth)); } // Evaluate our expression try { if (exp.getValue(context, Boolean.class)) { return depth; } } catch (Exception e) { LOG.error("Failed to evaluate expression {}. Msg: {}", exp.getExpressionString(), e.getMessage()); throw new NoSuchElementException(); } if (maxDepth > depth) { // Recurse return getMatchingIndex(exp, valuesByName, depth+1); } throw new NoSuchElementException(); }
private static int getMatchingIndex(Expression exp, ListMultimap<String, String> valuesByName, int depth) throws NoSuchElementException { // Build the context with values from all the attributes at the current depth final StandardEvaluationContext context = new StandardEvaluationContext(); int maxDepth = 0; for (String name : valuesByName.keySet()) { List<String> values = valuesByName.get(name); // Keep track of the largest depth maxDepth = Math.max(maxDepth, values.size()); // Skip the variable if there are no values are the current depth if (values.size() < depth + 1) { continue; } // Store the value for the current depth in the context context.setVariable(name, values.get(depth)); } // Evaluate our expression try { if (exp.getValue(context, Boolean.class)) { return depth; } } catch (Exception e) { LOG.error("Failed to evaluate expression {}. Msg: {}", exp.getExpressionString(), e.getMessage()); throw new NoSuchElementException(); } if (maxDepth > depth) { // Recurse return getMatchingIndex(exp, valuesByName, depth+1); } throw new NoSuchElementException(); }