Search in sources :

Example 6 with CommandContext

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

the class RebuildGraphWebOp 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);
    final ImmutableList<ObjectId> updatedObjects = geogig.command(RebuildGraphOp.class).call();
    context.setResponseContent(new CommandResponse() {

        @Override
        public void write(ResponseWriter out) throws Exception {
            out.start();
            out.writeRebuildGraphResponse(updatedObjects, quiet);
            out.finish();
        }
    });
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) RebuildGraphOp(org.locationtech.geogig.api.plumbing.RebuildGraphOp) ObjectId(org.locationtech.geogig.api.ObjectId) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) CommandResponse(org.locationtech.geogig.web.api.CommandResponse)

Example 7 with CommandContext

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

the class Log method run.

/**
     * Runs the command and builds the appropriate response
     * 
     * @param context - the context to use for this command
     * 
     * @throws IllegalArgumentException
     */
@Override
public void run(final CommandContext context) {
    final Context geogig = this.getCommandLocator(context);
    LogOp op = geogig.command(LogOp.class).setFirstParentOnly(firstParentOnly);
    if (skip != null) {
        op.setSkip(skip.intValue());
    }
    if (limit != null) {
        op.setLimit(limit.intValue());
    }
    if (this.sinceTime != null || this.untilTime != null) {
        Date since = new Date(0);
        Date until = new Date();
        if (this.sinceTime != null) {
            since = new Date(geogig.command(ParseTimestamp.class).setString(this.sinceTime).call());
        }
        if (this.untilTime != null) {
            until = new Date(geogig.command(ParseTimestamp.class).setString(this.untilTime).call());
        }
        op.setTimeRange(new Range<Date>(Date.class, since, until));
    }
    if (this.since != null) {
        Optional<ObjectId> since;
        since = geogig.command(RevParse.class).setRefSpec(this.since).call();
        Preconditions.checkArgument(since.isPresent(), "Object not found '%s'", this.since);
        op.setSince(since.get());
    }
    if (this.until != null) {
        Optional<ObjectId> until;
        until = geogig.command(RevParse.class).setRefSpec(this.until).call();
        Preconditions.checkArgument(until.isPresent(), "Object not found '%s'", this.until);
        op.setUntil(until.get());
    }
    if (paths != null && !paths.isEmpty()) {
        for (String path : paths) {
            op.addPath(path);
        }
    }
    final Iterator<RevCommit> log = op.call();
    Iterators.advance(log, page * elementsPerPage);
    if (countChanges) {
        final String pathFilter;
        if (paths != null && !paths.isEmpty()) {
            pathFilter = paths.get(0);
        } else {
            pathFilter = null;
        }
        Function<RevCommit, CommitWithChangeCounts> changeCountFunctor = new Function<RevCommit, CommitWithChangeCounts>() {

            @Override
            public CommitWithChangeCounts apply(RevCommit input) {
                ObjectId parent = ObjectId.NULL;
                if (input.getParentIds().size() > 0) {
                    parent = input.getParentIds().get(0);
                }
                int added = 0;
                int modified = 0;
                int removed = 0;
                // If it's a shallow clone, the commit may not exist
                if (parent.equals(ObjectId.NULL) || geogig.stagingDatabase().exists(parent)) {
                    final Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(parent).setNewVersion(input.getId()).setFilter(pathFilter).call();
                    while (diff.hasNext()) {
                        DiffEntry entry = diff.next();
                        if (entry.changeType() == DiffEntry.ChangeType.ADDED) {
                            added++;
                        } else if (entry.changeType() == DiffEntry.ChangeType.MODIFIED) {
                            modified++;
                        } else {
                            removed++;
                        }
                    }
                }
                return new CommitWithChangeCounts(input, added, modified, removed);
            }
        };
        final Iterator<CommitWithChangeCounts> summarizedLog = Iterators.transform(log, changeCountFunctor);
        context.setResponseContent(new CommandResponse() {

            @Override
            public void write(ResponseWriter out) throws Exception {
                out.start();
                out.writeCommitsWithChangeCounts(summarizedLog, elementsPerPage);
                out.finish();
            }
        });
    } else if (summary) {
        if (paths != null && paths.size() > 0) {
            context.setResponseContent(new StreamResponse() {

                @Override
                public void write(Writer out) throws Exception {
                    writeCSV(context.getGeoGIG(), out, log);
                }
            });
        } else {
            throw new CommandSpecException("You must specify a feature type path when getting a summary.");
        }
    } else {
        final boolean rangeLog = returnRange;
        context.setResponseContent(new CommandResponse() {

            @Override
            public void write(ResponseWriter out) throws Exception {
                out.start();
                out.writeCommits(log, elementsPerPage, rangeLog);
                out.finish();
            }
        });
    }
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) ObjectId(org.locationtech.geogig.api.ObjectId) LogOp(org.locationtech.geogig.api.porcelain.LogOp) StreamResponse(org.locationtech.geogig.web.api.StreamResponse) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) Date(java.util.Date) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) Function(com.google.common.base.Function) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) RevParse(org.locationtech.geogig.api.plumbing.RevParse) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) Writer(java.io.Writer) RevCommit(org.locationtech.geogig.api.RevCommit) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 8 with CommandContext

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();
        }
    });
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) 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) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 9 with CommandContext

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
    }
}
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 10 with CommandContext

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."));
        }
    }
}
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)

Aggregations

Context (org.locationtech.geogig.api.Context)24 CommandContext (org.locationtech.geogig.web.api.CommandContext)24 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)24 ResponseWriter (org.locationtech.geogig.web.api.ResponseWriter)24 CommandSpecException (org.locationtech.geogig.web.api.CommandSpecException)15 ObjectId (org.locationtech.geogig.api.ObjectId)9 RevCommit (org.locationtech.geogig.api.RevCommit)7 NodeRef (org.locationtech.geogig.api.NodeRef)6 Ref (org.locationtech.geogig.api.Ref)6 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)5 Optional (com.google.common.base.Optional)4 SymRef (org.locationtech.geogig.api.SymRef)4 RevFeature (org.locationtech.geogig.api.RevFeature)3 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)3 RevTree (org.locationtech.geogig.api.RevTree)3 RefParse (org.locationtech.geogig.api.plumbing.RefParse)3 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)3 RevParse (org.locationtech.geogig.api.plumbing.RevParse)3 MergeScenarioReport (org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport)3 Geometry (com.vividsolutions.jts.geom.Geometry)2