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);
*/
}
}
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;
}
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);
}
}
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());
}
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());
}
Aggregations