use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class BinaryPackedObjects method write.
/**
* @return the number of objects written
*/
public long write(ObjectFunnel funnel, List<ObjectId> want, List<ObjectId> have, Set<ObjectId> sent, Callback callback, boolean traverseCommits, Deduplicator deduplicator) throws IOException {
for (ObjectId i : want) {
if (!database.exists(i)) {
throw new NoSuchElementException(format("Wanted commit: '%s' is not known", i));
}
}
LOGGER.info("scanning for previsit list...");
Stopwatch sw = Stopwatch.createStarted();
ImmutableList<ObjectId> needsPrevisit = traverseCommits ? scanForPrevisitList(want, have, deduplicator) : ImmutableList.copyOf(have);
LOGGER.info(String.format("Previsit list built in %s for %,d ids: %s. Calculating reachable content ids...", sw.stop(), needsPrevisit.size(), needsPrevisit));
deduplicator.reset();
sw.reset().start();
ImmutableList<ObjectId> previsitResults = reachableContentIds(needsPrevisit, deduplicator);
LOGGER.info(String.format("reachableContentIds took %s for %,d ids", sw.stop(), previsitResults.size()));
deduplicator.reset();
LOGGER.info("obtaining post order iterator on range...");
sw.reset().start();
Iterator<RevObject> objects = PostOrderIterator.range(want, new ArrayList<ObjectId>(previsitResults), database, traverseCommits, deduplicator);
long objectCount = 0;
LOGGER.info("PostOrderIterator.range took {}", sw.stop());
try {
LOGGER.info("writing objects to remote...");
while (objects.hasNext()) {
RevObject object = objects.next();
funnel.funnel(object);
objectCount++;
callback.callback(Suppliers.ofInstance(object));
}
} catch (IOException e) {
String causeMessage = Throwables.getRootCause(e).getMessage();
LOGGER.info(String.format("writing of objects failed after %,d objects. Cause: '%s'", objectCount, causeMessage));
throw e;
}
return objectCount;
}
use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class FilteredDiffIterator method computeNext.
/**
* Compute the next {@link DiffEntry} that matches our {@link RepositoryFilter}.
*/
protected DiffEntry computeNext() {
while (source.hasNext()) {
DiffEntry input = source.next();
// DiffTree) that doesn't report tree changes even is setReportTrees(true) was set.
if (input.isChange() && input.getOldObject().getType().equals(TYPE.TREE)) {
continue;
}
NodeRef oldObject = filter(input.getOldObject());
NodeRef newObject;
if (oldObject != null) {
newObject = input.getNewObject();
if (newObject != null) {
// we are tracking this object, but we still need to process the new object
RevObject object = sourceRepo.command(RevObjectParse.class).setObjectId(newObject.getNode().getObjectId()).call().get();
RevObject metadata = null;
if (newObject.getMetadataId() != ObjectId.NULL) {
metadata = sourceRepo.command(RevObjectParse.class).setObjectId(newObject.getMetadataId()).call().get();
}
processObject(object);
processObject(metadata);
}
} else {
newObject = filter(input.getNewObject());
}
if (oldObject == null && newObject == null) {
filtered = true;
continue;
}
return new DiffEntry(oldObject, newObject);
}
return endOfData();
}
use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class FilteredDiffIterator method filter.
private NodeRef filter(NodeRef node) {
if (node == null) {
return null;
}
RevObject object = sourceRepo.objectDatabase().get(node.objectId());
RevObject metadata = null;
if (!node.getMetadataId().isNull()) {
metadata = sourceRepo.objectDatabase().get(node.getMetadataId());
}
if (node.getType() == TYPE.FEATURE) {
if (trackingObject(object.getId())) {
// We are already tracking this object, continue to do so
return node;
}
RevFeatureType revFeatureType = (RevFeatureType) metadata;
if (!repoFilter.filterObject(revFeatureType, node.getParentPath(), object)) {
return null;
}
}
processObject(object);
processObject(metadata);
return node;
}
use of org.locationtech.geogig.api.RevObject in project GeoGig by boundlessgeo.
the class ExportOp method _call.
/**
* Executes the export operation using the parameters that have been specified.
*
* @return a FeatureCollection with the specified features
*/
@Override
protected SimpleFeatureStore _call() {
final StagingDatabase database = stagingDatabase();
if (filterFeatureTypeId != null) {
RevObject filterType = database.getIfPresent(filterFeatureTypeId);
checkArgument(filterType instanceof RevFeatureType, "Provided filter feature type is does not exist");
}
final SimpleFeatureStore targetStore = getTargetStore();
final String refspec = resolveRefSpec();
final String treePath = refspec.substring(refspec.indexOf(':') + 1);
final RevTree rootTree = resolveRootTree(refspec);
final NodeRef typeTreeRef = resolTypeTreeRef(refspec, treePath, rootTree);
final ObjectId defaultMetadataId = typeTreeRef.getMetadataId();
final RevTree typeTree = database.getTree(typeTreeRef.objectId());
final ProgressListener progressListener = getProgressListener();
progressListener.started();
progressListener.setDescription("Exporting from " + path + " to " + targetStore.getName().getLocalPart() + "... ");
FeatureCollection<SimpleFeatureType, SimpleFeature> asFeatureCollection = new BaseFeatureCollection<SimpleFeatureType, SimpleFeature>() {
@Override
public FeatureIterator<SimpleFeature> features() {
final Iterator<SimpleFeature> plainFeatures = getFeatures(typeTree, database, defaultMetadataId, progressListener);
Iterator<SimpleFeature> adaptedFeatures = adaptToArguments(plainFeatures, defaultMetadataId);
Iterator<Optional<Feature>> transformed = Iterators.transform(adaptedFeatures, ExportOp.this.function);
Iterator<SimpleFeature> filtered = Iterators.filter(Iterators.transform(transformed, new Function<Optional<Feature>, SimpleFeature>() {
@Override
public SimpleFeature apply(Optional<Feature> input) {
return (SimpleFeature) (input.isPresent() ? input.get() : null);
}
}), Predicates.notNull());
return new DelegateFeatureIterator<SimpleFeature>(filtered);
}
};
// add the feature collection to the feature store
final Transaction transaction;
if (transactional) {
transaction = new DefaultTransaction("create");
} else {
transaction = Transaction.AUTO_COMMIT;
}
try {
targetStore.setTransaction(transaction);
try {
targetStore.addFeatures(asFeatureCollection);
transaction.commit();
} catch (final Exception e) {
if (transactional) {
transaction.rollback();
}
Throwables.propagateIfInstanceOf(e, GeoToolsOpException.class);
throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_ADD);
} finally {
transaction.close();
}
} catch (IOException e) {
throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_ADD);
}
progressListener.complete();
return targetStore;
}
Aggregations