Search in sources :

Example 6 with AttributeExpressionImpl

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

the class TestCswRecordMapperFilterVisitor 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(During.class));
    During duplicate = (During) 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) During(org.opengis.filter.temporal.During) PropertyIsGreaterThan(org.opengis.filter.PropertyIsGreaterThan) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 7 with AttributeExpressionImpl

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

the class TestCswRecordMapperFilterVisitor method testVisitWithMappedName.

@Test
public void testVisitWithMappedName() {
    AttributeExpressionImpl propName = new AttributeExpressionImpl(new NameImpl(new QName(CswConstants.DUBLIN_CORE_SCHEMA, CswConstants.CSW_ALTERNATIVE, CswConstants.DUBLIN_CORE_NAMESPACE_PREFIX)));
    CswRecordMapperFilterVisitor visitor = new CswRecordMapperFilterVisitor(metacardType, mockMetacardTypeList);
    PropertyName propertyName = (PropertyName) visitor.visit(propName, null);
    assertThat(propertyName.getPropertyName(), is(Core.TITLE));
    assertThat(propertyName.getPropertyName(), not(is(CswConstants.CSW_ALTERNATIVE)));
}
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 8 with AttributeExpressionImpl

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

the class MockQuery method addContextualFilter.

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

Example 9 with AttributeExpressionImpl

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

the class CswQueryFactory method buildSort.

private SortBy buildSort(SortByType sort) throws CswException {
    if (sort == null || sort.getSortProperty() == null) {
        return null;
    }
    SortBy[] sortByArr = parseSortBy(sort);
    if (sortByArr.length > 1) {
        LOGGER.debug("Query request has multiple sort criteria, only primary will be used");
    }
    SortBy sortBy = sortByArr[0];
    if (sortBy.getPropertyName() == null) {
        LOGGER.debug("No property name in primary sort criteria");
        return null;
    }
    if (!attributeRegistry.lookup(sortBy.getPropertyName().getPropertyName()).isPresent() && !DefaultCswRecordMap.hasDefaultMetacardFieldForPrefixedString(sortBy.getPropertyName().getPropertyName(), sortBy.getPropertyName().getNamespaceContext())) {
        throw new CswException("Property " + sortBy.getPropertyName().getPropertyName() + " is not a valid SortBy Field", CswConstants.INVALID_PARAMETER_VALUE, "SortProperty");
    }
    String name = DefaultCswRecordMap.getDefaultMetacardFieldForPrefixedString(sortBy.getPropertyName().getPropertyName(), sortBy.getPropertyName().getNamespaceContext());
    PropertyName propName = new AttributeExpressionImpl(new NameImpl(name));
    return new SortByImpl(propName, sortBy.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) SortBy(org.opengis.filter.sort.SortBy) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)

Example 10 with AttributeExpressionImpl

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

the class OpenSearchQueryTest method verifyContextualFilter.

// private Document getDocument( String xml ) throws Exception
// {
// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// factory.setNamespaceAware( true );
// DocumentBuilder builder = factory.newDocumentBuilder();
// StringReader reader = new StringReader( xml );
// InputSource inputSource = new InputSource( reader );
// Document doc = builder.parse( inputSource );
// reader.close();
//
// return doc;
// }
// private String getFilterAsXml( Filter filter ) throws Exception
// {
// FilterTransformer transform = new FilterTransformer();
// transform.setIndentation( 2 );
// String filterXml = transform.transform( filter );
// LOGGER.debug( filterXml );
//
// return filterXml;
// }
private void verifyContextualFilter(Filter filter, String expectedPropertyName, String expectedSearchTerm) throws Exception {
    LikeFilterImpl likeFilter = (LikeFilterImpl) filter;
    AttributeExpressionImpl expression = (AttributeExpressionImpl) likeFilter.getExpression();
    LOGGER.debug("propertyName = {}", expression.getPropertyName());
    assertEquals(expectedPropertyName, expression.getPropertyName());
    String extractedSearchTerm = likeFilter.getLiteral();
    LOGGER.debug("extractedSearchTerm = [{}]", extractedSearchTerm);
    assertEquals(expectedSearchTerm, extractedSearchTerm);
}
Also used : LikeFilterImpl(org.geotools.filter.LikeFilterImpl) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl)

Aggregations

AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)15 NameImpl (org.geotools.feature.NameImpl)5 LikeFilterImpl (org.geotools.filter.LikeFilterImpl)5 QName (javax.xml.namespace.QName)4 Expression (org.opengis.filter.expression.Expression)4 PropertyName (org.opengis.filter.expression.PropertyName)4 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)3 ContextualPredicate (ddf.catalog.pubsub.predicate.ContextualPredicate)3 ArrayList (java.util.ArrayList)3 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)3 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)3 Test (org.junit.Test)3 SpatialFilter (ddf.catalog.impl.filter.SpatialFilter)2 EntryPredicate (ddf.catalog.pubsub.predicate.EntryPredicate)2 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)2 Predicate (ddf.catalog.pubsub.predicate.Predicate)2 TemporalPredicate (ddf.catalog.pubsub.predicate.TemporalPredicate)2 Date (java.util.Date)2 Filter (org.opengis.filter.Filter)2 SortByImpl (ddf.catalog.filter.impl.SortByImpl)1