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());
}
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());
}
}
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();
}
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);
}
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");
}
}
Aggregations