Search in sources :

Example 41 with RevTreeBuilder

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

the class Index method getParentTree.

/**
     * @param currentIndexHead
     * @param diffEntry
     * @param parentTress
     * @param parentMetadataIds
     * @return
     */
private RevTreeBuilder getParentTree(RevTree currentIndexHead, String parentPath, Map<String, RevTreeBuilder> parentTress, Map<String, ObjectId> parentMetadataIds) {
    RevTreeBuilder parentBuilder = parentTress.get(parentPath);
    if (parentBuilder == null) {
        ObjectId parentMetadataId = null;
        if (NodeRef.ROOT.equals(parentPath)) {
            parentBuilder = currentIndexHead.builder(getDatabase());
        } else {
            Optional<NodeRef> parentRef = context.command(FindTreeChild.class).setIndex(true).setParent(currentIndexHead).setChildPath(parentPath).call();
            if (parentRef.isPresent()) {
                parentMetadataId = parentRef.get().getMetadataId();
            }
            parentBuilder = context.command(FindOrCreateSubtree.class).setParent(Suppliers.ofInstance(Optional.of(getTree()))).setIndex(true).setChildPath(parentPath).call().builder(getDatabase());
        }
        parentTress.put(parentPath, parentBuilder);
        if (parentMetadataId != null) {
            parentMetadataIds.put(parentPath, parentMetadataId);
        }
    }
    return parentBuilder;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder)

Example 42 with RevTreeBuilder

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

the class WorkingTree method delete.

/**
     * Deletes a feature type from the working tree and updates the WORK_HEAD ref.
     * 
     * @param typeName feature type to remove
     * @throws Exception
     */
public void delete(final Name typeName) throws Exception {
    checkNotNull(typeName);
    RevTreeBuilder workRoot = getTree().builder(indexDatabase);
    final String treePath = typeName.getLocalPart();
    if (workRoot.get(treePath).isPresent()) {
        workRoot.remove(treePath);
        RevTree newRoot = workRoot.build();
        indexDatabase.put(newRoot);
        updateWorkHead(newRoot.getId());
    }
}
Also used : RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree)

Example 43 with RevTreeBuilder

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

the class WorkingTree method delete.

/**
     * 
     * @param features the features to delete
     */
public void delete(Iterator<String> features) {
    Map<String, RevTreeBuilder> parents = Maps.newHashMap();
    final RevTree currentWorkHead = getTree();
    while (features.hasNext()) {
        String featurePath = features.next();
        // System.err.println("removing " + feature);
        String parentPath = NodeRef.parentPath(featurePath);
        RevTreeBuilder parentTree;
        if (parents.containsKey(parentPath)) {
            parentTree = parents.get(parentPath);
        } else {
            parentTree = context.command(FindOrCreateSubtree.class).setIndex(true).setParent(Suppliers.ofInstance(Optional.of(currentWorkHead))).setChildPath(parentPath).call().builder(indexDatabase);
            parents.put(parentPath, parentTree);
        }
        String featureName = NodeRef.nodeFromPath(featurePath);
        parentTree.remove(featureName);
    }
    ObjectId newTree = null;
    for (Map.Entry<String, RevTreeBuilder> entry : parents.entrySet()) {
        String path = entry.getKey();
        RevTreeBuilder parentTree = entry.getValue();
        RevTree newTypeTree = parentTree.build();
        ObjectId metadataId = null;
        Optional<NodeRef> currentTreeRef = context.command(FindTreeChild.class).setIndex(true).setParent(currentWorkHead).setChildPath(path).call();
        if (currentTreeRef.isPresent()) {
            metadataId = currentTreeRef.get().getMetadataId();
        }
        newTree = context.command(WriteBack.class).setAncestor(getTreeSupplier()).setChildPath(path).setToIndex(true).setTree(newTypeTree).setMetadataId(metadataId).call();
        updateWorkHead(newTree);
    }
}
Also used : WriteBack(org.locationtech.geogig.api.plumbing.WriteBack) NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) Map(java.util.Map) RevTree(org.locationtech.geogig.api.RevTree)

Example 44 with RevTreeBuilder

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

the class DiffTreeTest method tree.

private RevTree tree(int nFeatures, ObjectDatabase db) {
    RevTreeBuilder b = new RevTreeBuilder(db);
    for (int i = 0; i < nFeatures; i++) {
        b.put(feature(i));
    }
    RevTree tree = b.build();
    db.put(tree);
    return tree;
}
Also used : RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree)

Example 45 with RevTreeBuilder

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

the class DiffTreeTest method testChangeTypeFilter.

@Test
public void testChangeTypeFilter() {
    ObjectDatabase db = geogit.getContext().objectDatabase();
    final RevTree tree1 = tree(1000, db);
    final RevTree tree2 = tree(50, db);
    final RevTree tree2Changed;
    {
        RevTreeBuilder builder = new RevTreeBuilder(db, tree2);
        // add 10 changed features, and delete 10 more
        for (int i = 0; i < 20; i++) {
            if (i % 2 == 0) {
                builder.remove(String.valueOf(i));
            } else {
                builder.put(feature(i, ObjectId.forString("changed" + i)));
            }
        }
        tree2Changed = builder.build();
        db.put(tree2Changed);
        assertEquals(tree2.size() - 10, tree2Changed.size());
    }
    final RevTree root1 = createRoot(db, tree1, tree2);
    final RevTree root2 = createRoot(db, tree1, tree2Changed);
    assertChangeTypeFilter(ObjectId.NULL, root1.getId(), (int) (tree1.size() + tree2.size()), 0, 0);
    assertChangeTypeFilter(root1.getId(), ObjectId.NULL, 0, (int) (tree1.size() + tree2.size()), 0);
    assertChangeTypeFilter(tree2.getId(), tree2Changed.getId(), 0, 10, 10);
    assertChangeTypeFilter(root1.getId(), root2.getId(), 0, 10, 10);
    assertChangeTypeFilter(root2.getId(), root1.getId(), 10, 0, 10);
}
Also used : ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Aggregations

RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)58 RevTree (org.locationtech.geogig.api.RevTree)47 ObjectId (org.locationtech.geogig.api.ObjectId)27 Test (org.junit.Test)25 NodeRef (org.locationtech.geogig.api.NodeRef)24 Node (org.locationtech.geogig.api.Node)14 DepthSearch (org.locationtech.geogig.repository.DepthSearch)6 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)5 Stopwatch (com.google.common.base.Stopwatch)4 Envelope (com.vividsolutions.jts.geom.Envelope)4 Map (java.util.Map)4 Context (org.locationtech.geogig.api.Context)4 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)4 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)4 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)4 Before (org.junit.Before)3 FindOrCreateSubtree (org.locationtech.geogig.api.plumbing.FindOrCreateSubtree)3 WriteBack (org.locationtech.geogig.api.plumbing.WriteBack)3 DepthTreeIterator (org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator)3 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)3