ColumnMatchDataRouter extends AbstractDataRouter implements IDataRouter, IBuiltInExtensionPoint { public List<Expression> parse(String routerExpression) throws SyntaxParsingException { List<Expression> expressions = new ArrayList<Expression>(); if (!StringUtils.isBlank(routerExpression)) { String[] operators = { Expression.NOT_EQUALS, Expression.EQUALS, Expression.NOT_CONTAINS, Expression.CONTAINS}; String[] expTokens = routerExpression.split("\\s*(\\s+or|\\s+OR)?(\r\n|\r|\n)(or\\s+|OR\\s+)?\\s*" + "|\\s+or\\s+" + "|\\s+OR\\s+"); if (expTokens != null) { for (String t : expTokens) { if (!StringUtils.isBlank(t)) { boolean isFound = false; for (String operator : operators) { if (t.contains(operator)) { String[] tokens = t.split(operator); if (tokens.length == 2) { tokens[0] = parseColumn(tokens[0]); tokens[1] = parseValue(tokens[1]); expressions.add(new Expression(operator, tokens)); isFound = true; break; } } } if (!isFound) { log.warn("The provided column match expression was invalid: {}. The full expression is {}.", t, routerExpression); throw new SyntaxParsingException("The provided column match expression was invalid: " + t + ". The full expression is " + routerExpression + "."); } } } } } else { log.warn("The provided column match expression is empty"); } return expressions; } ColumnMatchDataRouter();  ColumnMatchDataRouter(IConfigurationService configurationService, ISymmetricDialect symmetricDialect); Set<String> routeToNodes(SimpleRouterContext routingContext,
            DataMetaData dataMetaData, Set<Node> nodes, boolean initialLoad, boolean initialLoadSelectUsed, TriggerRouter triggerRouter); List<Expression> parse(String routerExpression);  }
@Test public void testExpressionUsingLineFeedsParsing() { ColumnMatchDataRouter router = new ColumnMatchDataRouter(); List<Expression> expressions = router.parse("one=two\ntwo=three\rthree!=:EXTERNAL_ID"); assertEquals(3, expressions.size()); assertEquals("two",expressions.get(0).tokens[1]); assertEquals("three",expressions.get(2).tokens[0]); assertEquals(false,expressions.get(2).hasEquals); }
@Test public void testExpressionOrParsing() { ColumnMatchDataRouter router = new ColumnMatchDataRouter(); List<Expression> expressions = router.parse("one=door OR two=three or three!=:EXTERNAL_ID"); assertEquals(3, expressions.size()); assertEquals("door",expressions.get(0).tokens[1]); assertEquals("three",expressions.get(2).tokens[0]); assertEquals(false,expressions.get(2).hasEquals); }
@Test public void testExpressionTickParsing() { ColumnMatchDataRouter router = new ColumnMatchDataRouter(); List<Expression> expressions = router.parse("one='two three' OR four='five'\r\nor six=isn't \r\n seven='can''t'" + " or eight='yall \n nine=' ten ' or eleven = 'twelve' "); assertEquals(7, expressions.size()); assertEquals("one",expressions.get(0).tokens[0]); assertEquals("two three",expressions.get(0).tokens[1]); assertEquals("four",expressions.get(1).tokens[0]); assertEquals("five",expressions.get(1).tokens[1]); assertEquals("six",expressions.get(2).tokens[0]); assertEquals("isn't",expressions.get(2).tokens[1]); assertEquals("seven",expressions.get(3).tokens[0]); assertEquals("can't",expressions.get(3).tokens[1]); assertEquals("eight",expressions.get(4).tokens[0]); assertEquals("'yall",expressions.get(4).tokens[1]); assertEquals("nine",expressions.get(5).tokens[0]); assertEquals(" ten ",expressions.get(5).tokens[1]); assertEquals("eleven",expressions.get(6).tokens[0]); assertEquals("twelve",expressions.get(6).tokens[1]); }
@Test public void testExpressionOrAndLineFeedsParsing() { ColumnMatchDataRouter router = new ColumnMatchDataRouter(); List<Expression> expressions = router.parse("one=two OR three=four\r\nor five!=:EXTERNAL_ID"); assertEquals(3, expressions.size()); assertEquals("two",expressions.get(0).tokens[1]); assertEquals("three",expressions.get(1).tokens[0]); assertEquals("five",expressions.get(2).tokens[0]); assertEquals(false,expressions.get(2).hasEquals); }
@Test public void testExpressionWithOrInColumnName() { ColumnMatchDataRouter router = new ColumnMatchDataRouter(); List<Expression> expressions = router.parse("ORDER_ID=:EXTERNAL_ID"); assertEquals(1, expressions.size()); assertEquals("ORDER_ID",expressions.get(0).tokens[0]); assertEquals(":EXTERNAL_ID",expressions.get(0).tokens[1]); }