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