Search in sources :

Example 56 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 57 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 58 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)

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