Search in sources :

Example 81 with RevObject

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;
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException)

Example 82 with RevObject

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();
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) RevObject(org.locationtech.geogig.api.RevObject) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 83 with RevObject

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;
}
Also used : RevObject(org.locationtech.geogig.api.RevObject) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Example 84 with RevObject

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;
}
Also used : DelegateFeatureIterator(org.geotools.feature.collection.DelegateFeatureIterator) Optional(com.google.common.base.Optional) RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) RevFeature(org.locationtech.geogig.api.RevFeature) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DefaultTransaction(org.geotools.data.DefaultTransaction) IOException(java.io.IOException) NodeRef(org.locationtech.geogig.api.NodeRef) Function(com.google.common.base.Function) ProgressListener(org.locationtech.geogig.api.ProgressListener) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeatureStore(org.geotools.data.simple.SimpleFeatureStore) BaseFeatureCollection(org.geotools.feature.collection.BaseFeatureCollection) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree) StagingDatabase(org.locationtech.geogig.storage.StagingDatabase)

Aggregations

RevObject (org.locationtech.geogig.api.RevObject)84 ObjectId (org.locationtech.geogig.api.ObjectId)51 RevCommit (org.locationtech.geogig.api.RevCommit)30 NodeRef (org.locationtech.geogig.api.NodeRef)22 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)22 RevTree (org.locationtech.geogig.api.RevTree)21 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)17 RevFeature (org.locationtech.geogig.api.RevFeature)17 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)16 Feature (org.opengis.feature.Feature)16 IOException (java.io.IOException)15 LinkedList (java.util.LinkedList)15 LogOp (org.locationtech.geogig.api.porcelain.LogOp)14 GeoGIG (org.locationtech.geogig.api.GeoGIG)13 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)11 HashMap (java.util.HashMap)10 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)10 Optional (com.google.common.base.Optional)8 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)8