@Test public void testSortAuthorizablesForDeletion() throws RepositoryException { when(group1.getID()).thenReturn("group1"); when(group2.getID()).thenReturn("group2"); when(group3.getID()).thenReturn("group3"); when(group4.getID()).thenReturn("group4"); when(group5.getID()).thenReturn("group5"); when(group6.getID()).thenReturn("group6"); when(group7.getID()).thenReturn("group7"); when(user1.getID()).thenReturn("user1"); when(user2.getID()).thenReturn("user2"); when(group4.declaredMemberOf()).thenAnswer(GroupIteratorAnswer.forGroups(group3, group2)); when(user1.declaredMemberOf()).thenAnswer(GroupIteratorAnswer.forGroups(group1, group5)); when(group1.declaredMemberOf()).thenAnswer(GroupIteratorAnswer.forGroups(group4)); when(group5.declaredMemberOf()).thenAnswer(GroupIteratorAnswer.forGroups(group1, group2, group3)); when(user2.declaredMemberOf()).thenAnswer(GroupIteratorAnswer.forGroups(group2, group3)); when(group2.declaredMemberOf()).thenAnswer(GroupIteratorAnswer.forGroups(group3)); List<Authorizable> authsToDelete = Arrays.<Authorizable> asList(group1, group2, group3, group4, group5, group6, user1, user2); acInstallationServiceImpl.sortAuthorizablesForDeletion(authsToDelete); assertTrue(authsToDelete.indexOf(group4) < authsToDelete.indexOf(group3)); assertTrue(authsToDelete.indexOf(group4) < authsToDelete.indexOf(group2)); assertTrue(authsToDelete.indexOf(user1) < authsToDelete.indexOf(group1)); assertTrue(authsToDelete.indexOf(user1) < authsToDelete.indexOf(group5)); assertTrue(authsToDelete.indexOf(group1) < authsToDelete.indexOf(group4)); assertTrue(authsToDelete.indexOf(group5) < authsToDelete.indexOf(group1)); assertTrue(authsToDelete.indexOf(group5) < authsToDelete.indexOf(group2)); assertTrue(authsToDelete.indexOf(group5) < authsToDelete.indexOf(group3)); assertTrue(authsToDelete.indexOf(user2) < authsToDelete.indexOf(group2)); assertTrue(authsToDelete.indexOf(user2) < authsToDelete.indexOf(group3)); assertTrue(authsToDelete.indexOf(group2) < authsToDelete.indexOf(group3)); }
void sortAuthorizablesForDeletion(List<Authorizable> authorizablesToDelete) throws RepositoryException { outer: for (int i = 0; i < authorizablesToDelete.size();) { Authorizable currentAuthorizable = authorizablesToDelete.get(i); Iterator<Group> declaredMemberOfIt = currentAuthorizable.declaredMemberOf(); LOG.trace("At index {}: {}", i, currentAuthorizable.getID()); while (declaredMemberOfIt != null && declaredMemberOfIt.hasNext()) { Group groupOfAuthorizable = declaredMemberOfIt.next(); int groupOfAuthorizableIndex = authorizablesToDelete.indexOf(groupOfAuthorizable); LOG.trace(" Is member of at index {}: {}", groupOfAuthorizableIndex, groupOfAuthorizable.getID()); if (groupOfAuthorizableIndex > -1 && groupOfAuthorizableIndex < i) { LOG.trace(" Swap at index {} (groupOfAuthorizableIndex {}):", i, groupOfAuthorizableIndex); authorizablesToDelete.set(groupOfAuthorizableIndex, currentAuthorizable); authorizablesToDelete.set(i, groupOfAuthorizable); i = groupOfAuthorizableIndex; continue outer; } } i++; } }
AcInstallationServiceImpl implements AcInstallationService, AcInstallationServiceInternal, AceService { void sortAuthorizablesForDeletion(List<Authorizable> authorizablesToDelete) throws RepositoryException { outer: for (int i = 0; i < authorizablesToDelete.size();) { Authorizable currentAuthorizable = authorizablesToDelete.get(i); Iterator<Group> declaredMemberOfIt = currentAuthorizable.declaredMemberOf(); LOG.trace("At index {}: {}", i, currentAuthorizable.getID()); while (declaredMemberOfIt != null && declaredMemberOfIt.hasNext()) { Group groupOfAuthorizable = declaredMemberOfIt.next(); int groupOfAuthorizableIndex = authorizablesToDelete.indexOf(groupOfAuthorizable); LOG.trace(" Is member of at index {}: {}", groupOfAuthorizableIndex, groupOfAuthorizable.getID()); if (groupOfAuthorizableIndex > -1 && groupOfAuthorizableIndex < i) { LOG.trace(" Swap at index {} (groupOfAuthorizableIndex {}):", i, groupOfAuthorizableIndex); authorizablesToDelete.set(groupOfAuthorizableIndex, currentAuthorizable); authorizablesToDelete.set(i, groupOfAuthorizable); i = groupOfAuthorizableIndex; continue outer; } } i++; } } }
AcInstallationServiceImpl implements AcInstallationService, AcInstallationServiceInternal, AceService { void sortAuthorizablesForDeletion(List<Authorizable> authorizablesToDelete) throws RepositoryException { outer: for (int i = 0; i < authorizablesToDelete.size();) { Authorizable currentAuthorizable = authorizablesToDelete.get(i); Iterator<Group> declaredMemberOfIt = currentAuthorizable.declaredMemberOf(); LOG.trace("At index {}: {}", i, currentAuthorizable.getID()); while (declaredMemberOfIt != null && declaredMemberOfIt.hasNext()) { Group groupOfAuthorizable = declaredMemberOfIt.next(); int groupOfAuthorizableIndex = authorizablesToDelete.indexOf(groupOfAuthorizable); LOG.trace(" Is member of at index {}: {}", groupOfAuthorizableIndex, groupOfAuthorizable.getID()); if (groupOfAuthorizableIndex > -1 && groupOfAuthorizableIndex < i) { LOG.trace(" Swap at index {} (groupOfAuthorizableIndex {}):", i, groupOfAuthorizableIndex); authorizablesToDelete.set(groupOfAuthorizableIndex, currentAuthorizable); authorizablesToDelete.set(i, groupOfAuthorizable); i = groupOfAuthorizableIndex; continue outer; } } i++; } }  }
AcInstallationServiceImpl implements AcInstallationService, AcInstallationServiceInternal, AceService { void sortAuthorizablesForDeletion(List<Authorizable> authorizablesToDelete) throws RepositoryException { outer: for (int i = 0; i < authorizablesToDelete.size();) { Authorizable currentAuthorizable = authorizablesToDelete.get(i); Iterator<Group> declaredMemberOfIt = currentAuthorizable.declaredMemberOf(); LOG.trace("At index {}: {}", i, currentAuthorizable.getID()); while (declaredMemberOfIt != null && declaredMemberOfIt.hasNext()) { Group groupOfAuthorizable = declaredMemberOfIt.next(); int groupOfAuthorizableIndex = authorizablesToDelete.indexOf(groupOfAuthorizable); LOG.trace(" Is member of at index {}: {}", groupOfAuthorizableIndex, groupOfAuthorizable.getID()); if (groupOfAuthorizableIndex > -1 && groupOfAuthorizableIndex < i) { LOG.trace(" Swap at index {} (groupOfAuthorizableIndex {}):", i, groupOfAuthorizableIndex); authorizablesToDelete.set(groupOfAuthorizableIndex, currentAuthorizable); authorizablesToDelete.set(i, groupOfAuthorizable); i = groupOfAuthorizableIndex; continue outer; } } i++; } }  @Activate void activate(Configuration configuration, BundleContext bundleContext); @Override InstallationLog apply(); @Override InstallationLog apply(String configurationRootPath); @Override InstallationLog apply(String[] restrictedToPaths); @Override InstallationLog apply(String configurationRootPath, String[] restrictedToPaths); @Override InstallationLog apply(String configurationRootPath, String[] restrictedToPaths, boolean skipIfConfigUnchanged); @Override void installConfigurationFiles(PersistableInstallationLogger installLog, Map<String, String> configurationFileContentsByFilename,
            String[] restrictedToPaths, Session session); void installConfigurationFiles(PersistableInstallationLogger installLog, Map<String, String> configurationFileContentsByFilename,
            String[] restrictedToPaths, Session session, boolean skipIfConfigUnchanged); @Override boolean isReadyToStart(); @Override String purgeACL(String path); @Override String purgeACLs(String path); @Override String purgeAuthorizablesFromConfig(); @Override String purgeAuthorizablesFromConfig(String configRootPath); @Override String purgeAuthorizables(String[] authorizableIds); @Override @Deprecated String getConfiguredAcConfigurationRootPath(); List<String> getConfigurationRootPaths(); @Override Set<String> getCurrentConfigurationPaths(); Set<String> getAllAuthorizablesFromConfig(Session session, String configRootPath); String getVersion(); @Override AcInstallationHistoryPojo execute(); @Override AcInstallationHistoryPojo execute(String configurationRootPath); @Override AcInstallationHistoryPojo execute(String[] restrictedToPaths); @Override AcInstallationHistoryPojo execute(String configurationRootPath, String[] restrictedToPaths); }
AcInstallationServiceImpl implements AcInstallationService, AcInstallationServiceInternal, AceService { void sortAuthorizablesForDeletion(List<Authorizable> authorizablesToDelete) throws RepositoryException { outer: for (int i = 0; i < authorizablesToDelete.size();) { Authorizable currentAuthorizable = authorizablesToDelete.get(i); Iterator<Group> declaredMemberOfIt = currentAuthorizable.declaredMemberOf(); LOG.trace("At index {}: {}", i, currentAuthorizable.getID()); while (declaredMemberOfIt != null && declaredMemberOfIt.hasNext()) { Group groupOfAuthorizable = declaredMemberOfIt.next(); int groupOfAuthorizableIndex = authorizablesToDelete.indexOf(groupOfAuthorizable); LOG.trace(" Is member of at index {}: {}", groupOfAuthorizableIndex, groupOfAuthorizable.getID()); if (groupOfAuthorizableIndex > -1 && groupOfAuthorizableIndex < i) { LOG.trace(" Swap at index {} (groupOfAuthorizableIndex {}):", i, groupOfAuthorizableIndex); authorizablesToDelete.set(groupOfAuthorizableIndex, currentAuthorizable); authorizablesToDelete.set(i, groupOfAuthorizable); i = groupOfAuthorizableIndex; continue outer; } } i++; } }  @Activate void activate(Configuration configuration, BundleContext bundleContext); @Override InstallationLog apply(); @Override InstallationLog apply(String configurationRootPath); @Override InstallationLog apply(String[] restrictedToPaths); @Override InstallationLog apply(String configurationRootPath, String[] restrictedToPaths); @Override InstallationLog apply(String configurationRootPath, String[] restrictedToPaths, boolean skipIfConfigUnchanged); @Override void installConfigurationFiles(PersistableInstallationLogger installLog, Map<String, String> configurationFileContentsByFilename,
            String[] restrictedToPaths, Session session); void installConfigurationFiles(PersistableInstallationLogger installLog, Map<String, String> configurationFileContentsByFilename,
            String[] restrictedToPaths, Session session, boolean skipIfConfigUnchanged); @Override boolean isReadyToStart(); @Override String purgeACL(String path); @Override String purgeACLs(String path); @Override String purgeAuthorizablesFromConfig(); @Override String purgeAuthorizablesFromConfig(String configRootPath); @Override String purgeAuthorizables(String[] authorizableIds); @Override @Deprecated String getConfiguredAcConfigurationRootPath(); List<String> getConfigurationRootPaths(); @Override Set<String> getCurrentConfigurationPaths(); Set<String> getAllAuthorizablesFromConfig(Session session, String configRootPath); String getVersion(); @Override AcInstallationHistoryPojo execute(); @Override AcInstallationHistoryPojo execute(String configurationRootPath); @Override AcInstallationHistoryPojo execute(String[] restrictedToPaths); @Override AcInstallationHistoryPojo execute(String configurationRootPath, String[] restrictedToPaths);  }