use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class WriteTree2 method handleNewTrees.
private void handleNewTrees(TreeDifference treeDifference, Set<String> ignoreList) {
SortedSet<NodeRef> newTrees = treeDifference.findNewTrees();
for (NodeRef ref : newTrees) {
final String path = ref.path();
if (ignoreList.contains(path)) {
continue;
}
ignoreList.add(path);
if (!filterMatchesOrIsParent(path)) {
MutableTree rightTree = treeDifference.getRightTree();
if (filterApplies(path, rightTree)) {
// can't optimize
RevTree newTree = applyChanges(null, ref);
Node newNode = Node.tree(ref.name(), newTree.getId(), ref.getMetadataId());
MutableTree leftTree = treeDifference.getLeftTree();
leftTree.forceChild(ref.getParentPath(), newNode);
}
} else {
LOGGER.trace("Creating new tree {}", path);
deepMove(ref.getNode());
MutableTree leftTree = treeDifference.getLeftTree();
String parentPath = ref.getParentPath();
Node node = ref.getNode();
leftTree.setChild(parentPath, node);
}
}
}
use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class FindOrCreateSubtree method _call.
/**
* Executes the command.
*
* @return the subtree if it was found, or a new one if it wasn't
*/
@Override
protected RevTree _call() {
checkNotNull(parentSupplier, "parent");
checkNotNull(childPath, "childPath");
ObjectId subtreeId;
if (parentSupplier.get().isPresent()) {
RevTree parent = parentSupplier.get().get();
Optional<NodeRef> treeChildRef = command(FindTreeChild.class).setIndex(indexDb).setParentPath(parentPath).setChildPath(childPath).setParent(Suppliers.ofInstance(parent)).call();
if (treeChildRef.isPresent()) {
NodeRef treeRef = treeChildRef.get();
if (!TYPE.TREE.equals(treeRef.getType())) {
throw new IllegalArgumentException("Object exists as child of tree " + parent.getId() + " but is not a tree: " + treeChildRef);
}
subtreeId = treeRef.objectId();
} else {
subtreeId = RevTree.EMPTY_TREE_ID;
}
} else {
subtreeId = RevTree.EMPTY_TREE_ID;
}
if (RevTree.EMPTY_TREE_ID.equals(subtreeId)) {
return RevTree.EMPTY;
}
ObjectDatabase target = indexDb ? stagingDatabase() : objectDatabase();
RevTree tree = target.getTree(subtreeId);
return tree;
}
use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class CheckoutOpTest method testCheckoutPathFilter.
@Test
public void testCheckoutPathFilter() throws Exception {
ObjectId points1Id = insertAndAdd(points1);
geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
insert(points1_modified);
CheckoutResult result = geogig.command(CheckoutOp.class).addPath("Points/Points.1").call();
Optional<RevTree> workTree = geogig.command(RevObjectParse.class).setObjectId(result.getNewTree()).call(RevTree.class);
Optional<NodeRef> nodeRef = geogig.command(FindTreeChild.class).setParent(workTree.get()).setChildPath("Points/Points.1").call();
assertEquals(points1Id, nodeRef.get().getNode().getObjectId());
}
use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class RevTreeTextSerialiationTest method testMalformedSerializedObject.
@Test
public void testMalformedSerializedObject() throws Exception {
// TODO: add more cases here
// a wrong type
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
writer.write(TYPE.FEATURE.name() + "\n");
writer.flush();
ObjectReader<RevTree> reader = factory.createRevTreeReader();
try {
reader.read(ObjectId.forString("ID_STRING"), new ByteArrayInputStream(out.toByteArray()));
fail();
} catch (Exception e) {
assertTrue(e.getMessage().equals("Wrong type: FEATURE"));
}
}
use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class ApplyPatchOpTest method testModifiedFeatureType.
@Test
public void testModifiedFeatureType() throws Exception {
insert(points2, points3, points1B);
Patch patch = new Patch();
RevFeatureType oldFeatureType = RevFeatureTypeImpl.build(pointsType);
RevFeatureType featureType = RevFeatureTypeImpl.build(modifiedPointsType);
patch.addFeatureType(featureType);
patch.addAlteredTree(new FeatureTypeDiff(pointsName, oldFeatureType.getId(), featureType.getId()));
geogig.command(ApplyPatchOp.class).setPatch(patch).call();
RevTree root = repo.workingTree().getTree();
assertNotNull(root);
Optional<Node> typeTree = findTreeChild(root, pointsName);
assertTrue(typeTree.isPresent());
assertEquals(featureType.getId(), typeTree.get().getMetadataId().get());
Optional<Node> featureNode = findTreeChild(root, NodeRef.appendChild(pointsName, idP2));
assertTrue(featureNode.isPresent());
assertEquals(oldFeatureType.getId(), featureNode.get().getMetadataId().get());
featureNode = findTreeChild(root, NodeRef.appendChild(pointsName, idP1));
assertTrue(featureNode.isPresent());
assertFalse(featureNode.get().getMetadataId().isPresent());
}
Aggregations