Search in sources :

Example 36 with AttributeExpressionImpl

use of org.geotools.filter.AttributeExpressionImpl in project ddf by codice.

the class CswRecordMapperFilterVisitorTest method testVisitPropertyIsGreaterThanTemporal.

@Test
public void testVisitPropertyIsGreaterThanTemporal() {
    Expression val = factory.literal(new Date(System.currentTimeMillis() - 1000));
    Expression test = new AttributeExpressionImpl(new NameImpl(new QName(CswConstants.DUBLIN_CORE_SCHEMA, "TestDate", CswConstants.DUBLIN_CORE_NAMESPACE_PREFIX)));
    PropertyIsGreaterThan filter = factory.greater(test, val);
    Object obj = visitor.visit(filter, null);
    assertThat(obj, instanceOf(PropertyIsGreaterThan.class));
    PropertyIsGreaterThan duplicate = (PropertyIsGreaterThan) obj;
    assertThat(duplicate.getExpression1(), is(test));
    assertThat(duplicate.getExpression2(), is(val));
}
Also used : NameImpl(org.geotools.feature.NameImpl) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) QName(javax.xml.namespace.QName) Date(java.util.Date) PropertyIsGreaterThan(org.opengis.filter.PropertyIsGreaterThan) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 37 with AttributeExpressionImpl

use of org.geotools.filter.AttributeExpressionImpl in project hale by halestudio.

the class CqlToMappingConditionTranslator method translate.

/**
 * {@inheritDoc}
 */
@Override
public ModelMappingCondition translate(Filter source) throws TranslationException {
    ModelMappingCondition filter = new ModelMappingCondition();
    FilterNode root = null;
    if (isLogical(source)) {
        LogicFilterImpl logicFilter = (LogicFilterImpl) source;
        root = factory.createLogicNode(logicFilter);
        List<?> children = logicFilter.getChildren();
        for (Object child : children) {
            createNode(root, (Filter) child);
        }
    } else // if it's a comparison filter we assume we are at the start of the tree
    if (isComparison(source)) {
        CompareFilterImpl compare = (CompareFilterImpl) source;
        AbstractComparisonNode cn = factory.createComparisonNode(compare);
        cn.setLeft(getLeftContents((AttributeExpressionImpl) compare.getExpression1()));
        cn.setRight(getRightContents(compare.getExpression2()));
        root = cn;
    } else // likewise if it's a geometric filter
    if (isGeometric(source)) {
        GeometryFilterImpl geometric = (GeometryFilterImpl) source;
        AbstractGeometricNode gn = factory.createGeometricNode(geometric);
        gn.setLeft(getLeftContents((AttributeExpressionImpl) geometric.getExpression1()));
        gn.setRight(getRightContents(geometric.getExpression2()));
        setGeometricOperationSpecifics(gn, geometric);
        root = gn;
    }
    filter.setRoot(root);
    return filter;
}
Also used : AbstractGeometricNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.geometric.AbstractGeometricNode) CompareFilterImpl(org.geotools.filter.CompareFilterImpl) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) FilterNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode) LogicFilterImpl(org.geotools.filter.LogicFilterImpl) ModelMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition) GeometryFilterImpl(org.geotools.filter.GeometryFilterImpl) AbstractComparisonNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.AbstractComparisonNode)

Example 38 with AttributeExpressionImpl

use of org.geotools.filter.AttributeExpressionImpl in project ddf by codice.

the class OpenSearchQueryTest method verifyLikeFilter.

private void verifyLikeFilter(Filter filter, String expectedPropertyName, String expectedValue) {
    assertTrue(filter instanceof LikeFilterImpl);
    LikeFilterImpl likeFilter = (LikeFilterImpl) filter;
    AttributeExpressionImpl expression = (AttributeExpressionImpl) likeFilter.getExpression();
    LOGGER.debug("propertyName = {}", expression.getPropertyName());
    assertEquals(expectedPropertyName, expression.getPropertyName());
    String pattern = likeFilter.getLiteral();
    LOGGER.debug("value to search for = {}", pattern);
    assertEquals(expectedValue, pattern);
}
Also used : LikeFilterImpl(org.geotools.filter.LikeFilterImpl) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl)

Example 39 with AttributeExpressionImpl

use of org.geotools.filter.AttributeExpressionImpl in project ddf by codice.

the class SubscriptionFilterVisitor method visit.

/**
 * PropertyIsLike filter maps to a Contextual search criteria.
 */
@Override
public Object visit(PropertyIsLike filter, Object data) {
    LOGGER.debug("ENTERING: PropertyIsLike filter");
    String wildcard = filter.getWildCard();
    String escape = filter.getEscape();
    String single = filter.getSingleChar();
    boolean isFuzzy = false;
    List<String> textPathList = null;
    LikeFilterImpl likeFilter = (LikeFilterImpl) filter;
    Expression expression = likeFilter.getExpression();
    // ContentTypePredicate
    if (expression instanceof PropertyName) {
        PropertyName propertyName = (PropertyName) expression;
        if (Metacard.CONTENT_TYPE.equals(propertyName.getPropertyName())) {
            LOGGER.debug("Expression is ContentType.");
            String typeValue = likeFilter.getLiteral();
            ContentTypePredicate predicate = new ContentTypePredicate(typeValue, null);
            return predicate;
        } else if (Metacard.CONTENT_TYPE_VERSION.equals(propertyName.getPropertyName())) {
            LOGGER.debug("Expression is ContentTypeVersion.");
            String versionValue = likeFilter.getLiteral();
            ContentTypePredicate predicate = new ContentTypePredicate(null, versionValue);
            return predicate;
        }
    }
    if (expression instanceof AttributeExpressionImpl) {
        AttributeExpressionImpl textPathExpression = (AttributeExpressionImpl) expression;
        textPathList = extractXpathSelectors(textPathExpression);
    } else if (expression instanceof FuzzyFunction) {
        FuzzyFunction fuzzyFunction = (FuzzyFunction) expression;
        LOGGER.debug("fuzzy search");
        isFuzzy = true;
        List<Expression> expressions = fuzzyFunction.getParameters();
        AttributeExpressionImpl firstExpression = (AttributeExpressionImpl) expressions.get(0);
        if (!Metacard.ANY_TEXT.equals(firstExpression.getPropertyName())) {
            LOGGER.debug("fuzzy search has a text path section");
            textPathList = extractXpathSelectors(firstExpression);
        }
    }
    String searchPhrase = likeFilter.getLiteral();
    LOGGER.debug("raw searchPhrase = [{}]", searchPhrase);
    String sterilizedSearchPhrase = sterilize(searchPhrase, wildcard, escape, single);
    LOGGER.debug("sterilizedSearchPhrase = [{}]", sterilizedSearchPhrase);
    ContextualPredicate contextPred = new ContextualPredicate(sterilizedSearchPhrase, isFuzzy, likeFilter.isMatchingCase(), textPathList);
    LOGGER.debug("EXITING: PropertyIsLike filter");
    return contextPred;
}
Also used : PropertyName(org.opengis.filter.expression.PropertyName) FuzzyFunction(ddf.catalog.impl.filter.FuzzyFunction) LikeFilterImpl(org.geotools.filter.LikeFilterImpl) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) ContextualPredicate(ddf.catalog.pubsub.predicate.ContextualPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) ArrayList(java.util.ArrayList) List(java.util.List)

Example 40 with AttributeExpressionImpl

use of org.geotools.filter.AttributeExpressionImpl in project ddf by codice.

the class CswQueryFactory method normalizeSortBy.

private SortBy normalizeSortBy(SortBy cswSortBy) {
    if (cswSortBy == null || cswSortBy.getPropertyName() == null) {
        return null;
    }
    String propertyName = cswSortBy.getPropertyName().getPropertyName();
    if (propertyName == null) {
        LOGGER.debug("Property in SortBy Field is null");
        return null;
    }
    NamespaceSupport namespaceContext = cswSortBy.getPropertyName().getNamespaceContext();
    if (!attributeRegistry.lookup(propertyName).isPresent() && !cswRecordMap.hasProperty(propertyName, namespaceContext)) {
        LOGGER.debug("Property {} is not a valid SortBy Field", propertyName);
        return null;
    }
    String name = cswRecordMap.getProperty(propertyName, namespaceContext);
    PropertyName propName = new AttributeExpressionImpl(new NameImpl(name));
    return new SortByImpl(propName, cswSortBy.getSortOrder());
}
Also used : PropertyName(org.opengis.filter.expression.PropertyName) NameImpl(org.geotools.feature.NameImpl) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) SortByImpl(ddf.catalog.filter.impl.SortByImpl) NamespaceSupport(org.xml.sax.helpers.NamespaceSupport)

Aggregations

AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)50 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)20 Expression (org.opengis.filter.expression.Expression)19 NameImpl (org.geotools.feature.NameImpl)13 Test (org.junit.Test)10 PropertyName (org.opengis.filter.expression.PropertyName)10 LikeFilterImpl (org.geotools.filter.LikeFilterImpl)9 ArrayList (java.util.ArrayList)8 QName (javax.xml.namespace.QName)8 FunctionExpressionImpl (org.geotools.filter.FunctionExpressionImpl)7 MathExpressionImpl (org.geotools.filter.MathExpressionImpl)7 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)6 FilterFactoryImpl (org.geotools.filter.FilterFactoryImpl)5 HashMap (java.util.HashMap)4 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)3 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)3 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)3 ContextualPredicate (ddf.catalog.pubsub.predicate.ContextualPredicate)3 Date (java.util.Date)3 FunctionExpression (org.geotools.filter.FunctionExpression)3