use of org.locationtech.geogig.api.porcelain.NothingToCommitException in project GeoGig by boundlessgeo.
the class CommitOpTest method testNoCommitterEmail.
@Test
public void testNoCommitterEmail() throws Exception {
try {
geogig.command(AddOp.class).addPattern(".").call();
geogig.command(CommitOp.class).call();
fail("expected NothingToCommitException");
} catch (NothingToCommitException e) {
assertTrue(true);
}
injector.configDatabase().remove("user.email");
CommitOp commitCommand = geogig.command(CommitOp.class);
exception.expect(IllegalStateException.class);
commitCommand.setAllowEmpty(true).call();
}
use of org.locationtech.geogig.api.porcelain.NothingToCommitException in project GeoGig by boundlessgeo.
the class CommitOpTest method testCancel.
@Test
public void testCancel() throws Exception {
ProgressListener listener1 = mock(ProgressListener.class);
when(listener1.isCanceled()).thenReturn(true);
ProgressListener listener2 = mock(ProgressListener.class);
when(listener2.isCanceled()).thenReturn(false, true);
ProgressListener listener3 = mock(ProgressListener.class);
when(listener3.isCanceled()).thenReturn(false, false, true);
try {
geogig.command(AddOp.class).addPattern(".").call();
geogig.command(CommitOp.class).call();
fail("expected NothingToCommitException");
} catch (NothingToCommitException e) {
assertTrue(true);
}
CommitOp commitCommand1 = geogig.command(CommitOp.class);
commitCommand1.setProgressListener(listener1);
assertNull(commitCommand1.setAllowEmpty(true).call());
CommitOp commitCommand2 = geogig.command(CommitOp.class);
commitCommand2.setProgressListener(listener2);
assertNull(commitCommand2.setAllowEmpty(true).call());
CommitOp commitCommand3 = geogig.command(CommitOp.class);
commitCommand3.setProgressListener(listener3);
assertNull(commitCommand3.setAllowEmpty(true).call());
}
use of org.locationtech.geogig.api.porcelain.NothingToCommitException in project GeoGig by boundlessgeo.
the class OSMDownload method runInternal.
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
checkParameter(filterFile != null ^ bbox != null || update, "You must specify a filter file or a bounding box");
checkParameter((filterFile != null || bbox != null) ^ update, "Filters cannot be used when updating");
GeoGIG geogig = cli.getGeogig();
checkState(geogig.getRepository().index().isClean() && geogig.getRepository().workingTree().isClean(), "Working tree and index are not clean");
checkParameter(!rebase || update, "--rebase switch can only be used when updating");
checkParameter(filterFile == null || filterFile.exists(), "The specified filter file does not exist");
checkParameter(bbox == null || bbox.size() == 4, "The specified bounding box is not correct");
osmAPIUrl = resolveAPIURL();
Optional<OSMReport> report;
GeogigTransaction tx = geogig.command(TransactionBegin.class).call();
try {
AbstractGeoGigOp<Optional<OSMReport>> cmd;
if (update) {
cmd = tx.command(OSMUpdateOp.class).setAPIUrl(osmAPIUrl).setRebase(rebase).setMessage(message).setProgressListener(cli.getProgressListener());
} else {
cmd = tx.command(OSMDownloadOp.class).setBbox(bbox).setFilterFile(filterFile).setKeepFiles(keepFiles).setMessage(message).setMappingFile(mappingFile).setOsmAPIUrl(osmAPIUrl).setSaveFile(saveFile).setProgressListener(cli.getProgressListener());
}
report = cmd.call();
tx.commit();
} catch (RuntimeException e) {
tx.abort();
if (e instanceof NothingToCommitException) {
throw new CommandFailedException(e.getMessage(), e);
}
throw e;
}
if (report.isPresent()) {
OSMReport rep = report.get();
String msg;
if (rep.getUnpprocessedCount() > 0) {
msg = String.format("\nSome elements returned by the specified filter could not be processed.\n" + "Processed entities: %,d.\nWrong or uncomplete elements: %,d.\nNodes: %,d.\nWays: %,d.\n", rep.getCount(), rep.getUnpprocessedCount(), rep.getNodeCount(), rep.getWayCount());
} else {
msg = String.format("\nProcessed entities: %,d.\n Nodes: %,d.\n Ways: %,d\n", rep.getCount(), rep.getNodeCount(), rep.getWayCount());
}
cli.getConsole().println(msg);
}
}
use of org.locationtech.geogig.api.porcelain.NothingToCommitException in project GeoGig by boundlessgeo.
the class OSMDownloadOpTest method testUpdate.
@Ignore
@Test
public void testUpdate() throws Exception {
String filename = OSMImportOp.class.getResource("fire_station_filter.txt").getFile();
File filterFile = new File(filename);
OSMDownloadOp download = geogig.command(OSMDownloadOp.class);
download.setFilterFile(filterFile).setOsmAPIUrl(OSMUtils.DEFAULT_API_ENDPOINT).call();
Optional<Node> tree = geogig.getRepository().getRootTreeChild("node");
assertTrue(tree.isPresent());
tree = geogig.getRepository().getRootTreeChild("way");
assertTrue(tree.isPresent());
List<OSMLogEntry> entries = geogig.command(ReadOSMLogEntries.class).call();
assertFalse(entries.isEmpty());
OSMUpdateOp update = geogig.command(OSMUpdateOp.class);
try {
update.setAPIUrl(OSMUtils.DEFAULT_API_ENDPOINT).call();
} catch (NothingToCommitException e) {
// No new data
}
}
use of org.locationtech.geogig.api.porcelain.NothingToCommitException in project GeoGig by boundlessgeo.
the class GeogigTransactionState method commit.
@Override
public void commit() throws IOException {
Preconditions.checkState(this.geogigTx != null);
/*
* This follows suite with the hack set on GeoSever's
* org.geoserver.wfs.Transaction.getDatastoreTransaction()
*/
final Optional<String> txUserName = getTransactionProperty(VERSIONING_COMMIT_AUTHOR);
final Optional<String> fullName = getTransactionProperty("fullname");
final Optional<String> email = getTransactionProperty("email");
final String author = fullName.isPresent() ? fullName.get() : txUserName.orNull();
String commitMessage = getTransactionProperty(VERSIONING_COMMIT_MESSAGE).orNull();
this.geogigTx.command(AddOp.class).call();
try {
CommitOp commitOp = this.geogigTx.command(CommitOp.class);
if (txUserName != null) {
commitOp.setAuthor(author, email.orNull());
}
if (commitMessage == null) {
commitMessage = composeDefaultCommitMessage();
}
commitOp.setMessage(commitMessage);
commitOp.call();
} catch (NothingToCommitException nochanges) {
// ok
}
try {
this.geogigTx.setAuthor(author, email.orNull()).commit();
} catch (ConflictsException e) {
// TODO: how should this be handled?
this.geogigTx.abort();
}
this.geogigTx = null;
}
Aggregations