use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class FeatureNodeRefFromRefspec method getFeatureFromRefSpec.
private Optional<RevFeature> getFeatureFromRefSpec() {
Optional<RevObject> revObject = command(RevObjectParse.class).setRefSpec(ref).call(RevObject.class);
if (!revObject.isPresent()) {
// let's try to see if it is a feature in the working tree
NodeRef.checkValidPath(ref);
Optional<NodeRef> elementRef = command(FindTreeChild.class).setParent(workingTree().getTree()).setChildPath(ref).setIndex(true).call();
Preconditions.checkArgument(elementRef.isPresent(), "Invalid reference: %s", ref);
ObjectId id = elementRef.get().objectId();
revObject = command(RevObjectParse.class).setObjectId(id).call(RevObject.class);
}
if (revObject.isPresent()) {
Preconditions.checkArgument(TYPE.FEATURE.equals(revObject.get().getType()), "%s does not resolve to a feature", ref);
return Optional.of(RevFeature.class.cast(revObject.get()));
} else {
return Optional.absent();
}
}
use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class CloneOpTest method testCloneWithTags.
@Test
public void testCloneWithTags() throws Exception {
// Commit several features to the remote
List<Feature> features = Arrays.asList(points1, lines1, points2, lines2, points3, lines3);
LinkedList<RevCommit> expected = new LinkedList<RevCommit>();
List<RevTag> tags = Lists.newArrayList();
for (Feature f : features) {
ObjectId oId = insertAndAdd(remoteGeogig.geogig, f);
final RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).call();
expected.addFirst(commit);
Optional<RevObject> childObject = remoteGeogig.geogig.command(RevObjectParse.class).setObjectId(oId).call();
assertTrue(childObject.isPresent());
RevTag tag = remoteGeogig.geogig.command(TagCreateOp.class).setCommitId(commit.getId()).setName(f.getIdentifier().getID()).call();
tags.add(tag);
}
// Make sure the remote has all of the commits
Iterator<RevCommit> logs = remoteGeogig.geogig.command(LogOp.class).call();
List<RevCommit> logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expected, logged);
// Make sure the remote has all of the tags
ImmutableList<RevTag> remoteTags = remoteGeogig.geogig.command(TagListOp.class).call();
assertEquals(tags.size(), remoteTags.size());
for (RevTag tag : tags) {
assertTrue(remoteTags.contains(tag));
}
// Make sure the local repository has no commits prior to clone
logs = localGeogig.geogig.command(LogOp.class).call();
assertNotNull(logs);
assertFalse(logs.hasNext());
// clone from the remote
CloneOp clone = clone();
clone.setDepth(0);
clone.setRepositoryURL(remoteGeogig.envHome.getCanonicalPath()).call();
// Make sure the local repository got all of the commits
logs = localGeogig.geogig.command(LogOp.class).call();
logged = new ArrayList<RevCommit>();
for (; logs.hasNext(); ) {
logged.add(logs.next());
}
assertEquals(expected, logged);
/*
* This is commented out, since the clone operation does not clone tags yet This test
* verifies that no errors are raised when the repo to clone contains tags, but not to
* verify that tags are also cloned, since that is not supported
*
* I leave this dommented code here, to uncomment it once tag support is implemented for the
* clone operation
*
*
* // Make sure the local repository got all of the tags
*
* ImmutableList<RevTag> localTags = localGeogig.geogig.command(TagListOp.class).call();
*
* assertEquals(tags.size(), localTags.size());
*
* for (RevTag tag : tags) {
*
* assertTrue(localTags.contains(tag));
*
* }
*/
}
use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class ShpExportDiff 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");
}
}
use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class WalkGraph method runInternal.
@Override
public void runInternal(GeogigCLI cli) throws IOException {
String ref;
if (refList.isEmpty()) {
ref = null;
} else {
ref = refList.get(0);
}
Deduplicator deduplicator = cli.getGeogig().command(CreateDeduplicator.class).call();
try {
Iterator<RevObject> iter = //
cli.getGeogig().command(WalkGraphOp.class).setReference(//
ref).setDeduplicator(//
deduplicator).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;
}
Function<RevObject, CharSequence> printFunctor = new Function<RevObject, CharSequence>() {
@Override
public CharSequence apply(RevObject input) {
if (verbose) {
return String.format("%s: %s %s", input.getId(), input.getType(), input);
} else {
return String.format("%s: %s", input.getId(), input.getType());
}
}
};
Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);
while (lines.hasNext()) {
console.println(lines.next());
}
console.flush();
} finally {
deduplicator.release();
}
}
use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class TagRemoveOp method _call.
/**
* Executes the tag removal operation.
*
* @return the tag to remove
*
*/
@Override
protected RevTag _call() throws RuntimeException {
String fullPath = Ref.TAGS_PREFIX + name;
Optional<RevObject> revTag = command(RevObjectParse.class).setRefSpec(fullPath).call();
Preconditions.checkArgument(revTag.isPresent(), "Wrong tag name: " + name);
Preconditions.checkArgument(revTag.get().getType().equals(RevObject.TYPE.TAG), name + " does not resolve to a tag");
UpdateRef updateRef = command(UpdateRef.class).setName(fullPath).setDelete(true).setReason("Delete tag " + name);
Optional<Ref> tagRef = updateRef.call();
checkState(tagRef.isPresent());
return (RevTag) revTag.get();
}
Aggregations