Search in sources :

Example 41 with ObjectId

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

the class FindOrCreateSubtree method _call.

/**
     * Executes the command.
     * 
     * @return the subtree if it was found, or a new one if it wasn't
     */
@Override
protected RevTree _call() {
    checkNotNull(parentSupplier, "parent");
    checkNotNull(childPath, "childPath");
    ObjectId subtreeId;
    if (parentSupplier.get().isPresent()) {
        RevTree parent = parentSupplier.get().get();
        Optional<NodeRef> treeChildRef = command(FindTreeChild.class).setIndex(indexDb).setParentPath(parentPath).setChildPath(childPath).setParent(Suppliers.ofInstance(parent)).call();
        if (treeChildRef.isPresent()) {
            NodeRef treeRef = treeChildRef.get();
            if (!TYPE.TREE.equals(treeRef.getType())) {
                throw new IllegalArgumentException("Object exists as child of tree " + parent.getId() + " but is not a tree: " + treeChildRef);
            }
            subtreeId = treeRef.objectId();
        } else {
            subtreeId = RevTree.EMPTY_TREE_ID;
        }
    } else {
        subtreeId = RevTree.EMPTY_TREE_ID;
    }
    if (RevTree.EMPTY_TREE_ID.equals(subtreeId)) {
        return RevTree.EMPTY;
    }
    ObjectDatabase target = indexDb ? stagingDatabase() : objectDatabase();
    RevTree tree = target.getTree(subtreeId);
    return tree;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) RevTree(org.locationtech.geogig.api.RevTree)

Example 42 with ObjectId

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

the class CloneOpTest method testClone.

@Test
public void testClone() 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>();
    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());
    }
    // 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 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);
}
Also used : CloneOp(org.locationtech.geogig.api.porcelain.CloneOp) 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) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 43 with ObjectId

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

the class CloneOpTest method testShallowClone.

@Test
public void testShallowClone() 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>();
    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());
    }
    // 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 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(2);
    clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).call();
    // Make sure the local repository got only 2 commits
    logs = localGeogig.geogig.command(LogOp.class).call();
    logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(2, logged.size());
    assertEquals(expected.get(0), logged.get(0));
    assertEquals(expected.get(1), logged.get(1));
}
Also used : CloneOp(org.locationtech.geogig.api.porcelain.CloneOp) 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) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 44 with ObjectId

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

the class RevCommitSerializationTest method testCommitRoundTrippin.

@Test
public void testCommitRoundTrippin() throws Exception {
    long currentTime = System.currentTimeMillis();
    int timeZoneOffset = TimeZone.getDefault().getOffset(currentTime);
    CommitBuilder builder = new CommitBuilder();
    String author = "groldan";
    builder.setAuthor(author);
    String authorEmail = "groldan@boundlessgeo.com";
    builder.setAuthorEmail(authorEmail);
    builder.setAuthorTimestamp(currentTime);
    builder.setAuthorTimeZoneOffset(timeZoneOffset);
    String committer = "mleslie";
    builder.setCommitter(committer);
    String committerEmail = "mleslie@boundlessgeo.com";
    builder.setCommitterEmail(committerEmail);
    builder.setCommitterTimestamp(currentTime);
    builder.setCommitterTimeZoneOffset(timeZoneOffset);
    ObjectId treeId = ObjectId.forString("Fake tree");
    builder.setTreeId(treeId);
    ObjectId parent1 = ObjectId.forString("Parent 1 of fake commit");
    ObjectId parent2 = ObjectId.forString("Parent 2 of fake commit");
    List<ObjectId> parents = Arrays.asList(parent1, parent2);
    builder.setParentIds(parents);
    RevCommit cmtIn = builder.build();
    assertNotNull(cmtIn);
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectWriter<RevCommit> write = factory.createObjectWriter(TYPE.COMMIT);
    write.write(cmtIn, bout);
    // System.err.println(bout);
    byte[] bytes = bout.toByteArray();
    assertTrue(bytes.length > 0);
    ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
    ObjectReader<RevCommit> read = factory.createCommitReader();
    RevCommit cmtOut = read.read(cmtIn.getId(), bin);
    assertEquals(treeId, cmtOut.getTreeId());
    assertEquals(parents, cmtOut.getParentIds());
    assertEquals(author, cmtOut.getAuthor().getName().get());
    assertEquals(authorEmail, cmtOut.getAuthor().getEmail().get());
    assertEquals(committer, cmtOut.getCommitter().getName().get());
    assertEquals(committerEmail, cmtOut.getCommitter().getEmail().get());
    assertEquals(currentTime, cmtOut.getCommitter().getTimestamp());
    assertEquals(timeZoneOffset, cmtOut.getCommitter().getTimeZoneOffset());
    assertEquals(currentTime, cmtOut.getAuthor().getTimestamp());
    assertEquals(timeZoneOffset, cmtOut.getAuthor().getTimeZoneOffset());
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) ByteArrayInputStream(java.io.ByteArrayInputStream) CommitBuilder(org.locationtech.geogig.api.CommitBuilder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 45 with ObjectId

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

the class CheckoutOpTest method testCheckoutPathFilter.

@Test
public void testCheckoutPathFilter() throws Exception {
    ObjectId points1Id = insertAndAdd(points1);
    geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    insert(points1_modified);
    CheckoutResult result = geogig.command(CheckoutOp.class).addPath("Points/Points.1").call();
    Optional<RevTree> workTree = geogig.command(RevObjectParse.class).setObjectId(result.getNewTree()).call(RevTree.class);
    Optional<NodeRef> nodeRef = geogig.command(FindTreeChild.class).setParent(workTree.get()).setChildPath("Points/Points.1").call();
    assertEquals(points1Id, nodeRef.get().getNode().getObjectId());
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) CheckoutResult(org.locationtech.geogig.api.porcelain.CheckoutResult) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) RevTree(org.locationtech.geogig.api.RevTree) 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