PotOwnerTasksPreprocessor extends UserTasksPreprocessor { @SuppressWarnings("rawtypes") @Override public void preprocess(DataSetLookup lookup) { if (identityProvider == null || userGroupCallback == null) { return; } final List<String> groupsForUser = Optional.ofNullable(userGroupCallback.getGroupsForUser(identityProvider.getName())).orElse(new ArrayList<>()); final List<Comparable> orgEntities = new ArrayList<>(groupsForUser); orgEntities.add(identityProvider.getName()); final ColumnFilter myGroupFilter = AND( equalsTo(COLUMN_ORGANIZATIONAL_ENTITY, orgEntities), OR(equalsTo(COLUMN_ACTUALOWNER, ""), isNull(COLUMN_ACTUALOWNER))); final ColumnFilter columnFilter = AND( OR(isNull(COLUMN_EXCLUDED_OWNER), notEqualsTo(COLUMN_EXCLUDED_OWNER, identityProvider.getName())), OR(myGroupFilter, equalsTo(COLUMN_ACTUALOWNER, identityProvider.getName()))); 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); } super.preprocess(lookup); } PotOwnerTasksPreprocessor(IdentityProvider identityProvider,
                                     UserGroupCallback userGroupCallback,
                                     DataSetMetadata metadata); @SuppressWarnings("rawtypes") @Override void preprocess(DataSetLookup lookup);  }
@Test public void testSetUser() { String role1 = "role1"; String role2 = "role2"; String userId = "userId"; when(userGroupCallback.getGroupsForUser(userId)).thenReturn(Arrays.asList(role1, role2)); when(identityProvider.getName()).thenReturn(userId); potOwnerTasksPreprocessor.preprocess(dataSetLookup); assertEquals("((ENTITY_ID is_null OR ENTITY_ID != " + userId + ") AND ((ID = " + role1 + ", " + role2 + ", " + userId + " AND (ACTUALOWNER = OR ACTUALOWNER is_null )) OR ACTUALOWNER = " + userId + "))", dataSetLookup.getFirstFilterOp().getColumnFilterList().get(0).toString()); }
@Test public void testSetUserWithoutRoles() { String userId = "userId"; when(userGroupCallback.getGroupsForUser(userId)).thenReturn(Collections.emptyList()); when(identityProvider.getName()).thenReturn(userId); potOwnerTasksPreprocessor.preprocess(dataSetLookup); assertEquals("((ENTITY_ID is_null OR ENTITY_ID != " + userId + ") AND ((ID = " + userId + " AND (ACTUALOWNER = OR ACTUALOWNER is_null )) OR ACTUALOWNER = " + userId + "))", dataSetLookup.getFirstFilterOp().getColumnFilterList().get(0).toString()); }
@Test public void testNullGroups() { String userId = "userId"; when(userGroupCallback.getGroupsForUser(userId)).thenReturn(null); when(identityProvider.getName()).thenReturn(userId); potOwnerTasksPreprocessor.preprocess(dataSetLookup); assertEquals("((ENTITY_ID is_null OR ENTITY_ID != " + userId + ") AND ((ID = " + userId + " AND (ACTUALOWNER = OR ACTUALOWNER is_null )) OR ACTUALOWNER = " + userId + "))", dataSetLookup.getFirstFilterOp().getColumnFilterList().get(0).toString()); }