RuntimeKieServerDataSetProvider implements DataSetProvider { @Override public DataSet lookupDataSet(DataSetDef def, DataSetLookup lookup) throws Exception { ConsoleDataSetLookup dataSetLookup = adoptLookup(def, lookup); LOGGER.debug("Data Set lookup using Server Template Id: {}", dataSetLookup.getServerTemplateId()); if (dataSetLookup.getServerTemplateId() == null || dataSetLookup.getServerTemplateId().isEmpty()) { return buildDataSet(def, new ArrayList<>(), new ArrayList<>()); } List<QueryParam> filterParams = new ArrayList<>(); QueryFilterSpec filterSpec = new QueryFilterSpec(); for (DataSetFilter filter : dataSetLookup.getOperationList(DataSetFilter.class)) { if (filter != null) { for (ColumnFilter cFilter : filter.getColumnFilterList()) { if (cFilter instanceof CoreFunctionFilter) { CoreFunctionFilter coreFunctionFilter = (CoreFunctionFilter) cFilter; filterParams.add(new QueryParam(coreFunctionFilter.getColumnId(), coreFunctionFilter.getType().toString(), coreFunctionFilter.getParameters())); } else if (cFilter instanceof LogicalExprFilter) { LogicalExprFilter logicalExprFilter = (LogicalExprFilter) cFilter; filterParams.add(new QueryParam(logicalExprFilter.getColumnId(), logicalExprFilter.getLogicalOperator().toString(), logicalExprFilter.getLogicalTerms())); } } } } List<DataColumn> extraColumns = new ArrayList<DataColumn>(); List<DataSetGroup> dataSetGroups = lookup.getFirstGroupOpSelections(); for (DataSetGroup group : dataSetGroups) { if (group.getSelectedIntervalList() != null && group.getSelectedIntervalList().size() > 0) { appendIntervalSelection(group, filterParams); } } DataSetGroup dataSetGroup = dataSetLookup.getLastGroupOp(); handleDataSetGroup(def, dataSetGroup, filterParams, extraColumns); if (!filterParams.isEmpty()) { filterSpec.setParameters(filterParams.toArray(new QueryParam[filterParams.size()])); } DataSetSort sort = dataSetLookup.getFirstSortOp(); if (sort != null) { SortOrder sortOrder = SortOrder.UNSPECIFIED; StringBuilder orderBy = new StringBuilder(); for (ColumnSort cSort : sort.getColumnSortList()) { orderBy.append(cSort.getColumnId()).append(","); sortOrder = cSort.getOrder(); } orderBy.deleteCharAt(orderBy.length() - 1); filterSpec.setOrderBy(orderBy.toString()); filterSpec.setAscending(sortOrder.equals(SortOrder.ASCENDING)); } final List<List> instances = performQuery((RemoteDataSetDef) def, dataSetLookup, filterSpec); LOGGER.debug("Query client returned {} row(s)", instances.size()); return buildDataSet(def, instances, extraColumns); }  @Override DataSetProviderType getType(); @Override DataSetMetadata getDataSetMetadata(DataSetDef def); @Override DataSet lookupDataSet(DataSetDef def,
                                 DataSetLookup lookup); @Override boolean isDataSetOutdated(DataSetDef def); static final DataSetProviderType TYPE; }
@Test public void lookupDataSetLogicalExprTest() throws Exception { DataSetLookup lookup = new DataSetLookup(); lookup.setDataSetUUID(""); when(dataSetDef.getUUID()).thenReturn(""); when(kieServerConnectionInfoProvider.verifiedConnectionInfo(dataSetDef)).thenReturn(connectionInfo); final ColumnFilter testFilter = OR(likeTo("column1", "%value%"), likeTo("column2", "%value%")); DataSetFilter filter = new DataSetFilter(); filter.addFilterColumn(testFilter); lookup.addOperation(filter); when(queryClient.replaceQuery(eq(connectionInfo), any())).thenReturn(definition); when(queryClient.getQuery(eq(connectionInfo), any())).thenReturn(definition); kieServerDataSetProvider.lookupDataSet(dataSetDef, ConsoleDataSetLookup.fromInstance(lookup, SERVER_TEMPLATE)); final ArgumentCaptor<QueryFilterSpec> captorEdit = ArgumentCaptor.forClass(QueryFilterSpec.class); verify(queryClient).query(eq(connectionInfo), anyString(), captorEdit.capture(), anyInt(), anyInt()); assertNotNull(captorEdit.getValue()); QueryParam[] parameters = captorEdit.getValue().getParameters(); assertEquals(1, parameters.length); List<CoreFunctionFilter> expr = (List<CoreFunctionFilter>) parameters[0].getValue(); assertEquals("OR", parameters[0].getOperator()); assertEquals("column1 like %value%, true", expr.get(0).toString()); assertEquals("column2 like %value%, true", expr.get(1).toString()); }