Search in sources :

Example 36 with Node

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

the class WriteBack method writeBack.

private ObjectId writeBack(RevTreeBuilder ancestor, final String ancestorPath, final RevTree childTree, final String childPath, final ObjectDatabase targetDatabase, final ObjectId metadataId) {
    final ObjectId treeId = childTree.getId();
    targetDatabase.put(childTree);
    final boolean isDirectChild = NodeRef.isDirectChild(ancestorPath, childPath);
    if (isDirectChild) {
        Envelope treeBounds = null;
        if (!metadataId.isNull()) {
            // only include bounds for trees with a default feature type
            treeBounds = SpatialOps.boundsOf(childTree);
        }
        String childName = childPath;
        Node treeNode = Node.create(childName, treeId, metadataId, TYPE.TREE, treeBounds);
        ancestor.put(treeNode);
        RevTree newAncestor = ancestor.build();
        targetDatabase.put(newAncestor);
        return newAncestor.getId();
    }
    final String parentPath = NodeRef.parentPath(childPath);
    Optional<NodeRef> parentRef = getTreeChild(ancestor, parentPath);
    RevTreeBuilder parentBuilder;
    ObjectId parentMetadataId = ObjectId.NULL;
    if (parentRef.isPresent()) {
        ObjectId parentId = parentRef.get().objectId();
        parentMetadataId = parentRef.get().getMetadataId();
        parentBuilder = getTree(parentId, targetDatabase).builder(targetDatabase);
    } else {
        parentBuilder = RevTree.EMPTY.builder(targetDatabase);
    }
    String childName = NodeRef.nodeFromPath(childPath);
    Envelope treeBounds = null;
    if (!metadataId.isNull()) {
        // only include bounds for trees with a default feature type
        treeBounds = SpatialOps.boundsOf(childTree);
    }
    Node treeNode = Node.create(childName, treeId, metadataId, TYPE.TREE, treeBounds);
    parentBuilder.put(treeNode);
    RevTree parent = parentBuilder.build();
    return writeBack(ancestor, ancestorPath, parent, parentPath, targetDatabase, parentMetadataId);
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) Envelope(com.vividsolutions.jts.geom.Envelope) RevTree(org.locationtech.geogig.api.RevTree)

Example 37 with Node

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

the class WriteTree2 method handleDeletedTrees.

private void handleDeletedTrees(TreeDifference treeDifference, Set<String> ignoreList) {
    SortedSet<NodeRef> deletes = treeDifference.findDeletes();
    for (NodeRef ref : deletes) {
        String path = ref.path();
        if (ignoreList.contains(path)) {
            continue;
        }
        ignoreList.add(path);
        if (!filterMatchesOrIsParent(path)) {
            if (filterApplies(path, treeDifference.getRightTree())) {
                // can't optimize
                RevTree newTree = applyChanges(ref, null);
                Node newNode = Node.tree(ref.name(), newTree.getId(), ref.getMetadataId());
                MutableTree leftTree = treeDifference.getLeftTree();
                leftTree.forceChild(ref.getParentPath(), newNode);
            }
        } else {
            MutableTree leftTree = treeDifference.getLeftTree();
            leftTree.removeChild(path);
        }
    }
}
Also used : MutableTree(org.locationtech.geogig.api.plumbing.diff.MutableTree) NodeRef(org.locationtech.geogig.api.NodeRef) Node(org.locationtech.geogig.api.Node) RevTree(org.locationtech.geogig.api.RevTree)

Example 38 with Node

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

the class WriteTree2 method handleNewTrees.

private void handleNewTrees(TreeDifference treeDifference, Set<String> ignoreList) {
    SortedSet<NodeRef> newTrees = treeDifference.findNewTrees();
    for (NodeRef ref : newTrees) {
        final String path = ref.path();
        if (ignoreList.contains(path)) {
            continue;
        }
        ignoreList.add(path);
        if (!filterMatchesOrIsParent(path)) {
            MutableTree rightTree = treeDifference.getRightTree();
            if (filterApplies(path, rightTree)) {
                // can't optimize
                RevTree newTree = applyChanges(null, ref);
                Node newNode = Node.tree(ref.name(), newTree.getId(), ref.getMetadataId());
                MutableTree leftTree = treeDifference.getLeftTree();
                leftTree.forceChild(ref.getParentPath(), newNode);
            }
        } else {
            LOGGER.trace("Creating new tree {}", path);
            deepMove(ref.getNode());
            MutableTree leftTree = treeDifference.getLeftTree();
            String parentPath = ref.getParentPath();
            Node node = ref.getNode();
            leftTree.setChild(parentPath, node);
        }
    }
}
Also used : MutableTree(org.locationtech.geogig.api.plumbing.diff.MutableTree) NodeRef(org.locationtech.geogig.api.NodeRef) Node(org.locationtech.geogig.api.Node) RevTree(org.locationtech.geogig.api.RevTree)

Example 39 with Node

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

the class MutableTree method createFromPaths.

public static MutableTree createFromPaths(final ObjectId rootId, final Map<String, NodeRef> entries) {
    List<NodeRef> refsByDepth = Lists.newArrayList(entries.values());
    Collections.sort(refsByDepth, DEEPEST_LAST_COMPARATOR);
    Node rootNode = Node.create(ROOT, rootId, ObjectId.NULL, TYPE.TREE, null);
    MutableTree root = new MutableTree(rootNode);
    Envelope bounds = new Envelope();
    for (NodeRef entry : refsByDepth) {
        Node node = entry.getNode();
        node.expand(bounds);
        String parentPath = entry.getParentPath();
        root.setChild(parentPath, node);
    }
    // recreate root node with the appropriate bounds
    rootNode = Node.create(ROOT, rootId, ObjectId.NULL, TYPE.TREE, bounds);
    root.setNode(rootNode);
    return root;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) Node(org.locationtech.geogig.api.Node) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 40 with Node

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

the class ApplyPatchOpTest method testModifiedFeatureType.

@Test
public void testModifiedFeatureType() throws Exception {
    insert(points2, points3, points1B);
    Patch patch = new Patch();
    RevFeatureType oldFeatureType = RevFeatureTypeImpl.build(pointsType);
    RevFeatureType featureType = RevFeatureTypeImpl.build(modifiedPointsType);
    patch.addFeatureType(featureType);
    patch.addAlteredTree(new FeatureTypeDiff(pointsName, oldFeatureType.getId(), featureType.getId()));
    geogig.command(ApplyPatchOp.class).setPatch(patch).call();
    RevTree root = repo.workingTree().getTree();
    assertNotNull(root);
    Optional<Node> typeTree = findTreeChild(root, pointsName);
    assertTrue(typeTree.isPresent());
    assertEquals(featureType.getId(), typeTree.get().getMetadataId().get());
    Optional<Node> featureNode = findTreeChild(root, NodeRef.appendChild(pointsName, idP2));
    assertTrue(featureNode.isPresent());
    assertEquals(oldFeatureType.getId(), featureNode.get().getMetadataId().get());
    featureNode = findTreeChild(root, NodeRef.appendChild(pointsName, idP1));
    assertTrue(featureNode.isPresent());
    assertFalse(featureNode.get().getMetadataId().isPresent());
}
Also used : FeatureTypeDiff(org.locationtech.geogig.api.plumbing.diff.FeatureTypeDiff) Node(org.locationtech.geogig.api.Node) Patch(org.locationtech.geogig.api.plumbing.diff.Patch) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Aggregations

Node (org.locationtech.geogig.api.Node)117 RevTree (org.locationtech.geogig.api.RevTree)56 Test (org.junit.Test)50 ObjectId (org.locationtech.geogig.api.ObjectId)44 NodeRef (org.locationtech.geogig.api.NodeRef)24 Bucket (org.locationtech.geogig.api.Bucket)20 TreeTestSupport.featureNode (org.locationtech.geogig.api.plumbing.diff.TreeTestSupport.featureNode)18 Envelope (com.vividsolutions.jts.geom.Envelope)16 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)14 RevCommit (org.locationtech.geogig.api.RevCommit)10 Map (java.util.Map)9 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)9 Patch (org.locationtech.geogig.api.plumbing.diff.Patch)9 File (java.io.File)7 RevFeature (org.locationtech.geogig.api.RevFeature)7 WorkingTree (org.locationtech.geogig.repository.WorkingTree)7 Feature (org.opengis.feature.Feature)7 SimpleFeature (org.opengis.feature.simple.SimpleFeature)7 Stopwatch (com.google.common.base.Stopwatch)6 SortedMap (java.util.SortedMap)5