Search in sources :

Example 46 with NodeRef

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();
        }
    });
}
Also used : ParseTimestamp(org.locationtech.geogig.api.plumbing.ParseTimestamp) LogOp(org.locationtech.geogig.api.porcelain.LogOp) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) NodeRef(org.locationtech.geogig.api.NodeRef) RevPerson(org.locationtech.geogig.api.RevPerson) RevParse(org.locationtech.geogig.api.plumbing.RevParse) RevCommit(org.locationtech.geogig.api.RevCommit) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) ObjectId(org.locationtech.geogig.api.ObjectId) Date(java.util.Date) LsTreeOp(org.locationtech.geogig.api.plumbing.LsTreeOp) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter)

Example 47 with NodeRef

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.");
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) Repository(org.locationtech.geogig.repository.Repository) ConsoleReader(jline.console.ConsoleReader) GeoGIG(org.locationtech.geogig.api.GeoGIG) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 48 with NodeRef

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());
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) Ansi(org.fusesource.jansi.Ansi)

Example 49 with NodeRef

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));
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) Repository(org.locationtech.geogig.repository.Repository) ConsoleReader(jline.console.ConsoleReader) ArrayList(java.util.ArrayList) RemoveOp(org.locationtech.geogig.api.porcelain.RemoveOp) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException)

Example 50 with NodeRef

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
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) HeapObjectDatabse(org.locationtech.geogig.storage.memory.HeapObjectDatabse) RevTree(org.locationtech.geogig.api.RevTree) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

NodeRef (org.locationtech.geogig.api.NodeRef)161 ObjectId (org.locationtech.geogig.api.ObjectId)91 RevTree (org.locationtech.geogig.api.RevTree)67 Test (org.junit.Test)62 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)40 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)27 RevFeature (org.locationtech.geogig.api.RevFeature)25 Node (org.locationtech.geogig.api.Node)24 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)24 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)23 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)22 RevObject (org.locationtech.geogig.api.RevObject)21 RevCommit (org.locationtech.geogig.api.RevCommit)19 Map (java.util.Map)15 SimpleFeature (org.opengis.feature.simple.SimpleFeature)15 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)14 Feature (org.opengis.feature.Feature)13 Optional (com.google.common.base.Optional)12 GeoGIG (org.locationtech.geogig.api.GeoGIG)11 LsTreeOp (org.locationtech.geogig.api.plumbing.LsTreeOp)11