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