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