CoreFunctionQueryParamBuilder implements QueryParamBuilder<Object> { @Override public Object build() { if (filterParams.length == 0 || filterParams.length <= index) { return null; } QueryParam param = filterParams[index]; index++; if ("group".equalsIgnoreCase(param.getOperator())) { if (param.getValue().size() > 1) { return new GroupColumnFilter(param.getColumn(), (String)param.getValue().get(0), (String)param.getValue().get(1), (Integer)param.getValue().get(2)); } else { return new GroupColumnFilter(param.getColumn(), (String)param.getValue().get(0), null, -1); } } ColumnFilter filter = buildExpressionColumnFilter(param); if (filter != null) { return filter; } AggregateFunctionType aggregationType = AggregateFunctionType.getByName(param.getOperator()); if (aggregationType != null) { return new AggregateColumnFilter(aggregationType, param.getColumn(), (String)param.getValue().get(0)); } return new ExtraColumnFilter(param.getColumn(), (String)param.getValue().get(0)); } CoreFunctionQueryParamBuilder(QueryParam...filterParams); @Override Object build();  }
@Test public void testLogicalExprPassedAsQueryParam() { ArrayList values = new ArrayList(); values.add("value1"); values.add("value2"); final ColumnFilter filter1 = likeTo(COLUMN_PROCESSNAME, "%processName%"); final ColumnFilter filter2 = likeTo(COLUMN_PROCESSID, "%processName%"); ArrayList terms = new ArrayList(); terms.add(filter1); terms.add(filter2); QueryParam queryParam = new QueryParam("", LogicalExprType.OR.toString(), terms); ArrayList queryParams = new ArrayList(); queryParams.add(queryParam); coreFunctionQueryParamBuilder = new CoreFunctionQueryParamBuilder(queryParam); Object builded = coreFunctionQueryParamBuilder.build(); assertTrue(builded instanceof LogicalExprFilter); assertEquals("(" + COLUMN_PROCESSNAME + " like %processName%, true OR " + COLUMN_PROCESSID + " like %processName%, true)", builded.toString()); }
@Test public void testTreeQueryParam() { QueryParam likeParamName = new QueryParam(COLUMN_PROCESSNAME, CoreFunctionType.LIKE_TO.toString(), Collections.singletonList("%processName%")); QueryParam likeParamId = new QueryParam(COLUMN_PROCESSID, CoreFunctionType.LIKE_TO.toString(), Collections.singletonList("%processName%")); List<Object> terms = new ArrayList<>(); terms.add(likeParamName); terms.add(likeParamId); QueryParam queryParamOR = new QueryParam("", LogicalExprType.OR.toString(), terms); QueryParam likeParamIdentity = new QueryParam(QueryResultMapper.COLUMN_IDENTITY, CoreFunctionType.EQUALS_TO.toString(), Collections.singletonList("1234")); List<Object> queryParamsAndTerms = new ArrayList<>(); queryParamsAndTerms.add(likeParamIdentity); queryParamsAndTerms.add(queryParamOR); QueryParam queryParam = new QueryParam("", LogicalExprType.AND.toString(), queryParamsAndTerms); coreFunctionQueryParamBuilder = new CoreFunctionQueryParamBuilder(queryParam); Object builded = coreFunctionQueryParamBuilder.build(); assertTrue(builded instanceof LogicalExprFilter); assertEquals("(USER_IDENTITY = 1234 AND (PROCESSNAME like %processName% OR PROCESSID like %processName%))", builded.toString()); }