use of org.locationtech.geogig.web.api.CommandResponse in project GeoGig by boundlessgeo.
the class BlameWebOp method run.
/**
* Runs the command and builds the appropriate response.
*
* @param context - the context to use for this command
*/
@Override
public void run(CommandContext context) {
final Context geogig = this.getCommandLocator(context);
Optional<ObjectId> commit = Optional.absent();
if (branchOrCommit != null) {
commit = geogig.command(RevParse.class).setRefSpec(branchOrCommit).call();
if (!commit.isPresent()) {
throw new CommandSpecException("Could not resolve branch or commit");
}
}
try {
final BlameReport report = geogig.command(BlameOp.class).setPath(path).setCommit(commit.orNull()).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
try {
out.writeBlameReport(report);
} catch (XMLStreamException e) {
throw new CommandSpecException("Error writing stream.");
}
out.finish();
}
});
} catch (BlameException e) {
switch(e.statusCode) {
case PATH_NOT_FEATURE:
throw new CommandSpecException("The supplied path does not resolve to a feature");
case FEATURE_NOT_FOUND:
throw new CommandSpecException("The supplied path does not exist");
}
}
}
use of org.locationtech.geogig.web.api.CommandResponse in project GeoGig by boundlessgeo.
the class CheckoutWebOp method run.
/**
* Runs the command and builds the appropriate response
*
* @throws CommandSpecException
*/
@Override
public void run(CommandContext context) {
if (this.getTransactionId() == null) {
throw new CommandSpecException("No transaction was specified, checkout requires a transaction to preserve the stability of the repository.");
}
final Context geogig = this.getCommandLocator(context);
CheckoutOp command = geogig.command(CheckoutOp.class);
if (branchOrCommit != null) {
Optional<Ref> head = geogig.command(RefParse.class).setName(Ref.HEAD).call();
if (!head.isPresent()) {
throw new CommandSpecException("Repository has no HEAD, can't merge.");
}
final String target = ((SymRef) head.get()).getTarget();
command.setSource(branchOrCommit).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeElement("OldTarget", target);
out.writeElement("NewTarget", branchOrCommit);
out.finish();
}
});
} else if (path != null) {
command.addPath(path);
if (ours && !theirs) {
command.setOurs(ours);
} else if (theirs && !ours) {
command.setTheirs(theirs);
} else {
throw new CommandSpecException("Please specify either ours or theirs to update the feature path specified.");
}
command.call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeElement("Path", path);
out.writeElement("Strategy", ours ? "ours" : "theirs");
out.finish();
}
});
} else {
throw new CommandSpecException("No branch or commit specified for checkout.");
}
}
use of org.locationtech.geogig.web.api.CommandResponse in project GeoGig by boundlessgeo.
the class Commit method run.
/**
* Runs the command and builds the appropriate response
*
* @param context - the context to use for this command
* @throws CommandSpecException
*/
@Override
public void run(CommandContext context) {
if (this.getTransactionId() == null) {
throw new CommandSpecException("No transaction was specified, commit requires a transaction to preserve the stability of the repository.");
}
final Context geogig = this.getCommandLocator(context);
RevCommit commit;
try {
commit = geogig.command(CommitOp.class).setAuthor(authorName.orNull(), authorEmail.orNull()).setMessage(message).setAllowEmpty(true).setAll(all).call();
assert commit != null;
} catch (NothingToCommitException noChanges) {
context.setResponseContent(CommandResponse.warning("Nothing to commit"));
commit = null;
} catch (IllegalStateException e) {
context.setResponseContent(CommandResponse.warning(e.getMessage()));
commit = null;
}
if (commit != null) {
final RevCommit commitToWrite = commit;
final ObjectId parentId = commit.parentN(0).or(ObjectId.NULL);
final Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(parentId).setNewVersion(commit.getId()).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeCommitResponse(commitToWrite, diff);
out.finish();
}
});
}
}
use of org.locationtech.geogig.web.api.CommandResponse in project GeoGig by boundlessgeo.
the class RefParseWeb method run.
/**
* Runs the command and builds the appropriate response
*
* @param context - the context to use for this command
*
* @throws CommandSpecException
*/
@Override
public void run(CommandContext context) {
if (refSpec == null) {
throw new CommandSpecException("No name was given.");
}
final Context geogig = this.getCommandLocator(context);
Optional<Ref> ref;
try {
ref = geogig.command(RefParse.class).setName(refSpec).call();
} catch (Exception e) {
context.setResponseContent(CommandResponse.error("Aborting UpdateRef: " + e.getMessage()));
return;
}
if (ref.isPresent()) {
final Ref newRef = ref.get();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeRefParseResponse(newRef);
out.finish();
}
});
} else {
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeEmptyRefResponse();
out.finish();
}
});
}
}
use of org.locationtech.geogig.web.api.CommandResponse in project GeoGig by boundlessgeo.
the class RemoteWebOp method remotePing.
private void remotePing(CommandContext context, final Context geogig) {
Optional<Remote> remote = geogig.command(RemoteResolve.class).setName(remoteName).call();
final boolean remotePingResponse;
if (remote.isPresent()) {
Optional<IRemoteRepo> remoteRepo = RemoteUtils.newRemote(GlobalContextBuilder.builder.build(), remote.get(), null, null);
Ref ref = null;
if (remoteRepo.isPresent()) {
try {
remoteRepo.get().open();
ref = remoteRepo.get().headRef();
remoteRepo.get().close();
} catch (IOException e) {
// Do nothing, we will write the response later.
}
}
remotePingResponse = ref != null;
} else {
remotePingResponse = false;
}
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeRemotePingResponse(remotePingResponse);
out.finish();
}
});
}
Aggregations