@Test public void simpleQueryWithoutBrowsePermissionOrSelectors() throws Exception { List<String> queryPath = asList("org", "foo"); when(securityHelper.anyPermitted(any())).thenReturn(false); when(selectorManager.browseActive(asList(REPOSITORY_NAME), asList(FORMAT_NAME))).thenReturn(emptyList()); underTest.getByPath(repository, queryPath, MAX_NODES); verify(securityHelper).anyPermitted(any(RepositoryViewPermission.class)); verify(selectorManager).browseActive(asList(REPOSITORY_NAME), asList(FORMAT_NAME)); verifyNoMoreInteractions(browseNodeEntityAdapter, securityHelper, selectorManager); }
@Override @Guarded(by = STARTED) public Iterable<BrowseNode> getByPath( final Repository repository, final List<String> path, final int maxNodes) { String repositoryName = repository.getName(); String format = repository.getFormat().getValue(); List<SelectorConfiguration> selectors = emptyList(); if (!hasBrowsePermission(repositoryName, format)) { selectors = selectorManager.browseActive(asList(repositoryName), asList(format)); if (selectors.isEmpty()) { return emptyList(); } } Map<String, Object> filterParameters = new HashMap<>(); String assetFilter = buildAssetFilter(repository, selectors, filterParameters); BrowseNodeFilter filter = browseNodeFilters.getOrDefault(format, (node, name) -> true); List<BrowseNode> results; if (repository.getType() instanceof GroupType) { BrowseNodeIdentity identity = browseNodeIdentities.getOrDefault(format, BrowseNode::getName); Equivalence<OrientBrowseNode> browseNodeEquivalence = Equivalence.equals().onResultOf(identity::identity); results = members(repository) .map(m -> getByPath(m.getName(), path, maxNodes, assetFilter, filterParameters)) .flatMap(List::stream) .map(browseNodeEquivalence::wrap) .distinct() .map(Wrapper::get) .filter(node -> filter.test(node, repositoryName.equals(node.getRepositoryName()))) .limit(maxNodes) .collect(toList()); } else { results = getByPath(repository.getName(), path, maxNodes, assetFilter, filterParameters).stream() .filter(node -> filter.test(node, repositoryName.equals(node.getRepositoryName()))) .collect(toList()); } results.sort(getBrowseNodeComparator(format)); return results; }
OrientBrowseNodeStore extends StateGuardLifecycleSupport implements BrowseNodeQueryService { @Override @Guarded(by = STARTED) public Iterable<BrowseNode> getByPath( final Repository repository, final List<String> path, final int maxNodes) { String repositoryName = repository.getName(); String format = repository.getFormat().getValue(); List<SelectorConfiguration> selectors = emptyList(); if (!hasBrowsePermission(repositoryName, format)) { selectors = selectorManager.browseActive(asList(repositoryName), asList(format)); if (selectors.isEmpty()) { return emptyList(); } } Map<String, Object> filterParameters = new HashMap<>(); String assetFilter = buildAssetFilter(repository, selectors, filterParameters); BrowseNodeFilter filter = browseNodeFilters.getOrDefault(format, (node, name) -> true); List<BrowseNode> results; if (repository.getType() instanceof GroupType) { BrowseNodeIdentity identity = browseNodeIdentities.getOrDefault(format, BrowseNode::getName); Equivalence<OrientBrowseNode> browseNodeEquivalence = Equivalence.equals().onResultOf(identity::identity); results = members(repository) .map(m -> getByPath(m.getName(), path, maxNodes, assetFilter, filterParameters)) .flatMap(List::stream) .map(browseNodeEquivalence::wrap) .distinct() .map(Wrapper::get) .filter(node -> filter.test(node, repositoryName.equals(node.getRepositoryName()))) .limit(maxNodes) .collect(toList()); } else { results = getByPath(repository.getName(), path, maxNodes, assetFilter, filterParameters).stream() .filter(node -> filter.test(node, repositoryName.equals(node.getRepositoryName()))) .collect(toList()); } results.sort(getBrowseNodeComparator(format)); return results; } }
OrientBrowseNodeStore extends StateGuardLifecycleSupport implements BrowseNodeQueryService { @Override @Guarded(by = STARTED) public Iterable<BrowseNode> getByPath( final Repository repository, final List<String> path, final int maxNodes) { String repositoryName = repository.getName(); String format = repository.getFormat().getValue(); List<SelectorConfiguration> selectors = emptyList(); if (!hasBrowsePermission(repositoryName, format)) { selectors = selectorManager.browseActive(asList(repositoryName), asList(format)); if (selectors.isEmpty()) { return emptyList(); } } Map<String, Object> filterParameters = new HashMap<>(); String assetFilter = buildAssetFilter(repository, selectors, filterParameters); BrowseNodeFilter filter = browseNodeFilters.getOrDefault(format, (node, name) -> true); List<BrowseNode> results; if (repository.getType() instanceof GroupType) { BrowseNodeIdentity identity = browseNodeIdentities.getOrDefault(format, BrowseNode::getName); Equivalence<OrientBrowseNode> browseNodeEquivalence = Equivalence.equals().onResultOf(identity::identity); results = members(repository) .map(m -> getByPath(m.getName(), path, maxNodes, assetFilter, filterParameters)) .flatMap(List::stream) .map(browseNodeEquivalence::wrap) .distinct() .map(Wrapper::get) .filter(node -> filter.test(node, repositoryName.equals(node.getRepositoryName()))) .limit(maxNodes) .collect(toList()); } else { results = getByPath(repository.getName(), path, maxNodes, assetFilter, filterParameters).stream() .filter(node -> filter.test(node, repositoryName.equals(node.getRepositoryName()))) .collect(toList()); } results.sort(getBrowseNodeComparator(format)); return results; } @Inject  OrientBrowseNodeStore(
      @Named("component") final Provider<DatabaseInstance> databaseInstance,
      final BrowseNodeEntityAdapter entityAdapter,
      final SecurityHelper securityHelper,
      final SelectorManager selectorManager,
      final BrowseNodeConfiguration configuration,
      final Map<String, BrowseNodeFilter> browseNodeFilters,
      final Map<String, BrowseNodeIdentity> browseNodeIdentities,
      final Map<String, BrowseNodeComparator> browseNodeComparators); }
OrientBrowseNodeStore extends StateGuardLifecycleSupport implements BrowseNodeQueryService { @Override @Guarded(by = STARTED) public Iterable<BrowseNode> getByPath( final Repository repository, final List<String> path, final int maxNodes) { String repositoryName = repository.getName(); String format = repository.getFormat().getValue(); List<SelectorConfiguration> selectors = emptyList(); if (!hasBrowsePermission(repositoryName, format)) { selectors = selectorManager.browseActive(asList(repositoryName), asList(format)); if (selectors.isEmpty()) { return emptyList(); } } Map<String, Object> filterParameters = new HashMap<>(); String assetFilter = buildAssetFilter(repository, selectors, filterParameters); BrowseNodeFilter filter = browseNodeFilters.getOrDefault(format, (node, name) -> true); List<BrowseNode> results; if (repository.getType() instanceof GroupType) { BrowseNodeIdentity identity = browseNodeIdentities.getOrDefault(format, BrowseNode::getName); Equivalence<OrientBrowseNode> browseNodeEquivalence = Equivalence.equals().onResultOf(identity::identity); results = members(repository) .map(m -> getByPath(m.getName(), path, maxNodes, assetFilter, filterParameters)) .flatMap(List::stream) .map(browseNodeEquivalence::wrap) .distinct() .map(Wrapper::get) .filter(node -> filter.test(node, repositoryName.equals(node.getRepositoryName()))) .limit(maxNodes) .collect(toList()); } else { results = getByPath(repository.getName(), path, maxNodes, assetFilter, filterParameters).stream() .filter(node -> filter.test(node, repositoryName.equals(node.getRepositoryName()))) .collect(toList()); } results.sort(getBrowseNodeComparator(format)); return results; } @Inject  OrientBrowseNodeStore(
      @Named("component") final Provider<DatabaseInstance> databaseInstance,
      final BrowseNodeEntityAdapter entityAdapter,
      final SecurityHelper securityHelper,
      final SelectorManager selectorManager,
      final BrowseNodeConfiguration configuration,
      final Map<String, BrowseNodeFilter> browseNodeFilters,
      final Map<String, BrowseNodeIdentity> browseNodeIdentities,
      final Map<String, BrowseNodeComparator> browseNodeComparators); @Guarded(by = STARTED) void createComponentNode(final String repositoryName,
                                  final String format,
                                  final List<BrowsePath> paths,
                                  final Component component); @Guarded(by = STARTED) void createAssetNode(final String repositoryName,
                              final String format,
                              final List<BrowsePath> paths,
                              final Asset asset); @Guarded(by = STARTED) boolean assetNodeExists(final Asset asset); @Guarded(by = STARTED) void deleteComponentNode(final Component component); @Guarded(by = STARTED) void deleteAssetNode(final Asset asset); @Guarded(by = STARTED) void deleteByRepository(final String repositoryName); @Override @Guarded(by = STARTED) Iterable<BrowseNode> getByPath(
      final Repository repository,
      final List<String> path,
      final int maxNodes); @Override List<BrowseListItem> toListItems(final Repository repository, final Iterable<BrowseNode> nodes); }
OrientBrowseNodeStore extends StateGuardLifecycleSupport implements BrowseNodeQueryService { @Override @Guarded(by = STARTED) public Iterable<BrowseNode> getByPath( final Repository repository, final List<String> path, final int maxNodes) { String repositoryName = repository.getName(); String format = repository.getFormat().getValue(); List<SelectorConfiguration> selectors = emptyList(); if (!hasBrowsePermission(repositoryName, format)) { selectors = selectorManager.browseActive(asList(repositoryName), asList(format)); if (selectors.isEmpty()) { return emptyList(); } } Map<String, Object> filterParameters = new HashMap<>(); String assetFilter = buildAssetFilter(repository, selectors, filterParameters); BrowseNodeFilter filter = browseNodeFilters.getOrDefault(format, (node, name) -> true); List<BrowseNode> results; if (repository.getType() instanceof GroupType) { BrowseNodeIdentity identity = browseNodeIdentities.getOrDefault(format, BrowseNode::getName); Equivalence<OrientBrowseNode> browseNodeEquivalence = Equivalence.equals().onResultOf(identity::identity); results = members(repository) .map(m -> getByPath(m.getName(), path, maxNodes, assetFilter, filterParameters)) .flatMap(List::stream) .map(browseNodeEquivalence::wrap) .distinct() .map(Wrapper::get) .filter(node -> filter.test(node, repositoryName.equals(node.getRepositoryName()))) .limit(maxNodes) .collect(toList()); } else { results = getByPath(repository.getName(), path, maxNodes, assetFilter, filterParameters).stream() .filter(node -> filter.test(node, repositoryName.equals(node.getRepositoryName()))) .collect(toList()); } results.sort(getBrowseNodeComparator(format)); return results; } @Inject  OrientBrowseNodeStore(
      @Named("component") final Provider<DatabaseInstance> databaseInstance,
      final BrowseNodeEntityAdapter entityAdapter,
      final SecurityHelper securityHelper,
      final SelectorManager selectorManager,
      final BrowseNodeConfiguration configuration,
      final Map<String, BrowseNodeFilter> browseNodeFilters,
      final Map<String, BrowseNodeIdentity> browseNodeIdentities,
      final Map<String, BrowseNodeComparator> browseNodeComparators); @Guarded(by = STARTED) void createComponentNode(final String repositoryName,
                                  final String format,
                                  final List<BrowsePath> paths,
                                  final Component component); @Guarded(by = STARTED) void createAssetNode(final String repositoryName,
                              final String format,
                              final List<BrowsePath> paths,
                              final Asset asset); @Guarded(by = STARTED) boolean assetNodeExists(final Asset asset); @Guarded(by = STARTED) void deleteComponentNode(final Component component); @Guarded(by = STARTED) void deleteAssetNode(final Asset asset); @Guarded(by = STARTED) void deleteByRepository(final String repositoryName); @Override @Guarded(by = STARTED) Iterable<BrowseNode> getByPath(
      final Repository repository,
      final List<String> path,
      final int maxNodes); @Override List<BrowseListItem> toListItems(final Repository repository, final Iterable<BrowseNode> nodes);  }