Search in sources :

Example 1 with ResourceId

use of org.opengis.filter.identity.ResourceId in project GeoGig by boundlessgeo.

the class GeoGigFeatureStoreTest method testAddFeatures.

@Test
public void testAddFeatures() throws Exception {
    FeatureCollection<SimpleFeatureType, SimpleFeature> collection;
    collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3));
    try {
        points.addFeatures(collection);
        fail("Expected UnsupportedOperationException on AUTO_COMMIT");
    } catch (UnsupportedOperationException e) {
        assertTrue(e.getMessage().contains("AUTO_COMMIT"));
    }
    Transaction tx = new DefaultTransaction();
    points.setTransaction(tx);
    assertSame(tx, points.getTransaction());
    try {
        List<FeatureId> addedFeatures = points.addFeatures(collection);
        assertNotNull(addedFeatures);
        assertEquals(3, addedFeatures.size());
        for (FeatureId id : addedFeatures) {
            assertFalse(id instanceof ResourceId);
            assertNotNull(id.getFeatureVersion());
        }
        // assert transaction isolation
        assertEquals(3, points.getFeatures().size());
        assertEquals(0, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
        tx.commit();
        assertEquals(3, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
    } catch (Exception e) {
        tx.rollback();
        throw e;
    } finally {
        tx.close();
    }
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) ResourceId(org.opengis.filter.identity.ResourceId) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DefaultTransaction(org.geotools.data.DefaultTransaction) Test(org.junit.Test)

Example 2 with ResourceId

use of org.opengis.filter.identity.ResourceId in project GeoGig by boundlessgeo.

the class GeoGigFeatureSourceTest method testFeatureIdsAreVersioned.

@Test
public void testFeatureIdsAreVersioned() throws IOException {
    SimpleFeatureCollection collection = pointsSource.getFeatures(Query.ALL);
    SimpleFeatureIterator features = collection.features();
    Set<FeatureId> ids = Sets.newHashSet();
    try {
        while (features.hasNext()) {
            SimpleFeature next = features.next();
            FeatureId identifier = next.getIdentifier();
            ids.add(identifier);
        }
    } finally {
        features.close();
    }
    List<NodeRef> refs = toList(repo.command(LsTreeOp.class).setReference(pointsName).setStrategy(Strategy.FEATURES_ONLY).call());
    assertEquals(3, refs.size());
    Map<String, NodeRef> expected = new HashMap<String, NodeRef>();
    for (NodeRef ref : refs) {
        expected.put(ref.path(), ref);
    }
    for (FeatureId id : ids) {
        assertFalse("ResourceId is a query object", id instanceof ResourceId);
        assertNotNull(id.getID());
        assertNotNull(id + " has no featureVersion set", id.getFeatureVersion());
        NodeRef ref = expected.get(id.getID());
        assertNotNull(ref);
        assertEquals(ref.objectId().toString(), id.getFeatureVersion());
    }
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) NodeRef(org.locationtech.geogig.api.NodeRef) SimpleFeatureIterator(org.geotools.data.simple.SimpleFeatureIterator) HashMap(java.util.HashMap) ResourceId(org.opengis.filter.identity.ResourceId) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 FeatureId (org.opengis.filter.identity.FeatureId)2 ResourceId (org.opengis.filter.identity.ResourceId)2 HashMap (java.util.HashMap)1 DefaultTransaction (org.geotools.data.DefaultTransaction)1 Transaction (org.geotools.data.Transaction)1 SimpleFeatureCollection (org.geotools.data.simple.SimpleFeatureCollection)1 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)1 NodeRef (org.locationtech.geogig.api.NodeRef)1 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)1