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);
}
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);
}
}
}
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);
}
}
}
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;
}
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());
}
Aggregations