DeploymentIdsPreprocessor implements DataSetPreprocessor { @Override public void preprocess(DataSetLookup lookup) { if (identityProvider == null) { return; } final List<String> deploymentIds = deploymentRolesManager.getDeploymentsForUser(identityProvider); ColumnFilter columnFilter; if(deploymentIds != null && !deploymentIds.isEmpty()){ columnFilter = in(columnId, deploymentIds); } else { columnFilter = equalsTo(impossibleConditionColumnId,-1); } LOGGER.debug("Adding column filter: {}", columnFilter); if (lookup.getFirstFilterOp() != null) { lookup.getFirstFilterOp().addFilterColumn(columnFilter); } else { DataSetFilter filter = new DataSetFilter(); filter.addFilterColumn(columnFilter); lookup.addOperation(filter); } } DeploymentIdsPreprocessor(DeploymentRolesManager deploymentRolesManager,
                                     IdentityProvider identityProvider,
                                     String columnId,
                                     String impossibleConditionColumnId); @Override void preprocess(DataSetLookup lookup);  }
@Test public void testQueryWithUserAvailableDeployments() { dataSetLookup = spy(new DataSetLookup()); String deploymentId1 = "deployment1"; String deploymentId2 = "deployment2"; when(deploymentRolesManager.getDeploymentsForUser(identityProvider)).thenReturn( Arrays.asList(deploymentId1,deploymentId2)); preprocessor.preprocess(dataSetLookup); assertEquals("DEPLOYMENTID in deployment1, deployment2", dataSetLookup.getFirstFilterOp().getColumnFilterList().get(0).toString()); }
@Test public void testQueryWithoutUserAvailableDeployments() { dataSetLookup = spy(new DataSetLookup()); when(deploymentRolesManager.getDeploymentsForUser(identityProvider)).thenReturn(new ArrayList<>()); preprocessor.preprocess(dataSetLookup); assertEquals("TASKID = -1", dataSetLookup.getFirstFilterOp().getColumnFilterList().get(0).toString()); }