@Test public void deleteFolderShouldSkipAssetCreatedAfterTheGivenTimestamp() { mockAssetBrowseNode("assetId", DateTime.now().plusHours(1)); service.deleteFolder(repository, "com/sonatype", DateTime.now(), () -> false); verifyZeroInteractions(componentMaintenance); }
@Override public void deleteFolder(final Repository repository, final String treePath, final DateTime timestamp, final BooleanSupplier cancelledCheck) { boolean canDeleteComponent = securityHelper.isPermitted(new RepositoryViewPermission(repository, BreadActions.DELETE))[0]; ComponentMaintenance componentMaintenance = repository.facet(ComponentMaintenance.class); Queue<String> paths = new PriorityQueue<>(); paths.add(treePath); while (!cancelledCheck.getAsBoolean() && !paths.isEmpty()) { String basePath = paths.poll(); List<String> path = Arrays.asList(basePath.split("/")); Iterable<BrowseNode> nodes = browseNodeQueryService.getByPath(repository, path, configuration.getMaxNodes()); Iterator<BrowseNode> nodeIterator = nodes.iterator(); while (!cancelledCheck.getAsBoolean() && nodeIterator.hasNext()) { BrowseNode node = nodeIterator.next(); if (!node.isLeaf()) { paths.offer(basePath + "/" + node.getName()); } else if (canDeleteComponent && node.getAssetId() == null && node.getComponentId() != null) { deleteComponent(repository, node.getComponentId(), timestamp, componentMaintenance); } if (node.getAssetId() != null) { deleteAsset(repository, node.getAssetId(), timestamp, componentMaintenance); } } } }
DeleteFolderServiceImpl extends ComponentSupport implements DeleteFolderService { @Override public void deleteFolder(final Repository repository, final String treePath, final DateTime timestamp, final BooleanSupplier cancelledCheck) { boolean canDeleteComponent = securityHelper.isPermitted(new RepositoryViewPermission(repository, BreadActions.DELETE))[0]; ComponentMaintenance componentMaintenance = repository.facet(ComponentMaintenance.class); Queue<String> paths = new PriorityQueue<>(); paths.add(treePath); while (!cancelledCheck.getAsBoolean() && !paths.isEmpty()) { String basePath = paths.poll(); List<String> path = Arrays.asList(basePath.split("/")); Iterable<BrowseNode> nodes = browseNodeQueryService.getByPath(repository, path, configuration.getMaxNodes()); Iterator<BrowseNode> nodeIterator = nodes.iterator(); while (!cancelledCheck.getAsBoolean() && nodeIterator.hasNext()) { BrowseNode node = nodeIterator.next(); if (!node.isLeaf()) { paths.offer(basePath + "/" + node.getName()); } else if (canDeleteComponent && node.getAssetId() == null && node.getComponentId() != null) { deleteComponent(repository, node.getComponentId(), timestamp, componentMaintenance); } if (node.getAssetId() != null) { deleteAsset(repository, node.getAssetId(), timestamp, componentMaintenance); } } } } }
DeleteFolderServiceImpl extends ComponentSupport implements DeleteFolderService { @Override public void deleteFolder(final Repository repository, final String treePath, final DateTime timestamp, final BooleanSupplier cancelledCheck) { boolean canDeleteComponent = securityHelper.isPermitted(new RepositoryViewPermission(repository, BreadActions.DELETE))[0]; ComponentMaintenance componentMaintenance = repository.facet(ComponentMaintenance.class); Queue<String> paths = new PriorityQueue<>(); paths.add(treePath); while (!cancelledCheck.getAsBoolean() && !paths.isEmpty()) { String basePath = paths.poll(); List<String> path = Arrays.asList(basePath.split("/")); Iterable<BrowseNode> nodes = browseNodeQueryService.getByPath(repository, path, configuration.getMaxNodes()); Iterator<BrowseNode> nodeIterator = nodes.iterator(); while (!cancelledCheck.getAsBoolean() && nodeIterator.hasNext()) { BrowseNode node = nodeIterator.next(); if (!node.isLeaf()) { paths.offer(basePath + "/" + node.getName()); } else if (canDeleteComponent && node.getAssetId() == null && node.getComponentId() != null) { deleteComponent(repository, node.getComponentId(), timestamp, componentMaintenance); } if (node.getAssetId() != null) { deleteAsset(repository, node.getAssetId(), timestamp, componentMaintenance); } } } } @Inject  DeleteFolderServiceImpl(
      final BrowseNodeQueryService browseNodeQueryService,
      final BrowseNodeConfiguration configuration,
      final AssetStore assetStore,
      final ContentPermissionChecker contentPermissionChecker,
      final VariableResolverAdapterManager variableResolverAdapterManager,
      final SecurityHelper securityHelper); }
DeleteFolderServiceImpl extends ComponentSupport implements DeleteFolderService { @Override public void deleteFolder(final Repository repository, final String treePath, final DateTime timestamp, final BooleanSupplier cancelledCheck) { boolean canDeleteComponent = securityHelper.isPermitted(new RepositoryViewPermission(repository, BreadActions.DELETE))[0]; ComponentMaintenance componentMaintenance = repository.facet(ComponentMaintenance.class); Queue<String> paths = new PriorityQueue<>(); paths.add(treePath); while (!cancelledCheck.getAsBoolean() && !paths.isEmpty()) { String basePath = paths.poll(); List<String> path = Arrays.asList(basePath.split("/")); Iterable<BrowseNode> nodes = browseNodeQueryService.getByPath(repository, path, configuration.getMaxNodes()); Iterator<BrowseNode> nodeIterator = nodes.iterator(); while (!cancelledCheck.getAsBoolean() && nodeIterator.hasNext()) { BrowseNode node = nodeIterator.next(); if (!node.isLeaf()) { paths.offer(basePath + "/" + node.getName()); } else if (canDeleteComponent && node.getAssetId() == null && node.getComponentId() != null) { deleteComponent(repository, node.getComponentId(), timestamp, componentMaintenance); } if (node.getAssetId() != null) { deleteAsset(repository, node.getAssetId(), timestamp, componentMaintenance); } } } } @Inject  DeleteFolderServiceImpl(
      final BrowseNodeQueryService browseNodeQueryService,
      final BrowseNodeConfiguration configuration,
      final AssetStore assetStore,
      final ContentPermissionChecker contentPermissionChecker,
      final VariableResolverAdapterManager variableResolverAdapterManager,
      final SecurityHelper securityHelper); @Override void deleteFolder(final Repository repository,
                           final String treePath,
                           final DateTime timestamp,
                           final BooleanSupplier cancelledCheck); }
DeleteFolderServiceImpl extends ComponentSupport implements DeleteFolderService { @Override public void deleteFolder(final Repository repository, final String treePath, final DateTime timestamp, final BooleanSupplier cancelledCheck) { boolean canDeleteComponent = securityHelper.isPermitted(new RepositoryViewPermission(repository, BreadActions.DELETE))[0]; ComponentMaintenance componentMaintenance = repository.facet(ComponentMaintenance.class); Queue<String> paths = new PriorityQueue<>(); paths.add(treePath); while (!cancelledCheck.getAsBoolean() && !paths.isEmpty()) { String basePath = paths.poll(); List<String> path = Arrays.asList(basePath.split("/")); Iterable<BrowseNode> nodes = browseNodeQueryService.getByPath(repository, path, configuration.getMaxNodes()); Iterator<BrowseNode> nodeIterator = nodes.iterator(); while (!cancelledCheck.getAsBoolean() && nodeIterator.hasNext()) { BrowseNode node = nodeIterator.next(); if (!node.isLeaf()) { paths.offer(basePath + "/" + node.getName()); } else if (canDeleteComponent && node.getAssetId() == null && node.getComponentId() != null) { deleteComponent(repository, node.getComponentId(), timestamp, componentMaintenance); } if (node.getAssetId() != null) { deleteAsset(repository, node.getAssetId(), timestamp, componentMaintenance); } } } } @Inject  DeleteFolderServiceImpl(
      final BrowseNodeQueryService browseNodeQueryService,
      final BrowseNodeConfiguration configuration,
      final AssetStore assetStore,
      final ContentPermissionChecker contentPermissionChecker,
      final VariableResolverAdapterManager variableResolverAdapterManager,
      final SecurityHelper securityHelper); @Override void deleteFolder(final Repository repository,
                           final String treePath,
                           final DateTime timestamp,
                           final BooleanSupplier cancelledCheck);  }