Package org.locationtech.geogig.web.api

Examples of org.locationtech.geogig.web.api.CommandSpecException


        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.");
        }
    }
View Full Code Here


        if (object.isPresent()) {
            RevTree tree = (RevTree) object.get();
            return geogig.command(FindTreeChild.class).setParent(tree).setChildPath(path).call();
        } else {
            throw new CommandSpecException("Couldn't resolve treeId");
        }
    }
View Full Code Here

     * @throws CommandSpecException
     */
    @Override
    public void run(CommandContext context) {
        if (path == null || path.trim().isEmpty()) {
            throw new CommandSpecException("No path for feature name specifed");
        }

        final Context geogig = this.getCommandLocator(context);
        ObjectId newId = geogig.command(ResolveTreeish.class).setTreeish(newTreeish).call().get();

        ObjectId oldId = geogig.command(ResolveTreeish.class).setTreeish(oldTreeish).call().get();

        RevFeature newFeature = null;
        RevFeatureType newFeatureType = null;

        RevFeature oldFeature = null;
        RevFeatureType oldFeatureType = null;

        final Map<PropertyDescriptor, AttributeDiff> diffs;

        Optional<NodeRef> ref = parseID(newId, geogig);

        Optional<RevObject> object;

        // need these to determine if the feature was added or removed so I can build the diffs
        // myself until the FeatureDiff supports null values
        boolean removed = false;
        boolean added = false;

        if (ref.isPresent()) {
            object = geogig.command(RevObjectParse.class).setObjectId(ref.get().getMetadataId())
                    .call();
            if (object.isPresent() && object.get() instanceof RevFeatureType) {
                newFeatureType = (RevFeatureType) object.get();
            } else {
                throw new CommandSpecException("Couldn't resolve newCommit's featureType");
            }
            object = geogig.command(RevObjectParse.class).setObjectId(ref.get().objectId()).call();
            if (object.isPresent() && object.get() instanceof RevFeature) {
                newFeature = (RevFeature) object.get();
            } else {
                throw new CommandSpecException("Couldn't resolve newCommit's feature");
            }
        } else {
            removed = true;
        }

        if (!oldId.equals(ObjectId.NULL)) {
            ref = parseID(oldId, geogig);

            if (ref.isPresent()) {
                object = geogig.command(RevObjectParse.class)
                        .setObjectId(ref.get().getMetadataId()).call();
                if (object.isPresent() && object.get() instanceof RevFeatureType) {
                    oldFeatureType = (RevFeatureType) object.get();
                } else {
                    throw new CommandSpecException("Couldn't resolve oldCommit's featureType");
                }
                object = geogig.command(RevObjectParse.class).setObjectId(ref.get().objectId())
                        .call();
                if (object.isPresent() && object.get() instanceof RevFeature) {
                    oldFeature = (RevFeature) object.get();
                } else {
                    throw new CommandSpecException("Couldn't resolve oldCommit's feature");
                }
            } else {
                added = true;
            }
        } else {
View Full Code Here

     * @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)
View Full Code Here

     * @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;

View Full Code Here

TOP

Related Classes of org.locationtech.geogig.web.api.CommandSpecException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.