use of org.locationtech.geogig.api.plumbing.LsTreeOp.Strategy in project GeoGig by boundlessgeo.
the class LsTree method runInternal.
@Override
public void runInternal(final GeogigCLI cli) throws IOException {
String ref;
if (refList.isEmpty()) {
ref = null;
} else {
ref = refList.get(0);
}
Strategy lsStrategy = Strategy.CHILDREN;
if (recursive) {
if (includeTrees) {
lsStrategy = Strategy.DEPTHFIRST;
} else if (onlyTrees) {
lsStrategy = Strategy.DEPTHFIRST_ONLY_TREES;
} else {
lsStrategy = Strategy.DEPTHFIRST_ONLY_FEATURES;
}
} else {
if (onlyTrees) {
lsStrategy = Strategy.TREES_ONLY;
}
}
Iterator<NodeRef> iter = cli.getGeogig().command(LsTreeOp.class).setReference(ref).setStrategy(lsStrategy).call();
final ConsoleReader console = cli.getConsole();
Function<NodeRef, CharSequence> printFunctor = new Function<NodeRef, CharSequence>() {
@Override
public CharSequence apply(NodeRef input) {
StringBuilder sb = new StringBuilder();
if (!verbose) {
sb.append(input.path());
} else {
Envelope env = new Envelope();
input.getNode().expand(env);
StringBuilder sbenv = new StringBuilder();
sbenv.append(Double.toString(env.getMinX())).append(";").append(Double.toString(env.getMaxX())).append(";").append(Double.toString(env.getMinY())).append(";").append(Double.toString(env.getMaxY()));
sb.append(input.getMetadataId().toString()).append(' ').append(input.getType().toString().toLowerCase()).append(' ').append(input.objectId().toString()).append(' ').append(input.path()).append(' ').append(sbenv);
if (input.getType().equals(TYPE.TREE)) {
RevTree tree = cli.getGeogig().command(RevObjectParse.class).setObjectId(input.objectId()).call(RevTree.class).get();
sb.append(' ').append(tree.size()).append(' ').append(tree.numTrees());
}
}
return sb;
}
};
Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);
while (lines.hasNext()) {
console.println(lines.next());
}
console.flush();
}
use of org.locationtech.geogig.api.plumbing.LsTreeOp.Strategy in project GeoGig by boundlessgeo.
the class Ls method runInternal.
@Override
public void runInternal(GeogigCLI cli) throws IOException {
String ref;
if (refList.isEmpty()) {
ref = null;
} else {
ref = refList.get(0);
}
Strategy lsStrategy = Strategy.CHILDREN;
if (recursive) {
if (includeTrees) {
lsStrategy = Strategy.DEPTHFIRST;
} else if (onlyTrees) {
lsStrategy = Strategy.DEPTHFIRST_ONLY_TREES;
} else {
lsStrategy = Strategy.DEPTHFIRST_ONLY_FEATURES;
}
} else {
if (onlyTrees) {
lsStrategy = Strategy.TREES_ONLY;
}
}
Iterator<NodeRef> iter = cli.getGeogig().command(LsTreeOp.class).setReference(ref).setStrategy(lsStrategy).call();
final ConsoleReader console = cli.getConsole();
if (!iter.hasNext()) {
if (ref == null) {
console.println("The working tree is empty");
} else {
console.println("The specified path is empty");
}
return;
}
int depth = 0;
if (ref == null) {
console.println("Root tree/");
} else {
console.println(ref + "/");
depth = ref.split("/").length - 1;
}
final int rootDepth = depth;
Function<NodeRef, CharSequence> printFunctor = new Function<NodeRef, CharSequence>() {
@Override
public CharSequence apply(NodeRef input) {
String path = input.path();
int depth = path.split("/").length - rootDepth;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < depth; i++) {
sb.append('\t');
}
sb.append(input.getNode().getName());
if (input.getType().equals(TYPE.TREE)) {
sb.append('/');
}
if (verbose) {
sb.append(' ').append(abbrev(input.getMetadataId())).append(' ').append(abbrev(input.objectId()));
}
return sb.toString();
}
private String abbrev(ObjectId oid) {
return abbrev == null ? oid.toString() : oid.toString().substring(0, abbrev.intValue());
}
};
Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);
while (lines.hasNext()) {
console.println(lines.next());
}
console.flush();
}
use of org.locationtech.geogig.api.plumbing.LsTreeOp.Strategy in project GeoGig by boundlessgeo.
the class WriteTree2Test method getRefsByPath.
private ImmutableMap<String, NodeRef> getRefsByPath(ObjectId repoRoot, boolean includeFeatures) {
Strategy strategy = includeFeatures ? Strategy.DEPTHFIRST : Strategy.DEPTHFIRST_ONLY_TREES;
Iterator<NodeRef> iterator = geogig.command(LsTreeOp.class).setReference(repoRoot.toString()).setStrategy(strategy).call();
Function<NodeRef, String> keyFunction = new Function<NodeRef, String>() {
@Override
public String apply(NodeRef input) {
return input.path();
}
};
ImmutableMap<String, NodeRef> refsByPath = Maps.uniqueIndex(iterator, keyFunction);
return refsByPath;
}
Aggregations