/** * DOCUMENT ME! * * @param reader DOCUMENT ME! * @throws IOException DOCUMENT ME! */ public void setFeatures(FeatureReader<SimpleFeatureType, SimpleFeature> reader) throws IOException { FeatureStore<SimpleFeatureType, SimpleFeature> store = store(); // check if the feature reader needs to be retyped if (!store.getSchema().equals(reader.getFeatureType())) { reader = new RetypingFeatureCollection.RetypingFeatureReader(reader, store.getSchema()); } store().setFeatures(reader); }
/** * see interface for details. * * @param fc * @throws IOException */ public List<FeatureId> addFeatures(FeatureCollection<SimpleFeatureType, SimpleFeature> fc) throws IOException { FeatureStore<SimpleFeatureType, SimpleFeature> store = store(); // check if the feature collection needs to be retyped if (!store.getSchema().equals(fc.getSchema())) { fc = new RetypingFeatureCollection(DataUtilities.simple(fc), store.getSchema()); } return store().addFeatures(fc); }
/** * A safe cast to SimpleFeatureStore; that will introduce a wrapper if it has to. * * <p>Please keep the use of this class to a minimum; if you are expecting a * FeatureStore<SimpleFeatureType,SimpleFeature> please make use of SimpleFeatureStore if you * possibly can. * * @since 2.7 */ public static SimpleFeatureStore simple(FeatureStore store) { if (store instanceof FeatureLocking) { return simple((FeatureLocking) store); } if (store instanceof SimpleFeatureStore) { return (SimpleFeatureStore) store; } if (store.getSchema() instanceof SimpleFeatureType) { return new SimpleFeatureStoreBridge(store); } throw new IllegalArgumentException( "The provided feature store contains complex features, cannot be bridged to a simple one"); }
/** * A safe cast to SimpleFeatureStore; that will introduce a wrapper if it has to. * <p> * Please keep the use of this class to a minimum; if you are expecting a * FeatureStore<SimpleFeatureType,SimpleFeature> please make use of SimpleFeatureStore if you * possibly can. * * @since 2.7 */ public static SimpleFeatureStore simple(FeatureStore store) { if (store instanceof FeatureLocking) { return simple((FeatureLocking) store); } if (store instanceof SimpleFeatureStore) { return (SimpleFeatureStore) store; } if (store.getSchema() instanceof SimpleFeatureType) { return new SimpleFeatureStoreBridge(store); } throw new IllegalArgumentException( "The provided feature store contains complex features, cannot be bridged to a simple one"); }
private void updateDescription(String collection, String product, String description) throws IOException { // prepare the update Filter filter = getProductFilter(collection, product); runTransactionOnProductStore( fs -> { // set the description to the specified value final FeatureType schema = fs.getSchema(); final String nsURI = schema.getName().getNamespaceURI(); fs.modifyFeatures( new NameImpl(nsURI, OpenSearchAccess.DESCRIPTION), description, filter); }); }
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { FeatureStore<SimpleFeatureType, SimpleFeature> store; if (layer.getFeatureSource() instanceof FeatureStore) { store = (FeatureStore<SimpleFeatureType, SimpleFeature>) layer.getFeatureSource(); DefaultTransaction transaction = new DefaultTransaction("trans_maj"); store.setTransaction(transaction); FilterFactory ff = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints()); Filter filter = ff.id(Collections.singleton(features.get(rowIndex).getIdentifier())); FeatureType schema = store.getSchema(); AttributeDescriptor NAME = (AttributeDescriptor) schema.getDescriptor(getColumnName(columnIndex)); try { store.modifyFeatures(NAME, aValue, filter); transaction.commit(); } catch (IOException ex) { ex.printStackTrace(); try { transaction.rollback(); } catch (IOException e) { e.printStackTrace(); } } setQuery(query); } }
final String nsURI = fs.getSchema().getName().getNamespaceURI(); Filter filter = getProductFilter(collection, product);
fc, featureDataConverter, featureStore.getSchema(), tx, task,
fs.addFeatures(singleton(productFeature)); final String nsURI = fs.getSchema().getName().getNamespaceURI(); Filter filter = getProductFilter(collection, productId);
fs.addFeatures(singleton(collectionFeature)); final String nsURI = fs.getSchema().getName().getNamespaceURI(); Filter filter = FF.equal(FF.property(COLLECTION_ID), FF.literal(eoId), true);
@Test public void testReadOnlyFeatureStore() throws Exception { // build up the mock SimpleFeatureType schema = createNiceMock(SimpleFeatureType.class); expect(schema.getName()).andReturn(new NameImpl("testFT")); replay(schema); FeatureStore fs = createNiceMock(FeatureStore.class); expect(fs.getSchema()).andReturn(schema); replay(fs); SecuredFeatureStore ro = new SecuredFeatureStore(fs, WrapperPolicy.readOnlyChallenge(null)); try { ro.addFeatures(createNiceMock(FeatureCollection.class)); fail("This should have thrown a security exception"); } catch (Exception e) { if (ReadOnlyDataStoreTest.isSpringSecurityException(e) == false) fail("Should have failed with a security exception"); } }
@Before public void setUp() throws Exception { SimpleFeatureType schema = createNiceMock(SimpleFeatureType.class); expect(schema.getTypeName()).andReturn("testSchema").anyTimes(); expect(schema.getName()).andReturn(new NameImpl("testSchema")).anyTimes(); replay(schema); feature = createNiceMock(SimpleFeature.class); expect(feature.getID()).andReturn("testSchema.1").anyTimes(); expect(feature.getType()).andReturn(schema).anyTimes(); expect(feature.getFeatureType()).andReturn(schema).anyTimes(); replay(feature); DefaultFeatureCollection fc = new DefaultFeatureCollection(); fc.add(feature); store = createNiceMock(FeatureStore.class); expect(store.getSchema()).andReturn(schema).anyTimes(); expect(store.getFeatures()).andReturn(fc).anyTimes(); expect(store.getFeatures((Filter) anyObject())).andReturn(fc).anyTimes(); expect(store.getFeatures((Query) anyObject())).andReturn(fc).anyTimes(); replay(store); /*expect(fc.features()).andReturn(it).anyTimes(); expect(fc.sort(sort)).andReturn(fc).anyTimes(); expect(fc.subCollection(Filter.INCLUDE)).andReturn(fc).anyTimes(); expect(fc.getSchema()).andReturn(schema).anyTimes(); replay(fc);*/ }
void addFeature(FeatureStore store, String wkt, Object... atts) throws Exception { SimpleFeatureBuilder b = new SimpleFeatureBuilder((SimpleFeatureType) store.getSchema()); b.add(new WKTReader().read(wkt)); for (Object att : atts) { b.add(att); } DefaultFeatureCollection features = new DefaultFeatureCollection(null, null); features.add(b.buildFeature(null)); store.addFeatures(features); }
void addFeature(FeatureStore store, String wkt, Object... atts) throws Exception { SimpleFeatureBuilder b = new SimpleFeatureBuilder((SimpleFeatureType) store.getSchema()); b.add(new WKTReader().read(wkt)); for (Object att : atts) { b.add(att); } DefaultFeatureCollection features = new DefaultFeatureCollection(null, null); features.add(b.buildFeature(null)); store.addFeatures(features); }
void addFeatures(FeatureStore fs, FeatureCollection features) throws Exception { SimpleFeatureBuilder b = new SimpleFeatureBuilder((SimpleFeatureType) fs.getSchema()); DefaultFeatureCollection toAdd = new DefaultFeatureCollection(null, null); FeatureIterator it = features.features(); try { SimpleFeature f = null; int i = 0; while (it.hasNext()) { f = (SimpleFeature) it.next(); b.init(f); b.add(f.getAttribute("pointProperty")); b.add(i++); toAdd.add(b.buildFeature(null)); } } finally { it.close(); } fs.addFeatures(toAdd); }