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