use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class CommitOpTest method testCommitWithCustomAuthorAndCommitter.
@Test
public void testCommitWithCustomAuthorAndCommitter() throws Exception {
try {
geogig.command(AddOp.class).addPattern(".").call();
geogig.command(CommitOp.class).call();
fail("expected NothingToCommitException");
} catch (NothingToCommitException e) {
assertTrue(true);
}
ObjectId oid1 = insertAndAdd(points1);
ObjectId oid2 = insertAndAdd(points2);
geogig.command(AddOp.class).addPattern(".").call();
CommitOp commitCommand = geogig.command(CommitOp.class);
commitCommand.setAuthor("John Doe", "John@Doe.com");
commitCommand.setCommitter("Jane Doe", "Jane@Doe.com");
RevCommit commit = commitCommand.call();
assertNotNull(commit);
assertNotNull(commit.getParentIds());
assertEquals(0, commit.getParentIds().size());
assertFalse(commit.parentN(0).isPresent());
assertNotNull(commit.getId());
assertEquals("John Doe", commit.getAuthor().getName().get());
assertEquals("John@Doe.com", commit.getAuthor().getEmail().get());
assertEquals("Jane Doe", commit.getCommitter().getName().get());
assertEquals("Jane@Doe.com", commit.getCommitter().getEmail().get());
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(oid1, featureBlobId.get().getObjectId());
featureId = points2.getIdentifier().getID();
featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
assertTrue(featureBlobId.isPresent());
assertEquals(oid2, featureBlobId.get().getObjectId());
ObjectId commitId = geogig.command(RevParse.class).setRefSpec(Ref.HEAD).call().get();
assertEquals(commit.getId(), commitId);
}
use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class CommitOpTest method testPathFiltering.
@Test
public void testPathFiltering() throws Exception {
insertAndAdd(points1);
insertAndAdd(points2);
RevCommit commit = geogig.command(CommitOp.class).call();
insertAndAdd(points3);
insertAndAdd(lines1);
insertAndAdd(lines2);
insertAndAdd(lines3);
List<String> filters = Arrays.asList("Points/Points.3", "Lines/Lines.1", "Lines/Lines.3");
commit = geogig.command(CommitOp.class).setPathFilters(filters).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());
featureId = points2.getIdentifier().getID();
featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
assertTrue(featureBlobId.isPresent());
featureId = points3.getIdentifier().getID();
featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
assertTrue(featureBlobId.isPresent());
typeTreeId = repo.getTreeChild(root, linesName);
assertTrue(typeTreeId.isPresent());
typeTree = repo.getTree(typeTreeId.get().getObjectId());
assertNotNull(typeTree);
featureId = lines1.getIdentifier().getID();
featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(linesName, featureId));
assertTrue(featureBlobId.isPresent());
featureId = lines2.getIdentifier().getID();
featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(linesName, featureId));
assertFalse(featureBlobId.isPresent());
featureId = lines3.getIdentifier().getID();
featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(linesName, featureId));
assertTrue(featureBlobId.isPresent());
}
use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class CommitOpTest method testPathFilteringWithUnstaged.
@Test
public void testPathFilteringWithUnstaged() throws Exception {
insertAndAdd(points1);
insertAndAdd(points2);
RevCommit commit = geogig.command(CommitOp.class).call();
insertAndAdd(lines1);
insertAndAdd(lines3);
insert(lines2);
insert(points3);
List<String> filters = Arrays.asList(pointsName, linesName);
commit = geogig.command(CommitOp.class).setPathFilters(filters).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());
featureId = points2.getIdentifier().getID();
featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
assertTrue(featureBlobId.isPresent());
featureId = points3.getIdentifier().getID();
featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
assertFalse(featureBlobId.isPresent());
typeTreeId = repo.getTreeChild(root, linesName);
assertTrue(typeTreeId.isPresent());
typeTree = repo.getTree(typeTreeId.get().getObjectId());
assertNotNull(typeTree);
featureId = lines1.getIdentifier().getID();
featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(linesName, featureId));
assertTrue(featureBlobId.isPresent());
featureId = lines2.getIdentifier().getID();
featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(linesName, featureId));
assertFalse(featureBlobId.isPresent());
featureId = lines3.getIdentifier().getID();
featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(linesName, featureId));
assertTrue(featureBlobId.isPresent());
}
use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class ShpExportDiff method getFeatureType.
private SimpleFeatureType getFeatureType(String path, GeogigCLI cli) {
checkParameter(path != null, "No path specified.");
String refspec;
if (path.contains(":")) {
refspec = path;
} else {
refspec = "WORK_HEAD:" + path;
}
checkParameter(!refspec.endsWith(":"), "No path specified.");
final GeoGIG geogig = cli.getGeogig();
Optional<ObjectId> rootTreeId = geogig.command(ResolveTreeish.class).setTreeish(refspec.split(":")[0]).call();
checkParameter(rootTreeId.isPresent(), "Couldn't resolve '" + refspec + "' to a treeish object");
RevTree rootTree = geogig.getRepository().getTree(rootTreeId.get());
Optional<NodeRef> featureTypeTree = geogig.command(FindTreeChild.class).setChildPath(refspec.split(":")[1]).setParent(rootTree).setIndex(true).call();
checkParameter(featureTypeTree.isPresent(), "pathspec '" + refspec.split(":")[1] + "' did not match any valid path");
Optional<RevObject> revObject = cli.getGeogig().command(RevObjectParse.class).setObjectId(featureTypeTree.get().getMetadataId()).call();
if (revObject.isPresent() && revObject.get() instanceof RevFeatureType) {
RevFeatureType revFeatureType = (RevFeatureType) revObject.get();
if (revFeatureType.type() instanceof SimpleFeatureType) {
return (SimpleFeatureType) revFeatureType.type();
} else {
throw new InvalidParameterException("Cannot find feature type for the specified path");
}
} else {
throw new InvalidParameterException("Cannot find feature type for the specified path");
}
}
use of org.locationtech.geogig.api.RevTree in project GeoGig by boundlessgeo.
the class ExportDiffOp method _call.
/**
* Executes the export operation using the parameters that have been specified.
*
* @return a FeatureCollection with the specified features
*/
@Override
protected SimpleFeatureStore _call() {
final SimpleFeatureStore targetStore = getTargetStore();
final String refspec = old ? oldRef : newRef;
final RevTree rootTree = resolveRootTree(refspec);
final NodeRef typeTreeRef = resolTypeTreeRef(refspec, path, rootTree);
final ObjectId defaultMetadataId = typeTreeRef.getMetadataId();
final ProgressListener progressListener = getProgressListener();
progressListener.started();
progressListener.setDescription("Exporting diffs for path '" + path + "'... ");
FeatureCollection<SimpleFeatureType, SimpleFeature> asFeatureCollection = new BaseFeatureCollection<SimpleFeatureType, SimpleFeature>() {
@Override
public FeatureIterator<SimpleFeature> features() {
Iterator<DiffEntry> diffs = command(DiffOp.class).setOldVersion(oldRef).setNewVersion(newRef).setFilter(path).call();
final Iterator<SimpleFeature> plainFeatures = getFeatures(diffs, old, stagingDatabase(), defaultMetadataId, progressListener);
Iterator<Optional<Feature>> transformed = Iterators.transform(plainFeatures, ExportDiffOp.this.function);
Iterator<SimpleFeature> filtered = Iterators.filter(Iterators.transform(transformed, new Function<Optional<Feature>, SimpleFeature>() {
@Override
public SimpleFeature apply(Optional<Feature> input) {
return (SimpleFeature) (input.isPresent() ? input.get() : null);
}
}), Predicates.notNull());
return new DelegateFeatureIterator<SimpleFeature>(filtered);
}
};
// add the feature collection to the feature store
final Transaction transaction;
if (transactional) {
transaction = new DefaultTransaction("create");
} else {
transaction = Transaction.AUTO_COMMIT;
}
try {
targetStore.setTransaction(transaction);
try {
targetStore.addFeatures(asFeatureCollection);
transaction.commit();
} catch (final Exception e) {
if (transactional) {
transaction.rollback();
}
Throwables.propagateIfInstanceOf(e, GeoToolsOpException.class);
throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_ADD);
} finally {
transaction.close();
}
} catch (IOException e) {
throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_ADD);
}
progressListener.complete();
return targetStore;
}
Aggregations