Search in sources :

Example 1 with DepthSearch

use of org.locationtech.geogig.repository.DepthSearch in project GeoGig by boundlessgeo.

the class RevTreeBuilder method getInternal.

private Optional<Node> getInternal(final String key, final boolean deep) {
    Node found = featureChanges.get(key);
    if (found == null) {
        found = treeChanges.get(key);
    }
    if (found != null) {
        return Optional.of(found);
    }
    if (!deep) {
        return Optional.absent();
    }
    if (deletes.contains(key)) {
        return Optional.absent();
    }
    final Integer bucketIndex = computeBucket(key);
    final Bucket bucket = bucketTreesByBucket.get(bucketIndex);
    if (bucket == null) {
        return Optional.absent();
    }
    RevTree subtree = loadTree(bucket.id());
    DepthSearch depthSearch = new DepthSearch(db);
    Optional<Node> node = depthSearch.getDirectChild(subtree, key, depth + 1);
    if (node.isPresent()) {
        return Optional.of(node.get());
    } else {
        return Optional.absent();
    }
}
Also used : DepthSearch(org.locationtech.geogig.repository.DepthSearch)

Example 2 with DepthSearch

use of org.locationtech.geogig.repository.DepthSearch in project GeoGig by boundlessgeo.

the class ApplyPatchOp method applyPatch.

private void applyPatch(Patch patch) {
    final WorkingTree workTree = workingTree();
    final StagingDatabase indexDb = stagingDatabase();
    if (reverse) {
        patch = patch.reversed();
    }
    List<FeatureInfo> removed = patch.getRemovedFeatures();
    for (FeatureInfo feature : removed) {
        workTree.delete(NodeRef.parentPath(feature.getPath()), NodeRef.nodeFromPath(feature.getPath()));
    }
    List<FeatureInfo> added = patch.getAddedFeatures();
    for (FeatureInfo feature : added) {
        workTree.insert(NodeRef.parentPath(feature.getPath()), feature.getFeature());
    }
    List<FeatureDiff> diffs = patch.getModifiedFeatures();
    for (FeatureDiff diff : diffs) {
        String path = diff.getPath();
        DepthSearch depthSearch = new DepthSearch(indexDb);
        Optional<NodeRef> noderef = depthSearch.find(workTree.getTree(), path);
        RevFeatureType oldRevFeatureType = command(RevObjectParse.class).setObjectId(noderef.get().getMetadataId()).call(RevFeatureType.class).get();
        String refSpec = Ref.WORK_HEAD + ":" + path;
        RevFeature feature = command(RevObjectParse.class).setRefSpec(refSpec).call(RevFeature.class).get();
        RevFeatureType newRevFeatureType = getFeatureType(diff, feature, oldRevFeatureType);
        ImmutableList<Optional<Object>> values = feature.getValues();
        ImmutableList<PropertyDescriptor> oldDescriptors = oldRevFeatureType.sortedDescriptors();
        ImmutableList<PropertyDescriptor> newDescriptors = newRevFeatureType.sortedDescriptors();
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) newRevFeatureType.type());
        Map<Name, Optional<?>> attrs = Maps.newHashMap();
        for (int i = 0; i < oldDescriptors.size(); i++) {
            PropertyDescriptor descriptor = oldDescriptors.get(i);
            if (newDescriptors.contains(descriptor)) {
                Optional<Object> value = values.get(i);
                attrs.put(descriptor.getName(), value);
            }
        }
        Set<Entry<PropertyDescriptor, AttributeDiff>> featureDiffs = diff.getDiffs().entrySet();
        for (Iterator<Entry<PropertyDescriptor, AttributeDiff>> iterator = featureDiffs.iterator(); iterator.hasNext(); ) {
            Entry<PropertyDescriptor, AttributeDiff> entry = iterator.next();
            if (!entry.getValue().getType().equals(TYPE.REMOVED)) {
                Optional<?> oldValue = attrs.get(entry.getKey().getName());
                attrs.put(entry.getKey().getName(), entry.getValue().applyOn(oldValue));
            }
        }
        Set<Entry<Name, Optional<?>>> entries = attrs.entrySet();
        for (Iterator<Entry<Name, Optional<?>>> iterator = entries.iterator(); iterator.hasNext(); ) {
            Entry<Name, Optional<?>> entry = iterator.next();
            featureBuilder.set(entry.getKey(), entry.getValue().orNull());
        }
        SimpleFeature featureToInsert = featureBuilder.buildFeature(NodeRef.nodeFromPath(path));
        workTree.insert(NodeRef.parentPath(path), featureToInsert);
    }
    ImmutableList<FeatureTypeDiff> alteredTrees = patch.getAlteredTrees();
    for (FeatureTypeDiff diff : alteredTrees) {
        Optional<RevFeatureType> featureType;
        if (diff.getOldFeatureType().isNull()) {
            featureType = patch.getFeatureTypeFromId(diff.getNewFeatureType());
            workTree.createTypeTree(diff.getPath(), featureType.get().type());
        } else if (diff.getNewFeatureType().isNull()) {
            workTree.delete(diff.getPath());
        } else {
            featureType = patch.getFeatureTypeFromId(diff.getNewFeatureType());
            workTree.updateTypeTree(diff.getPath(), featureType.get().type());
        }
    }
}
Also used : FeatureInfo(org.locationtech.geogig.api.FeatureInfo) Name(org.opengis.feature.type.Name) WorkingTree(org.locationtech.geogig.repository.WorkingTree) FeatureDiff(org.locationtech.geogig.api.plumbing.diff.FeatureDiff) NodeRef(org.locationtech.geogig.api.NodeRef) Entry(java.util.Map.Entry) RevFeature(org.locationtech.geogig.api.RevFeature) AttributeDiff(org.locationtech.geogig.api.plumbing.diff.AttributeDiff) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) StagingDatabase(org.locationtech.geogig.storage.StagingDatabase) Optional(com.google.common.base.Optional) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DepthSearch(org.locationtech.geogig.repository.DepthSearch) FeatureTypeDiff(org.locationtech.geogig.api.plumbing.diff.FeatureTypeDiff) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 3 with DepthSearch

use of org.locationtech.geogig.repository.DepthSearch 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());
}
Also used : DepthSearch(org.locationtech.geogig.repository.DepthSearch) ObjectId(org.locationtech.geogig.api.ObjectId) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 4 with DepthSearch

use of org.locationtech.geogig.repository.DepthSearch in project GeoGig by boundlessgeo.

the class WriteBackTest method testPreserveMetadataId.

@Test
public void testPreserveMetadataId() {
    RevTreeBuilder oldRoot = new RevTreeBuilder(odb);
    RevTree tree = new RevTreeBuilder(odb).put(blob("blob")).build();
    final ObjectId treeMetadataId = ObjectId.forString("fakeMdId");
    ObjectId newRootId = writeBack.setAncestor(oldRoot).setChildPath("level1/level2").setTree(tree).setMetadataId(treeMetadataId).call();
    Optional<NodeRef> ref;
    DepthSearch depthSearch = new DepthSearch(odb);
    ref = depthSearch.find(newRootId, "level1/level2");
    assertTrue(ref.isPresent());
    assertTrue(ref.get().getNode().getMetadataId().isPresent());
    assertFalse(ref.get().getNode().getMetadataId().get().isNull());
    assertEquals(treeMetadataId, ref.get().getNode().getMetadataId().get());
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) DepthSearch(org.locationtech.geogig.repository.DepthSearch) ObjectId(org.locationtech.geogig.api.ObjectId) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Example 5 with DepthSearch

use of org.locationtech.geogig.repository.DepthSearch in project GeoGig by boundlessgeo.

the class WriteBackTest method testSiblingsNested.

@Test
public void testSiblingsNested() {
    RevTreeBuilder oldRoot = 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(oldRoot).setChildPath("subtree1/level2").setTree(tree1).call();
    ObjectId newRootId2 = writeBack.setAncestor(odb.getTree(newRootId1).builder(odb)).setChildPath("subtree2/level2/level3").setTree(tree2).call();
    // created the intermediate tree node?
    DepthSearch depthSearch = new DepthSearch(odb);
    assertTrue(depthSearch.find(newRootId2, "subtree1").isPresent());
    assertTrue(depthSearch.find(newRootId2, "subtree1/level2").isPresent());
    assertTrue(depthSearch.find(newRootId2, "subtree1/level2/blob").isPresent());
    assertTrue(depthSearch.find(newRootId2, "subtree2").isPresent());
    assertTrue(depthSearch.find(newRootId2, "subtree2/level2").isPresent());
    assertTrue(depthSearch.find(newRootId2, "subtree2/level2/level3").isPresent());
    assertTrue(depthSearch.find(newRootId2, "subtree2/level2/level3/blob").isPresent());
}
Also used : DepthSearch(org.locationtech.geogig.repository.DepthSearch) ObjectId(org.locationtech.geogig.api.ObjectId) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Aggregations

DepthSearch (org.locationtech.geogig.repository.DepthSearch)11 ObjectId (org.locationtech.geogig.api.ObjectId)9 NodeRef (org.locationtech.geogig.api.NodeRef)8 RevTree (org.locationtech.geogig.api.RevTree)7 Test (org.junit.Test)6 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)6 Entry (java.util.Map.Entry)3 RevFeature (org.locationtech.geogig.api.RevFeature)3 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)3 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)3 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)3 FeatureInfo (org.locationtech.geogig.api.FeatureInfo)2 RevObject (org.locationtech.geogig.api.RevObject)2 AttributeDiff (org.locationtech.geogig.api.plumbing.diff.AttributeDiff)2 FeatureDiff (org.locationtech.geogig.api.plumbing.diff.FeatureDiff)2 Optional (com.google.common.base.Optional)1 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)1 TYPE (org.locationtech.geogig.api.RevObject.TYPE)1 DiffFeature (org.locationtech.geogig.api.plumbing.DiffFeature)1 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)1