Search in sources :

Example 11 with CommitOp

use of org.locationtech.geogig.api.porcelain.CommitOp in project GeoGig by boundlessgeo.

the class OSMHistoryImport method commit.

/**
     * @param cli
     * @param changeset
     * @throws IOException
     */
private void commit(GeogigCLI cli, Changeset changeset) throws IOException {
    Preconditions.checkArgument(!changeset.isOpen());
    ConsoleReader console = cli.getConsole();
    console.print("Committing changeset " + changeset.getId() + "...");
    console.flush();
    GeoGIG geogig = cli.getGeogig();
    CommitOp command = geogig.command(CommitOp.class);
    command.setAllowEmpty(true);
    String message = "";
    if (changeset.getComment().isPresent()) {
        message = changeset.getComment().get() + "\nchangeset " + changeset.getId();
    } else {
        message = "changeset " + changeset.getId();
    }
    command.setMessage(message);
    final String userName = changeset.getUserName();
    command.setAuthor(userName, null);
    command.setAuthorTimestamp(changeset.getCreated());
    // osm timestamps are in GMT
    command.setAuthorTimeZoneOffset(0);
    if (userName != null) {
        command.setCommitter(userName, null);
    }
    command.setCommitterTimestamp(changeset.getClosed().get());
    // osm timestamps are in GMT
    command.setCommitterTimeZoneOffset(0);
    ProgressListener listener = cli.getProgressListener();
    listener.setProgress(0f);
    listener.started();
    command.setProgressListener(listener);
    try {
        RevCommit commit = command.call();
        Ref head = geogig.command(RefParse.class).setName(Ref.HEAD).call().get();
        Preconditions.checkState(commit.getId().equals(head.getObjectId()));
        updateBranchChangeset(geogig, changeset.getId());
        listener.complete();
        console.println("Commit " + commit.getId().toString());
        console.flush();
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) NodeRef(org.locationtech.geogig.api.NodeRef) ConsoleReader(jline.console.ConsoleReader) ProgressListener(org.locationtech.geogig.api.ProgressListener) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) RefParse(org.locationtech.geogig.api.plumbing.RefParse) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) GeoGIG(org.locationtech.geogig.api.GeoGIG) URISyntaxException(java.net.URISyntaxException) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) IOException(java.io.IOException) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 12 with CommitOp

use of org.locationtech.geogig.api.porcelain.CommitOp 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

CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)12 Test (org.junit.Test)9 NothingToCommitException (org.locationtech.geogig.api.porcelain.NothingToCommitException)9 RevCommit (org.locationtech.geogig.api.RevCommit)8 ObjectId (org.locationtech.geogig.api.ObjectId)5 RevTree (org.locationtech.geogig.api.RevTree)5 RevParse (org.locationtech.geogig.api.plumbing.RevParse)4 Node (org.locationtech.geogig.api.Node)3 NodeRef (org.locationtech.geogig.api.NodeRef)3 ConsoleReader (jline.console.ConsoleReader)2 GeoGIG (org.locationtech.geogig.api.GeoGIG)2 ProgressListener (org.locationtech.geogig.api.ProgressListener)2 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)2 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)2 AddOp (org.locationtech.geogig.api.porcelain.AddOp)2 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)2 WorkingTree (org.locationtech.geogig.repository.WorkingTree)2 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1