use of org.locationtech.geogig.api.plumbing.RevObjectParse in project GeoGig by boundlessgeo.
the class OSMMapOp method getFeatures.
private Iterator<Feature> getFeatures(String ref) {
Optional<ObjectId> id = command(RevParse.class).setRefSpec(ref).call();
if (!id.isPresent()) {
return Iterators.emptyIterator();
}
LsTreeOp op = command(LsTreeOp.class).setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES).setReference(ref);
Iterator<NodeRef> iterator = op.call();
Function<NodeRef, Feature> nodeRefToFeature = new Function<NodeRef, Feature>() {
private final //
Map<String, FeatureBuilder> builders = //
ImmutableMap.<//
String, //
FeatureBuilder>of(//
OSMUtils.NODE_TYPE_NAME, //
new FeatureBuilder(RevFeatureTypeImpl.build(OSMUtils.nodeType())), //
OSMUtils.WAY_TYPE_NAME, new FeatureBuilder(RevFeatureTypeImpl.build(OSMUtils.wayType())));
private final RevObjectParse parseCommand = command(RevObjectParse.class);
@Override
@Nullable
public Feature apply(@Nullable NodeRef ref) {
RevFeature revFeature = parseCommand.setObjectId(ref.objectId()).call(RevFeature.class).get();
final String parentPath = ref.getParentPath();
FeatureBuilder featureBuilder = builders.get(parentPath);
String fid = ref.name();
Feature feature = featureBuilder.build(fid, revFeature);
return feature;
}
};
return Iterators.transform(iterator, nodeRefToFeature);
}
use of org.locationtech.geogig.api.plumbing.RevObjectParse in project GeoGig by boundlessgeo.
the class BlameOp method _call.
@Override
protected BlameReport _call() {
String fullPath = (commit != null ? commit.toString() : Ref.HEAD) + ":" + path;
Optional<ObjectId> id = command(RevParse.class).setRefSpec(fullPath).call();
if (!id.isPresent()) {
throw new BlameException(StatusCode.FEATURE_NOT_FOUND);
}
TYPE type = command(ResolveObjectType.class).setObjectId(id.get()).call();
if (!type.equals(TYPE.FEATURE)) {
throw new BlameException(StatusCode.PATH_NOT_FEATURE);
}
Optional<RevFeatureType> featureType = command(ResolveFeatureType.class).setRefSpec(path).call();
BlameReport report = new BlameReport(featureType.get());
Iterator<RevCommit> log = command(LogOp.class).addPath(path).setUntil(commit).call();
RevCommit commit = log.next();
RevObjectParse revObjectParse = command(RevObjectParse.class);
DiffOp diffOp = command(DiffOp.class);
DiffFeature diffFeature = command(DiffFeature.class);
while (!report.isComplete()) {
if (!log.hasNext()) {
String refSpec = commit.getId().toString() + ":" + path;
RevFeature feature = revObjectParse.setRefSpec(refSpec).call(RevFeature.class).get();
report.setFirstVersion(feature, commit);
break;
}
RevCommit commitB = log.next();
Iterator<DiffEntry> diffs = diffOp.setNewVersion(commit.getId()).setOldVersion(commitB.getId()).setReportTrees(false).call();
while (diffs.hasNext()) {
DiffEntry diff = diffs.next();
if (path.equals(diff.newPath())) {
if (diff.isAdd()) {
String refSpec = commit.getId().toString() + ":" + path;
RevFeature feature = revObjectParse.setRefSpec(refSpec).call(RevFeature.class).get();
report.setFirstVersion(feature, commit);
break;
}
FeatureDiff featureDiff = diffFeature.setNewVersion(Suppliers.ofInstance(diff.getNewObject())).setOldVersion(Suppliers.ofInstance(diff.getOldObject())).call();
Map<PropertyDescriptor, AttributeDiff> attribDiffs = featureDiff.getDiffs();
Iterator<PropertyDescriptor> iter = attribDiffs.keySet().iterator();
while (iter.hasNext()) {
PropertyDescriptor key = iter.next();
Optional<?> value = attribDiffs.get(key).getNewValue();
String attribute = key.getName().toString();
report.addDiff(attribute, value, commit);
}
}
}
commit = commitB;
}
return report;
}
Aggregations