use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class StatisticsWebOp method run.
/**
* Runs the command and builds the appropriate response
*
* @param context - the context to use for this command
*/
@Override
public void run(CommandContext context) {
final Context geogig = this.getCommandLocator(context);
final List<FeatureTypeStats> stats = Lists.newArrayList();
LogOp logOp = geogig.command(LogOp.class).setFirstParentOnly(true);
final Iterator<RevCommit> log;
if (since != null && !since.trim().isEmpty()) {
Date untilTime = new Date();
Date sinceTime = new Date(geogig.command(ParseTimestamp.class).setString(since).call());
logOp.setTimeRange(new Range<Date>(Date.class, sinceTime, untilTime));
}
if (this.until != null) {
Optional<ObjectId> until;
until = geogig.command(RevParse.class).setRefSpec(this.until).call();
Preconditions.checkArgument(until.isPresent(), "Object not found '%s'", this.until);
logOp.setUntil(until.get());
}
LsTreeOp lsTreeOp = geogig.command(LsTreeOp.class).setStrategy(LsTreeOp.Strategy.TREES_ONLY);
if (path != null && !path.trim().isEmpty()) {
lsTreeOp.setReference(path);
logOp.addPath(path);
}
final Iterator<NodeRef> treeIter = lsTreeOp.call();
while (treeIter.hasNext()) {
NodeRef node = treeIter.next();
stats.add(new FeatureTypeStats(node.path(), context.getGeoGIG().getRepository().getTree(node.objectId()).size()));
}
log = logOp.call();
RevCommit firstCommit = null;
RevCommit lastCommit = null;
int totalCommits = 0;
final List<RevPerson> authors = Lists.newArrayList();
if (log.hasNext()) {
lastCommit = log.next();
authors.add(lastCommit.getAuthor());
totalCommits++;
}
while (log.hasNext()) {
firstCommit = log.next();
RevPerson newAuthor = firstCommit.getAuthor();
// If the author isn't defined, use the committer for the purposes of statistics.
if (!newAuthor.getName().isPresent() && !newAuthor.getEmail().isPresent()) {
newAuthor = firstCommit.getCommitter();
}
if (newAuthor.getName().isPresent() || newAuthor.getEmail().isPresent()) {
boolean authorFound = false;
for (RevPerson author : authors) {
if (newAuthor.getName().equals(author.getName()) && newAuthor.getEmail().equals(author.getEmail())) {
authorFound = true;
break;
}
}
if (!authorFound) {
authors.add(newAuthor);
}
}
totalCommits++;
}
int addedFeatures = 0;
int modifiedFeatures = 0;
int removedFeatures = 0;
if (since != null && !since.trim().isEmpty() && firstCommit != null && lastCommit != null) {
final Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(firstCommit.getId()).setNewVersion(lastCommit.getId()).setFilter(path).call();
while (diff.hasNext()) {
DiffEntry entry = diff.next();
if (entry.changeType() == DiffEntry.ChangeType.ADDED) {
addedFeatures++;
} else if (entry.changeType() == DiffEntry.ChangeType.MODIFIED) {
modifiedFeatures++;
} else {
removedFeatures++;
}
}
}
final RevCommit first = firstCommit;
final RevCommit last = lastCommit;
final int total = totalCommits;
final int added = addedFeatures;
final int modified = modifiedFeatures;
final int removed = removedFeatures;
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start(true);
out.writeStatistics(stats, first, last, total, authors, added, modified, removed);
out.finish();
}
});
}
use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class Clean method runInternal.
@Override
public void runInternal(GeogigCLI cli) throws IOException {
final ConsoleReader console = cli.getConsole();
final GeoGIG geogig = cli.getGeogig();
String pathFilter = null;
if (!path.isEmpty()) {
pathFilter = path.get(0);
}
if (dryRun) {
if (pathFilter != null) {
// check that is a valid path
Repository repository = cli.getGeogig().getRepository();
NodeRef.checkValidPath(pathFilter);
Optional<NodeRef> ref = repository.command(FindTreeChild.class).setIndex(true).setParent(repository.workingTree().getTree()).setChildPath(pathFilter).call();
checkParameter(ref.isPresent(), "pathspec '%s' did not match any tree", pathFilter);
checkParameter(ref.get().getType() == TYPE.TREE, "pathspec '%s' did not resolve to a tree", pathFilter);
}
Iterator<DiffEntry> unstaged = geogig.command(DiffWorkTree.class).setFilter(pathFilter).call();
while (unstaged.hasNext()) {
DiffEntry entry = unstaged.next();
if (entry.changeType() == ChangeType.ADDED) {
console.println("Would remove " + entry.newPath());
}
}
} else {
geogig.command(CleanOp.class).setPath(pathFilter).call();
console.println("Clean operation completed succesfully.");
}
}
use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class FullDiffPrinter method print.
@Override
public void print(GeoGIG geogig, ConsoleReader console, DiffEntry entry) throws IOException {
Ansi ansi = AnsiDecorator.newAnsi(console.getTerminal().isAnsiSupported());
final NodeRef newObject = entry.getNewObject();
final NodeRef oldObject = entry.getOldObject();
String oldMode = oldObject == null ? shortOid(ObjectId.NULL) : shortOid(oldObject.getMetadataId());
String newMode = newObject == null ? shortOid(ObjectId.NULL) : shortOid(newObject.getMetadataId());
String oldId = oldObject == null ? shortOid(ObjectId.NULL) : shortOid(oldObject.objectId());
String newId = newObject == null ? shortOid(ObjectId.NULL) : shortOid(newObject.objectId());
ansi.a(oldMode).a(" ");
ansi.a(newMode).a(" ");
ansi.a(oldId).a(" ");
ansi.a(newId).a(" ");
ansi.fg(entry.changeType() == ADDED ? GREEN : (entry.changeType() == MODIFIED ? YELLOW : RED));
char type = entry.changeType().toString().charAt(0);
ansi.a(" ").a(type).reset();
ansi.a(" ").a(formatPath(entry));
console.println(ansi.toString());
}
use of org.locationtech.geogig.api.NodeRef 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.NodeRef in project GeoGig by boundlessgeo.
the class MutableTreeTest method testBuild.
@Test
@Ignore
public void testBuild() {
ObjectDatabase origin = new HeapObjectDatabse();
origin.open();
ObjectDatabase target = new HeapObjectDatabse();
target.open();
RevTree tree = root.build(origin, target);
Iterator<NodeRef> treeRefs = new DepthTreeIterator("", ObjectId.NULL, tree, target, Strategy.RECURSIVE_TREES_ONLY);
MutableTree createFromRefs = MutableTree.createFromRefs(root.getNode().getObjectId(), treeRefs);
// TODO finish
}
Aggregations