Search in sources :

Example 21 with AttributeExpressionImpl

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

the class PropertyMapperVisitorTest method testPropertyMapperVisit.

@Test
public void testPropertyMapperVisit() {
    Map<String, String> map = new HashMap<>();
    map.put("prop", "newProp");
    PropertyMapperVisitor mapper = new PropertyMapperVisitor(map);
    PropertyName propertyName = new PropertyNameImpl("prop");
    AttributeExpressionImpl exp = (AttributeExpressionImpl) mapper.visit(propertyName, new FilterFactoryImpl());
    assertThat(exp.getPropertyName(), equalTo("newProp"));
}
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)

Example 22 with AttributeExpressionImpl

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

the class PropertyMapperVisitorTest method testPropertyMapperVisitNullProperty.

@Test
public void testPropertyMapperVisitNullProperty() {
    Map<String, String> map = new HashMap<>();
    PropertyMapperVisitor mapper = new PropertyMapperVisitor(map);
    AttributeExpressionImpl exp = (AttributeExpressionImpl) mapper.visit((PropertyName) null, new FilterFactoryImpl());
    assertThat(exp, nullValue());
}
Also used : PropertyName(org.opengis.filter.expression.PropertyName) HashMap(java.util.HashMap) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) Test(org.junit.Test)

Example 23 with AttributeExpressionImpl

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

the class CswRecordMapperFilterVisitorTest method testVisitWithBoundingBoxProperty.

@Test
public void testVisitWithBoundingBoxProperty() {
    AttributeExpressionImpl propName = new AttributeExpressionImpl(new NameImpl(new QName(CswConstants.DUBLIN_CORE_SCHEMA, CswConstants.OWS_BOUNDING_BOX, CswConstants.DUBLIN_CORE_NAMESPACE_PREFIX)));
    CswRecordMapperFilterVisitor visitor = new CswRecordMapperFilterVisitor(DEFAULT_CSW_RECORD_MAP, attributeRegistry);
    PropertyName propertyName = (PropertyName) visitor.visit(propName, null);
    assertThat(propertyName.getPropertyName(), is(Metacard.ANY_GEO));
}
Also used : NameImpl(org.geotools.feature.NameImpl) PropertyName(org.opengis.filter.expression.PropertyName) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) QName(javax.xml.namespace.QName) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 24 with AttributeExpressionImpl

use of org.geotools.filter.AttributeExpressionImpl 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)

Example 25 with AttributeExpressionImpl

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

the class CqlToMappingConditionTranslator method getRightContents.

private LeafNode getRightContents(Expression expression) {
    LeafNode node = new LeafNode();
    if (LiteralExpressionImpl.class.isAssignableFrom(expression.getClass())) {
        LiteralExpressionImpl literal = (LiteralExpressionImpl) expression;
        if (literal.getValue() instanceof com.vividsolutions.jts.geom.Geometry) {
            throw new IllegalArgumentException(// $NON-NLS-1$
            "Geometric literals are " + // $NON-NLS-1$
            "not supported! Found " + literal.getValue().getClass().getCanonicalName());
        }
        node.setLiteralValue(LiteralValue.getNew(literal.getValue()));
    } else if (AttributeExpressionImpl.class.isAssignableFrom(expression.getClass())) {
        AttributeExpressionImpl attribute = (AttributeExpressionImpl) expression;
        node.setPropertyName(attribute.getPropertyName());
    } else {
        throw new IllegalArgumentException(// $NON-NLS-1$
        "Unsupported expression type: " + expression.getClass().getCanonicalName());
    }
    return node;
}
Also used : AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) LeafNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.terminal.LeafNode)

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