/** * Returns a filter that will check if the object passed to it can be accessed by the user * * @param resourceAccesssManager * @param user */ public static Filter buildUserAccessFilter( ResourceAccessManager resourceAccesssManager, Authentication user) { org.opengis.filter.expression.Function visible = new InMemorySecurityFilter(resourceAccesssManager, user); FilterFactory factory = Predicates.factory; // create a filter combined with the security credentials check Filter filter = factory.equals(factory.literal(Boolean.TRUE), visible); return filter; }
public void testStrIndexOf() throws IOException { if (skipTests(FilterFunction_strIndexOf.class)) { return; } Function func = ff.function("strIndexOf", ff.property(aname("stringProperty")), ff.literal("er")); Filter filter = ff.equals(func, ff.literal(1)); assertFeatures(fs, filter, tname("ft1") + ".0"); }
public Function buildInFunction(String functionName, Object[] valueList) { Stream<Literal> values = Arrays.stream(valueList).map(v -> filterFac.literal(v)); Stream<PropertyName> property = Stream.of(filterFac.property("testAttr")); Expression[] literals = Stream.concat(property, values).toArray(i -> new Expression[i]); return filterFac.function(functionName, literals); } }
public void testNumberFormat2() { FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); Literal pattern = ff.literal("###,###.##"); Literal number = ff.literal("-123456.7891"); Literal minus = ff.literal("x"); Literal ds = ff.literal(":"); Literal gs = ff.literal(";"); Function f = ff.function("numberFormat2", new Expression[] {pattern, number, minus, ds, gs}); assertEquals("x123;456:79", f.evaluate(null, String.class)); }
public void testStrStartsWith() throws IOException { if (skipTests(FilterFunction_strStartsWith.class)) { return; } Function func = ff.function( "strStartsWith", ff.property(aname("stringProperty")), ff.literal("ze")); Filter filter = ff.equals(func, ff.literal(true)); assertFeatures(fs, filter, tname("ft1") + ".0"); }
protected PropertyIsEqualTo createFunctionFilter() throws Exception { FilterFunction_geometryType geomTypeExpr = new FilterFunction_geometryType(); geomTypeExpr.setParameters(Arrays.asList(new Expression[] {ff.property("geom")})); PropertyIsEqualTo filter = ff.equals(geomTypeExpr, ff.literal("Polygon")); return filter; }
public void testChainIntersection() { Function innerBuffer1 = ff.function("buffer", ff.property("the_geom"), ff.literal(3)); Function innerBuffer2 = ff.function("buffer", ff.property("other_geom"), ff.literal(2)); Function geomTx = ff.function("intersection", innerBuffer1, innerBuffer2); ReferencedEnvelope re = new ReferencedEnvelope(0, 2, 0, 2, null); GeometryTransformationVisitor visitor = new GeometryTransformationVisitor(); ReferencedEnvelope result = (ReferencedEnvelope) geomTx.accept(visitor, re); ReferencedEnvelope expected = new ReferencedEnvelope(-3, 5, -3, 5, null); assertEquals(expected, result); } }
/** * Returns a predicate that checks a CatalogInfo object's property for inequality with the * provided property value. * * <p>The <tt>property</tt> parameter may be specified as a "path" of the form "prop1.prop2". If * any of the resulting properties along the path result in null this method will return null. * * <p>Indexed access to nested list and array properties is supported through the syntax {@code * "prop1[M].prop2.prop3[N]"}, where {@code prop1} and {@code prop3} are list or array * properties, {@code M} is the index of the {@code prop2} element to retrieve from {@code * prop1}, and {@code N} is the index of array or list property {@code prop3} to retrieve. * Indexed access to {{java.util.Set}} properties is <b>not</b> supported. * * <p>Evaluation of nested properties for <b>any</b> member of a collection property is at the * moment not supported * * <p> * * @param property the qualified property name of the predicate's input object to evaluate * @param expected the value to check the input object's property against * @see PropertyIsEqualTo */ public static Filter notEqual(final String property, final Object expected) { return factory.notEqual(factory.property(property), factory.literal(expected)); } }
@Test public void testStrReplace() { Literal foo = ff.literal("foo"); Literal o = ff.literal("o"); Literal bar = ff.literal("bar"); Function f = ff.function("strReplace", new Expression[] {foo, o, bar, ff.literal(true)}); String s = (String) f.evaluate(null, String.class); assertEquals("fbarbar", s); f = ff.function("strReplace", new Expression[] {foo, o, bar, ff.literal(false)}); s = (String) f.evaluate(null, String.class); assertEquals("fbaro", s); }
public void testStrSubstringStart() throws IOException { if (skipTests(FilterFunction_strSubstringStart.class)) { return; } // intentionally mixing string and int literals Function func = ff.function( "strSubstringStart", ff.property(aname("stringProperty")), ff.literal("1")); Filter filter = ff.equals(func, ff.literal("ero")); assertFeatures(fs, filter, tname("ft1") + ".0"); }
public void testChainBuffer() { // check buffer chaining Function innerBuffer = ff.function("buffer", ff.property("the_geom"), ff.literal(3)); Function geomTx = ff.function("buffer", innerBuffer, ff.literal(2)); ReferencedEnvelope re = new ReferencedEnvelope(0, 2, 0, 2, null); GeometryTransformationVisitor visitor = new GeometryTransformationVisitor(); ReferencedEnvelope result = (ReferencedEnvelope) geomTx.accept(visitor, re); ReferencedEnvelope expected = new ReferencedEnvelope(-5, 7, -5, 7, null); assertEquals(expected, result); }
private CatalogInfo replaceCatalogInfo(CatalogInfo ci) { String id = ci.getId(); Catalog catalog = (Catalog) GeoServerExtensions.bean("catalog"); FilterFactory ff = CommonFactoryFinder.getFilterFactory(); Class iface = getCatalogInfoInterface(ci.getClass()); CatalogInfo replacement = catalog.get(iface, ff.equal(ff.property("id"), ff.literal(id), true)); return replacement; }
@Test public void testConcatenate() throws Exception { assertEquals( "ab", ff.function("strConcat", ff.literal("a"), ff.literal("b")).evaluate(null)); assertEquals( "a", ff.function("strConcat", ff.literal("a"), ff.literal(null)).evaluate(null)); assertEquals( "b", ff.function("strConcat", ff.literal(null), ff.literal("b")).evaluate(null)); assertNull(ff.function("strConcat", ff.literal(null), ff.literal(null)).evaluate(null)); } }
public void testStrEqualsIgnoreCase() throws IOException { if (skipTests(FilterFunction_strEqualsIgnoreCase.class)) { return; } Function func = ff.function( "strEqualsIgnoreCase", ff.property(aname("stringProperty")), ff.literal("ZeRo")); Filter filter = ff.equals(func, ff.literal(true)); assertFeatures(fs, filter, tname("ft1") + ".0"); }