Search in sources :

Example 86 with NodeRef

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());
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) DepthTreeIterator(org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 87 with NodeRef

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());
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) DepthTreeIterator(org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 88 with NodeRef

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());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) WorkingTree(org.locationtech.geogig.repository.WorkingTree) NodeRef(org.locationtech.geogig.api.NodeRef) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 89 with NodeRef

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());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) WorkingTree(org.locationtech.geogig.repository.WorkingTree) NodeRef(org.locationtech.geogig.api.NodeRef) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 90 with NodeRef

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;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) Node(org.locationtech.geogig.api.Node) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Maps.newTreeMap(com.google.common.collect.Maps.newTreeMap)

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