Search in sources :

Example 51 with WorkingTree

use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.

the class GlobalState method delete.

public static boolean delete(Feature f) throws Exception {
    GeoGIG geogig = geogigCLI.newGeoGIG();
    try {
        final WorkingTree workTree = geogig.getRepository().workingTree();
        Name name = f.getType().getName();
        String localPart = name.getLocalPart();
        String id = f.getIdentifier().getID();
        boolean existed = workTree.delete(localPart, id);
        return existed;
    } finally {
        geogig.close();
    }
}
Also used : WorkingTree(org.locationtech.geogig.repository.WorkingTree) GeoGIG(org.locationtech.geogig.api.GeoGIG) Name(org.opengis.feature.type.Name)

Example 52 with WorkingTree

use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.

the class GeogigFeatureStore method addFeatures.

@Override
public final List<FeatureId> addFeatures(FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection) throws IOException {
    if (Transaction.AUTO_COMMIT.equals(getTransaction())) {
        throw new UnsupportedOperationException("GeoGIG does not support AUTO_COMMIT");
    }
    Preconditions.checkState(getDataStore().isAllowTransactions(), "Transactions not supported; head is not a local branch");
    final WorkingTree workingTree = delegate.getWorkingTree();
    final String path = delegate.getTypeTreePath();
    ProgressListener listener = new DefaultProgressListener();
    final List<FeatureId> insertedFids = Lists.newArrayList();
    List<Node> deferringTarget = new AbstractList<Node>() {

        @Override
        public boolean add(Node node) {
            String fid = node.getName();
            String version = node.getObjectId().toString();
            insertedFids.add(new FeatureIdVersionedImpl(fid, version));
            return true;
        }

        @Override
        public Node get(int index) {
            throw new UnsupportedOperationException();
        }

        @Override
        public int size() {
            return 0;
        }
    };
    Integer count = (Integer) null;
    FeatureIterator<SimpleFeature> featureIterator = featureCollection.features();
    try {
        Iterator<SimpleFeature> features;
        features = new FeatureIteratorIterator<SimpleFeature>(featureIterator);
        /*
             * Make sure to transform the incoming features to the native schema to avoid situations
             * where geogig would change the metadataId of the RevFeature nodes due to small
             * differences in the default and incoming schema such as namespace or missing
             * properties
             */
        final SimpleFeatureType nativeSchema = delegate.getNativeType();
        features = Iterators.transform(features, new SchemaInforcer(nativeSchema));
        workingTree.insert(path, features, listener, deferringTarget, count);
    } catch (Exception e) {
        throw new IOException(e);
    } finally {
        featureIterator.close();
    }
    return insertedFids;
}
Also used : AbstractList(java.util.AbstractList) Node(org.locationtech.geogig.api.Node) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) IOException(java.io.IOException) FeatureId(org.opengis.filter.identity.FeatureId) WorkingTree(org.locationtech.geogig.repository.WorkingTree) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) ProgressListener(org.locationtech.geogig.api.ProgressListener) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureIdVersionedImpl(org.geotools.filter.identity.FeatureIdVersionedImpl)

Example 53 with WorkingTree

use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.

the class GeogigFeatureStore method modifyFeatures.

@Override
public void modifyFeatures(Name[] names, Object[] values, Filter filter) throws IOException {
    Preconditions.checkState(getDataStore().isAllowTransactions(), "Transactions not supported; head is not a local branch");
    final WorkingTree workingTree = delegate.getWorkingTree();
    final String path = delegate.getTypeTreePath();
    Iterator<SimpleFeature> features = modifyingFeatureIterator(names, values, filter);
    /*
         * Make sure to transform the incoming features to the native schema to avoid situations
         * where geogig would change the metadataId of the RevFeature nodes due to small differences
         * in the default and incoming schema such as namespace or missing properties
         */
    final SimpleFeatureType nativeSchema = delegate.getNativeType();
    features = Iterators.transform(features, new SchemaInforcer(nativeSchema));
    try {
        ProgressListener listener = new DefaultProgressListener();
        Integer count = (Integer) null;
        List<Node> target = (List<Node>) null;
        workingTree.insert(path, features, listener, target, count);
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : Node(org.locationtech.geogig.api.Node) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) IOException(java.io.IOException) WorkingTree(org.locationtech.geogig.repository.WorkingTree) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) DefaultProgressListener(org.locationtech.geogig.api.DefaultProgressListener) ProgressListener(org.locationtech.geogig.api.ProgressListener) AbstractList(java.util.AbstractList) List(java.util.List)

Example 54 with WorkingTree

use of org.locationtech.geogig.repository.WorkingTree in project GeoGig by boundlessgeo.

the class ImportOp method _call.

/**
     * Executes the import operation using the parameters that have been specified. Features will be
     * added to the working tree, and a new working tree will be constructed. Either {@code all} or
     * {@code table}, but not both, must be set prior to the import process.
     * 
     * @return RevTree the new working tree
     */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected RevTree _call() {
    // check preconditions and get the actual list of type names to import
    final String[] typeNames = checkPreconditions();
    for (int i = 0; i < typeNames.length; i++) {
        try {
            typeNames[i] = URLDecoder.decode(typeNames[i], Charsets.UTF_8.displayName());
        } catch (UnsupportedEncodingException e) {
        // shouldn't reach here.
        }
    }
    ProgressListener progressListener = getProgressListener();
    progressListener.started();
    // use a local variable not to alter the command's state
    boolean overwrite = this.overwrite;
    if (alter) {
        overwrite = false;
    }
    final WorkingTree workTree = workingTree();
    RevFeatureType destPathFeatureType = null;
    final boolean destPathProvided = destPath != null;
    if (destPathProvided) {
        destPathFeatureType = this.command(ResolveFeatureType.class).setRefSpec(destPath).call().orNull();
        // only the last one will be imported.
        if (overwrite) {
            try {
                workTree.delete(destPath);
            } catch (Exception e) {
                throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_INSERT);
            }
            overwrite = false;
        }
    }
    int tableCount = 0;
    for (String typeName : typeNames) {
        {
            tableCount++;
            String tableName = String.format("%-16s", typeName);
            if (typeName.length() > 16) {
                tableName = tableName.substring(0, 13) + "...";
            }
            progressListener.setDescription("Importing " + tableName + " (" + tableCount + "/" + typeNames.length + ")... ");
        }
        FeatureSource featureSource = getFeatureSource(typeName);
        SimpleFeatureType featureType = (SimpleFeatureType) featureSource.getSchema();
        final String fidPrefix = featureType.getTypeName() + ".";
        String path;
        if (destPath == null) {
            path = featureType.getTypeName();
        } else {
            NodeRef.checkValidPath(destPath);
            path = destPath;
            featureType = forceFeatureTypeName(featureType, path);
        }
        featureType = overrideGeometryName(featureType);
        featureSource = new ForceTypeAndFidFeatureSource<FeatureType, Feature>(featureSource, featureType, fidPrefix);
        boolean hasPrimaryKey = hasPrimaryKey(typeName);
        boolean forbidSorting = !usePaging || !hasPrimaryKey;
        ((ForceTypeAndFidFeatureSource) featureSource).setForbidSorting(forbidSorting);
        if (destPathFeatureType != null && adaptToDefaultFeatureType && !alter) {
            featureSource = new FeatureTypeAdapterFeatureSource<FeatureType, Feature>(featureSource, destPathFeatureType.type());
        }
        ProgressListener taskProgress = subProgress(100.f / typeNames.length);
        if (overwrite) {
            try {
                workTree.delete(path);
                workTree.createTypeTree(path, featureType);
            } catch (Exception e) {
                throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_INSERT);
            }
        }
        if (alter) {
            // first we modify the feature type and the existing features, if needed
            workTree.updateTypeTree(path, featureType);
            Iterator<Feature> transformedIterator = transformFeatures(featureType, path);
            try {
                final Integer collectionSize = collectionSize(featureSource);
                workTree.insert(path, transformedIterator, taskProgress, null, collectionSize);
            } catch (Exception e) {
                throw new GeoToolsOpException(StatusCode.UNABLE_TO_INSERT);
            }
        }
        try {
            insert(workTree, path, featureSource, taskProgress);
        } catch (GeoToolsOpException e) {
            throw e;
        } catch (Exception e) {
            throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_INSERT);
        }
    }
    progressListener.setProgress(100.f);
    progressListener.complete();
    return workTree.getTree();
}
Also used : ForwardingFeatureSource(org.locationtech.geogig.api.data.ForwardingFeatureSource) JDBCFeatureSource(org.geotools.jdbc.JDBCFeatureSource) FeatureSource(org.geotools.data.FeatureSource) ResolveFeatureType(org.locationtech.geogig.api.plumbing.ResolveFeatureType) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureType(org.opengis.feature.type.FeatureType) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) RevFeature(org.locationtech.geogig.api.RevFeature) DecoratingFeature(org.geotools.feature.DecoratingFeature) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) WorkingTree(org.locationtech.geogig.repository.WorkingTree) ProgressListener(org.locationtech.geogig.api.ProgressListener) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Aggregations

WorkingTree (org.locationtech.geogig.repository.WorkingTree)54 Test (org.junit.Test)32 AddOp (org.locationtech.geogig.api.porcelain.AddOp)25 List (java.util.List)18 ImmutableList (com.google.common.collect.ImmutableList)17 File (java.io.File)17 ArrayList (java.util.ArrayList)16 RevFeature (org.locationtech.geogig.api.RevFeature)15 Optional (com.google.common.base.Optional)12 SimpleFeature (org.opengis.feature.simple.SimpleFeature)12 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)11 NodeRef (org.locationtech.geogig.api.NodeRef)10 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)9 Name (org.opengis.feature.type.Name)9 GeoGIG (org.locationtech.geogig.api.GeoGIG)7 Node (org.locationtech.geogig.api.Node)7 ProgressListener (org.locationtech.geogig.api.ProgressListener)6 RevCommit (org.locationtech.geogig.api.RevCommit)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)5 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)5