use of org.locationtech.geogig.web.api.CommandContext in project GeoGig by boundlessgeo.
the class Diff 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 (oldRefSpec == null || oldRefSpec.trim().isEmpty()) {
throw new CommandSpecException("No old ref spec");
}
final Context geogig = this.getCommandLocator(context);
final Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(oldRefSpec).setNewVersion(newRefSpec).setFilter(pathFilter).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
if (showGeometryChanges) {
out.writeGeometryChanges(geogig, diff, page, elementsPerPage);
} else {
out.writeDiffEntries("diff", page * elementsPerPage, elementsPerPage, diff);
}
out.finish();
}
});
}
use of org.locationtech.geogig.web.api.CommandContext in project GeoGig by boundlessgeo.
the class EndTransaction 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("There isn't a transaction to end.");
}
final Context transaction = this.getCommandLocator(context);
TransactionEnd endTransaction = context.getGeoGIG().command(TransactionEnd.class);
try {
final boolean closed = endTransaction.setCancel(cancel).setTransaction((GeogigTransaction) transaction).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
if (closed) {
out.writeTransactionId(null);
} else {
out.writeTransactionId(getTransactionId());
}
out.finish();
}
});
} catch (MergeConflictsException m) {
final RevCommit ours = context.getGeoGIG().getRepository().getCommit(m.getOurs());
final RevCommit theirs = context.getGeoGIG().getRepository().getCommit(m.getTheirs());
final Optional<ObjectId> ancestor = transaction.command(FindCommonAncestor.class).setLeft(ours).setRight(theirs).call();
context.setResponseContent(new CommandResponse() {
final MergeScenarioReport report = transaction.command(ReportMergeScenarioOp.class).setMergeIntoCommit(ours).setToMergeCommit(theirs).call();
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
Optional<RevCommit> mergeCommit = Optional.absent();
out.writeMergeResponse(mergeCommit, report, transaction, ours.getId(), theirs.getId(), ancestor.get());
out.finish();
}
});
} catch (RebaseConflictsException r) {
// TODO: Handle rebase exception
}
}
use of org.locationtech.geogig.web.api.CommandContext in project GeoGig by boundlessgeo.
the class FetchWebOp 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) {
final Context geogig = this.getCommandLocator(context);
FetchOp command = geogig.command(FetchOp.class);
command.addRemote(remote);
try {
final TransferSummary result = command.setAll(fetchAll).setPrune(prune).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeFetchResponse(result);
out.finish();
}
});
} catch (SynchronizationException e) {
switch(e.statusCode) {
case HISTORY_TOO_SHALLOW:
default:
context.setResponseContent(CommandResponse.error("Unable to fetch, the remote history is shallow."));
}
}
}
use of org.locationtech.geogig.web.api.CommandContext in project GeoGig by boundlessgeo.
the class BranchWebOp 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) {
if (list) {
final Context geogig = this.getCommandLocator(context);
final List<Ref> localBranches = geogig.command(BranchListOp.class).call();
final List<Ref> remoteBranches;
if (remotes) {
remoteBranches = geogig.command(BranchListOp.class).setLocal(false).setRemotes(remotes).call();
} else {
remoteBranches = Lists.newLinkedList();
}
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeBranchListResponse(localBranches, remoteBranches);
out.finish();
}
});
}
}
use of org.locationtech.geogig.web.api.CommandContext in project GeoGig by boundlessgeo.
the class CatWebOp 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) {
Preconditions.checkArgument(object != null && !object.equals(ObjectId.NULL));
final Context geogig = this.getCommandLocator(context);
Preconditions.checkState(geogig.stagingDatabase().exists(object));
final RevObject revObject = geogig.stagingDatabase().get(object);
switch(revObject.getType()) {
case COMMIT:
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeCommit((RevCommit) revObject, "commit", null, null, null);
out.finish();
}
});
break;
case TREE:
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeTree((RevTree) revObject, "tree");
out.finish();
}
});
break;
case FEATURE:
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeFeature((RevFeature) revObject, "feature");
out.finish();
}
});
break;
case FEATURETYPE:
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeFeatureType((RevFeatureType) revObject, "featuretype");
out.finish();
}
});
break;
case TAG:
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeTag((RevTag) revObject, "tag");
out.finish();
}
});
break;
}
}
Aggregations