Search in sources :

Example 26 with LiteralExpressionImpl

use of org.geotools.filter.LiteralExpressionImpl 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 27 with LiteralExpressionImpl

use of org.geotools.filter.LiteralExpressionImpl 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 28 with LiteralExpressionImpl

use of org.geotools.filter.LiteralExpressionImpl 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 29 with LiteralExpressionImpl

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

the class CswRecordMapperFilterVisitor method convertGeometryExpressionToEpsg4326.

private static void convertGeometryExpressionToEpsg4326(Expression expression) {
    if (expression instanceof LiteralExpressionImpl) {
        LiteralExpressionImpl literalExpression = (LiteralExpressionImpl) expression;
        Object valueObj = literalExpression.getValue();
        if (valueObj instanceof Geometry) {
            Geometry geometry = (Geometry) valueObj;
            Object userDataObj = geometry.getUserData();
            if (userDataObj instanceof CoordinateReferenceSystem) {
                CoordinateReferenceSystem sourceCRS = (CoordinateReferenceSystem) userDataObj;
                Geometry convertedGeometry = null;
                try {
                    convertedGeometry = GeospatialUtil.transformToEPSG4326LonLatFormat(geometry, sourceCRS);
                    literalExpression.setValue(convertedGeometry);
                } catch (GeoFormatException e) {
                    LOGGER.debug("Unable to convert geometry {} to EPSG:4326 format", valueObj, e);
                }
            }
        }
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) GeoFormatException(org.codice.ddf.libs.geo.GeoFormatException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 30 with LiteralExpressionImpl

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

the class CatalogFeatureQueryableTest method testQuery.

@Test
public void testQuery() throws UnsupportedQueryException, SourceUnavailableException, FederationException, FeatureQueryException {
    final ArgumentCaptor<QueryRequest> requestArgument = ArgumentCaptor.forClass(QueryRequest.class);
    QueryResponse queryResponse = getMockQueryResponse();
    when(catalogFramework.query(any())).thenReturn(queryResponse);
    List<SimpleFeature> results = catalogFeatureQueryable.query(COUNTRY_CODE, "PCL1", 1);
    verify(catalogFramework, atLeastOnce()).query(requestArgument.capture());
    SimpleFeature result = results.get(0);
    Geometry geometry = (Geometry) result.getDefaultGeometry();
    assertThat(geometry.getNumPoints(), is(WKT_NUM_POINTS));
    assertThat(geometry.getGeometryType(), is(WKT_TYPE));
    QueryImpl query = (QueryImpl) requestArgument.getValue().getQuery();
    Filter filter = query.getFilter();
    And and = (And) filter;
    List<Filter> filters = and.getChildren();
    assertThat(filters, hasSize(3));
    List<String> attributes = new ArrayList<>();
    List<String> values = new ArrayList<>();
    for (Filter compFilter : filters) {
        String attribute;
        String value;
        if (compFilter instanceof IsEqualsToImpl) {
            IsEqualsToImpl equals = (IsEqualsToImpl) compFilter;
            AttributeExpressionImpl attributeExpression = (AttributeExpressionImpl) equals.getExpression1();
            attribute = attributeExpression.getPropertyName();
            LiteralExpressionImpl literalExpression = (LiteralExpressionImpl) equals.getExpression2();
            value = (String) literalExpression.getValue();
        } else {
            LikeFilterImpl likeFilter = (LikeFilterImpl) compFilter;
            AttributeExpressionImpl literalExpression = (AttributeExpressionImpl) likeFilter.getExpression();
            attribute = literalExpression.getPropertyName();
            value = likeFilter.getLiteral();
        }
        attributes.add(attribute);
        values.add(value);
    }
    assertThat(attributes, hasSize(3));
    assertThat(attributes, hasItems(Location.COUNTRY_CODE, Core.METACARD_TAGS, Core.METACARD_TAGS));
    assertThat(values, hasSize(3));
    assertThat(values, hasItems(COUNTRY_CODE, GAZETTEER_METACARD_TAG, GeoCodingConstants.COUNTRY_TAG));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) LikeFilterImpl(org.geotools.filter.LikeFilterImpl) ArrayList(java.util.ArrayList) IsEqualsToImpl(org.geotools.filter.IsEqualsToImpl) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Geometry(org.locationtech.jts.geom.Geometry) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) And(org.opengis.filter.And) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) QueryResponse(ddf.catalog.operation.QueryResponse) Test(org.junit.Test)

Aggregations

LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)58 Expression (org.opengis.filter.expression.Expression)33 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)20 AttributeType (ddf.catalog.data.AttributeType)7 MathExpressionImpl (org.geotools.filter.MathExpressionImpl)7 FunctionExpressionImpl (org.geotools.filter.FunctionExpressionImpl)6 MarkImpl (org.geotools.styling.MarkImpl)6 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 ConstantExpression (org.geotools.filter.ConstantExpression)4 IsEqualsToImpl (org.geotools.filter.IsEqualsToImpl)4 Literal (org.opengis.filter.expression.Literal)4 XMLFieldLiteralString (com.sldeditor.common.xml.ui.XMLFieldLiteralString)3 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)3 Color (java.awt.Color)3 Geometry (org.locationtech.jts.geom.Geometry)3 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)2 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)2 FieldConfigColour (com.sldeditor.ui.detail.config.FieldConfigColour)2