use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.
the class GeoGigAPI method getFeatureFromHead.
/**
* Returns a feature from the Head of the repository, given its full path
*
* Returns null if the given path doesn't resolve to a feature
*
* @param path the path to the feature to return
*/
public Feature getFeatureFromHead(String path) {
String name = NodeRef.nodeFromPath(path);
String refSpec = "HEAD:" + path;
Optional<RevFeature> revFeature = repository.command(RevObjectParse.class).setRefSpec(refSpec).call(RevFeature.class);
if (revFeature.isPresent()) {
RevFeatureType revFeatureType = repository.command(ResolveFeatureType.class).setRefSpec(refSpec).call().get();
FeatureBuilder builder = new FeatureBuilder(revFeatureType);
return builder.build(name, revFeature.get());
} else {
return null;
}
}
use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.
the class ApplyPatchOpTest method testAddEmptyFeatureTypePatch.
@Test
public void testAddEmptyFeatureTypePatch() throws Exception {
Patch patch = new Patch();
RevFeatureType featureType = RevFeatureTypeImpl.build(pointsType);
patch.addFeatureType(featureType);
patch.addAlteredTree(new FeatureTypeDiff(pointsName, null, featureType.getId()));
geogig.command(ApplyPatchOp.class).setPatch(patch).call();
RevTree root = repo.workingTree().getTree();
assertNotNull(root);
Optional<Node> typeTreeId = findTreeChild(root, pointsName);
RevTree typeTree = repo.getTree(typeTreeId.get().getObjectId());
assertNotNull(typeTree);
assertEquals(featureType.getId(), typeTreeId.get().getMetadataId().get());
}
use of org.locationtech.geogig.api.RevFeatureType in project GeoGig by boundlessgeo.
the class CreateOSMChangesetOp method _call.
/**
* Executes the diff operation.
*
* @return an iterator to a set of differences between the two trees
* @see DiffEntry
*/
@Override
protected Iterator<ChangeContainer> _call() {
Iterator<DiffEntry> nodeIterator = command(DiffOp.class).setFilter(OSMUtils.NODE_TYPE_NAME).setNewVersion(newRefSpec).setOldVersion(oldRefSpec).setReportTrees(false).call();
Iterator<DiffEntry> wayIterator = command(DiffOp.class).setFilter(OSMUtils.WAY_TYPE_NAME).setNewVersion(newRefSpec).setOldVersion(oldRefSpec).setReportTrees(false).call();
Iterator<DiffEntry> iterator = Iterators.concat(nodeIterator, wayIterator);
final EntityConverter converter = new EntityConverter();
Function<DiffEntry, ChangeContainer> function = new Function<DiffEntry, ChangeContainer>() {
@Override
@Nullable
public ChangeContainer apply(@Nullable DiffEntry diff) {
NodeRef ref = diff.changeType().equals(ChangeType.REMOVED) ? diff.getOldObject() : diff.getNewObject();
RevFeature revFeature = command(RevObjectParse.class).setObjectId(ref.objectId()).call(RevFeature.class).get();
RevFeatureType revFeatureType = command(RevObjectParse.class).setObjectId(ref.getMetadataId()).call(RevFeatureType.class).get();
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) revFeatureType.type());
ImmutableList<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors();
ImmutableList<Optional<Object>> values = revFeature.getValues();
for (int i = 0; i < descriptors.size(); i++) {
PropertyDescriptor descriptor = descriptors.get(i);
Optional<Object> value = values.get(i);
featureBuilder.set(descriptor.getName(), value.orNull());
}
SimpleFeature feature = featureBuilder.buildFeature(ref.name());
Entity entity = converter.toEntity(feature, id);
EntityContainer container;
if (entity instanceof Node) {
container = new NodeContainer((Node) entity);
} else {
container = new WayContainer((Way) entity);
}
ChangeAction action = diff.changeType().equals(ChangeType.ADDED) ? ChangeAction.Create : diff.changeType().equals(ChangeType.MODIFIED) ? ChangeAction.Modify : ChangeAction.Delete;
return new ChangeContainer(container, action);
}
};
return Iterators.transform(iterator, function);
}
Aggregations