Search in sources :

Example 11 with NodeRef

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

the class ResolveFeatureType method _call.

@Override
protected Optional<RevFeatureType> _call() {
    Preconditions.checkState(refSpec != null, "ref spec has not been set.");
    final String fullRefspec;
    if (refSpec.contains(":")) {
        fullRefspec = refSpec;
    } else {
        fullRefspec = Ref.WORK_HEAD + ":" + refSpec;
    }
    final String ref = fullRefspec.substring(0, fullRefspec.indexOf(':'));
    final String path = fullRefspec.substring(fullRefspec.indexOf(':') + 1);
    ObjectId parentId = command(ResolveTreeish.class).setTreeish(ref).call().get();
    Optional<RevTree> parent = command(RevObjectParse.class).setObjectId(parentId).call(RevTree.class);
    if (!parent.isPresent()) {
        return Optional.absent();
    }
    Optional<NodeRef> node = command(FindTreeChild.class).setParent(parent.get()).setChildPath(path).setIndex(true).call();
    if (!node.isPresent()) {
        return Optional.absent();
    }
    NodeRef found = node.get();
    ObjectId metadataID = found.getMetadataId();
    Optional<RevFeatureType> ft = command(RevObjectParse.class).setObjectId(metadataID).call(RevFeatureType.class);
    return ft;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree)

Example 12 with NodeRef

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

the class WriteBack method getTreeChild.

private Optional<NodeRef> getTreeChild(RevTreeBuilder parent, String childPath) {
    RevTree realParent = parent.build();
    FindTreeChild cmd = command(FindTreeChild.class).setIndex(true).setParent(realParent).setChildPath(childPath);
    Optional<NodeRef> nodeRef = cmd.call();
    return nodeRef;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) RevTree(org.locationtech.geogig.api.RevTree)

Example 13 with NodeRef

use of org.locationtech.geogig.api.NodeRef 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 14 with NodeRef

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

the class WriteTree method resolveSourceTreeRef.

private void resolveSourceTreeRef(String parentPath, Map<String, NodeRef> indexChangedTrees, Map<String, ObjectId> metadataCache, RevTree stageHead) {
    if (NodeRef.ROOT.equals(parentPath)) {
        return;
    }
    NodeRef indexTreeRef = indexChangedTrees.get(parentPath);
    if (indexTreeRef == null) {
        Optional<NodeRef> treeRef = Optional.absent();
        if (!stageHead.isEmpty()) {
            // slight optimization, may save a lot of processing on
            // large first commits
            treeRef = command(FindTreeChild.class).setIndex(true).setParent(stageHead).setChildPath(parentPath).call();
        }
        if (treeRef.isPresent()) {
            // may not be in case of a delete
            indexTreeRef = treeRef.get();
            indexChangedTrees.put(parentPath, indexTreeRef);
            metadataCache.put(parentPath, indexTreeRef.getMetadataId());
        }
    } else {
        metadataCache.put(parentPath, indexTreeRef.getMetadataId());
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef)

Example 15 with NodeRef

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

the class WriteTree method resolveTargetTree.

private RevTreeBuilder resolveTargetTree(final RevTree root, String treePath, Map<String, RevTreeBuilder> treeCache, Map<String, ObjectId> metadataCache, ObjectId fallbackMetadataId, ObjectDatabase repositoryDatabase) {
    RevTreeBuilder treeBuilder = treeCache.get(treePath);
    if (treeBuilder == null) {
        if (NodeRef.ROOT.equals(treePath)) {
            treeBuilder = root.builder(repositoryDatabase);
        } else {
            Optional<NodeRef> treeRef = command(FindTreeChild.class).setIndex(false).setParent(root).setChildPath(treePath).call();
            if (treeRef.isPresent()) {
                metadataCache.put(treePath, treeRef.get().getMetadataId());
                treeBuilder = command(RevObjectParse.class).setObjectId(treeRef.get().objectId()).call(RevTree.class).get().builder(repositoryDatabase);
            } else {
                metadataCache.put(treePath, fallbackMetadataId);
                treeBuilder = new RevTreeBuilder(repositoryDatabase);
            }
        }
        treeCache.put(treePath, treeBuilder);
    }
    return treeBuilder;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree)

Aggregations

NodeRef (org.locationtech.geogig.api.NodeRef)161 ObjectId (org.locationtech.geogig.api.ObjectId)91 RevTree (org.locationtech.geogig.api.RevTree)67 Test (org.junit.Test)62 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)40 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)27 RevFeature (org.locationtech.geogig.api.RevFeature)25 Node (org.locationtech.geogig.api.Node)24 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)24 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)23 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)22 RevObject (org.locationtech.geogig.api.RevObject)21 RevCommit (org.locationtech.geogig.api.RevCommit)19 Map (java.util.Map)15 SimpleFeature (org.opengis.feature.simple.SimpleFeature)15 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)14 Feature (org.opengis.feature.Feature)13 Optional (com.google.common.base.Optional)12 GeoGIG (org.locationtech.geogig.api.GeoGIG)11 LsTreeOp (org.locationtech.geogig.api.plumbing.LsTreeOp)11