Search in sources :

Example 11 with NothingToCommitException

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();
}
Also used : NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) Test(org.junit.Test)

Example 12 with NothingToCommitException

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());
}
Also used : ProgressListener(org.locationtech.geogig.api.ProgressListener) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) Test(org.junit.Test)

Example 13 with NothingToCommitException

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);
    }
}
Also used : GeogigTransaction(org.locationtech.geogig.api.GeogigTransaction) Optional(com.google.common.base.Optional) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) OSMReport(org.locationtech.geogig.osm.internal.OSMReport) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) OSMUpdateOp(org.locationtech.geogig.osm.internal.OSMUpdateOp) TransactionBegin(org.locationtech.geogig.api.plumbing.TransactionBegin) OSMDownloadOp(org.locationtech.geogig.osm.internal.OSMDownloadOp) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Example 14 with NothingToCommitException

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
    }
}
Also used : ReadOSMLogEntries(org.locationtech.geogig.osm.internal.log.ReadOSMLogEntries) Node(org.locationtech.geogig.api.Node) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) File(java.io.File) OSMLogEntry(org.locationtech.geogig.osm.internal.log.OSMLogEntry) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with NothingToCommitException

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;
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) ConflictsException(org.locationtech.geogig.api.porcelain.ConflictsException)

Aggregations

NothingToCommitException (org.locationtech.geogig.api.porcelain.NothingToCommitException)15 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)10 Test (org.junit.Test)9 ObjectId (org.locationtech.geogig.api.ObjectId)8 RevCommit (org.locationtech.geogig.api.RevCommit)8 RevParse (org.locationtech.geogig.api.plumbing.RevParse)6 Node (org.locationtech.geogig.api.Node)5 RevTree (org.locationtech.geogig.api.RevTree)4 GeoGIG (org.locationtech.geogig.api.GeoGIG)3 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)3 DiffOp (org.locationtech.geogig.api.porcelain.DiffOp)3 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)3 ConsoleReader (jline.console.ConsoleReader)2 Ansi (org.fusesource.jansi.Ansi)2 Ref (org.locationtech.geogig.api.Ref)2 MergeOp (org.locationtech.geogig.api.porcelain.MergeOp)2 Optional (com.google.common.base.Optional)1 File (java.io.File)1 TimeoutException (java.util.concurrent.TimeoutException)1 Ignore (org.junit.Ignore)1