use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class OSMUpdateOp method _call.
/**
* Executes the {@code OSMUpdateOp} operation.
*
* @return a {@link OSMDownloadReport} of the operation
*/
@Override
protected Optional<OSMReport> _call() {
final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call();
Preconditions.checkState(currHead.isPresent(), "Repository has no HEAD, can't update.");
Preconditions.checkState(currHead.get() instanceof SymRef, "Can't update from detached HEAD");
List<OSMLogEntry> entries = command(ReadOSMLogEntries.class).call();
checkArgument(!entries.isEmpty(), "Not in a geogig repository with OSM data");
Iterator<RevCommit> log = command(LogOp.class).setFirstParentOnly(false).setTopoOrder(false).call();
RevCommit lastCommit = null;
OSMLogEntry lastEntry = null;
while (log.hasNext()) {
RevCommit commit = log.next();
for (OSMLogEntry entry : entries) {
if (entry.getId().equals(commit.getTreeId())) {
lastCommit = commit;
lastEntry = entry;
break;
}
}
if (lastCommit != null) {
break;
}
}
checkNotNull(lastCommit, "The current branch does not contain OSM data");
command(BranchCreateOp.class).setSource(lastCommit.getId().toString()).setName(OSMUtils.OSM_FETCH_BRANCH).setAutoCheckout(true).setForce(true).call();
Optional<String> filter = command(ReadOSMFilterFile.class).setEntry(lastEntry).call();
Preconditions.checkState(filter.isPresent(), "Filter file not found");
message = message == null ? "Updated OSM data" : message;
Optional<OSMReport> report = command(OSMImportOp.class).setMessage(message).setFilter(filter.get()).setDataSource(apiUrl).setProgressListener(getProgressListener()).call();
if (!report.isPresent()) {
return report;
}
if (!getProgressListener().isCanceled()) {
command(CheckoutOp.class).setSource(((SymRef) currHead.get()).getTarget()).call();
Optional<Ref> upstreamRef = command(RefParse.class).setName(OSMUtils.OSM_FETCH_BRANCH).call();
Supplier<ObjectId> commitSupplier = Suppliers.ofInstance(upstreamRef.get().getObjectId());
if (rebase) {
getProgressListener().setDescription("Rebasing updated features...");
command(RebaseOp.class).setUpstream(commitSupplier).setProgressListener(getProgressListener()).call();
} else {
getProgressListener().setDescription("Merging updated features...");
command(MergeOp.class).addCommit(commitSupplier).setProgressListener(getProgressListener()).call();
}
}
return report;
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class HashObject method _call.
/**
* Hashes a RevObject using a SHA1 hasher.
*
* @return a new ObjectId created from the hash of the RevObject.
*/
@Override
protected ObjectId _call() {
Preconditions.checkState(object != null, "Object has not been set.");
final Hasher hasher = ObjectId.HASH_FUNCTION.newHasher();
@SuppressWarnings("unchecked") final Funnel<RevObject> funnel = (Funnel<RevObject>) FUNNELS[object.getType().value()];
funnel.funnel(object, hasher);
final byte[] rawKey = hasher.hash().asBytes();
final ObjectId id = ObjectId.createNoClone(rawKey);
return id;
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class LsTreeOp method _call.
/**
* @see java.util.concurrent.Callable#call()
*/
protected Iterator<NodeRef> _call() {
String ref = this.ref;
if (ref == null) {
ref = Ref.WORK_HEAD;
}
ObjectId metadataId = ObjectId.NULL;
final String path = ref.lastIndexOf(':') != -1 ? ref.substring(ref.lastIndexOf(':') + 1) : "";
if (!path.isEmpty()) {
final String providedRefName = ref.lastIndexOf(':') != -1 ? ref.substring(0, ref.lastIndexOf(':')) : null;
if (providedRefName != null) {
Optional<ObjectId> rootTreeId = command(ResolveTreeish.class).setTreeish(providedRefName).call();
if (rootTreeId.isPresent()) {
RevTree rootTree = command(RevObjectParse.class).setObjectId(rootTreeId.get()).call(RevTree.class).get();
Optional<NodeRef> treeRef = command(FindTreeChild.class).setChildPath(path).setIndex(true).setParent(rootTree).call();
metadataId = treeRef.isPresent() ? treeRef.get().getMetadataId() : ObjectId.NULL;
}
}
}
// is it just a ref name?
Optional<Ref> reference = command(RefParse.class).setName(ref).call();
if (reference.isPresent()) {
if (reference.get().getObjectId().isNull()) {
return Iterators.emptyIterator();
}
}
Optional<RevObject> revObject = command(RevObjectParse.class).setRefSpec(ref).call(RevObject.class);
Optional<NodeRef> treeRef = Optional.absent();
if (!revObject.isPresent()) {
if (Ref.WORK_HEAD.equals(ref)) {
// tree but it is empty
return Iterators.emptyIterator();
}
// let's try to see if it is a feature type or feature in the working tree
NodeRef.checkValidPath(ref);
treeRef = command(FindTreeChild.class).setParent(workingTree().getTree()).setChildPath(ref).setIndex(true).call();
Preconditions.checkArgument(treeRef.isPresent(), "Invalid reference: %s", ref);
ObjectId treeId = treeRef.get().objectId();
metadataId = treeRef.get().getMetadataId();
revObject = command(RevObjectParse.class).setObjectId(treeId).call(RevObject.class);
}
checkArgument(revObject.isPresent(), "Invalid reference: %s", ref);
final TYPE type = revObject.get().getType();
switch(type) {
case FEATURE:
NodeRef nodeRef = treeRef.isPresent() ? treeRef.get() : null;
List<NodeRef> nodeRefs = Lists.newArrayList();
nodeRefs.add(nodeRef);
// If show trees options is passed in show all trees that contain this feature
if (this.strategy == Strategy.TREES_ONLY) {
if (nodeRef != null) {
while (!nodeRef.getParentPath().isEmpty()) {
treeRef = command(FindTreeChild.class).setParent(workingTree().getTree()).setChildPath(nodeRef.getParentPath()).setIndex(true).call();
nodeRef = treeRef.get();
nodeRefs.add(nodeRef);
}
}
}
return nodeRefs.iterator();
case COMMIT:
RevCommit revCommit = (RevCommit) revObject.get();
ObjectId treeId = revCommit.getTreeId();
revObject = command(RevObjectParse.class).setObjectId(treeId).call(RevObject.class);
case TREE:
DepthTreeIterator.Strategy iterStrategy;
switch(this.strategy) {
case CHILDREN:
iterStrategy = DepthTreeIterator.Strategy.CHILDREN;
break;
case FEATURES_ONLY:
iterStrategy = DepthTreeIterator.Strategy.FEATURES_ONLY;
break;
case TREES_ONLY:
iterStrategy = DepthTreeIterator.Strategy.TREES_ONLY;
break;
case DEPTHFIRST:
iterStrategy = DepthTreeIterator.Strategy.RECURSIVE;
break;
case DEPTHFIRST_ONLY_FEATURES:
iterStrategy = DepthTreeIterator.Strategy.RECURSIVE_FEATURES_ONLY;
break;
case DEPTHFIRST_ONLY_TREES:
iterStrategy = DepthTreeIterator.Strategy.RECURSIVE_TREES_ONLY;
break;
default:
throw new IllegalStateException("Unknown strategy: " + this.strategy);
}
RevTree tree = (RevTree) revObject.get();
ObjectDatabase database = stagingDatabase();
DepthTreeIterator iter = new DepthTreeIterator(path, metadataId, tree, database, iterStrategy);
iter.setBoundsFilter(refBoundsFilter);
return iter;
default:
throw new IllegalArgumentException(String.format("Invalid reference: %s", ref));
}
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class RebuildGraphOp method _call.
/**
* Executes the {@code RebuildGraphOp} operation.
*
* @return a list of {@link ObjectId}s that were found to be missing or incomplete
*/
@Override
protected ImmutableList<ObjectId> _call() {
Repository repository = repository();
Preconditions.checkState(!repository.isSparse(), "Cannot rebuild the graph of a sparse repository.");
List<ObjectId> updated = new LinkedList<ObjectId>();
ImmutableList<Ref> branches = command(BranchListOp.class).setLocal(true).setRemotes(true).call();
GraphDatabase graphDb = repository.graphDatabase();
for (Ref ref : branches) {
Iterator<RevCommit> commits = command(LogOp.class).setUntil(ref.getObjectId()).call();
while (commits.hasNext()) {
RevCommit next = commits.next();
if (graphDb.put(next.getId(), next.getParentIds())) {
updated.add(next.getId());
}
}
}
return ImmutableList.copyOf(updated);
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class ResolveFeatureType method _call.
@Override
protected Optional<RevFeatureType> _call() {
Preconditions.checkState(refSpec != null, "ref spec has not been set.");
final String fullRefspec;
if (refSpec.contains(":")) {
fullRefspec = refSpec;
} else {
fullRefspec = Ref.WORK_HEAD + ":" + refSpec;
}
final String ref = fullRefspec.substring(0, fullRefspec.indexOf(':'));
final String path = fullRefspec.substring(fullRefspec.indexOf(':') + 1);
ObjectId parentId = command(ResolveTreeish.class).setTreeish(ref).call().get();
Optional<RevTree> parent = command(RevObjectParse.class).setObjectId(parentId).call(RevTree.class);
if (!parent.isPresent()) {
return Optional.absent();
}
Optional<NodeRef> node = command(FindTreeChild.class).setParent(parent.get()).setChildPath(path).setIndex(true).call();
if (!node.isPresent()) {
return Optional.absent();
}
NodeRef found = node.get();
ObjectId metadataID = found.getMetadataId();
Optional<RevFeatureType> ft = command(RevObjectParse.class).setObjectId(metadataID).call(RevFeatureType.class);
return ft;
}
Aggregations