Search in sources :

Example 6 with NodeRef

use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.

the class LsTreeOpTest method testRefAndPathListing.

@Test
public void testRefAndPathListing() {
    Iterator<NodeRef> iter = geogig.command(LsTreeOp.class).setReference("HEAD:Points").call();
    List<NodeRef> nodes = ImmutableList.copyOf(iter);
    assertEquals(3, nodes.size());
    for (NodeRef ref : nodes) {
        ObjectId metadataId = ref.getMetadataId();
        assertFalse(metadataId.isNull());
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) Test(org.junit.Test)

Example 7 with NodeRef

use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.

the class MergeOpTest method testOctopusMerge.

@Test
public void testOctopusMerge() throws Exception {
    insertAndAdd(points1);
    RevCommit initialCommit = geogig.command(CommitOp.class).call();
    geogig.command(BranchCreateOp.class).setName("branch1").call();
    geogig.command(BranchCreateOp.class).setName("branch2").call();
    geogig.command(BranchCreateOp.class).setName("branch3").call();
    geogig.command(BranchCreateOp.class).setName("branch4").call();
    geogig.command(BranchCreateOp.class).setName("branch5").call();
    geogig.command(BranchCreateOp.class).setName("branch6").call();
    geogig.command(CheckoutOp.class).setSource("branch1").call();
    ObjectId points2Id = insertAndAdd(points2);
    RevCommit branch1 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch2").call();
    ObjectId points3Id = insertAndAdd(points3);
    RevCommit branch2 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch3").call();
    ObjectId lines1Id = insertAndAdd(lines1);
    RevCommit branch3 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch4").call();
    ObjectId lines2Id = insertAndAdd(lines2);
    RevCommit branch4 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch5").call();
    ObjectId lines3Id = insertAndAdd(lines3);
    RevCommit branch5 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch6").call();
    ObjectId points1Id = insertAndAdd(points1_modified);
    RevCommit branch6 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("master").call();
    geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getId())).addCommit(Suppliers.ofInstance(branch2.getId())).addCommit(Suppliers.ofInstance(branch3.getId())).addCommit(Suppliers.ofInstance(branch4.getId())).addCommit(Suppliers.ofInstance(branch5.getId())).addCommit(Suppliers.ofInstance(branch6.getId())).call();
    Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setChildPath(pointsName + "/" + idP1).call();
    assertTrue(ref.isPresent());
    assertEquals(points1Id, ref.get().getNode().getObjectId());
    ref = geogig.command(FindTreeChild.class).setChildPath(pointsName + "/" + idP2).call();
    assertTrue(ref.isPresent());
    assertEquals(points2Id, ref.get().getNode().getObjectId());
    ref = geogig.command(FindTreeChild.class).setChildPath(pointsName + "/" + idP3).call();
    assertTrue(ref.isPresent());
    assertEquals(points3Id, ref.get().getNode().getObjectId());
    ref = geogig.command(FindTreeChild.class).setChildPath(linesName + "/" + idL1).call();
    assertTrue(ref.isPresent());
    assertEquals(lines1Id, ref.get().getNode().getObjectId());
    ref = geogig.command(FindTreeChild.class).setChildPath(linesName + "/" + idL2).call();
    assertTrue(ref.isPresent());
    assertEquals(lines2Id, ref.get().getNode().getObjectId());
    ref = geogig.command(FindTreeChild.class).setChildPath(linesName + "/" + idL3).call();
    assertTrue(ref.isPresent());
    assertEquals(lines3Id, ref.get().getNode().getObjectId());
    Iterator<RevCommit> log = geogig.command(LogOp.class).setFirstParentOnly(true).call();
    // MergeCommit
    RevCommit logMerge = log.next();
    assertEquals(7, logMerge.getParentIds().size());
    // Initial Commit
    RevCommit initial = log.next();
    assertEquals(initialCommit.getMessage(), initial.getMessage());
    assertEquals(initialCommit.getCommitter().getName(), initial.getCommitter().getName());
    assertEquals(initialCommit.getCommitter().getEmail(), initial.getCommitter().getEmail());
    assertEquals(initialCommit.getAuthor().getTimeZoneOffset(), initial.getAuthor().getTimeZoneOffset());
    assertEquals(initialCommit.getCommitter().getTimeZoneOffset(), initial.getCommitter().getTimeZoneOffset());
    assertEquals(initialCommit.getTreeId(), initial.getTreeId());
    assertEquals(initialCommit.getId(), initial.getId());
    assertFalse(log.hasNext());
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) MergeOp(org.locationtech.geogig.api.porcelain.MergeOp) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 8 with NodeRef

use of org.locationtech.geogig.api.NodeRef 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 9 with NodeRef

use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.

the class OSMUnmapOp method _call.

@Override
protected RevTree _call() {
    Optional<OSMMappingLogEntry> entry = command(ReadOSMMappingLogEntry.class).setPath(path).call();
    if (entry.isPresent()) {
        Optional<Mapping> opt = command(ReadOSMMapping.class).setEntry(entry.get()).call();
        if (opt.isPresent()) {
            mapping = opt.get();
        }
    }
    Iterator<NodeRef> iter = command(LsTreeOp.class).setReference(path).setStrategy(Strategy.FEATURES_ONLY).call();
    FeatureMapFlusher flusher = new FeatureMapFlusher(workingTree());
    while (iter.hasNext()) {
        NodeRef node = iter.next();
        RevFeature revFeature = command(RevObjectParse.class).setObjectId(node.objectId()).call(RevFeature.class).get();
        RevFeatureType revFeatureType = command(RevObjectParse.class).setObjectId(node.getMetadataId()).call(RevFeatureType.class).get();
        List<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors();
        ImmutableList<Optional<Object>> values = revFeature.getValues();
        SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) revFeatureType.type());
        String id = null;
        for (int i = 0; i < descriptors.size(); i++) {
            PropertyDescriptor descriptor = descriptors.get(i);
            if (descriptor.getName().getLocalPart().equals("id")) {
                id = values.get(i).get().toString();
            }
            Optional<Object> value = values.get(i);
            featureBuilder.set(descriptor.getName(), value.orNull());
        }
        Preconditions.checkNotNull(id, "No 'id' attribute found");
        SimpleFeature feature = featureBuilder.buildFeature(id);
        unmapFeature(feature, flusher);
    }
    flusher.flushAll();
    if (entry.isPresent()) {
        Iterator<DiffEntry> diffs = command(DiffTree.class).setPathFilter(path).setNewTree(workingTree().getTree().getId()).setOldTree(entry.get().getPostMappingId()).call();
        while (diffs.hasNext()) {
            DiffEntry diff = diffs.next();
            if (diff.changeType().equals(DiffEntry.ChangeType.REMOVED)) {
                ObjectId featureId = diff.getOldObject().getNode().getObjectId();
                RevFeature revFeature = command(RevObjectParse.class).setObjectId(featureId).call(RevFeature.class).get();
                RevFeatureType revFeatureType = command(RevObjectParse.class).setObjectId(diff.getOldObject().getMetadataId()).call(RevFeatureType.class).get();
                List<PropertyDescriptor> descriptors = revFeatureType.sortedDescriptors();
                ImmutableList<Optional<Object>> values = revFeature.getValues();
                SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder((SimpleFeatureType) revFeatureType.type());
                String id = null;
                for (int i = 0; i < descriptors.size(); i++) {
                    PropertyDescriptor descriptor = descriptors.get(i);
                    if (descriptor.getName().getLocalPart().equals("id")) {
                        id = values.get(i).get().toString();
                    }
                    Optional<Object> value = values.get(i);
                    featureBuilder.set(descriptor.getName(), value.orNull());
                }
                Preconditions.checkNotNull(id, "No 'id' attribute found");
                SimpleFeature feature = featureBuilder.buildFeature(id);
                Class<?> clazz = feature.getDefaultGeometryProperty().getType().getBinding();
                String deletePath = clazz.equals(Point.class) ? OSMUtils.NODE_TYPE_NAME : OSMUtils.WAY_TYPE_NAME;
                workingTree().delete(deletePath, id);
            }
        }
    }
    return workingTree().getTree();
}
Also used : ReadOSMMapping(org.locationtech.geogig.osm.internal.log.ReadOSMMapping) LineString(com.vividsolutions.jts.geom.LineString) ReadOSMMappingLogEntry(org.locationtech.geogig.osm.internal.log.ReadOSMMappingLogEntry) OSMMappingLogEntry(org.locationtech.geogig.osm.internal.log.OSMMappingLogEntry) NodeRef(org.locationtech.geogig.api.NodeRef) RevFeature(org.locationtech.geogig.api.RevFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) ObjectId(org.locationtech.geogig.api.ObjectId) Point(com.vividsolutions.jts.geom.Point) Point(com.vividsolutions.jts.geom.Point) SimpleFeature(org.opengis.feature.simple.SimpleFeature) LsTreeOp(org.locationtech.geogig.api.plumbing.LsTreeOp) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 10 with NodeRef

use of org.locationtech.geogig.api.NodeRef in project GeoGig by boundlessgeo.

the class LsTreeOp method _call.

/**
     * @see java.util.concurrent.Callable#call()
     */
protected Iterator<NodeRef> _call() {
    String ref = this.ref;
    if (ref == null) {
        ref = Ref.WORK_HEAD;
    }
    ObjectId metadataId = ObjectId.NULL;
    final String path = ref.lastIndexOf(':') != -1 ? ref.substring(ref.lastIndexOf(':') + 1) : "";
    if (!path.isEmpty()) {
        final String providedRefName = ref.lastIndexOf(':') != -1 ? ref.substring(0, ref.lastIndexOf(':')) : null;
        if (providedRefName != null) {
            Optional<ObjectId> rootTreeId = command(ResolveTreeish.class).setTreeish(providedRefName).call();
            if (rootTreeId.isPresent()) {
                RevTree rootTree = command(RevObjectParse.class).setObjectId(rootTreeId.get()).call(RevTree.class).get();
                Optional<NodeRef> treeRef = command(FindTreeChild.class).setChildPath(path).setIndex(true).setParent(rootTree).call();
                metadataId = treeRef.isPresent() ? treeRef.get().getMetadataId() : ObjectId.NULL;
            }
        }
    }
    // is it just a ref name?
    Optional<Ref> reference = command(RefParse.class).setName(ref).call();
    if (reference.isPresent()) {
        if (reference.get().getObjectId().isNull()) {
            return Iterators.emptyIterator();
        }
    }
    Optional<RevObject> revObject = command(RevObjectParse.class).setRefSpec(ref).call(RevObject.class);
    Optional<NodeRef> treeRef = Optional.absent();
    if (!revObject.isPresent()) {
        if (Ref.WORK_HEAD.equals(ref)) {
            // tree but it is empty
            return Iterators.emptyIterator();
        }
        // let's try to see if it is a feature type or feature in the working tree
        NodeRef.checkValidPath(ref);
        treeRef = command(FindTreeChild.class).setParent(workingTree().getTree()).setChildPath(ref).setIndex(true).call();
        Preconditions.checkArgument(treeRef.isPresent(), "Invalid reference: %s", ref);
        ObjectId treeId = treeRef.get().objectId();
        metadataId = treeRef.get().getMetadataId();
        revObject = command(RevObjectParse.class).setObjectId(treeId).call(RevObject.class);
    }
    checkArgument(revObject.isPresent(), "Invalid reference: %s", ref);
    final TYPE type = revObject.get().getType();
    switch(type) {
        case FEATURE:
            NodeRef nodeRef = treeRef.isPresent() ? treeRef.get() : null;
            List<NodeRef> nodeRefs = Lists.newArrayList();
            nodeRefs.add(nodeRef);
            // If show trees options is passed in show all trees that contain this feature
            if (this.strategy == Strategy.TREES_ONLY) {
                if (nodeRef != null) {
                    while (!nodeRef.getParentPath().isEmpty()) {
                        treeRef = command(FindTreeChild.class).setParent(workingTree().getTree()).setChildPath(nodeRef.getParentPath()).setIndex(true).call();
                        nodeRef = treeRef.get();
                        nodeRefs.add(nodeRef);
                    }
                }
            }
            return nodeRefs.iterator();
        case COMMIT:
            RevCommit revCommit = (RevCommit) revObject.get();
            ObjectId treeId = revCommit.getTreeId();
            revObject = command(RevObjectParse.class).setObjectId(treeId).call(RevObject.class);
        case TREE:
            DepthTreeIterator.Strategy iterStrategy;
            switch(this.strategy) {
                case CHILDREN:
                    iterStrategy = DepthTreeIterator.Strategy.CHILDREN;
                    break;
                case FEATURES_ONLY:
                    iterStrategy = DepthTreeIterator.Strategy.FEATURES_ONLY;
                    break;
                case TREES_ONLY:
                    iterStrategy = DepthTreeIterator.Strategy.TREES_ONLY;
                    break;
                case DEPTHFIRST:
                    iterStrategy = DepthTreeIterator.Strategy.RECURSIVE;
                    break;
                case DEPTHFIRST_ONLY_FEATURES:
                    iterStrategy = DepthTreeIterator.Strategy.RECURSIVE_FEATURES_ONLY;
                    break;
                case DEPTHFIRST_ONLY_TREES:
                    iterStrategy = DepthTreeIterator.Strategy.RECURSIVE_TREES_ONLY;
                    break;
                default:
                    throw new IllegalStateException("Unknown strategy: " + this.strategy);
            }
            RevTree tree = (RevTree) revObject.get();
            ObjectDatabase database = stagingDatabase();
            DepthTreeIterator iter = new DepthTreeIterator(path, metadataId, tree, database, iterStrategy);
            iter.setBoundsFilter(refBoundsFilter);
            return iter;
        default:
            throw new IllegalArgumentException(String.format("Invalid reference: %s", ref));
    }
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) NodeRef(org.locationtech.geogig.api.NodeRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) DepthTreeIterator(org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator) TYPE(org.locationtech.geogig.api.RevObject.TYPE) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit)

Aggregations

NodeRef (org.locationtech.geogig.api.NodeRef)161 ObjectId (org.locationtech.geogig.api.ObjectId)91 RevTree (org.locationtech.geogig.api.RevTree)67 Test (org.junit.Test)62 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)40 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)27 RevFeature (org.locationtech.geogig.api.RevFeature)25 Node (org.locationtech.geogig.api.Node)24 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)24 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)23 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)22 RevObject (org.locationtech.geogig.api.RevObject)21 RevCommit (org.locationtech.geogig.api.RevCommit)19 Map (java.util.Map)15 SimpleFeature (org.opengis.feature.simple.SimpleFeature)15 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)14 Feature (org.opengis.feature.Feature)13 Optional (com.google.common.base.Optional)12 GeoGIG (org.locationtech.geogig.api.GeoGIG)11 LsTreeOp (org.locationtech.geogig.api.plumbing.LsTreeOp)11