private Collection<NameSpaceContainer> traverseEntity(final NamespaceKey root) throws NamespaceException { final LinkedList<NameSpaceContainer> toBeTraversed = new LinkedList<>(listEntity(root)); final LinkedList<NameSpaceContainer> visited = new LinkedList<>(); while (!toBeTraversed.isEmpty()) { final NameSpaceContainer container = toBeTraversed.removeFirst(); if (NamespaceUtils.isListable(container.getType())) { toBeTraversed.addAll(listEntity(new NamespaceKey(container.getFullPathList()))); } visited.add(container); } return visited; }
private void populateNextFewKeys() { while (!stack.isEmpty()) { final NamespaceKey top = stack.pop(); final Iterable<NameSpaceContainer> children; try { children = iterateEntity(top); } catch (NamespaceException e) { throw new RuntimeException("failed during dataset listing of sub-tree under: " + root); } for (final NameSpaceContainer child : children) { final NamespaceKey childKey = new NamespaceKey(child.getFullPathList()); if (child.getType() == DATASET) { nextFewKeys.add(childKey); continue; } assert isListable(child.getType()) : "child container is not listable type"; stack.push(childKey); } if (!nextFewKeys.isEmpty()) { // suspend if few keys are loaded break; } } }
@Override public Iterable<NamespaceKey> getAllDatasets(final NamespaceKey root) throws NamespaceException { final NameSpaceContainer rootContainer = namespace.get(new NamespaceInternalKey(root, keyNormalization).getKey()); if (rootContainer == null) { return Collections.emptyList(); } if (!isListable(rootContainer.getType())) { return Collections.emptyList(); } return () -> new LazyIteratorOverDatasets(root); }
/** * Helper method which travels the tree rooted at the given key and deletes all children in a DFS traversal * (except the root). In order to delete an entity, user should have edit permissions on its parent, * no need of any permission requirements on the entity that is being deleted (Linux FileSystem permission model) * * @param key * @param container * @throws NamespaceException */ private void traverseAndDeleteChildren(final NamespaceInternalKey key, final NameSpaceContainer container) throws NamespaceException { if (!NamespaceUtils.isListable(container.getType())) { return; } for (NameSpaceContainer child : listEntity(key.getPath())) { doTraverseAndDeleteChildren(child); } }
@Override public List<NameSpaceContainer> list(NamespaceKey root) throws NamespaceException { final List<NameSpaceContainer> entitiesOnPath = getEntitiesOnPath(root); final NameSpaceContainer rootContainer = lastElement(entitiesOnPath); if (rootContainer == null) { throw new NamespaceNotFoundException(root, "not found"); } if (!isListable(rootContainer.getType())) { throw new NamespaceNotFoundException(root, "no listable entity found"); } return doList(root, entitiesOnPath); }