Search in sources :

Example 36 with RevObject

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

the class FeatureNodeRefFromRefspec method getFeatureFromRefSpec.

private Optional<RevFeature> getFeatureFromRefSpec() {
    Optional<RevObject> revObject = command(RevObjectParse.class).setRefSpec(ref).call(RevObject.class);
    if (!revObject.isPresent()) {
        // let's try to see if it is a feature in the working tree
        NodeRef.checkValidPath(ref);
        Optional<NodeRef> elementRef = command(FindTreeChild.class).setParent(workingTree().getTree()).setChildPath(ref).setIndex(true).call();
        Preconditions.checkArgument(elementRef.isPresent(), "Invalid reference: %s", ref);
        ObjectId id = elementRef.get().objectId();
        revObject = command(RevObjectParse.class).setObjectId(id).call(RevObject.class);
    }
    if (revObject.isPresent()) {
        Preconditions.checkArgument(TYPE.FEATURE.equals(revObject.get().getType()), "%s does not resolve to a feature", ref);
        return Optional.of(RevFeature.class.cast(revObject.get()));
    } else {
        return Optional.absent();
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) RevFeature(org.locationtech.geogig.api.RevFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse)

Example 37 with RevObject

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

the class CloneOpTest method testCloneWithTags.

@Test
public void testCloneWithTags() throws Exception {
    // Commit several features to the remote
    List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
    LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
    List<RevTag> tags = Lists.newArrayList();
    for (Feature f : features) {
        ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
        final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).call();
        expected.addFirst(commit);
        Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
        assertTrue(childObject.isPresent());
        RevTag tag = remoteGeogig.geogig.command(TagCreateOp.class).setCommitId(commit.getId()).setName(f.getIdentifier().getID()).call();
        tags.add(tag);
    }
    // Make sure the remote has all of the commits
    Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expected, logged);
    // Make sure the remote has all of the tags
    ImmutableList<RevTag> remoteTags = remoteGeogig.geogig.command(TagListOp.class).call();
    assertEquals(tags.size(), remoteTags.size());
    for (RevTag tag : tags) {
        assertTrue(remoteTags.contains(tag));
    }
    // Make sure the local repository has no commits prior to clone
    logs = localGeogig.geogig.command(LogOp.class).call();
    assertNotNull(logs);
    assertFalse(logs.hasNext());
    // clone from the remote
    CloneOp clone = clone();
    clone.setDepth(0);
    clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).call();
    // Make sure the local repository got all of the commits
    logs = localGeogig.geogig.command(LogOp.class).call();
    logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expected, logged);
/*
         * This is commented out, since the clone operation does not clone tags yet This test
         * verifies that no errors are raised when the repo to clone contains tags, but not to
         * verify that tags are also cloned, since that is not supported
         * 
         * I leave this dommented code here, to uncomment it once tag support is implemented for the
         * clone operation
         * 
         * 
         * // Make sure the local repository got all of the tags
         * 
         * ImmutableList<RevTag> localTags = localGeogig.geogig.command(TagListOp.class).call();
         * 
         * assertEquals(tags.size(), localTags.size());
         * 
         * for (RevTag tag : tags) {
         * 
         * assertTrue(localTags.contains(tag));
         * 
         * }
         */
}
Also used : CloneOp(org.locationtech.geogig.api.porcelain.CloneOp) RevTag(org.locationtech.geogig.api.RevTag) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) Feature(org.opengis.feature.Feature) LinkedList(java.util.LinkedList) TagListOp(org.locationtech.geogig.api.porcelain.TagListOp) TagCreateOp(org.locationtech.geogig.api.porcelain.TagCreateOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 38 with RevObject

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

the class ShpExportDiff method getFeatureType.

private SimpleFeatureType getFeatureType(String path, GeogigCLI cli) {
    checkParameter(path != null, "No path specified.");
    String refspec;
    if (path.contains(":")) {
        refspec = path;
    } else {
        refspec = "WORK_HEAD:" + path;
    }
    checkParameter(!refspec.endsWith(":"), "No path specified.");
    final GeoGIG geogig = cli.getGeogig();
    Optional<ObjectId> rootTreeId = geogig.command(ResolveTreeish.class).setTreeish(refspec.split(":")[0]).call();
    checkParameter(rootTreeId.isPresent(), "Couldn't resolve '" + refspec + "' to a treeish object");
    RevTree rootTree = geogig.getRepository().getTree(rootTreeId.get());
    Optional<NodeRef> featureTypeTree = geogig.command(FindTreeChild.class).setChildPath(refspec.split(":")[1]).setParent(rootTree).setIndex(true).call();
    checkParameter(featureTypeTree.isPresent(), "pathspec '" + refspec.split(":")[1] + "' did not match any valid path");
    Optional<RevObject> revObject = cli.getGeogig().command(RevObjectParse.class).setObjectId(featureTypeTree.get().getMetadataId()).call();
    if (revObject.isPresent() && revObject.get() instanceof RevFeatureType) {
        RevFeatureType revFeatureType = (RevFeatureType) revObject.get();
        if (revFeatureType.type() instanceof SimpleFeatureType) {
            return (SimpleFeatureType) revFeatureType.type();
        } else {
            throw new InvalidParameterException("Cannot find feature type for the specified path");
        }
    } else {
        throw new InvalidParameterException("Cannot find feature type for the specified path");
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevTree(org.locationtech.geogig.api.RevTree)

Example 39 with RevObject

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

the class WalkGraph method runInternal.

@Override
public void runInternal(GeogigCLI cli) throws IOException {
    String ref;
    if (refList.isEmpty()) {
        ref = null;
    } else {
        ref = refList.get(0);
    }
    Deduplicator deduplicator = cli.getGeogig().command(CreateDeduplicator.class).call();
    try {
        Iterator<RevObject> iter = //
        cli.getGeogig().command(WalkGraphOp.class).setReference(//
        ref).setDeduplicator(//
        deduplicator).call();
        final ConsoleReader console = cli.getConsole();
        if (!iter.hasNext()) {
            if (ref == null) {
                console.println("The working tree is empty");
            } else {
                console.println("The specified path is empty");
            }
            return;
        }
        Function<RevObject, CharSequence> printFunctor = new Function<RevObject, CharSequence>() {

            @Override
            public CharSequence apply(RevObject input) {
                if (verbose) {
                    return String.format("%s: %s %s", input.getId(), input.getType(), input);
                } else {
                    return String.format("%s: %s", input.getId(), input.getType());
                }
            }
        };
        Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);
        while (lines.hasNext()) {
            console.println(lines.next());
        }
        console.flush();
    } finally {
        deduplicator.release();
    }
}
Also used : WalkGraphOp(org.locationtech.geogig.api.plumbing.WalkGraphOp) Function(com.google.common.base.Function) ConsoleReader(jline.console.ConsoleReader) RevObject(org.locationtech.geogig.api.RevObject) CreateDeduplicator(org.locationtech.geogig.api.plumbing.CreateDeduplicator) Deduplicator(org.locationtech.geogig.storage.Deduplicator) CreateDeduplicator(org.locationtech.geogig.api.plumbing.CreateDeduplicator)

Example 40 with RevObject

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

the class TagRemoveOp method _call.

/**
     * Executes the tag removal operation.
     * 
     * @return the tag to remove
     * 
     */
@Override
protected RevTag _call() throws RuntimeException {
    String fullPath = Ref.TAGS_PREFIX + name;
    Optional<RevObject> revTag = command(RevObjectParse.class).setRefSpec(fullPath).call();
    Preconditions.checkArgument(revTag.isPresent(), "Wrong tag name: " + name);
    Preconditions.checkArgument(revTag.get().getType().equals(RevObject.TYPE.TAG), name + " does not resolve to a tag");
    UpdateRef updateRef = command(UpdateRef.class).setName(fullPath).setDelete(true).setReason("Delete tag " + name);
    Optional<Ref> tagRef = updateRef.call();
    checkState(tagRef.isPresent());
    return (RevTag) revTag.get();
}
Also used : Ref(org.locationtech.geogig.api.Ref) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) RevTag(org.locationtech.geogig.api.RevTag) RevObject(org.locationtech.geogig.api.RevObject) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef)

Aggregations

RevObject (org.locationtech.geogig.api.RevObject)84 ObjectId (org.locationtech.geogig.api.ObjectId)51 RevCommit (org.locationtech.geogig.api.RevCommit)30 NodeRef (org.locationtech.geogig.api.NodeRef)22 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)22 RevTree (org.locationtech.geogig.api.RevTree)21 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)17 RevFeature (org.locationtech.geogig.api.RevFeature)17 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)16 Feature (org.opengis.feature.Feature)16 IOException (java.io.IOException)15 LinkedList (java.util.LinkedList)15 LogOp (org.locationtech.geogig.api.porcelain.LogOp)14 GeoGIG (org.locationtech.geogig.api.GeoGIG)13 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)11 HashMap (java.util.HashMap)10 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)10 Optional (com.google.common.base.Optional)8 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)8