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();
}
}
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());
}
}
}
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());
}
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());
}
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());
}
Aggregations