Search in sources :

Example 1 with RevObjectParse

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);
}
Also used : FeatureBuilder(org.locationtech.geogig.api.FeatureBuilder) ObjectId(org.locationtech.geogig.api.ObjectId) RevFeature(org.locationtech.geogig.api.RevFeature) Feature(org.opengis.feature.Feature) NodeRef(org.locationtech.geogig.api.NodeRef) Function(com.google.common.base.Function) LsTreeOp(org.locationtech.geogig.api.plumbing.LsTreeOp) RevFeature(org.locationtech.geogig.api.RevFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Nullable(javax.annotation.Nullable)

Example 2 with RevObjectParse

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;
}
Also used : PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) ObjectId(org.locationtech.geogig.api.ObjectId) DiffFeature(org.locationtech.geogig.api.plumbing.DiffFeature) FeatureDiff(org.locationtech.geogig.api.plumbing.diff.FeatureDiff) RevFeature(org.locationtech.geogig.api.RevFeature) AttributeDiff(org.locationtech.geogig.api.plumbing.diff.AttributeDiff) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) TYPE(org.locationtech.geogig.api.RevObject.TYPE) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevCommit(org.locationtech.geogig.api.RevCommit) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Aggregations

ObjectId (org.locationtech.geogig.api.ObjectId)2 RevFeature (org.locationtech.geogig.api.RevFeature)2 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)2 Function (com.google.common.base.Function)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 FeatureBuilder (org.locationtech.geogig.api.FeatureBuilder)1 NodeRef (org.locationtech.geogig.api.NodeRef)1 RevCommit (org.locationtech.geogig.api.RevCommit)1 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)1 TYPE (org.locationtech.geogig.api.RevObject.TYPE)1 DiffFeature (org.locationtech.geogig.api.plumbing.DiffFeature)1 LsTreeOp (org.locationtech.geogig.api.plumbing.LsTreeOp)1 AttributeDiff (org.locationtech.geogig.api.plumbing.diff.AttributeDiff)1 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)1 FeatureDiff (org.locationtech.geogig.api.plumbing.diff.FeatureDiff)1 Feature (org.opengis.feature.Feature)1 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)1