use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class WriteTree2Test method verifyTree.
private void verifyTree(ObjectDatabase objectDb, String path, ObjectId repoTreeId) {
assertTrue(String.format("tree '%s' (%s) is not present", path, repoTreeId), objectDb.exists(repoTreeId));
RevTree tree = objectDb.getTree(repoTreeId);
Iterator<Node> children = tree.children();
while (children.hasNext()) {
final Node node = children.next();
if (TYPE.TREE.equals(node.getType())) {
path = NodeRef.appendChild(path, node.getName());
ObjectId objectId = node.getObjectId();
verifyRepositoryTree(path, objectId);
} else if (TYPE.FEATURE.equals(node.getType())) {
verifyFeature(node);
} else {
throw new IllegalStateException(node.getType().toString());
}
verifyMetadata(node);
}
if (tree.buckets().isPresent()) {
ImmutableCollection<Bucket> buckets = tree.buckets().get().values();
for (Bucket b : buckets) {
ObjectId bucketTreeId = b.id();
verifyRepositoryTree(path + "/" + bucketTreeId.toString().substring(0, 8), bucketTreeId);
}
}
}
use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class WriteTree2Test method createHeadTree.
private RevTree createHeadTree(NodeRef... treeRefs) {
RevTree root = createFromRefs(objectDb, treeRefs);
objectDb.put(root);
CommitBuilder cb = new CommitBuilder(geogig.getPlatform());
ObjectId treeId = root.getId();
RevCommit commit = cb.setTreeId(treeId).setCommitter("Gabriel Roldan").setAuthor("Gabriel Roldan").build();
objectDb.put(commit);
SymRef head = (SymRef) geogig.command(RefParse.class).setName(Ref.HEAD).call().get();
final String currentBranch = head.getTarget();
geogig.command(UpdateRef.class).setName(currentBranch).setNewValue(commit.getId()).call();
verifyRepositoryTree(NodeRef.ROOT, treeId);
verifyTreeStructure(treeId, treeRefs);
return root;
}
use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class WriteTree2Test method createStageHeadTree.
private RevTree createStageHeadTree(NodeRef... treeRefs) {
RevTree root = createFromRefs(indexDb, treeRefs);
geogig.command(UpdateRef.class).setName(Ref.STAGE_HEAD).setNewValue(root.getId()).call();
return root;
}
use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class WriteTree2Test method tree.
/**
* Creates a tree reference for testing, forcing the specified id and metadata id, and with the
* specified number of features (zero or more).
* <p>
* Note the tree is saved to the specified database only if its a leaf tree (more than zero
* features), in order for the {@link #createFromRefs} method to be able of saving the parent
*/
private NodeRef tree(ObjectDatabase db, String path, String id, String mdId, int numFeatures) {
Preconditions.checkArgument(numFeatures != 0 || EMPTY_ID.equals(id), "for zero features trees use RevTree.EMPTY_TREE_ID");
final ObjectId treeId = id(id);
final ObjectId metadataId = id(mdId);
final String feturePrefix = NodeRef.nodeFromPath(path);
RevTreeBuilder b = new RevTreeBuilder(db);
if (numFeatures > 0) {
for (int i = 0; i < numFeatures; i++) {
Node fn = feature(db, feturePrefix, i);
b.put(fn);
}
}
RevTree fakenId = forceTreeId(b, treeId);
if (!db.exists(fakenId.getId())) {
db.put(fakenId);
}
if (!metadataId.isNull()) {
RevFeatureType fakeType = new RevFeatureTypeImpl(metadataId, pointsType);
if (!db.exists(fakeType.getId())) {
db.put(fakeType);
}
}
String name = NodeRef.nodeFromPath(path);
String parent = NodeRef.parentPath(path);
Envelope bounds = SpatialOps.boundsOf(fakenId);
Node node = Node.create(name, treeId, metadataId, TYPE.TREE, bounds);
return new NodeRef(node, parent, ObjectId.NULL);
}
use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class WriteBackTest method testSiblingsSingleLevel.
@Test
public void testSiblingsSingleLevel() {
RevTreeBuilder ancestor = new RevTreeBuilder(odb);
RevTree tree1 = new RevTreeBuilder(odb).put(blob("blob")).build();
RevTree tree2 = new RevTreeBuilder(odb).put(blob("blob")).build();
ObjectId newRootId1 = writeBack.setAncestor(ancestor).setChildPath("subtree1").setTree(tree1).call();
ancestor = odb.getTree(newRootId1).builder(odb);
ObjectId newRootId2 = writeBack.setAncestor(ancestor).setChildPath("subtree2").setTree(tree2).call();
// created the intermediate tree node?
DepthSearch depthSearch = new DepthSearch(odb);
assertTrue(depthSearch.find(newRootId2, "subtree1").isPresent());
assertTrue(depthSearch.find(newRootId2, "subtree2").isPresent());
assertTrue(depthSearch.find(newRootId2, "subtree1/blob").isPresent());
assertTrue(depthSearch.find(newRootId2, "subtree2/blob").isPresent());
}
Aggregations