Search in sources :

Example 71 with NodeRef

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

the class PGExport method getFeatureType.

private SimpleFeatureType getFeatureType(String path, GeogigCLI cli) {
    checkParameter(path != null, "No path specified.");
    String refspec;
    if (path.contains(":")) {
        refspec = path;
    } else {
        refspec = "WORK_HEAD:" + path;
    }
    checkParameter(!refspec.endsWith(":"), "No path specified.");
    final GeoGIG geogig = cli.getGeogig();
    Optional<ObjectId> rootTreeId = geogig.command(ResolveTreeish.class).setTreeish(refspec.split(":")[0]).call();
    checkParameter(rootTreeId.isPresent(), "Couldn't resolve '" + refspec + "' to a treeish object");
    RevTree rootTree = geogig.getRepository().getTree(rootTreeId.get());
    Optional<NodeRef> featureTypeTree = geogig.command(FindTreeChild.class).setChildPath(refspec.split(":")[1]).setParent(rootTree).setIndex(true).call();
    checkParameter(featureTypeTree.isPresent(), "pathspec '" + refspec.split(":")[1] + "' did not match any valid path");
    Optional<RevObject> revObject = cli.getGeogig().command(RevObjectParse.class).setObjectId(featureTypeTree.get().getMetadataId()).call();
    if (revObject.isPresent() && revObject.get() instanceof RevFeatureType) {
        RevFeatureType revFeatureType = (RevFeatureType) revObject.get();
        if (revFeatureType.type() instanceof SimpleFeatureType) {
            return (SimpleFeatureType) revFeatureType.type();
        } else {
            throw new InvalidParameterException("Cannot find feature type for the specified path");
        }
    } else {
        throw new InvalidParameterException("Cannot find feature type for the specified path");
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevTree(org.locationtech.geogig.api.RevTree)

Example 72 with NodeRef

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

the class GeoJsonExport method getFeatureType.

private SimpleFeatureType getFeatureType(String path, GeogigCLI cli) {
    checkParameter(path != null, "No path specified.");
    String refspec;
    if (path.contains(":")) {
        refspec = path;
    } else {
        refspec = "WORK_HEAD:" + path;
    }
    checkParameter(!refspec.endsWith(":"), "No path specified.");
    final GeoGIG geogig = cli.getGeogig();
    Optional<ObjectId> rootTreeId = geogig.command(ResolveTreeish.class).setTreeish(refspec.split(":")[0]).call();
    checkParameter(rootTreeId.isPresent(), "Couldn't resolve '" + refspec + "' to a treeish object");
    RevTree rootTree = geogig.getRepository().getTree(rootTreeId.get());
    Optional<NodeRef> featureTypeTree = geogig.command(FindTreeChild.class).setChildPath(refspec.split(":")[1]).setParent(rootTree).setIndex(true).call();
    checkParameter(featureTypeTree.isPresent(), "pathspec '" + refspec.split(":")[1] + "' did not match any valid path");
    Optional<RevObject> revObject = cli.getGeogig().command(RevObjectParse.class).setObjectId(featureTypeTree.get().getMetadataId()).call();
    if (revObject.isPresent() && revObject.get() instanceof RevFeatureType) {
        RevFeatureType revFeatureType = (RevFeatureType) revObject.get();
        if (revFeatureType.type() instanceof SimpleFeatureType) {
            return (SimpleFeatureType) revFeatureType.type();
        } else {
            throw new InvalidParameterException("Cannot find feature type for the specified path");
        }
    } else {
        throw new InvalidParameterException("Cannot find feature type for the specified path");
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevTree(org.locationtech.geogig.api.RevTree)

Example 73 with NodeRef

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

the class WorkingTreeTest method testGetFeatureTypeNames.

@Test
public void testGetFeatureTypeNames() throws Exception {
    List<Feature> featureList = new LinkedList<Feature>();
    featureList.add(points1);
    featureList.add(points2);
    featureList.add(points3);
    workTree.insert(pointsName, featureList.iterator(), LISTENER, null, 3);
    featureList = new LinkedList<Feature>();
    featureList.add(lines1);
    featureList.add(lines2);
    featureList.add(lines3);
    workTree.insert(linesName, featureList.iterator(), LISTENER, null, 3);
    List<NodeRef> featureTypes = workTree.getFeatureTypeTrees();
    assertEquals(2, featureTypes.size());
    List<String> featureTypeNames = new LinkedList<String>();
    for (NodeRef name : featureTypes) {
        featureTypeNames.add(name.name());
    }
    assertTrue(featureTypeNames.contains(pointsName));
    assertTrue(featureTypeNames.contains(linesName));
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 74 with NodeRef

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

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

the class ResponseWriter method writeLsTreeResponse.

/**
     * Writes the response for the {@link LsTree} command to the stream.
     * 
     * @param iter the iterator of {@link NodeRefs}
     * @param verbose if true, more detailed information about each node will be provided
     * @throws XMLStreamException
     */
public void writeLsTreeResponse(Iterator<NodeRef> iter, boolean verbose) throws XMLStreamException {
    while (iter.hasNext()) {
        NodeRef node = iter.next();
        out.writeStartElement("node");
        writeElement("path", node.path());
        if (verbose) {
            writeElement("metadataId", node.getMetadataId().toString());
            writeElement("type", node.getType().toString().toLowerCase());
            writeElement("objectId", node.objectId().toString());
        }
        out.writeEndElement();
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef)

Aggregations

NodeRef (org.locationtech.geogig.api.NodeRef)161 ObjectId (org.locationtech.geogig.api.ObjectId)91 RevTree (org.locationtech.geogig.api.RevTree)67 Test (org.junit.Test)62 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)40 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)27 RevFeature (org.locationtech.geogig.api.RevFeature)25 Node (org.locationtech.geogig.api.Node)24 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)24 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)23 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)22 RevObject (org.locationtech.geogig.api.RevObject)21 RevCommit (org.locationtech.geogig.api.RevCommit)19 Map (java.util.Map)15 SimpleFeature (org.opengis.feature.simple.SimpleFeature)15 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)14 Feature (org.opengis.feature.Feature)13 Optional (com.google.common.base.Optional)12 GeoGIG (org.locationtech.geogig.api.GeoGIG)11 LsTreeOp (org.locationtech.geogig.api.plumbing.LsTreeOp)11