Search in sources :

Example 16 with AttributeExpressionImpl

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

the class OpenSearchQueryTest method verifyEqualsFilter.

private void verifyEqualsFilter(Filter filter, String expectedPropertyName, String expectedValue) {
    assertTrue(filter instanceof IsEqualsToImpl);
    IsEqualsToImpl equalsFilter = (IsEqualsToImpl) filter;
    AttributeExpressionImpl expression1 = (AttributeExpressionImpl) equalsFilter.getExpression1();
    LOGGER.debug("propertyName = {}", expression1.getPropertyName());
    assertEquals(expectedPropertyName, expression1.getPropertyName());
    LiteralExpressionImpl expression2 = (LiteralExpressionImpl) equalsFilter.getExpression2();
    LOGGER.debug("version to search for = {}", expression2.getValue());
    assertEquals(expectedValue, expression2.getValue());
}
Also used : AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) IsEqualsToImpl(org.geotools.filter.IsEqualsToImpl)

Example 17 with AttributeExpressionImpl

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

the class SubscriptionFilterVisitor method visit.

/**
 * During filter maps to a Temporal (Absolute and Modified) search criteria.
 */
@Override
public Object visit(During filter, Object data) {
    LOGGER.debug("ENTERING: During filter");
    AttributeExpressionImpl temporalTypeAttribute = (AttributeExpressionImpl) filter.getExpression1();
    String temporalType = temporalTypeAttribute.getPropertyName();
    LiteralExpressionImpl timePeriodLiteral = (LiteralExpressionImpl) filter.getExpression2();
    Object literal = timePeriodLiteral.getValue();
    Predicate returnPredicate = null;
    if (literal instanceof Period) {
        Period timePeriod = (Period) literal;
        // Extract the start and end dates from the OGC TOverlaps filter
        Date start = timePeriod.getBeginning().getPosition().getDate();
        Date end = timePeriod.getEnding().getPosition().getDate();
        LOGGER.debug("time period lowerBound = {}", start);
        LOGGER.debug("time period upperBound = {}", end);
        LOGGER.debug("EXITING: (temporal) filter");
        returnPredicate = new TemporalPredicate(start, end, DateType.getDateType(temporalType));
    // CREATE RELATIVE
    } else if (literal instanceof PeriodDuration) {
        DefaultPeriodDuration duration = (DefaultPeriodDuration) literal;
        long offset = duration.getTimeInMillis();
        LOGGER.debug("EXITING: (temporal) filter");
        returnPredicate = new TemporalPredicate(offset, DateType.getDateType(temporalType));
    }
    LOGGER.debug("temporalType: {}", temporalType);
    LOGGER.debug("Temporal Predicate: {}", returnPredicate);
    LOGGER.debug("EXITING: During filter");
    return returnPredicate;
}
Also used : TemporalPredicate(ddf.catalog.pubsub.predicate.TemporalPredicate) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) Period(org.opengis.temporal.Period) Date(java.util.Date) PeriodDuration(org.opengis.temporal.PeriodDuration) DefaultPeriodDuration(org.geotools.temporal.object.DefaultPeriodDuration) DefaultPeriodDuration(org.geotools.temporal.object.DefaultPeriodDuration) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) EntryPredicate(ddf.catalog.pubsub.predicate.EntryPredicate) TemporalPredicate(ddf.catalog.pubsub.predicate.TemporalPredicate) ContextualPredicate(ddf.catalog.pubsub.predicate.ContextualPredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate)

Example 18 with AttributeExpressionImpl

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

the class SubscriptionFilterVisitor method visit.

/**
 * PropertyIsEqualTo filter maps to a Type/Version(s) and Entry search criteria.
 */
@Override
public Object visit(PropertyIsEqualTo filter, Object data) {
    LOGGER.debug("ENTERING: PropertyIsEqualTo filter");
    // TODO: consider if the contentType parameters are invalid (i.e. anything where type is
    // null)
    AttributeExpressionImpl exp1 = (AttributeExpressionImpl) filter.getExpression1();
    String propertyName = exp1.getPropertyName();
    LiteralExpressionImpl exp2 = (LiteralExpressionImpl) filter.getExpression2();
    Predicate predicate = null;
    if (Metacard.ID.equals(propertyName)) {
        String entryId = (String) exp2.getValue();
        LOGGER.debug("entry id for new entry predicate: {}", entryId);
        predicate = new EntryPredicate(entryId);
    } else if (Metacard.CONTENT_TYPE.equals(propertyName)) {
        String typeValue = (String) exp2.getValue();
        predicate = new ContentTypePredicate(typeValue, null);
    } else if (Metacard.CONTENT_TYPE_VERSION.equals(propertyName)) {
        String versionValue = (String) exp2.getValue();
        predicate = new ContentTypePredicate(null, versionValue);
    } else if (Metacard.RESOURCE_URI.equals(propertyName)) {
        URI productUri = null;
        if (exp2.getValue() instanceof URI) {
            productUri = (URI) exp2.getValue();
            predicate = new EntryPredicate(productUri);
        } else {
            try {
                productUri = new URI((String) exp2.getValue());
                predicate = new EntryPredicate(productUri);
            } catch (URISyntaxException e) {
                LOGGER.debug("URI Syntax exception creating EntryPredicate", e);
                throw new UnsupportedOperationException("Could not create a URI object from the given ResourceURI.", e);
            }
        }
    }
    LOGGER.debug("EXITING: PropertyIsEqualTo filter");
    return predicate;
}
Also used : AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) URISyntaxException(java.net.URISyntaxException) EntryPredicate(ddf.catalog.pubsub.predicate.EntryPredicate) URI(java.net.URI) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) EntryPredicate(ddf.catalog.pubsub.predicate.EntryPredicate) TemporalPredicate(ddf.catalog.pubsub.predicate.TemporalPredicate) ContextualPredicate(ddf.catalog.pubsub.predicate.ContextualPredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate)

Example 19 with AttributeExpressionImpl

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

the class MockQuery method addContextualFilter.

public void addContextualFilter(String searchPhrase, String textPathSections, boolean caseSensitive) {
    Filter filter = null;
    if (searchPhrase != null) {
        if (textPathSections != null) {
            List<Filter> xpathFilters = new ArrayList<Filter>();
            String[] selectors = textPathSections.split(",");
            for (int i = 0; i < selectors.length; i++) {
                Expression xpathRef = new AttributeExpressionImpl(selectors[i]);
                filter = FILTER_FACTORY.like(xpathRef, searchPhrase);
                xpathFilters.add(filter);
            }
            filter = FILTER_FACTORY.or(xpathFilters);
        } else {
            filter = FILTER_FACTORY.like(FILTER_FACTORY.property(Metacard.ANY_TEXT), searchPhrase, SubscriptionFilterVisitor.LUCENE_WILDCARD_CHAR, SubscriptionFilterVisitor.LUCENE_SINGLE_CHAR, SubscriptionFilterVisitor.LUCENE_ESCAPE_CHAR, caseSensitive);
        }
        if (filter != null) {
            filters.add(filter);
        }
    }
}
Also used : SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) Filter(org.opengis.filter.Filter) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) ArrayList(java.util.ArrayList)

Example 20 with AttributeExpressionImpl

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

the class PropertyMapperVisitorTest method testPropertyMapperVisitPassThrough.

@Test
public void testPropertyMapperVisitPassThrough() {
    Map<String, String> map = new HashMap<>();
    map.put("prop", "newProp");
    PropertyMapperVisitor mapper = new PropertyMapperVisitor(map);
    PropertyName propertyName = new PropertyNameImpl("myprop");
    AttributeExpressionImpl exp = (AttributeExpressionImpl) mapper.visit(propertyName, new FilterFactoryImpl());
    assertThat(exp.getPropertyName(), equalTo("myprop"));
}
Also used : PropertyName(org.opengis.filter.expression.PropertyName) HashMap(java.util.HashMap) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) PropertyNameImpl(ddf.catalog.filter.impl.PropertyNameImpl) Test(org.junit.Test)

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