Search in sources :

Example 6 with PropertyIsLike

use of org.opengis.filter.PropertyIsLike in project ddf by codice.

the class OpenSearchFilterVisitorTest method testPropertyLikeWildcard.

@Test
public void testPropertyLikeWildcard() {
    FilterFactory2 factory = new FilterFactoryImpl();
    PropertyIsLike textLikeFilter = factory.like(factory.property(Core.TITLE), UI_WILDCARD, UI_WILDCARD, "'", "_", false);
    OpenSearchFilterVisitorObject openSearchFilterVisitorObject = new OpenSearchFilterVisitorObject();
    OpenSearchFilterVisitorObject result = (OpenSearchFilterVisitorObject) openSearchFilterVisitor.visit(textLikeFilter, openSearchFilterVisitorObject);
    assertThat(result.getContextualSearch(), allOf(is(notNullValue()), hasProperty("searchPhraseMap", hasEntry(OpenSearchConstants.SEARCH_TERMS, WILDCARD))));
}
Also used : PropertyIsLike(org.opengis.filter.PropertyIsLike) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) FilterFactory2(org.opengis.filter.FilterFactory2) Test(org.junit.Test)

Example 7 with PropertyIsLike

use of org.opengis.filter.PropertyIsLike in project ddf by codice.

the class MockQuery method addTypeFilter.

public void addTypeFilter(List<MockTypeVersionsExtension> extensionList) {
    List<Filter> runningFilterList = new ArrayList<Filter>();
    for (MockTypeVersionsExtension e : extensionList) {
        String type = e.getExtensionTypeName();
        List<String> versions = e.getVersions();
        Filter oneTypeFilter = null;
        Expression expressionType = FILTER_FACTORY.property(Metacard.CONTENT_TYPE);
        Expression expressionVersion = FILTER_FACTORY.property(Metacard.CONTENT_TYPE_VERSION);
        // Logically 'AND' the type and versions together
        if (versions != null && !versions.isEmpty()) {
            List<Filter> andedTypeVersionPairs = new ArrayList<Filter>();
            for (String v : versions) {
                if (v != null) {
                    PropertyIsLike typeFilter = FILTER_FACTORY.like(expressionType, type, "*", "?", "\\", false);
                    PropertyIsLike versionFilter = FILTER_FACTORY.like(expressionVersion, v, "*", "?", "\\", false);
                    andedTypeVersionPairs.add(FILTER_FACTORY.and(typeFilter, versionFilter));
                }
            }
            // Check if we had any pairs and logically 'OR' them together.
            if (!andedTypeVersionPairs.isEmpty()) {
                oneTypeFilter = FILTER_FACTORY.or(andedTypeVersionPairs);
            } else {
                // if we don't have any pairs, means we don't have versions, handle single type
                oneTypeFilter = FILTER_FACTORY.like(expressionType, type, "*", "?", "\\", false);
            }
        } else {
            // we do not have versions, handle single type case
            oneTypeFilter = FILTER_FACTORY.like(expressionType, type, "*", "?", "\\", false);
        }
        runningFilterList.add(oneTypeFilter);
    }
    if (!runningFilterList.isEmpty()) {
        Filter filter = FILTER_FACTORY.or(runningFilterList);
        filters.add(filter);
    }
}
Also used : PropertyIsLike(org.opengis.filter.PropertyIsLike) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) Filter(org.opengis.filter.Filter) Expression(org.opengis.filter.expression.Expression) ArrayList(java.util.ArrayList)

Example 8 with PropertyIsLike

use of org.opengis.filter.PropertyIsLike in project ddf by codice.

the class CswRecordMapperFilterVisitorTest method testVisitPropertyIsFuzzy.

@Test
public void testVisitPropertyIsFuzzy() {
    visitor = new CswRecordMapperFilterVisitor(DEFAULT_CSW_RECORD_MAP, attributeRegistry);
    Expression val1 = factory.property("fooProperty");
    Expression val2 = factory.literal("fooLiteral");
    // PropertyIsFuzzy maps to a propertyIsLike filter with a fuzzy function
    GeotoolsFilterBuilder builder = new GeotoolsFilterBuilder();
    PropertyIsLike fuzzySearch = (PropertyIsLike) builder.attribute(val1.toString()).is().like().fuzzyText(val2.toString());
    PropertyIsLike visitedFilter = (PropertyIsLike) visitor.visit(fuzzySearch, null);
    assertThat(visitedFilter.getExpression(), is(instanceOf(FuzzyFunction.class)));
    assertThat(visitedFilter.getLiteral(), is(val2.toString()));
}
Also used : PropertyIsLike(org.opengis.filter.PropertyIsLike) Expression(org.opengis.filter.expression.Expression) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 9 with PropertyIsLike

use of org.opengis.filter.PropertyIsLike in project ddf by codice.

the class TestCswRecordMapperFilterVisitor method testSourceIdFilter.

@Test
public void testSourceIdFilter() {
    Expression val = factory.literal("source1");
    Expression val2 = factory.literal("source2");
    Expression sourceExpr = factory.property(Core.SOURCE_ID);
    PropertyIsEqualTo filter = factory.equal(sourceExpr, val, false);
    Filter filter2 = factory.equal(sourceExpr, val2, false);
    Filter likeFilter = factory.like(attrExpr, "something");
    Filter sourceFilter = factory.or(filter, filter2);
    Filter totalFilter = factory.and(sourceFilter, likeFilter);
    Object obj = totalFilter.accept(visitor, null);
    assertThat(obj, instanceOf(PropertyIsLike.class));
    PropertyIsLike duplicate = (PropertyIsLike) obj;
    assertThat(duplicate.getExpression(), is(attrExpr));
    assertThat(duplicate.getLiteral(), is("something"));
    assertThat(visitor.getSourceIds().size(), is(2));
}
Also used : PropertyIsLike(org.opengis.filter.PropertyIsLike) PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) Expression(org.opengis.filter.expression.Expression) Filter(org.opengis.filter.Filter) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 10 with PropertyIsLike

use of org.opengis.filter.PropertyIsLike in project sldeditor by robward-scisys.

the class FilterNode method setFilter.

/**
 * Sets the filter.
 *
 * @param filter the new expression
 * @param filterConfig the filter config
 */
public void setFilter(Filter filter, FilterConfigInterface filterConfig) {
    this.filter = filter;
    this.filterConfig = filterConfig;
    setDisplayString();
    this.removeAllChildren();
    TypeManager.getInstance().reset();
    if (filterConfig != null) {
        FilterName filterName = filterConfig.getFilterConfiguration();
        if (filter instanceof Not) {
            List<Filter> childFilterList = ((LogicFilterImpl) filter).getChildren();
            if (childFilterList.isEmpty()) {
                // No child filter so add a minimum 1 to work with.
                setFilterParameter(null, filterName.getParameter(0));
            } else {
                setFilterParameter(childFilterList.get(0), filterName.getParameter(0));
            }
        } else if (filter instanceof LogicFilterImpl) {
            List<Filter> childFilterList = ((LogicFilterImpl) filter).getChildren();
            if (childFilterList.isEmpty()) {
                // No child filter so add a minimum 2 to work with.
                setFilterParameter(null, filterName.getParameter(0));
                setFilterParameter(null, filterName.getParameter(0));
            } else {
                for (Filter childFilter : childFilterList) {
                    setFilterParameter(childFilter, filterName.getParameter(0));
                }
            }
        } else if (filter instanceof BinaryTemporalOperator) {
            setExpressionParameter(((BinaryTemporalOperator) filter).getExpression1(), filterName.getParameter(0));
            setExpressionParameter(((BinaryTemporalOperator) filter).getExpression2(), filterName.getParameter(1));
        } else if (filter instanceof PropertyIsNull) {
            setExpressionParameter(((PropertyIsNull) filter).getExpression(), filterName.getParameter(0));
        } else if (filter instanceof PropertyIsBetween) {
            setExpressionParameter(((PropertyIsBetween) filter).getLowerBoundary(), filterName.getParameter(0));
            setExpressionParameter(((PropertyIsBetween) filter).getExpression(), filterName.getParameter(1));
            setExpressionParameter(((PropertyIsBetween) filter).getUpperBoundary(), filterName.getParameter(2));
        } else if (filter instanceof PropertyIsLike) {
            setExpressionParameter(((PropertyIsLike) filter).getExpression(), filterName.getParameter(0));
            setExpressionParameter(ff.literal(((PropertyIsLike) filter).getLiteral()), filterName.getParameter(1));
            setExpressionParameter(ff.literal(((PropertyIsLike) filter).getWildCard()), filterName.getParameter(2));
            setExpressionParameter(ff.literal(((PropertyIsLike) filter).getSingleChar()), filterName.getParameter(3));
            setExpressionParameter(ff.literal(((PropertyIsLike) filter).getEscape()), filterName.getParameter(4));
            setExpressionParameter(ff.literal(((PropertyIsLike) filter).isMatchingCase()), filterName.getParameter(5));
        } else if (filter instanceof BinarySpatialOperator) {
            setExpressionParameter(((BinaryComparisonAbstract) filter).getExpression1(), filterName.getParameter(0));
            setExpressionParameter(((BinaryComparisonAbstract) filter).getExpression2(), filterName.getParameter(1));
        } else if (filter instanceof BinaryComparisonAbstract) {
            setExpressionParameter(((BinaryComparisonAbstract) filter).getExpression1(), filterName.getParameter(0));
            setExpressionParameter(((BinaryComparisonAbstract) filter).getExpression2(), filterName.getParameter(1));
            // which has no matchCase parameter
            if (filterName.getParameterList().size() > 2) {
                setExpressionParameter(ff.literal(((BinaryComparisonAbstract) filter).isMatchingCase()), filterName.getParameter(2));
            }
        }
    }
}
Also used : Not(org.opengis.filter.Not) BinaryTemporalOperator(org.opengis.filter.temporal.BinaryTemporalOperator) PropertyIsLike(org.opengis.filter.PropertyIsLike) PropertyIsNull(org.opengis.filter.PropertyIsNull) Filter(org.opengis.filter.Filter) LogicFilterImpl(org.geotools.filter.LogicFilterImpl) List(java.util.List) PropertyIsBetween(org.opengis.filter.PropertyIsBetween) FilterName(com.sldeditor.filter.v2.function.FilterName) BinaryComparisonAbstract(org.geotools.filter.BinaryComparisonAbstract) BinarySpatialOperator(org.opengis.filter.spatial.BinarySpatialOperator)

Aggregations

PropertyIsLike (org.opengis.filter.PropertyIsLike)13 Test (org.junit.Test)8 Filter (org.opengis.filter.Filter)7 Expression (org.opengis.filter.expression.Expression)6 ArrayList (java.util.ArrayList)5 LogicFilterImpl (org.geotools.filter.LogicFilterImpl)4 PropertyIsBetween (org.opengis.filter.PropertyIsBetween)4 PropertyIsNull (org.opengis.filter.PropertyIsNull)4 BinarySpatialOperator (org.opengis.filter.spatial.BinarySpatialOperator)4 BinaryTemporalOperator (org.opengis.filter.temporal.BinaryTemporalOperator)4 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)3 BinaryComparisonAbstract (org.geotools.filter.BinaryComparisonAbstract)3 Not (org.opengis.filter.Not)3 FilterConfigInterface (com.sldeditor.filter.v2.function.FilterConfigInterface)2 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)2 List (java.util.List)2 FidFilterImpl (org.geotools.filter.FidFilterImpl)2 PropertyIsGreaterThan (org.opengis.filter.PropertyIsGreaterThan)2 FilterName (com.sldeditor.filter.v2.function.FilterName)1 LineString (com.vividsolutions.jts.geom.LineString)1