Search in sources :

Example 6 with CommandSpecException

use of org.locationtech.geogig.web.api.CommandSpecException 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 7 with CommandSpecException

use of org.locationtech.geogig.web.api.CommandSpecException 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 8 with CommandSpecException

use of org.locationtech.geogig.web.api.CommandSpecException 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 9 with CommandSpecException

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

the class Log method writeCSV.

private void writeCSV(GeoGIG geogig, Writer out, Iterator<RevCommit> log) throws Exception {
    String response = "ChangeType,FeatureId,CommitId,Parent CommitIds,Author Name,Author Email,Author Commit Time,Committer Name,Committer Email,Committer Commit Time,Commit Message";
    out.write(response);
    response = "";
    String path = paths.get(0);
    // This is the feature type object
    Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setChildPath(path).setParent(geogig.getRepository().workingTree().getTree()).call();
    Optional<RevObject> type = Optional.absent();
    if (ref.isPresent()) {
        type = geogig.command(RevObjectParse.class).setRefSpec(ref.get().getMetadataId().toString()).call();
    } else {
        throw new CommandSpecException("Couldn't resolve the given path.");
    }
    if (type.isPresent() && type.get() instanceof RevFeatureType) {
        RevFeatureType featureType = (RevFeatureType) type.get();
        Collection<PropertyDescriptor> attribs = featureType.type().getDescriptors();
        int attributeLength = attribs.size();
        for (PropertyDescriptor attrib : attribs) {
            response += "," + escapeCsv(attrib.getName().toString());
        }
        response += '\n';
        out.write(response);
        response = "";
        RevCommit commit = null;
        while (log.hasNext()) {
            commit = log.next();
            String parentId = commit.getParentIds().size() >= 1 ? commit.getParentIds().get(0).toString() : ObjectId.NULL.toString();
            Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(parentId).setNewVersion(commit.getId().toString()).setFilter(path).call();
            while (diff.hasNext()) {
                DiffEntry entry = diff.next();
                response += entry.changeType().toString() + ",";
                String fid = "";
                if (entry.newPath() != null) {
                    if (entry.oldPath() != null) {
                        fid = entry.oldPath() + " -> " + entry.newPath();
                    } else {
                        fid = entry.newPath();
                    }
                } else if (entry.oldPath() != null) {
                    fid = entry.oldPath();
                }
                response += fid + ",";
                response += commit.getId().toString() + ",";
                response += parentId;
                if (commit.getParentIds().size() > 1) {
                    for (int index = 1; index < commit.getParentIds().size(); index++) {
                        response += " " + commit.getParentIds().get(index).toString();
                    }
                }
                response += ",";
                if (commit.getAuthor().getName().isPresent()) {
                    response += escapeCsv(commit.getAuthor().getName().get());
                }
                response += ",";
                if (commit.getAuthor().getEmail().isPresent()) {
                    response += escapeCsv(commit.getAuthor().getEmail().get());
                }
                response += "," + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z").format(new Date(commit.getAuthor().getTimestamp())) + ",";
                if (commit.getCommitter().getName().isPresent()) {
                    response += escapeCsv(commit.getCommitter().getName().get());
                }
                response += ",";
                if (commit.getCommitter().getEmail().isPresent()) {
                    response += escapeCsv(commit.getCommitter().getEmail().get());
                }
                response += "," + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z").format(new Date(commit.getCommitter().getTimestamp())) + ",";
                String message = escapeCsv(commit.getMessage());
                response += message;
                if (entry.newObjectId() == ObjectId.NULL) {
                    // Feature was removed so we need to fill out blank attribute values
                    for (int index = 0; index < attributeLength; index++) {
                        response += ",";
                    }
                } else {
                    // Feature was added or modified so we need to write out the
                    // attribute
                    // values from the feature
                    Optional<RevObject> feature = geogig.command(RevObjectParse.class).setObjectId(entry.newObjectId()).call();
                    RevFeature revFeature = (RevFeature) feature.get();
                    List<Optional<Object>> values = revFeature.getValues();
                    for (int index = 0; index < values.size(); index++) {
                        Optional<Object> value = values.get(index);
                        PropertyDescriptor attrib = (PropertyDescriptor) attribs.toArray()[index];
                        String stringValue = "";
                        if (value.isPresent()) {
                            FieldType attributeType = FieldType.forBinding(attrib.getType().getBinding());
                            switch(attributeType) {
                                case DATE:
                                    stringValue = new SimpleDateFormat("MM/dd/yyyy z").format((java.sql.Date) value.get());
                                    break;
                                case DATETIME:
                                    stringValue = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z").format((Date) value.get());
                                    break;
                                case TIME:
                                    stringValue = new SimpleDateFormat("HH:mm:ss z").format((Time) value.get());
                                    break;
                                case TIMESTAMP:
                                    stringValue = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z").format((Timestamp) value.get());
                                    break;
                                default:
                                    stringValue = escapeCsv(value.get().toString());
                            }
                            response += "," + stringValue;
                        } else {
                            response += ",";
                        }
                    }
                }
                response += '\n';
                out.write(response);
                response = "";
            }
        }
    } else {
        // Couldn't resolve FeatureType
        throw new CommandSpecException("Couldn't resolve the given path to a feature type.");
    }
}
Also used : Time(java.sql.Time) Timestamp(java.sql.Timestamp) ParseTimestamp(org.locationtech.geogig.api.plumbing.ParseTimestamp) NodeRef(org.locationtech.geogig.api.NodeRef) RevFeature(org.locationtech.geogig.api.RevFeature) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevCommit(org.locationtech.geogig.api.RevCommit) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) PropertyDescriptor(org.opengis.feature.type.PropertyDescriptor) Optional(com.google.common.base.Optional) RevObject(org.locationtech.geogig.api.RevObject) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) Date(java.util.Date) FieldType(org.locationtech.geogig.storage.FieldType) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevObject(org.locationtech.geogig.api.RevObject) SimpleDateFormat(java.text.SimpleDateFormat)

Example 10 with CommandSpecException

use of org.locationtech.geogig.web.api.CommandSpecException 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)

Aggregations

CommandSpecException (org.locationtech.geogig.web.api.CommandSpecException)25 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)21 ResponseWriter (org.locationtech.geogig.web.api.ResponseWriter)21 Context (org.locationtech.geogig.api.Context)16 CommandContext (org.locationtech.geogig.web.api.CommandContext)15 ObjectId (org.locationtech.geogig.api.ObjectId)9 RevCommit (org.locationtech.geogig.api.RevCommit)9 Optional (com.google.common.base.Optional)6 NodeRef (org.locationtech.geogig.api.NodeRef)5 Ref (org.locationtech.geogig.api.Ref)5 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)5 IOException (java.io.IOException)4 RevFeature (org.locationtech.geogig.api.RevFeature)4 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)4 RevObject (org.locationtech.geogig.api.RevObject)4 RevTree (org.locationtech.geogig.api.RevTree)4 GeoGIG (org.locationtech.geogig.api.GeoGIG)3 GeogigTransaction (org.locationtech.geogig.api.GeogigTransaction)3 Remote (org.locationtech.geogig.api.Remote)3 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)3