public UpdateTree removeChildTree(String childTreePath) { NodeRef.checkValidPath(childTreePath); childTreeUpdates.remove(childTreePath); childTreeRemoves.add(childTreePath); return this; }
public UpdateTree removeChildTree(String childTreePath) { NodeRef.checkValidPath(childTreePath); childTreeUpdates.remove(childTreePath); childTreeRemoves.add(childTreePath); return this; }
/** * @return an iterable with all elements in {@link #pathsToRemove} whose parent path are not in * {@code deleteTrees} */ private List<String> filterFeatures(Set<String> deleteTrees) { List<String> filtered = new ArrayList<>(this.pathsToRemove.size()); for (String pathToRemove : pathsToRemove) { if (deleteTrees.contains(pathToRemove) || deleteTrees.contains(NodeRef.parentPath(pathToRemove))) { continue; } NodeRef.checkValidPath(pathToRemove); filtered.add(pathToRemove); } return filtered; }
/** * @return an iterable with all elements in {@link #pathsToRemove} whose parent path are not in * {@code deleteTrees} */ private List<String> filterFeatures(Set<String> deleteTrees) { List<String> filtered = new ArrayList<>(this.pathsToRemove.size()); for (String pathToRemove : pathsToRemove) { if (deleteTrees.contains(pathToRemove) || deleteTrees.contains(NodeRef.parentPath(pathToRemove))) { continue; } NodeRef.checkValidPath(pathToRemove); filtered.add(pathToRemove); } return filtered; }
public UpdateTree setChild(NodeRef childTreeNode) { checkNotNull(childTreeNode); final String path = childTreeNode.path(); NodeRef.checkValidPath(path); checkArgument(RevObject.TYPE.TREE.equals(childTreeNode.getType())); childTreeRemoves.remove(path); childTreeUpdates.put(path, childTreeNode); return this; }
@Nullable public MutableTree removeChild(String path) { NodeRef.checkValidPath(path); final List<String> querySteps = NodeRef.split(path); List<String> visited = new ArrayList<>(querySteps.size()); MutableTree tree = this; MutableTree removed = null; for (Iterator<String> childNames = querySteps.iterator(); childNames.hasNext();) { String childName = childNames.next(); visited.add(childName); MutableTree child = tree.childTrees.get(childName); if (child == null) { break; } if (querySteps.equals(visited)) { removed = tree.childTrees.remove(childName); break; } else { tree = child; } } return removed; }
public UpdateTree setChild(NodeRef childTreeNode) { checkNotNull(childTreeNode); final String path = childTreeNode.path(); NodeRef.checkValidPath(path); checkArgument(RevObject.TYPE.TREE.equals(childTreeNode.getType())); childTreeRemoves.remove(path); childTreeUpdates.put(path, childTreeNode); return this; }
@Nullable public MutableTree removeChild(String path) { NodeRef.checkValidPath(path); final List<String> querySteps = NodeRef.split(path); List<String> visited = new ArrayList<>(querySteps.size()); MutableTree tree = this; MutableTree removed = null; for (Iterator<String> childNames = querySteps.iterator(); childNames.hasNext();) { String childName = childNames.next(); visited.add(childName); MutableTree child = tree.childTrees.get(childName); if (child == null) { break; } if (querySteps.equals(visited)) { removed = tree.childTrees.remove(childName); break; } else { tree = child; } } return removed; }
@Test public void testCheckValidPath() { NodeRef.checkValidPath("Points"); }
/** * Constructs a new {@code NodeRef} that points to the tree with the provided parameters. * * @param treePath the path of the tree * @param id the {@link ObjectId} of the tree * @param metadataId the metadata id of the tree * @return the newly constructed {@code NodeRef} */ public static NodeRef tree(String treePath, ObjectId id, ObjectId metadataId) { NodeRef.checkValidPath(treePath); checkNotNull(id); checkNotNull(metadataId); String parentPath = NodeRef.parentPath(treePath); String treeName = NodeRef.nodeFromPath(treePath); Node treeNode = Node.tree(treeName, id, metadataId); return NodeRef.create(parentPath, treeNode); } }
/** * Constructs a new {@code NodeRef} that points to the tree with the provided parameters. * * @param treePath the path of the tree * @param id the {@link ObjectId} of the tree * @param metadataId the metadata id of the tree * @return the newly constructed {@code NodeRef} */ public static NodeRef tree(String treePath, ObjectId id, ObjectId metadataId) { NodeRef.checkValidPath(treePath); checkNotNull(id); checkNotNull(metadataId); String parentPath = NodeRef.parentPath(treePath); String treeName = NodeRef.nodeFromPath(treePath); Node treeNode = RevObjectFactory.defaultInstance().createNode(treeName, id, metadataId, TYPE.TREE, null, null); return NodeRef.create(parentPath, treeNode); } }
private Optional<RevFeature> getFeatureFromRefSpec() { Optional<RevObject> revObject = command(RevObjectParse.class).setRefSpec(ref) .call(RevObject.class); if (!revObject.isPresent()) { // let's try to see if it is a feature in the working tree NodeRef.checkValidPath(ref); Optional<NodeRef> elementRef = command(FindTreeChild.class) .setParent(workingTree().getTree()).setChildPath(ref).call(); Preconditions.checkArgument(elementRef.isPresent(), "Invalid reference: %s", ref); ObjectId id = elementRef.get().getObjectId(); revObject = command(RevObjectParse.class).setObjectId(id).call(RevObject.class); } if (revObject.isPresent()) { Preconditions.checkArgument(TYPE.FEATURE.equals(revObject.get().getType()), "%s does not resolve to a feature", ref); return Optional.of(RevFeature.class.cast(revObject.get())); } else { return Optional.absent(); } }
private Optional<RevFeature> getFeatureFromRefSpec() { Optional<RevObject> revObject = command(RevObjectParse.class).setRefSpec(ref) .call(RevObject.class); if (!revObject.isPresent()) { // let's try to see if it is a feature in the working tree NodeRef.checkValidPath(ref); Optional<NodeRef> elementRef = command(FindTreeChild.class) .setParent(workingTree().getTree()).setChildPath(ref).call(); Preconditions.checkArgument(elementRef.isPresent(), "Invalid reference: %s", ref); ObjectId id = elementRef.get().getObjectId(); revObject = command(RevObjectParse.class).setObjectId(id).call(RevObject.class); } if (revObject.isPresent()) { Preconditions.checkArgument(TYPE.FEATURE.equals(revObject.get().getType()), "%s does not resolve to a feature", ref); return Optional.of(RevFeature.class.cast(revObject.get())); } else { return Optional.absent(); } }
@Test public void testCheckValidPathNull() { exception.expect(IllegalArgumentException.class); NodeRef.checkValidPath(null); }
@Test public void testCheckValidPathPathEndingWithSeperator() { exception.expect(IllegalArgumentException.class); NodeRef.checkValidPath("Points/"); }
@Test public void testCheckValidPathEmptyString() { exception.expect(IllegalArgumentException.class); NodeRef.checkValidPath(""); }
/** * @see java.util.concurrent.Callable#call() */ protected WorkingTree _call() { if (path != null) { // check that is a valid path NodeRef.checkValidPath(path); Optional<NodeRef> ref = command(FindTreeChild.class).setParent(workingTree().getTree()) .setChildPath(path).call(); Preconditions.checkArgument(ref.isPresent(), "pathspec '%s' did not match any tree", path); Preconditions.checkArgument(ref.get().getType() == TYPE.TREE, "pathspec '%s' did not resolve to a tree", path); } try (final AutoCloseableIterator<DiffEntry> unstaged = command(DiffWorkTree.class) .setFilter(path).call()) { final Iterator<DiffEntry> added = filter(unstaged, new Predicate<DiffEntry>() { @Override public boolean apply(@Nullable DiffEntry input) { return input.changeType().equals(ChangeType.ADDED); } }); workingTree().delete(transform(added, (de) -> de.newPath()), getProgressListener()); } return workingTree(); }
/** * Runs the command and builds the appropriate response. * * @param context - the context to use for this command * * @throws CommandSpecException */ @Override protected void runInternal(CommandContext context) { final Context geogig = this.getRepositoryContext(context); NodeRef.checkValidPath(path); RemoveOp command = geogig.command(RemoveOp.class).setRecursive(recursive); command.addPathToRemove(path).call(); context.setResponseContent(new CommandResponse() { @Override public void write(ResponseWriter out) throws Exception { out.start(); out.writeElement("Deleted", path); out.finish(); } }); }
@Override public synchronized NodeRef createTypeTree(final String treePath, final FeatureType featureType) { NodeRef.checkValidPath(treePath); final RevTree workHead = getTree(); final NodeRef currentTreeRef = context.command(FindTreeChild.class).setParent(workHead) .setChildPath(treePath).call().orNull(); if (null != currentTreeRef) { throw new IllegalArgumentException("Tree already exists at " + treePath); } final RevFeatureType revType = RevFeatureTypeBuilder.build(featureType); indexDatabase.put(revType); final ObjectId metadataId = revType.getId(); final String parentPath = NodeRef.parentPath(treePath); final String treeName = NodeRef.nodeFromPath(treePath); final NodeRef newTreeRef = NodeRef.create(parentPath, Node.tree(treeName, EMPTY_TREE_ID, metadataId)); final RevTree newWorkHead = context.command(UpdateTree.class).setRoot(workHead) .setChild(newTreeRef).call(); updateWorkHead(newWorkHead.getId()); NodeRef ref = context.command(FindTreeChild.class).setParent(newWorkHead) .setChildPath(treePath).call().orNull(); checkNotNull(ref, "tree wasn't created: " + treePath); return ref; }
@Override public synchronized NodeRef createTypeTree(final String treePath, final FeatureType featureType) { NodeRef.checkValidPath(treePath); final RevTree workHead = getTree(); final NodeRef currentTreeRef = context.command(FindTreeChild.class).setParent(workHead) .setChildPath(treePath).call().orNull(); if (null != currentTreeRef) { throw new IllegalArgumentException("Tree already exists at " + treePath); } final RevFeatureType revType = RevFeatureType.builder().type(featureType).build(); indexDatabase.put(revType); final ObjectId metadataId = revType.getId(); final String parentPath = NodeRef.parentPath(treePath); final String treeName = NodeRef.nodeFromPath(treePath); final NodeRef newTreeRef = NodeRef.create(parentPath, RevObjectFactory.defaultInstance() .createNode(treeName, EMPTY_TREE_ID, metadataId, TYPE.TREE, null, null)); final RevTree newWorkHead = context.command(UpdateTree.class).setRoot(workHead) .setChild(newTreeRef).call(); updateWorkHead(newWorkHead.getId()); NodeRef ref = context.command(FindTreeChild.class).setParent(newWorkHead) .setChildPath(treePath).call().orNull(); checkNotNull(ref, "tree wasn't created: " + treePath); return ref; }