use of org.opengis.filter.Id in project GeoGig by boundlessgeo.
the class GeoGigFeatureStoreTest method testModifyFeatures.
@Test
public void testModifyFeatures() throws Exception {
// add features circumventing FeatureStore.addFeatures to keep the test
// independent of the addFeatures functionality
insertAndAdd(lines1, lines2, lines3, points1, points2, points3);
geogig.command(CommitOp.class).call();
Id filter = ff.id(Collections.singleton(ff.featureId(idP1)));
Transaction tx = new DefaultTransaction();
points.setTransaction(tx);
try {
// initial value
SimpleFeature initial = points.getFeatures(filter).features().next();
assertEquals("StringProp1_1", initial.getAttribute("sp"));
// modify
points.modifyFeatures("sp", "modified", filter);
// modified value before commit
SimpleFeature modified = points.getFeatures(filter).features().next();
assertEquals("modified", modified.getAttribute("sp"));
// unmodified value before commit on another store instance (tx isolation)
assertEquals("StringProp1_1", dataStore.getFeatureSource(pointsTypeName).getFeatures(filter).features().next().getAttribute("sp"));
tx.commit();
// modified value after commit on another store instance
assertEquals("modified", dataStore.getFeatureSource(pointsTypeName).getFeatures(filter).features().next().getAttribute("sp"));
} catch (Exception e) {
tx.rollback();
throw e;
} finally {
tx.close();
}
points.setTransaction(Transaction.AUTO_COMMIT);
SimpleFeature modified = points.getFeatures(filter).features().next();
assertEquals("modified", modified.getAttribute("sp"));
}
use of org.opengis.filter.Id in project GeoGig by boundlessgeo.
the class GeoGigFeatureStoreTest method testRemoveFeatures.
@Test
public void testRemoveFeatures() throws Exception {
// add features circumventing FeatureStore.addFeatures to keep the test
// independent of the
// addFeatures functionality
insertAndAdd(lines1, lines2, lines3);
insertAndAdd(points1, points2, points3);
geogig.command(CommitOp.class).call();
Id filter = ff.id(Collections.singleton(ff.featureId(idP1)));
Transaction tx = new DefaultTransaction();
points.setTransaction(tx);
try {
// initial # of features
assertEquals(3, points.getFeatures().size());
// remove feature
points.removeFeatures(filter);
// #of features before commit on the same store
assertEquals(2, points.getFeatures().size());
// #of features before commit on a different store instance
assertEquals(3, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
tx.commit();
// #of features after commit on a different store instance
assertEquals(2, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
} catch (Exception e) {
tx.rollback();
throw e;
} finally {
tx.close();
}
points.setTransaction(Transaction.AUTO_COMMIT);
assertEquals(2, points.getFeatures().size());
assertEquals(0, points.getFeatures(filter).size());
}
use of org.opengis.filter.Id in project polymap4-core by Polymap4.
the class UnitOfWork method checkSubmitModified.
// public void revert( IProgressMonitor monitor ) {
// revert( Filter.INCLUDE, monitor );
// }
//
//
// /**
// *
// * @param filter Specifies what features to revert. null for all features.
// * @param monitor
// */
// public void revert( Filter filter, IProgressMonitor monitor ) {
// assert filter != null;
// monitor.beginTask( getLabel() + " revert", modified.size() );
//
// List<Feature> reverted = new ArrayList( modified.size() );
//
// for (FeatureBufferState buffered : modified.values()) {
// if (filter.evaluate( buffered.original() )) {
// buffer.unregisterFeatures( Collections.singletonList( buffered.feature() ) );
// reverted.add( buffered.feature() );
// }
// monitor.worked( 1 );
// }
// fireFeatureChangeEvent( FeatureChangeEvent.Type.FLUSHED, reverted );
//
// monitor.done();
// }
/**
* Check concurrent modifications with the store.
*/
protected void checkSubmitModified(FeatureBufferState buffered) throws ConcurrentModificationException, IOException {
FeatureId fid = buffered.feature().getIdentifier();
Id fidFilter = ff.id(Collections.singleton(fid));
// check concurrent modification
Feature[] stored = (Feature[]) fs.getFeatures(fidFilter).toArray(new Feature[1]);
if (stored.length == 0) {
throw new ConcurrentModificationException("Feature has been removed concurrently: " + fid);
} else if (stored.length > 1) {
throw new IllegalStateException("More than one feature for id: " + fid + "!?");
}
if (isFeatureModified(stored[0], buffered.original())) {
throw new ConcurrentModificationException("Objekt wurde von einem anderen Nutzer gleichzeitig ge�ndert: " + fid);
}
// write down
AttributeDescriptor[] type = {};
Object[] value = {};
for (Property origProp : buffered.original().getProperties()) {
if (origProp.getDescriptor() instanceof AttributeDescriptor) {
Property newProp = buffered.feature().getProperty(origProp.getName());
if (isPropertyModified(origProp.getValue(), newProp.getValue())) {
type = (AttributeDescriptor[]) ArrayUtils.add(type, origProp.getDescriptor());
value = ArrayUtils.add(value, newProp.getValue());
log.info("Attribute modified: " + origProp.getDescriptor().getName() + " = " + newProp.getValue() + " (" + fid.getID() + ")");
}
}
}
fs.modifyFeatures(type, value, fidFilter);
}
Aggregations