Search in sources :

Example 16 with FilterFactoryImpl

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

the class OpenSearchQueryTest method testOgcFilterEvaluateTemporalBetween.

@Test
public // @Ignore
void testOgcFilterEvaluateTemporalBetween() throws Exception {
    FilterFactory filterFactory = new FilterFactoryImpl();
    // get a calendar instance, which defaults to "now"
    Calendar calendar = Calendar.getInstance();
    // get a date to represent "today"
    Date now = calendar.getTime();
    SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
    String dateInRange = dateFormatter.format(now);
    // set calendar time in past to create start date for temporal filter's criteria
    calendar.add(Calendar.DAY_OF_YEAR, -1);
    Date start = calendar.getTime();
    String startDate = dateFormatter.format(start);
    LOGGER.debug("startDate = {}", startDate);
    // set calendar time in future to create end date for temporal filter's criteria
    calendar.add(Calendar.DAY_OF_YEAR, +3);
    Date end = calendar.getTime();
    String endDate = dateFormatter.format(end);
    LOGGER.debug("endDate = {}", endDate);
    // Test date between start and end dates
    Filter filter = filterFactory.between(filterFactory.literal(dateInRange), filterFactory.literal(startDate), filterFactory.literal(endDate));
    FilterTransformer transform = new FilterTransformer();
    transform.setIndentation(2);
    LOGGER.debug(transform.transform(filter));
    boolean result = filter.evaluate(null);
    LOGGER.debug("result = {}", result);
    assertTrue(result);
    // Test date that is after end date
    calendar.add(Calendar.DAY_OF_YEAR, +3);
    Date outOfRange = calendar.getTime();
    String outOfRangeDate = dateFormatter.format(outOfRange);
    filter = filterFactory.between(filterFactory.literal(outOfRangeDate), filterFactory.literal(startDate), filterFactory.literal(endDate));
    LOGGER.debug(transform.transform(filter));
    result = filter.evaluate(null);
    LOGGER.debug("result = {}", result);
    assertFalse(result);
    // Test date that is before start date
    calendar.add(Calendar.DAY_OF_YEAR, -20);
    Date outOfRange2 = calendar.getTime();
    String outOfRangeDate2 = dateFormatter.format(outOfRange2);
    filter = filterFactory.between(filterFactory.literal(outOfRangeDate2), filterFactory.literal(startDate), filterFactory.literal(endDate));
    LOGGER.debug(transform.transform(filter));
    result = filter.evaluate(null);
    LOGGER.debug("result = {}", result);
    assertFalse(result);
    // Test date that is equal to start date
    filter = filterFactory.between(filterFactory.literal(startDate), filterFactory.literal(startDate), filterFactory.literal(endDate));
    LOGGER.debug(transform.transform(filter));
    result = filter.evaluate(null);
    LOGGER.debug("result = {}", result);
    assertTrue(result);
    // Test date that is equal to end date
    filter = filterFactory.between(filterFactory.literal(endDate), filterFactory.literal(startDate), filterFactory.literal(endDate));
    LOGGER.debug(transform.transform(filter));
    result = filter.evaluate(null);
    LOGGER.debug("result = {}", result);
    assertTrue(result);
}
Also used : TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) BBoxSpatialFilter(org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) Calendar(java.util.Calendar) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) SimpleDateFormat(java.text.SimpleDateFormat) FilterFactory(org.opengis.filter.FilterFactory) Date(java.util.Date) FilterTransformer(org.geotools.filter.FilterTransformer) Test(org.junit.Test)

Example 17 with FilterFactoryImpl

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

the class TestPubSubOgcFilter method testContextualEvaluate.

@Test
@Ignore
public void testContextualEvaluate() throws TransformerException {
    FilterFactory filterFactory = new FilterFactoryImpl();
    Filter filter = filterFactory.like(filterFactory.literal("abcdef"), "abcdef");
    printFilter(filter);
    assertTrue(filter.evaluate(null));
    Filter filter2 = filterFactory.like(filterFactory.literal("123456"), "123456abc");
    assertFalse(filter2.evaluate(null));
}
Also used : Filter(org.opengis.filter.Filter) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) FilterFactory(org.opengis.filter.FilterFactory) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with FilterFactoryImpl

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

the class CatalogFrameworkImplTest method testInjectsAttributesOnQuery.

@Test
public void testInjectsAttributesOnQuery() throws Exception {
    final Metacard original = new MetacardImpl();
    final String id = framework.create(new CreateRequestImpl(Collections.singletonList(original), null)).getCreatedMetacards().get(0).getId();
    final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl("new attribute", true, true, false, false, BasicTypes.DOUBLE_TYPE);
    stubMetacardInjection(injectAttribute);
    final FilterFactory filterFactory = new FilterFactoryImpl();
    final Filter filter = filterFactory.equals(filterFactory.property(Metacard.ID), filterFactory.literal(id));
    final QueryRequest request = new QueryRequestImpl(new QueryImpl(filter));
    final QueryResponse response = framework.query(request);
    final Metacard queryMetacard = response.getResults().get(0).getMetacard();
    final MetacardType originalMetacardType = original.getMetacardType();
    final MetacardType queryMetacardType = queryMetacard.getMetacardType();
    assertThat(originalMetacardType.getName(), is(queryMetacardType.getName()));
    final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
    expectedAttributeDescriptors.add(injectAttribute);
    assertThat(queryMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Matchers.anyString(org.mockito.Matchers.anyString) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FilterFactory(org.opengis.filter.FilterFactory) MetacardType(ddf.catalog.data.MetacardType) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with FilterFactoryImpl

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

the class CatalogFrameworkImplTest method testPostQueryStopExecution.

@Test(expected = FederationException.class)
public void testPostQueryStopExecution() throws UnsupportedQueryException, FederationException, SourceUnavailableException {
    SourcePoller poller = mock(SourcePoller.class);
    when(poller.getCachedSource(isA(Source.class))).thenReturn(null);
    BundleContext context = null;
    FilterFactory filterFactory = new FilterFactoryImpl();
    Filter filter = filterFactory.like(filterFactory.property(Metacard.METADATA), "goodyear", "*", "?", "/", false);
    QueryRequest request = new QueryRequestImpl(new QueryImpl(filter));
    SourceResponseImpl sourceResponse = new SourceResponseImpl(request, new ArrayList<Result>());
    QueryResponseImpl queryResponse = new QueryResponseImpl(sourceResponse, "anyId");
    CatalogProvider provider = mock(CatalogProvider.class);
    when(provider.query(isA(QueryRequest.class))).thenReturn(sourceResponse);
    FederationStrategy federationStrategy = mock(FederationStrategy.class);
    when(federationStrategy.federate(isA(List.class), isA(QueryRequest.class))).thenReturn(queryResponse);
    PostQueryPlugin stopQueryPlugin = new PostQueryPlugin() {

        @Override
        public QueryResponse process(QueryResponse input) throws PluginExecutionException, StopProcessingException {
            throw new StopProcessingException("Testing that the framework will stop the query.");
        }
    };
    FrameworkProperties props = new FrameworkProperties();
    props.setCatalogProviders(Collections.singletonList((CatalogProvider) provider));
    props.setBundleContext(context);
    props.setPostQuery(Arrays.asList(stopQueryPlugin));
    props.setFederationStrategy(federationStrategy);
    props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
    props.setSourcePoller(poller);
    props.setFilterBuilder(new GeotoolsFilterBuilder());
    CatalogFrameworkImpl framework = createFramework(props);
    framework.query(request);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) FederationStrategy(ddf.catalog.federation.FederationStrategy) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Source(ddf.catalog.source.Source) ByteSource(com.google.common.io.ByteSource) CachedSource(ddf.catalog.util.impl.CachedSource) FederatedSource(ddf.catalog.source.FederatedSource) FilterFactory(org.opengis.filter.FilterFactory) SourcePoller(ddf.catalog.util.impl.SourcePoller) Result(ddf.catalog.data.Result) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Filter(org.opengis.filter.Filter) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyList(org.mockito.Matchers.anyList) PostQueryPlugin(ddf.catalog.plugin.PostQueryPlugin) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 20 with FilterFactoryImpl

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

the class TestQueryImpl method testSetFilterWithNullFilter.

@Test(expected = IllegalArgumentException.class)
public void testSetFilterWithNullFilter() {
    FilterFactory filterFactory = new FilterFactoryImpl();
    // Dummy filter copied from another test
    Filter filter1 = filterFactory.like(filterFactory.property(Metacard.METADATA), "million", DEFAULT_TEST_WILDCARD, DEFAULT_TEST_SINGLE_WILDCARD, "^", false);
    Filter filter2 = null;
    QueryImpl qi = new QueryImpl(filter1);
    assertEquals(filter1, qi.getFilter());
    qi.setFilter(filter2);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Aggregations

FilterFactoryImpl (org.geotools.filter.FilterFactoryImpl)25 Test (org.junit.Test)21 FilterFactory (org.opengis.filter.FilterFactory)20 QueryImpl (ddf.catalog.operation.impl.QueryImpl)16 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)15 Filter (org.opengis.filter.Filter)15 Metacard (ddf.catalog.data.Metacard)13 QueryResponse (ddf.catalog.operation.QueryResponse)9 ArrayList (java.util.ArrayList)9 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)8 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)8 QueryRequest (ddf.catalog.operation.QueryRequest)7 Date (java.util.Date)7 CreateResponse (ddf.catalog.operation.CreateResponse)6 Result (ddf.catalog.data.Result)5 FederationException (ddf.catalog.federation.FederationException)5 SourceResponse (ddf.catalog.operation.SourceResponse)5 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)5 Calendar (java.util.Calendar)5 Ignore (org.junit.Ignore)5