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);
}
}
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;
}
Aggregations