Search in sources :

Example 91 with ObjectId

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

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

the class Patch method addAlteredTree.

public void addAlteredTree(DiffEntry diff) {
    ObjectId oldFeatureType = diff.getOldObject() == null ? null : diff.getOldObject().getMetadataId();
    ObjectId newFeatureType = diff.getNewObject() == null ? null : diff.getNewObject().getMetadataId();
    String path = diff.oldPath() == null ? diff.newPath() : diff.oldPath();
    alteredTrees.add(new FeatureTypeDiff(path, oldFeatureType, newFeatureType));
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId)

Example 93 with ObjectId

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

the class CommitOpTest method testCommitWithAllOption.

@Test
public void testCommitWithAllOption() throws Exception {
    try {
        geogig.command(AddOp.class).addPattern(".").call();
        geogig.command(CommitOp.class).call();
        fail("expected NothingToCommitException");
    } catch (NothingToCommitException e) {
        assertTrue(true);
    }
    insertAndAdd(points1);
    geogig.command(AddOp.class).addPattern(".").call();
    RevCommit commit = geogig.command(CommitOp.class).call();
    ObjectId oid = insertAndAdd(points1_modified);
    CommitOp commitCommand = geogig.command(CommitOp.class);
    commit = commitCommand.setAll(true).call();
    assertNotNull(commit);
    assertNotNull(commit.getParentIds());
    assertEquals(1, commit.getParentIds().size());
    assertNotNull(commit.getId());
    ObjectId treeId = commit.getTreeId();
    assertNotNull(treeId);
    RevTree root = repo.getTree(treeId);
    assertNotNull(root);
    Optional<Node> typeTreeId = repo.getTreeChild(root, pointsName);
    assertTrue(typeTreeId.isPresent());
    RevTree typeTree = repo.getTree(typeTreeId.get().getObjectId());
    assertNotNull(typeTree);
    String featureId = points1.getIdentifier().getID();
    Optional<Node> featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
    assertTrue(featureBlobId.isPresent());
    assertEquals(oid, featureBlobId.get().getObjectId());
    ObjectId commitId = geogig.command(RevParse.class).setRefSpec(Ref.HEAD).call().get();
    assertEquals(commit.getId(), commitId);
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevParse(org.locationtech.geogig.api.plumbing.RevParse) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) Node(org.locationtech.geogig.api.Node) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 94 with ObjectId

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

the class CommitOpTest method testAmend.

@Test
public void testAmend() throws Exception {
    final ObjectId id = insertAndAdd(points1);
    final RevCommit commit1 = geogig.command(CommitOp.class).setMessage("Message").call();
    {
        assertCommit(commit1, null, null, null);
        assertEquals(id, repo.getRootTreeChild(appendChild(pointsName, idP1)).get().getObjectId());
        assertNotNull(repo.objectDatabase().get(id));
    }
    final ObjectId id2 = insertAndAdd(points2);
    final RevCommit commit2 = geogig.command(CommitOp.class).setAmend(true).call();
    {
        assertCommit(commit2, null, "groldan", "Message");
        Optional<RevFeature> p2 = geogig.command(RevObjectParse.class).setRefSpec("HEAD:" + appendChild(pointsName, idP2)).call(RevFeature.class);
        assertTrue(p2.isPresent());
        assertEquals(id2, p2.get().getId());
        Optional<RevFeature> p1 = geogig.command(RevObjectParse.class).setRefSpec("HEAD:" + appendChild(pointsName, idP1)).call(RevFeature.class);
        assertTrue(p1.isPresent());
        assertEquals(id, p1.get().getId());
    }
    Iterator<RevCommit> log = geogig.command(LogOp.class).call();
    assertTrue(log.hasNext());
    log.next();
    assertFalse(log.hasNext());
}
Also used : Optional(com.google.common.base.Optional) ObjectId(org.locationtech.geogig.api.ObjectId) LogOp(org.locationtech.geogig.api.porcelain.LogOp) RevFeature(org.locationtech.geogig.api.RevFeature) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 95 with ObjectId

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

the class CommitOpTest method testCommitAddsFeatureTypeToObjectDatabase.

@Test
public void testCommitAddsFeatureTypeToObjectDatabase() throws Exception {
    insertAndAdd(points1);
    ObjectId id = RevFeatureTypeImpl.build(pointsType).getId();
    geogig.command(AddOp.class).addPattern(".").call();
    RevCommit commit = geogig.command(CommitOp.class).call();
    assertNotNull(commit);
    RevFeatureType type = geogig.getRepository().objectDatabase().getFeatureType(id);
    assertEquals(id, type.getId());
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Aggregations

ObjectId (org.locationtech.geogig.api.ObjectId)361 Test (org.junit.Test)133 RevCommit (org.locationtech.geogig.api.RevCommit)109 NodeRef (org.locationtech.geogig.api.NodeRef)98 RevTree (org.locationtech.geogig.api.RevTree)91 RevObject (org.locationtech.geogig.api.RevObject)53 Ref (org.locationtech.geogig.api.Ref)46 Node (org.locationtech.geogig.api.Node)44 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)38 Feature (org.opengis.feature.Feature)35 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)34 LogOp (org.locationtech.geogig.api.porcelain.LogOp)28 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)27 LinkedList (java.util.LinkedList)26 ArrayList (java.util.ArrayList)25 RevFeature (org.locationtech.geogig.api.RevFeature)25 IOException (java.io.IOException)23 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)23 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)23 SymRef (org.locationtech.geogig.api.SymRef)22