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();
}
}
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;
}
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);
}
}
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();
}
Aggregations