Search in sources :

Example 61 with RevTree

use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.

the class RevTreeSerializationTest method write.

private byte[] write(RevTree tree) {
    try {
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ObjectWriter<RevTree> treeWriter = factory.<RevTree>createObjectWriter(RevObject.TYPE.TREE);
        treeWriter.write(tree, bout);
        return bout.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) RevTree(org.locationtech.geogig.api.RevTree)

Example 62 with RevTree

use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.

the class RevTreeSerializationTest method testRoundTripSpatialLeafTree.

@Test
public void testRoundTripSpatialLeafTree() {
    RevTree roundTripped = read(tree4_spatial_leaves.getId(), write(tree4_spatial_leaves));
    assertTreesAreEqual(tree4_spatial_leaves, roundTripped);
}
Also used : RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 63 with RevTree

use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.

the class RevTreeSerializationTest method testRoundTripBucketsFull.

@Test
public void testRoundTripBucketsFull() {
    ObjectId id = ObjectId.forString("fake");
    long size = 100000000;
    int childTreeCount = 0;
    Map<Integer, Bucket> bucketTrees = createBuckets(32);
    final RevTreeImpl tree = RevTreeImpl.createNodeTree(id, size, childTreeCount, bucketTrees);
    RevTree roundTripped = read(tree.getId(), write(tree));
    assertTreesAreEqual(tree, roundTripped);
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Bucket(org.locationtech.geogig.api.Bucket) RevTreeImpl(org.locationtech.geogig.api.RevTreeImpl) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 64 with RevTree

use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.

the class Show method printFormatted.

public void printFormatted(GeogigCLI cli) throws IOException {
    ConsoleReader console = cli.getConsole();
    GeoGIG geogig = cli.getGeogig();
    for (String ref : refs) {
        Optional<RevObject> obj = geogig.command(RevObjectParse.class).setRefSpec(ref).call();
        if (!obj.isPresent()) {
            ref = getFullRef(ref);
            obj = geogig.command(RevObjectParse.class).setRefSpec(ref).call();
        }
        checkParameter(obj.isPresent(), "refspec did not resolve to any object.");
        RevObject revObject = obj.get();
        if (revObject instanceof RevFeature) {
            Optional<RevFeatureType> opt = geogig.command(ResolveFeatureType.class).setRefSpec(ref).call();
            if (opt.isPresent()) {
                RevFeatureType ft = opt.get();
                ImmutableList<PropertyDescriptor> attribs = ft.sortedDescriptors();
                RevFeature feature = (RevFeature) revObject;
                Ansi ansi = super.newAnsi(console.getTerminal());
                ansi.newline().fg(Color.YELLOW).a("ID:  ").reset().a(feature.getId().toString()).newline();
                ansi.fg(Color.YELLOW).a("FEATURE TYPE ID:  ").reset().a(ft.getId().toString()).newline().newline();
                ansi.a("ATTRIBUTES  ").newline();
                ansi.a("----------  ").newline();
                ImmutableList<Optional<Object>> values = feature.getValues();
                int i = 0;
                for (Optional<Object> value : values) {
                    ansi.fg(Color.YELLOW).a(attribs.get(i).getName() + ": ").reset();
                    ansi.a(value.or("[NULL]").toString()).newline();
                    i++;
                }
                console.println(ansi.toString());
            } else {
                CharSequence s = geogig.command(CatObject.class).setObject(Suppliers.ofInstance(revObject)).call();
                console.println(s);
            }
        } else if (revObject instanceof RevTree) {
            RevTree tree = (RevTree) revObject;
            Optional<RevFeatureType> opt = geogig.command(ResolveFeatureType.class).setRefSpec(ref).call();
            checkParameter(opt.isPresent(), "Refspec must resolve to a commit, tree, feature or feature type");
            RevFeatureType ft = opt.get();
            Ansi ansi = super.newAnsi(console.getTerminal());
            ansi.fg(Color.YELLOW).a("TREE ID:  ").reset().a(tree.getId().toString()).newline();
            ansi.fg(Color.YELLOW).a("SIZE:  ").reset().a(Long.toString(tree.size())).newline();
            ansi.fg(Color.YELLOW).a("NUMBER Of SUBTREES:  ").reset().a(Integer.toString(tree.numTrees()).toString()).newline();
            printFeatureType(ansi, ft, true);
            console.println(ansi.toString());
        } else if (revObject instanceof RevCommit) {
            RevCommit commit = (RevCommit) revObject;
            Ansi ansi = super.newAnsi(console.getTerminal());
            ansi.a(Strings.padEnd("Commit:", 15, ' ')).fg(Color.YELLOW).a(commit.getId().toString()).reset().newline();
            ansi.a(Strings.padEnd("Author:", 15, ' ')).fg(Color.GREEN).a(formatPerson(commit.getAuthor())).reset().newline();
            ansi.a(Strings.padEnd("Committer:", 15, ' ')).fg(Color.GREEN).a(formatPerson(commit.getAuthor())).reset().newline();
            ansi.a(Strings.padEnd("Author date:", 15, ' ')).a("(").fg(Color.RED).a(estimateSince(geogig.getPlatform(), commit.getAuthor().getTimestamp())).reset().a(") ").a(new Date(commit.getAuthor().getTimestamp())).newline();
            ansi.a(Strings.padEnd("Committer date:", 15, ' ')).a("(").fg(Color.RED).a(estimateSince(geogig.getPlatform(), commit.getCommitter().getTimestamp())).reset().a(") ").a(new Date(commit.getCommitter().getTimestamp())).newline();
            ansi.a(Strings.padEnd("Subject:", 15, ' ')).a(commit.getMessage()).newline();
            console.println(ansi.toString());
        } else if (revObject instanceof RevFeatureType) {
            Ansi ansi = super.newAnsi(console.getTerminal());
            printFeatureType(ansi, (RevFeatureType) revObject, false);
            console.println(ansi.toString());
        } else {
            throw new InvalidParameterException("Refspec must resolve to a commit, tree, feature or feature type");
        }
        console.println();
    }
}
Also used : ResolveFeatureType(org.locationtech.geogig.api.plumbing.ResolveFeatureType) ConsoleReader(jline.console.ConsoleReader) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) RevObject(org.locationtech.geogig.api.RevObject) Date(java.util.Date) InvalidParameterException(java.security.InvalidParameterException) RevFeature(org.locationtech.geogig.api.RevFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) CatObject(org.locationtech.geogig.api.plumbing.CatObject) RevObject(org.locationtech.geogig.api.RevObject) Ansi(org.fusesource.jansi.Ansi) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 65 with RevTree

use of org.locationtech.geogig.api.RevTree 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

RevTree (org.locationtech.geogig.api.RevTree)214 Test (org.junit.Test)120 ObjectId (org.locationtech.geogig.api.ObjectId)91 NodeRef (org.locationtech.geogig.api.NodeRef)73 Node (org.locationtech.geogig.api.Node)56 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)47 RevCommit (org.locationtech.geogig.api.RevCommit)36 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)29 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)27 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)24 RevObject (org.locationtech.geogig.api.RevObject)21 RevFeature (org.locationtech.geogig.api.RevFeature)18 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)18 Bucket (org.locationtech.geogig.api.Bucket)17 TreeTestSupport.featureNode (org.locationtech.geogig.api.plumbing.diff.TreeTestSupport.featureNode)17 File (java.io.File)16 Ref (org.locationtech.geogig.api.Ref)16 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)15 GeoGIG (org.locationtech.geogig.api.GeoGIG)14 OSMImportOp (org.locationtech.geogig.osm.internal.OSMImportOp)14