Search in sources :

Example 11 with CommandResponse

use of org.locationtech.geogig.web.api.CommandResponse 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
    }
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) GeogigTransaction(org.locationtech.geogig.api.GeogigTransaction) Optional(com.google.common.base.Optional) RebaseConflictsException(org.locationtech.geogig.api.porcelain.RebaseConflictsException) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) MergeScenarioReport(org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport) MergeConflictsException(org.locationtech.geogig.api.porcelain.MergeConflictsException) RebaseConflictsException(org.locationtech.geogig.api.porcelain.RebaseConflictsException) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) MergeConflictsException(org.locationtech.geogig.api.porcelain.MergeConflictsException) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) TransactionEnd(org.locationtech.geogig.api.plumbing.TransactionEnd) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 12 with CommandResponse

use of org.locationtech.geogig.web.api.CommandResponse 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."));
        }
    }
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) FetchOp(org.locationtech.geogig.api.porcelain.FetchOp) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) TransferSummary(org.locationtech.geogig.api.porcelain.TransferSummary) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException)

Example 13 with CommandResponse

use of org.locationtech.geogig.web.api.CommandResponse 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();
            }
        });
    }
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) Ref(org.locationtech.geogig.api.Ref) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) BranchListOp(org.locationtech.geogig.api.porcelain.BranchListOp) CommandResponse(org.locationtech.geogig.web.api.CommandResponse)

Example 14 with CommandResponse

use of org.locationtech.geogig.web.api.CommandResponse 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;
    }
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) RevTag(org.locationtech.geogig.api.RevTag) RevObject(org.locationtech.geogig.api.RevObject) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) RevFeature(org.locationtech.geogig.api.RevFeature) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 15 with CommandResponse

use of org.locationtech.geogig.web.api.CommandResponse in project GeoGig by boundlessgeo.

the class AddWebOp 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, add requires a transaction to preserve the stability of the repository.");
    }
    final Context geogig = this.getCommandLocator(context);
    AddOp command = geogig.command(AddOp.class);
    if (path != null) {
        command.addPattern(path);
    }
    command.call();
    context.setResponseContent(new CommandResponse() {

        @Override
        public void write(ResponseWriter out) throws Exception {
            out.start();
            out.writeElement("Add", "Success");
            out.finish();
        }
    });
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) AddOp(org.locationtech.geogig.api.porcelain.AddOp) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException)

Aggregations

CommandResponse (org.locationtech.geogig.web.api.CommandResponse)32 ResponseWriter (org.locationtech.geogig.web.api.ResponseWriter)32 Context (org.locationtech.geogig.api.Context)24 CommandContext (org.locationtech.geogig.web.api.CommandContext)24 CommandSpecException (org.locationtech.geogig.web.api.CommandSpecException)23 ObjectId (org.locationtech.geogig.api.ObjectId)11 RevCommit (org.locationtech.geogig.api.RevCommit)9 Ref (org.locationtech.geogig.api.Ref)8 NodeRef (org.locationtech.geogig.api.NodeRef)6 Optional (com.google.common.base.Optional)5 IOException (java.io.IOException)5 Remote (org.locationtech.geogig.api.Remote)5 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)5 RemoteException (org.locationtech.geogig.api.porcelain.RemoteException)5 SymRef (org.locationtech.geogig.api.SymRef)4 MergeScenarioReport (org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport)4 GeogigTransaction (org.locationtech.geogig.api.GeogigTransaction)3 RevFeature (org.locationtech.geogig.api.RevFeature)3 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)3 RevTree (org.locationtech.geogig.api.RevTree)3