Search in sources :

Example 66 with NodeRef

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

the class ImportOpTest method testAlter.

@Test
public void testAlter() throws Exception {
    ImportOp importOp = geogig.command(ImportOp.class);
    importOp.setDataStore(TestHelper.createTestFactory().createDataStore(null));
    importOp.setTable("table1");
    importOp.call();
    importOp.setTable("table2");
    importOp.setDestinationPath("table1");
    importOp.setAlter(true);
    importOp.call();
    Iterator<NodeRef> features = geogig.command(LsTreeOp.class).setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES).call();
    ArrayList<NodeRef> list = Lists.newArrayList(features);
    assertEquals(3, list.size());
    Optional<RevFeature> feature = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:table1/feature1").call(RevFeature.class);
    assertTrue(feature.isPresent());
    ImmutableList<Optional<Object>> values = feature.get().getValues();
    assertEquals(2, values.size());
    assertTrue(values.get(0).isPresent());
    assertFalse(values.get(1).isPresent());
    TreeSet<ObjectId> set = Sets.newTreeSet();
    for (NodeRef node : list) {
        set.add(node.getMetadataId());
    }
    assertEquals(1, set.size());
    Optional<RevFeatureType> featureType = geogig.command(RevObjectParse.class).setObjectId(set.iterator().next()).call(RevFeatureType.class);
    assertTrue(featureType.isPresent());
    assertEquals("table1", featureType.get().getName().getLocalPart());
    assertEquals("name", featureType.get().sortedDescriptors().get(1).getName().getLocalPart());
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) Optional(com.google.common.base.Optional) ObjectId(org.locationtech.geogig.api.ObjectId) RevFeature(org.locationtech.geogig.api.RevFeature) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) Test(org.junit.Test)

Example 67 with NodeRef

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

the class ImportOpTest method testImportAllWithDifferentFeatureTypesAndDestPath.

@Test
public void testImportAllWithDifferentFeatureTypesAndDestPath() throws Exception {
    ImportOp importOp = geogig.command(ImportOp.class);
    importOp.setDataStore(TestHelper.createTestFactory().createDataStore(null));
    importOp.setAll(true);
    importOp.setDestinationPath("dest");
    importOp.setAdaptToDefaultFeatureType(false);
    importOp.call();
    Iterator<NodeRef> features = geogig.command(LsTreeOp.class).setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES).call();
    ArrayList<NodeRef> list = Lists.newArrayList(features);
    assertEquals(4, list.size());
    TreeSet<ObjectId> set = Sets.newTreeSet();
    for (NodeRef node : list) {
        set.add(node.getMetadataId());
    }
    assertEquals(4, set.size());
    for (ObjectId metadataId : set) {
        Optional<RevFeatureType> ft = geogig.command(RevObjectParse.class).setObjectId(metadataId).call(RevFeatureType.class);
        assertTrue(ft.isPresent());
        assertEquals("dest", ft.get().getName().getLocalPart());
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) Test(org.junit.Test)

Example 68 with NodeRef

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

the class RemoveOp method _call.

/**
     * @see java.util.concurrent.Callable#call()
     */
protected WorkingTree _call() {
    // Check that all paths are valid and exist
    for (String pathToRemove : pathsToRemove) {
        NodeRef.checkValidPath(pathToRemove);
        Optional<NodeRef> node;
        node = command(FindTreeChild.class).setParent(workingTree().getTree()).setIndex(true).setChildPath(pathToRemove).call();
        List<Conflict> conflicts = index().getConflicted(pathToRemove);
        if (conflicts.size() > 0) {
            for (Conflict conflict : conflicts) {
                stagingDatabase().removeConflict(null, conflict.getPath());
            }
        } else {
            Preconditions.checkArgument(node.isPresent(), "pathspec '%s' did not match any feature or tree", pathToRemove);
        }
    }
    // separate trees from features an delete accordingly
    for (String pathToRemove : pathsToRemove) {
        Optional<NodeRef> node = command(FindTreeChild.class).setParent(workingTree().getTree()).setIndex(true).setChildPath(pathToRemove).call();
        if (!node.isPresent()) {
            continue;
        }
        switch(node.get().getType()) {
            case TREE:
                workingTree().delete(pathToRemove);
                break;
            case FEATURE:
                String parentPath = NodeRef.parentPath(pathToRemove);
                String name = node.get().name();
                workingTree().delete(parentPath, name);
                break;
            default:
                break;
        }
        final long numChanges = workingTree().countUnstaged(pathToRemove).count();
        Iterator<DiffEntry> unstaged = workingTree().getUnstaged(pathToRemove);
        index().stage(getProgressListener(), unstaged, numChanges);
    }
    return workingTree();
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) CanRunDuringConflict(org.locationtech.geogig.di.CanRunDuringConflict) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 69 with NodeRef

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

the class TreeDifferenceTest method tree.

private NodeRef tree(String path, ObjectId treeId, @Nullable ObjectId metadataId) {
    String parentPath = NodeRef.parentPath(path);
    String name = NodeRef.nodeFromPath(path);
    Node node = treeNode(name, treeId, metadataId);
    return new NodeRef(node, parentPath, ObjectId.NULL);
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) Node(org.locationtech.geogig.api.Node)

Example 70 with NodeRef

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

the class ShpExport 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)

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