Search in sources :

Example 81 with NodeRef

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

the class FeatureNodeRefFromRefspec method _call.

@Override
protected Optional<NodeRef> _call() {
    Optional<RevFeature> feature = getFeatureFromRefSpec();
    if (feature.isPresent()) {
        RevFeatureType featureType = getFeatureTypeFromRefSpec();
        RevFeature feat = feature.get();
        Envelope bounds = SpatialOps.boundsOf(feat);
        Node node = Node.create(NodeRef.nodeFromPath(ref), feat.getId(), featureType.getId(), TYPE.FEATURE, bounds);
        return Optional.of(new NodeRef(node, NodeRef.parentPath(ref), featureType.getId()));
    } else {
        return Optional.absent();
    /*
             * new NodeRef(Node.create("", ObjectId.NULL, ObjectId.NULL, TYPE.FEATURE), "",
             * ObjectId.NULL);
             */
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) Node(org.locationtech.geogig.api.Node) RevFeature(org.locationtech.geogig.api.RevFeature) Envelope(com.vividsolutions.jts.geom.Envelope) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Example 82 with NodeRef

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

the class FeatureNodeRefFromRefspec method getFeatureTypeFromRefSpec.

private RevFeatureType getFeatureTypeFromRefSpec() {
    String featureTypeRef = NodeRef.parentPath(ref);
    String fullRef;
    if (featureTypeRef.contains(":")) {
        fullRef = featureTypeRef;
    } else {
        fullRef = "WORK_HEAD:" + featureTypeRef;
    }
    String treeRef = fullRef.split(":")[0];
    String path = fullRef.split(":")[1];
    ObjectId revTreeId = command(ResolveTreeish.class).setTreeish(treeRef).call().get();
    RevTree revTree = command(RevObjectParse.class).setObjectId(revTreeId).call(RevTree.class).get();
    Optional<NodeRef> nodeRef = command(FindTreeChild.class).setParent(revTree).setChildPath(path).setIndex(true).call();
    Preconditions.checkArgument(nodeRef.isPresent(), "Invalid reference: %s", ref);
    RevFeatureType revFeatureType = command(RevObjectParse.class).setObjectId(nodeRef.get().getMetadataId()).call(RevFeatureType.class).get();
    return revFeatureType;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) ResolveTreeish(org.locationtech.geogig.api.plumbing.ResolveTreeish) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree)

Example 83 with NodeRef

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

the class RemoveOpTest method testRemovalOfAllFeaturesOfAGivenType.

// TODO: Remove this test
@SuppressWarnings(value = { "unused" })
@Test
public void testRemovalOfAllFeaturesOfAGivenType() throws Exception {
    List<RevCommit> commits = populate(false, points1, points2, points3, lines1, lines2);
    String featureId = lines1.getIdentifier().getID();
    String path = NodeRef.appendChild(linesName, featureId);
    String featureId2 = lines2.getIdentifier().getID();
    String path2 = NodeRef.appendChild(linesName, featureId2);
    WorkingTree tree = geogig.command(RemoveOp.class).addPathToRemove(path).addPathToRemove(path2).call();
    geogig.command(AddOp.class).call();
    RevCommit commit = geogig.command(CommitOp.class).setMessage("Removed lines").call();
    Iterator<NodeRef> nodes = geogig.command(LsTreeOp.class).call();
    while (nodes.hasNext()) {
        NodeRef node = nodes.next();
        assertNotNull(node);
    }
    geogig.command(ResetOp.class).setMode(ResetMode.HARD).call();
    nodes = geogig.command(LsTreeOp.class).call();
    while (nodes.hasNext()) {
        NodeRef node = nodes.next();
        assertNotNull(node);
    }
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) WorkingTree(org.locationtech.geogig.repository.WorkingTree) NodeRef(org.locationtech.geogig.api.NodeRef) LsTreeOp(org.locationtech.geogig.api.plumbing.LsTreeOp) RemoveOp(org.locationtech.geogig.api.porcelain.RemoveOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 84 with NodeRef

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

the class RevertOpTest method testRevertModifiedFeatureConflictAndAbort.

@Test
public void testRevertModifiedFeatureConflictAndAbort() throws Exception {
    insertAndAdd(points1);
    @SuppressWarnings("unused") RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    insertAndAdd(points1_modified);
    RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1).call();
    Feature points1_modifiedB = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
    ObjectId oId = insertAndAdd(points1_modifiedB);
    RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1 + " again").call();
    try {
        geogig.command(RevertOp.class).addCommit(Suppliers.ofInstance(c2.getId())).call();
        fail();
    } catch (RevertConflictsException e) {
        assertTrue(e.getMessage().contains(idP1));
    }
    Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
    assertTrue(ref.isPresent());
    assertEquals(c3.getId(), ref.get().getObjectId());
    List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
    assertEquals(1, conflicts.size());
    String path = NodeRef.appendChild(pointsName, idP1);
    assertEquals(conflicts.get(0).getPath(), path);
    assertEquals(conflicts.get(0).getOurs(), RevFeatureBuilder.build(points1_modifiedB).getId());
    assertEquals(conflicts.get(0).getTheirs(), RevFeatureBuilder.build(points1).getId());
    geogig.command(RevertOp.class).setAbort(true).call();
    final Optional<Ref> currHead = geogig.command(RefParse.class).setName(Ref.HEAD).call();
    final Optional<ObjectId> headTreeId = geogig.command(ResolveTreeish.class).setTreeish(currHead.get().getObjectId()).call();
    RevTree headTree = repo.getTree(headTreeId.get());
    Optional<NodeRef> points1Node = geogig.command(FindTreeChild.class).setChildPath(NodeRef.appendChild(pointsName, idP1)).setParent(headTree).call();
    assertTrue(points1Node.isPresent());
    assertEquals(oId, points1Node.get().getNode().getObjectId());
}
Also used : ConflictsReadOp(org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp) ObjectId(org.locationtech.geogig.api.ObjectId) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) Feature(org.opengis.feature.Feature) NodeRef(org.locationtech.geogig.api.NodeRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) RevertConflictsException(org.locationtech.geogig.api.porcelain.RevertConflictsException) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 85 with NodeRef

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

the class RevertOpTest method testRevert.

@Test
public void testRevert() throws Exception {
    ObjectId oId1 = insertAndAdd(points1);
    RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    insertAndAdd(points2);
    RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
    insertAndAdd(points1_modified);
    RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for modified " + idP1).call();
    ObjectId oId3 = insertAndAdd(points3);
    RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
    deleteAndAdd(points3);
    RevCommit c5 = geogig.command(CommitOp.class).setMessage("commit for deleted " + idP3).call();
    // revert Points.2 add, Points.1 change, and Points.3 delete
    geogig.command(RevertOp.class).addCommit(Suppliers.ofInstance(c2.getId())).addCommit(Suppliers.ofInstance(c3.getId())).addCommit(Suppliers.ofInstance(c5.getId())).call();
    final Optional<Ref> currHead = geogig.command(RefParse.class).setName(Ref.HEAD).call();
    final Optional<ObjectId> headTreeId = geogig.command(ResolveTreeish.class).setTreeish(currHead.get().getObjectId()).call();
    RevTree headTree = repo.getTree(headTreeId.get());
    Optional<NodeRef> points1Node = geogig.command(FindTreeChild.class).setChildPath(NodeRef.appendChild(pointsName, idP1)).setParent(headTree).call();
    assertTrue(points1Node.isPresent());
    assertEquals(oId1, points1Node.get().getNode().getObjectId());
    Optional<NodeRef> points2Node = geogig.command(FindTreeChild.class).setChildPath(NodeRef.appendChild(pointsName, idP2)).setParent(headTree).call();
    assertFalse(points2Node.isPresent());
    Optional<NodeRef> points3Node = geogig.command(FindTreeChild.class).setChildPath(NodeRef.appendChild(pointsName, idP3)).setParent(headTree).call();
    assertTrue(points3Node.isPresent());
    assertEquals(oId3, points3Node.get().getNode().getObjectId());
    Iterator<RevCommit> log = geogig.command(LogOp.class).call();
    // There should be 3 new commits, followed by all of the previous commits.
    log.next();
    log.next();
    log.next();
    assertEquals(c5.getId(), log.next().getId());
    assertEquals(c4.getId(), log.next().getId());
    assertEquals(c3.getId(), log.next().getId());
    assertEquals(c2.getId(), log.next().getId());
    assertEquals(c1.getId(), log.next().getId());
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) LogOp(org.locationtech.geogig.api.porcelain.LogOp) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

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