use of org.locationtech.geogig.api.porcelain.RemoveOp in project GeoGig by boundlessgeo.
the class Remove method runInternal.
@Override
public void runInternal(GeogigCLI cli) throws IOException {
ConsoleReader console = cli.getConsole();
// check that there is something to remove
if (pathsToRemove.isEmpty()) {
printUsage(cli);
throw new CommandFailedException();
}
/*
* Separate trees and features, and check that, if there are trees to remove, the -r
* modifier is used
*/
ArrayList<String> trees = new ArrayList<String>();
Repository repository = cli.getGeogig().getRepository();
for (String pathToRemove : pathsToRemove) {
NodeRef.checkValidPath(pathToRemove);
Optional<NodeRef> node = repository.command(FindTreeChild.class).setParent(repository.workingTree().getTree()).setIndex(true).setChildPath(pathToRemove).call();
checkParameter(node.isPresent(), "pathspec '%s' did not match any feature or tree", pathToRemove);
NodeRef nodeRef = node.get();
if (nodeRef.getType() == TYPE.TREE) {
checkParameter(recursive, "Cannot remove tree %s if -r is not specified", nodeRef.path());
trees.add(pathToRemove);
}
}
int featuresCount = pathsToRemove.size() - trees.size();
/* Perform the remove operation */
RemoveOp op = cli.getGeogig().command(RemoveOp.class);
for (String pathToRemove : pathsToRemove) {
op.addPathToRemove(pathToRemove);
}
op.setProgressListener(cli.getProgressListener()).call();
/* And inform about it */
if (featuresCount > 0) {
console.print(String.format("Deleted %d feature(s)", featuresCount));
}
for (String tree : trees) {
console.print(String.format("Deleted %s tree", tree));
}
}
use of org.locationtech.geogig.api.porcelain.RemoveOp in project GeoGig by boundlessgeo.
the class RemoveWebOp method run.
/**
* Runs the command and builds the appropriate response.
*
* @param context - the context to use for this command
*
* @throws CommandSpecException
*/
@Override
public void run(CommandContext context) {
if (this.getTransactionId() == null) {
throw new CommandSpecException("No transaction was specified, remove requires a transaction to preserve the stability of the repository.");
}
if (this.path == null) {
throw new CommandSpecException("No path was specified for removal.");
}
final Context geogig = this.getCommandLocator(context);
RemoveOp command = geogig.command(RemoveOp.class);
NodeRef.checkValidPath(path);
Optional<NodeRef> node = geogig.command(FindTreeChild.class).setParent(geogig.workingTree().getTree()).setIndex(true).setChildPath(path).call();
if (node.isPresent()) {
NodeRef nodeRef = node.get();
if (nodeRef.getType() == TYPE.TREE) {
if (!recursive) {
throw new CommandSpecException("Recursive option must be used to remove a tree.");
}
}
}
command.addPathToRemove(path).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeElement("Deleted", path);
out.finish();
}
});
}
Aggregations