use of org.locationtech.geogig.api.GeogigTransaction 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.GeogigTransaction in project GeoGig by boundlessgeo.
the class GeogigTransactionTest method testBranchCreateCollision.
@Test
public void testBranchCreateCollision() throws Exception {
// make a commit
insertAndAdd(points1);
RevCommit mainCommit = geogig.command(CommitOp.class).setMessage("Commit1").call();
// start the first transaction
GeogigTransaction transaction1 = geogig.command(TransactionBegin.class).call();
// make a new branch
transaction1.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
// perform a commit in the transaction
insertAndAdd(transaction1, points2);
RevCommit transaction1Commit = transaction1.command(CommitOp.class).setMessage("Commit2").call();
// Verify that the base repository is unchanged
Iterator<RevCommit> logs = geogig.command(LogOp.class).call();
assertEquals(logs.next(), mainCommit);
assertFalse(logs.hasNext());
// Verify that the transaction has the commit
logs = transaction1.command(LogOp.class).call();
assertEquals(logs.next(), transaction1Commit);
assertEquals(logs.next(), mainCommit);
assertFalse(logs.hasNext());
// start the second transaction
GeogigTransaction transaction2 = geogig.command(TransactionBegin.class).call();
// make a new branch
transaction2.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
// perform a commit in the transaction
insertAndAdd(transaction2, points3);
RevCommit transaction2Commit = transaction2.command(CommitOp.class).setMessage("Commit3").call();
// Verify that the base repository is unchanged
logs = geogig.command(LogOp.class).call();
assertEquals(logs.next(), mainCommit);
assertFalse(logs.hasNext());
// Verify that the transaction has the commit
logs = transaction2.command(LogOp.class).call();
assertEquals(logs.next(), transaction2Commit);
assertEquals(logs.next(), mainCommit);
assertFalse(logs.hasNext());
// Commit the first transaction
geogig.command(TransactionEnd.class).setTransaction(transaction1).setRebase(true).call();
// Verify that the base repository has the changes from the transaction
logs = geogig.command(LogOp.class).call();
assertEquals(logs.next(), mainCommit);
assertFalse(logs.hasNext());
geogig.command(CheckoutOp.class).setSource("branch1").call();
logs = geogig.command(LogOp.class).call();
assertEquals(logs.next(), transaction1Commit);
assertEquals(logs.next(), mainCommit);
assertFalse(logs.hasNext());
// Now try to commit the second transaction
geogig.command(TransactionEnd.class).setTransaction(transaction2).setRebase(true).call();
// Verify that the base repository has the changes from the transaction
logs = geogig.command(LogOp.class).call();
RevCommit lastCommit = logs.next();
assertFalse(lastCommit.equals(transaction2Commit));
assertEquals(lastCommit.getMessage(), transaction2Commit.getMessage());
assertEquals(lastCommit.getAuthor(), transaction2Commit.getAuthor());
assertEquals(lastCommit.getCommitter().getName(), transaction2Commit.getCommitter().getName());
assertFalse(lastCommit.getCommitter().getTimestamp() == transaction2Commit.getCommitter().getTimestamp());
assertEquals(logs.next(), transaction1Commit);
assertEquals(logs.next(), mainCommit);
assertFalse(logs.hasNext());
}
use of org.locationtech.geogig.api.GeogigTransaction in project GeoGig by boundlessgeo.
the class GeogigTransactionTest method testSyncTransaction.
@Test
public void testSyncTransaction() throws Exception {
LinkedList<RevCommit> expectedMain = new LinkedList<RevCommit>();
LinkedList<RevCommit> expectedTransaction = new LinkedList<RevCommit>();
// make a commit
insertAndAdd(points1);
RevCommit firstCommit = geogig.command(CommitOp.class).call();
expectedMain.addFirst(firstCommit);
expectedTransaction.addFirst(firstCommit);
// start a transaction
GeogigTransaction t = geogig.command(TransactionBegin.class).call();
// perform a commit in the transaction
insertAndAdd(t, points2);
RevCommit transactionCommit = t.command(CommitOp.class).call();
expectedTransaction.addFirst(transactionCommit);
// perform a commit on the repo
insertAndAdd(points3);
RevCommit repoCommit = geogig.command(CommitOp.class).call();
expectedMain.addFirst(repoCommit);
// Verify that the base repository is unchanged
Iterator<RevCommit> logs = geogig.command(LogOp.class).call();
List<RevCommit> logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expectedMain, logged);
// Verify that the transaction has the commit
logs = t.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expectedTransaction, logged);
// Commit the transaction
geogig.command(TransactionEnd.class).setTransaction(t).call();
// Verify that a merge commit was created
logs = geogig.command(LogOp.class).call();
RevCommit lastCommit = logs.next();
assertFalse(lastCommit.equals(repoCommit));
assertTrue(lastCommit.getMessage().contains("Merge commit"));
assertEquals(lastCommit.getParentIds().get(0), transactionCommit.getId());
assertEquals(lastCommit.getParentIds().get(1), repoCommit.getId());
assertEquals(logs.next(), repoCommit);
assertEquals(logs.next(), transactionCommit);
assertEquals(logs.next(), firstCommit);
assertFalse(logs.hasNext());
}
use of org.locationtech.geogig.api.GeogigTransaction in project GeoGig by boundlessgeo.
the class GeogigTransactionTest method testCancelTransaction.
@Test
public void testCancelTransaction() throws Exception {
LinkedList<RevCommit> expectedMain = new LinkedList<RevCommit>();
// make a commit
insertAndAdd(points1);
RevCommit commit = geogig.command(CommitOp.class).call();
expectedMain.addFirst(commit);
// start a transaction
GeogigTransaction t = geogig.command(TransactionBegin.class).call();
// perform a commit in the transaction
insertAndAdd(t, points2);
commit = t.command(CommitOp.class).call();
// Verify that the base repository is unchanged
Iterator<RevCommit> logs = geogig.command(LogOp.class).call();
List<RevCommit> logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expectedMain, logged);
// Cancel the transaction
geogig.command(TransactionEnd.class).setCancel(true).setTransaction(t).call();
// Verify that the base repository is unchanged
logs = geogig.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expectedMain, logged);
}
use of org.locationtech.geogig.api.GeogigTransaction in project GeoGig by boundlessgeo.
the class GeogigTransactionTest method testConflictIsolation.
@Test
public void testConflictIsolation() throws Exception {
insertAndAdd(points2);
geogig.command(CommitOp.class).setMessage("foo").call();
geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
insertAndAdd(points1);
RevCommit mainCommit = geogig.command(CommitOp.class).setMessage("Commit1").call();
geogig.command(CheckoutOp.class).setSource("master").call();
insertAndAdd(points1_modified);
RevCommit modifiedCommit = geogig.command(CommitOp.class).setMessage("Commit2").call();
GeogigTransaction tx = geogig.command(TransactionBegin.class).call();
try {
tx.command(MergeOp.class).addCommit(Suppliers.ofInstance(mainCommit.getId())).call();
fail("Expected a merge conflict!");
} catch (org.locationtech.geogig.api.porcelain.MergeConflictsException e) {
// expected.
}
List<Conflict> txConflicts = tx.command(ConflictsReadOp.class).call();
List<Conflict> baseConflicts = geogig.command(ConflictsReadOp.class).call();
assertTrue("There should be no conflicts outside the transaction", baseConflicts.size() == 0);
assertTrue("There should be conflicts in the transaction", txConflicts.size() != 0);
}
Aggregations