Search in sources :

Example 1 with StagingArea

use of org.locationtech.geogig.repository.StagingArea in project GeoGig by boundlessgeo.

the class CommitOpTest method testCommitEmptyTreeOnNonEmptyRepo.

@Test
public void testCommitEmptyTreeOnNonEmptyRepo() throws Exception {
    insertAndAdd(points1, points2);
    geogig.command(CommitOp.class).call();
    // insertAndAdd(lines1, lines2);
    WorkingTree workingTree = geogig.getRepository().workingTree();
    final String emptyTreeName = "emptyTree";
    workingTree.createTypeTree(emptyTreeName, pointsType);
    {
        List<DiffEntry> unstaged = toList(workingTree.getUnstaged(null));
        assertEquals(unstaged.toString(), 1, unstaged.size());
        // assertEquals(NodeRef.ROOT, unstaged.get(0).newName());
        assertEquals(emptyTreeName, unstaged.get(0).newName());
    }
    geogig.command(AddOp.class).call();
    {
        StagingArea index = geogig.getRepository().index();
        List<DiffEntry> staged = toList(index.getStaged(null));
        assertEquals(staged.toString(), 1, staged.size());
        // assertEquals(NodeRef.ROOT, staged.get(0).newName());
        assertEquals(emptyTreeName, staged.get(0).newName());
    }
    CommitOp commitCommand = geogig.command(CommitOp.class);
    RevCommit commit = commitCommand.call();
    assertNotNull(commit);
    RevTree head = geogig.command(RevObjectParse.class).setObjectId(commit.getTreeId()).call(RevTree.class).get();
    Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setChildPath(emptyTreeName).setParent(head).call();
    assertTrue(ref.isPresent());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) WorkingTree(org.locationtech.geogig.repository.WorkingTree) NodeRef(org.locationtech.geogig.api.NodeRef) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) StagingArea(org.locationtech.geogig.repository.StagingArea) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 2 with StagingArea

use of org.locationtech.geogig.repository.StagingArea in project GeoGig by boundlessgeo.

the class StatusOp method _call.

@Override
protected StatusSummary _call() {
    WorkingTree workTree = workingTree();
    StagingArea index = index();
    StatusSummary summary = new StatusSummary();
    summary.countStaged = index.countStaged(null).count();
    summary.countUnstaged = workTree.countUnstaged(null).count();
    summary.countConflicted = index.countConflicted(null);
    if (summary.countStaged > 0) {
        summary.staged = command(DiffIndex.class).setReportTrees(true);
    }
    if (summary.countUnstaged > 0) {
        summary.unstaged = command(DiffWorkTree.class).setReportTrees(true);
    }
    if (summary.countConflicted > 0) {
        summary.conflicts = command(ConflictsReadOp.class);
    }
    return summary;
}
Also used : WorkingTree(org.locationtech.geogig.repository.WorkingTree) ConflictsReadOp(org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp) StagingArea(org.locationtech.geogig.repository.StagingArea)

Example 3 with StagingArea

use of org.locationtech.geogig.repository.StagingArea in project GeoGig by boundlessgeo.

the class OSMHistoryImport method parseGeometry.

/**
     * @param primitive
     * @param thisChangePointCache
     * @return
     */
private Geometry parseGeometry(GeoGIG geogig, Primitive primitive, Map<Long, Coordinate> thisChangePointCache) {
    if (primitive instanceof Relation) {
        return null;
    }
    if (primitive instanceof Node) {
        Optional<Point> location = ((Node) primitive).getLocation();
        return location.orNull();
    }
    final Way way = (Way) primitive;
    final ImmutableList<Long> nodes = way.getNodes();
    StagingArea index = geogig.getRepository().index();
    FeatureBuilder featureBuilder = new FeatureBuilder(NODE_REV_TYPE);
    List<Coordinate> coordinates = Lists.newArrayList(nodes.size());
    FindTreeChild findTreeChild = geogig.command(FindTreeChild.class);
    findTreeChild.setIndex(true);
    ObjectId rootTreeId = geogig.command(ResolveTreeish.class).setTreeish(Ref.HEAD).call().get();
    if (!rootTreeId.isNull()) {
        RevTree headTree = geogig.command(RevObjectParse.class).setObjectId(rootTreeId).call(RevTree.class).get();
        findTreeChild.setParent(headTree);
    }
    for (Long nodeId : nodes) {
        Coordinate coord = thisChangePointCache.get(nodeId);
        if (coord == null) {
            String fid = String.valueOf(nodeId);
            String path = NodeRef.appendChild(NODE_TYPE_NAME, fid);
            Optional<org.locationtech.geogig.api.Node> ref = index.findStaged(path);
            if (!ref.isPresent()) {
                Optional<NodeRef> nodeRef = findTreeChild.setChildPath(path).call();
                if (nodeRef.isPresent()) {
                    ref = Optional.of(nodeRef.get().getNode());
                } else {
                    ref = Optional.absent();
                }
            }
            if (ref.isPresent()) {
                org.locationtech.geogig.api.Node nodeRef = ref.get();
                RevFeature revFeature = index.getDatabase().getFeature(nodeRef.getObjectId());
                String id = NodeRef.nodeFromPath(nodeRef.getName());
                Feature feature = featureBuilder.build(id, revFeature);
                Point p = (Point) ((SimpleFeature) feature).getAttribute("location");
                if (p != null) {
                    coord = p.getCoordinate();
                    thisChangePointCache.put(Long.valueOf(nodeId), coord);
                }
            }
        }
        if (coord != null) {
            coordinates.add(coord);
        }
    }
    if (coordinates.size() < 2) {
        return null;
    }
    return GEOMF.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
}
Also used : SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder) FeatureBuilder(org.locationtech.geogig.api.FeatureBuilder) Node(org.locationtech.geogig.osm.internal.history.Node) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) RevFeature(org.locationtech.geogig.api.RevFeature) Way(org.locationtech.geogig.osm.internal.history.Way) NodeRef(org.locationtech.geogig.api.NodeRef) Relation(javax.management.relation.Relation) ResolveTreeish(org.locationtech.geogig.api.plumbing.ResolveTreeish) RevFeature(org.locationtech.geogig.api.RevFeature) ObjectId(org.locationtech.geogig.api.ObjectId) StagingArea(org.locationtech.geogig.repository.StagingArea) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) Point(com.vividsolutions.jts.geom.Point) Coordinate(com.vividsolutions.jts.geom.Coordinate) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) RevTree(org.locationtech.geogig.api.RevTree)

Aggregations

StagingArea (org.locationtech.geogig.repository.StagingArea)3 NodeRef (org.locationtech.geogig.api.NodeRef)2 RevTree (org.locationtech.geogig.api.RevTree)2 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)2 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)2 WorkingTree (org.locationtech.geogig.repository.WorkingTree)2 ImmutableList (com.google.common.collect.ImmutableList)1 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Point (com.vividsolutions.jts.geom.Point)1 List (java.util.List)1 Relation (javax.management.relation.Relation)1 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)1 Test (org.junit.Test)1 FeatureBuilder (org.locationtech.geogig.api.FeatureBuilder)1 ObjectId (org.locationtech.geogig.api.ObjectId)1 RevCommit (org.locationtech.geogig.api.RevCommit)1 RevFeature (org.locationtech.geogig.api.RevFeature)1 ResolveTreeish (org.locationtech.geogig.api.plumbing.ResolveTreeish)1 ConflictsReadOp (org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp)1 AddOp (org.locationtech.geogig.api.porcelain.AddOp)1