use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class RevTreeBuilderTest method testRemoveSplittedTree.
@Test
public void testRemoveSplittedTree() throws Exception {
final int numEntries = (int) (1.5 * RevTree.NORMALIZED_SIZE_LIMIT);
final ObjectId treeId = createAndSaveTree(numEntries, true);
final RevTree tree = odb.getTree(treeId);
// collect some keys to remove
final Set<String> removedKeys = new HashSet<String>();
{
int i = 0;
DepthTreeIterator it = new DepthTreeIterator("", ObjectId.NULL, tree, odb, Strategy.CHILDREN);
for (; it.hasNext(); i++) {
NodeRef entry = it.next();
if (i % 10 == 0) {
removedKeys.add(entry.path());
}
}
assertTrue(removedKeys.size() > 0);
}
RevTreeBuilder builder = tree.builder(odb);
for (String key : removedKeys) {
assertTrue(key, builder.get(key).isPresent());
builder.remove(key);
assertFalse(key, builder.get(key).isPresent());
}
for (String key : removedKeys) {
assertFalse(builder.get(key).isPresent());
}
final RevTree tree2 = builder.build();
for (String key : removedKeys) {
assertFalse(key, repo.getTreeChild(tree2, key).isPresent());
}
}
use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class RevTreeBuilderTest method testRemove.
@Test
public void testRemove() throws Exception {
final int numEntries = 1000;
ObjectId treeId = createAndSaveTree(numEntries, true);
final RevTree tree = odb.getTree(treeId);
// collect some keys to remove
final Set<String> removedKeys = new HashSet<String>();
{
int i = 0;
DepthTreeIterator it = new DepthTreeIterator("", ObjectId.NULL, tree, odb, Strategy.CHILDREN);
for (; it.hasNext(); i++) {
NodeRef entry = it.next();
if (i % 10 == 0) {
removedKeys.add(entry.path());
}
}
assertEquals(100, removedKeys.size());
}
final RevTreeBuilder builder = tree.builder(odb);
for (String key : removedKeys) {
assertTrue(builder.get(key).isPresent());
builder.remove(key);
assertFalse(builder.get(key).isPresent());
}
final RevTree tree2 = builder.build();
for (String key : removedKeys) {
assertFalse(repo.getTreeChild(tree2, key).isPresent());
}
}
use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class OSMMapOpTest method testMappingWithNoFilter.
@Test
public void testMappingWithNoFilter() throws Exception {
// Test that if no filter is specified in a mapping rule, all entities pass the filter
String filename = OSMImportOp.class.getResource("ways.xml").getFile();
File file = new File(filename);
geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
WorkingTree workTree = geogig.getRepository().workingTree();
long unstaged = workTree.countUnstaged("way").count();
assertTrue(unstaged > 0);
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).setMessage("msg").call();
Map<String, AttributeDefinition> fields = Maps.newHashMap();
Map<String, List<String>> filters = Maps.newHashMap();
fields.put("lit", new AttributeDefinition("lit", FieldType.STRING));
fields.put("geom", new AttributeDefinition("geom", FieldType.LINESTRING));
Map<String, List<String>> filterExclude = Maps.newHashMap();
MappingRule mappingRule = new MappingRule("allways", filters, filterExclude, fields, null);
List<MappingRule> mappingRules = Lists.newArrayList();
mappingRules.add(mappingRule);
Mapping mapping = new Mapping(mappingRules);
geogig.command(OSMMapOp.class).setMapping(mapping).call();
Iterator<NodeRef> allways = geogig.command(LsTreeOp.class).setReference("HEAD:allways").call();
assertTrue(allways.hasNext());
Iterator<NodeRef> ways = geogig.command(LsTreeOp.class).setReference("HEAD:allways").call();
ArrayList<NodeRef> listWays = Lists.newArrayList(ways);
ArrayList<NodeRef> listAllways = Lists.newArrayList(allways);
assertEquals(listWays.size(), listAllways.size());
}
use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class OSMMapOpTest method testMappingWithEmptyTagValueList.
@Test
public void testMappingWithEmptyTagValueList() throws Exception {
// Test that when no tags are specified, all entities pass the filter
String filename = OSMImportOp.class.getResource("ways.xml").getFile();
File file = new File(filename);
geogig.command(OSMImportOp.class).setDataSource(file.getAbsolutePath()).call();
WorkingTree workTree = geogig.getRepository().workingTree();
long unstaged = workTree.countUnstaged("way").count();
assertTrue(unstaged > 0);
geogig.command(AddOp.class).call();
geogig.command(CommitOp.class).setMessage("msg").call();
Map<String, AttributeDefinition> fields = Maps.newHashMap();
Map<String, List<String>> filters = Maps.newHashMap();
fields.put("lit", new AttributeDefinition("lit", FieldType.STRING));
fields.put("geom", new AttributeDefinition("geom", FieldType.POINT));
filters.put("highway", new ArrayList<String>());
Map<String, List<String>> filterExclude = Maps.newHashMap();
MappingRule mappingRule = new MappingRule("mapped", filters, filterExclude, fields, null);
List<MappingRule> mappingRules = Lists.newArrayList();
mappingRules.add(mappingRule);
Mapping mapping = new Mapping(mappingRules);
geogig.command(OSMMapOp.class).setMapping(mapping).call();
Iterator<NodeRef> iter = geogig.command(LsTreeOp.class).setReference("HEAD:mapped").call();
ArrayList<NodeRef> list = Lists.newArrayList(iter);
assertEquals(4, list.size());
}
use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.
the class TreeDifference method findRenames.
private SortedMap<NodeRef, NodeRef> findRenames(SortedMapDifference<String, MutableTree> difference) {
SortedMap<String, MutableTree> entriesOnlyOnLeft = difference.entriesOnlyOnLeft();
SortedMap<String, MutableTree> entriesOnlyOnRight = difference.entriesOnlyOnRight();
SortedMap<NodeRef, NodeRef> matches = newTreeMap();
for (Map.Entry<String, MutableTree> right : entriesOnlyOnRight.entrySet()) {
for (Map.Entry<String, MutableTree> left : entriesOnlyOnLeft.entrySet()) {
Node leftNode = left.getValue().getNode();
Node rightNode = right.getValue().getNode();
if (rightNode.getObjectId().equals(leftNode.getObjectId())) {
String leftParent = NodeRef.parentPath(left.getKey());
String rightParent = NodeRef.parentPath(right.getKey());
NodeRef leftRef = new NodeRef(leftNode, leftParent, ObjectId.NULL);
NodeRef rightRef = new NodeRef(rightNode, rightParent, ObjectId.NULL);
matches.put(leftRef, rightRef);
}
}
}
return matches;
}
Aggregations