BeanLayer implements VectorLayer, VectorLayerAssociationSupport, VectorLayerLazyFeatureConversionSupport { public Iterator<?> getElements(Filter filter, int offset, int maxResultSize) throws LayerException { if (null == filter) { filter = Filter.INCLUDE; } List<Object> filteredList = new ArrayList<Object>(); try { synchronized (featuresById) { for (Object feature : featuresById.values()) { if (filter.evaluate(feature)) { filteredList.add(feature); } } } } catch (Exception e) { throw new LayerException(e, ExceptionCode.FILTER_EVALUATION_PROBLEM, filter, getId()); } if (comparator != null) { Collections.sort(filteredList, comparator); } if (maxResultSize > 0) { int fromIndex = Math.max(0, offset); int toIndex = Math.min(offset + maxResultSize, filteredList.size()); toIndex = Math.max(fromIndex, toIndex); return filteredList.subList(fromIndex, toIndex).iterator(); } else { return filteredList.iterator(); } }  String getId(); @Api void setId(String id); CoordinateReferenceSystem getCrs(); boolean isCreateCapable(); boolean isUpdateCapable(); boolean isDeleteCapable(); boolean useLazyFeatureConversion(); @Api void setUseLazyFeatureConversion(boolean useLazyFeatureConversion); Iterator<?> getElements(Filter filter, int offset, int maxResultSize); Envelope getBounds(); Envelope getBounds(Filter queryFilter); FeatureModel getFeatureModel(); void setLayerInfo(VectorLayerInfo layerInfo); VectorLayerInfo getLayerInfo(); Object create(Object feature); Object read(String featureId); Object saveOrUpdate(Object feature); void delete(String featureId); List<Object> getFeatures(); void setFeatures(List<Object> features); List<Attribute<?>> getAttributes(String attributeName, Filter filter);  }
@Test public void simpleFilter() throws Exception { Filter filter = filterService.createCompareFilter("stringAttr", "=", "bean2"); Iterator<?> it = layer.getElements(filter, 0, 0); int t = 0; while (it.hasNext()) { Assert.assertTrue(it.next() instanceof FeatureBean); t++; } Assert.assertEquals(1, t); }
@Test public void nonExistingAttributeFilter() throws Exception { Filter filter = filterService.createCompareFilter("noSuchAttr", "=", "blabla"); try { layer.getElements(filter, 0, 0); Assert.fail("Expected filter evaluation exception for non-exisitng attribute"); } catch (LayerException e) { Assert.assertEquals(ExceptionCode.FILTER_EVALUATION_PROBLEM, e.getExceptionCode()); } }
@Test public void manyToOneFilter() throws Exception { Filter filter = filterService.parseFilter("manyToOneAttr.stringAttr='manyToOne - bean1'"); Iterator<?> it = layer.getElements(filter, 0, 0); int t = 0; while (it.hasNext()) { Assert.assertTrue(it.next() instanceof FeatureBean); t++; } Assert.assertEquals(1, t); }
@Test public void manyToOneIdFilter() throws Exception { Filter filter = filterService.parseFilter("manyToOneAttr.id=1"); Iterator<?> it = layer.getElements(filter, 0, 0); int t = 0; while (it.hasNext()) { Assert.assertTrue(it.next() instanceof FeatureBean); t++; } Assert.assertEquals(1, t); }
@Test public void manyToOneEcqlIdFilter() throws Exception { Filter filter = filterService.parseFilter("manyToOneAttr.\"id\"=1"); Iterator<?> it = layer.getElements(filter, 0, 0); int t = 0; while (it.hasNext()) { Assert.assertTrue(it.next() instanceof FeatureBean); t++; } Assert.assertEquals(1, t); }
@Test public void functionFilter() throws Exception { Filter filter = filterService.parseFilter("geometryType(geometry)='Point'"); Iterator<?> it = layer.getElements(filter, 0, 0); int t = 0; while (it.hasNext()) { Assert.assertTrue(it.next() instanceof FeatureBean); t++; } Assert.assertEquals(0, t); filter = filterService.parseFilter("geometryType(geometry)='MultiPolygon'"); it = layer.getElements(filter, 0, 0); t = 0; while (it.hasNext()) { Assert.assertTrue(it.next() instanceof FeatureBean); t++; } Assert.assertEquals(3, t); }