Search in sources :

Example 1 with TemporalFilter

use of ddf.catalog.impl.filter.TemporalFilter in project ddf by codice.

the class OpenSearchQueryTest method testOgcFilterEvaluateContextualLike.

@Test
@Ignore
public void testOgcFilterEvaluateContextualLike() throws Exception {
    // String input = "abc_cat_dog_xyz";
    String input = "<ns1:thing xmlns:ns1=\"http://ddf.codice.org/mynamespace\">cat</ns1:thing>";
    // String searchTerm = "cat";
    // List<Filter> filters = new ArrayList<Filter>();
    FilterFactory filterFactory = new FilterFactoryImpl();
    // Filter filter = filterFactory.like( filterFactory.property( "AnyText" ), searchTerm );
    // Filter filter = filterFactory.equal( filterFactory.property( "thing" ),
    // filterFactory.literal( searchTerm ), false );
    // Filter filter = filterFactory.like( filterFactory.property( Query.ANY_TEXT ), searchTerm,
    // "*", "?", "\\" );
    // Filter filter = filterFactory.equal( filterFactory.property( Query.ANY_TEXT ),
    // searchTerm, false );
    // Filter filter = filterFactory.like( filterFactory.property( Query.ANY_TEXT ), searchTerm,
    // "*", "?", "\\" );
    Calendar.getInstance().getTime();
    String startDate = "2011-10-8T05:48:27.891-07:00";
    String endDate = "2011-10-10T06:18:27.581-07:00";
    TemporalFilter temporalFilter = new TemporalFilter(startDate, endDate);
    // WORKS Filter filter = filterFactory.between( filterFactory.literal( new Date() ),
    // filterFactory.literal( temporalFilter.getStartDate() ), filterFactory.literal(
    // temporalFilter.getEndDate() ) );
    Filter filter = filterFactory.between(filterFactory.literal(new Date()), filterFactory.literal(temporalFilter.getStartDate()), filterFactory.literal(temporalFilter.getEndDate()));
    FilterTransformer transform = new FilterTransformer();
    transform.setIndentation(2);
    LOGGER.debug(transform.transform(filter));
    // VisualizingVisitor vv = new VisualizingVisitor() ;
    // filter.accept(vv, null) ;
    // vv.getMap();
    boolean result = filter.evaluate(input);
    LOGGER.debug("result = {}", result);
// filters.add( filter );
}
Also used : TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) 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) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) FilterFactory(org.opengis.filter.FilterFactory) Date(java.util.Date) FilterTransformer(org.geotools.filter.FilterTransformer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with TemporalFilter

use of ddf.catalog.impl.filter.TemporalFilter in project ddf by codice.

the class OpenSearchSource method applyFilters.

private void applyFilters(OpenSearchFilterVisitor visitor, WebClient client) {
    TemporalFilter temporalFilter = visitor.getTemporalSearch();
    if (temporalFilter != null) {
        LOGGER.debug("startDate = {}", temporalFilter.getStartDate());
        LOGGER.debug("endDate = {}", temporalFilter.getEndDate());
        OpenSearchSiteUtil.populateTemporal(client, temporalFilter, parameters);
    }
    SpatialFilter spatialFilter = visitor.getSpatialSearch();
    if (spatialFilter != null) {
        if (spatialFilter instanceof SpatialDistanceFilter) {
            try {
                OpenSearchSiteUtil.populateGeospatial(client, (SpatialDistanceFilter) spatialFilter, shouldConvertToBBox, parameters);
            } catch (UnsupportedQueryException e) {
                LOGGER.debug("Problem with populating geospatial criteria. ", e);
            }
        } else {
            try {
                OpenSearchSiteUtil.populateGeospatial(client, spatialFilter, shouldConvertToBBox, parameters);
            } catch (UnsupportedQueryException e) {
                LOGGER.debug("Problem with populating geospatial criteria. ", e);
            }
        }
    }
    if (localQueryOnly) {
        client.replaceQueryParam(URL_SRC_PARAMETER, LOCAL_SEARCH_PARAMETER);
    } else {
        client.replaceQueryParam(URL_SRC_PARAMETER, "");
    }
}
Also used : TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter)

Example 3 with TemporalFilter

use of ddf.catalog.impl.filter.TemporalFilter in project ddf by codice.

the class OpenSearchFilterVisitor method handleTemporal.

private void handleTemporal(BinaryTemporalOperator filter) {
    Literal literalWrapper = (Literal) filter.getExpression2();
    LOGGER.trace("literalWrapper.getValue() = {}", literalWrapper.getValue());
    Object literal = literalWrapper.evaluate(null);
    if (literal instanceof Period) {
        Period period = (Period) literal;
        // Extract the start and end dates from the filter
        Date start = period.getBeginning().getPosition().getDate();
        Date end = period.getEnding().getPosition().getDate();
        temporalSearch = new TemporalFilter(start, end);
        filters.add(filter);
    } else if (literal instanceof PeriodDuration) {
        DefaultPeriodDuration duration = (DefaultPeriodDuration) literal;
        // Extract the start and end dates from the filter
        Date end = Calendar.getInstance().getTime();
        Date start = new Date(end.getTime() - duration.getTimeInMillis());
        temporalSearch = new TemporalFilter(start, end);
        filters.add(filter);
    }
}
Also used : TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) PropertyIsEqualToLiteral(ddf.catalog.filter.impl.PropertyIsEqualToLiteral) Literal(org.opengis.filter.expression.Literal) 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)

Example 4 with TemporalFilter

use of ddf.catalog.impl.filter.TemporalFilter in project ddf by codice.

the class OpenSearchQueryTest method testTemporalFilterModifiedSearchStringDates.

@Test
public void testTemporalFilterModifiedSearchStringDates() throws Exception {
    String startDate = null;
    String endDate = null;
    // 30 minutes
    String dateOffset = "1800000";
    TemporalFilter temporalFilter = new TemporalFilter(Long.parseLong(dateOffset));
    LOGGER.debug(temporalFilter.toString());
    OpenSearchQuery query = new OpenSearchQuery(null, 0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
    query.addTemporalFilter(startDate, endDate, dateOffset);
    Filter filter = query.getFilter();
    // String filterXml = getFilterAsXml( filter );
    VerificationVisitor verificationVisitor = new VerificationVisitor();
    filter.accept(verificationVisitor, null);
    HashMap<String, FilterStatus> map = (HashMap<String, FilterStatus>) verificationVisitor.getMap();
    printFilterStatusMap(map);
    List<Filter> filters = getFilters(map, DuringImpl.class.getName());
    assertEquals(1, filters.size());
    verifyTemporalFilter(filters.get(0), temporalFilter.getStartDate().toString(), temporalFilter.getEndDate().toString(), false);
}
Also used : TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) DuringImpl(org.geotools.filter.temporal.DuringImpl) 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) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 5 with TemporalFilter

use of ddf.catalog.impl.filter.TemporalFilter in project ddf by codice.

the class TestOpenSearchSiteUtil method populateTemporal.

@Test
public void populateTemporal() {
    // TODO have actual set time strings to compare to
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    Date start = new Date(System.currentTimeMillis() - 10000000);
    Date end = new Date(System.currentTimeMillis());
    StringBuilder resultStr = new StringBuilder(url);
    TemporalFilter temporal = new TemporalFilter(start, end);
    WebClient webClient = WebClient.create(url.toString());
    OpenSearchSiteUtil.populateTemporal(webClient, temporal, Arrays.asList("q,src,mr,start,count,mt,dn,lat,lon,radius,bbox,polygon,dtstart,dtend,dateName,filter,sort".split(",")));
    String urlStr = webClient.getCurrentURI().toString();
    String startT = fmt.print(start.getTime());
    try {
        assertTrue(urlStr.indexOf(URLEncoder.encode(startT, "UTF-8")) != -1);
    } catch (UnsupportedEncodingException e) {
        fail(e.getMessage());
    }
    String endT = fmt.print(end.getTime());
    try {
        assertTrue(urlStr.indexOf(URLEncoder.encode(endT, "UTF-8")) != -1);
    } catch (UnsupportedEncodingException e) {
        fail(e.getMessage());
    }
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.TIME_START) != -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.TIME_END) != -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.TIME_NAME) == -1);
    try {
        new URL(resultStr.toString());
    } catch (MalformedURLException mue) {
        fail("URL is not valid: " + mue.getMessage());
    }
    LOGGER.info("URL after temporal population: {}", resultStr.toString());
}
Also used : TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) MalformedURLException(java.net.MalformedURLException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Matchers.containsString(org.hamcrest.Matchers.containsString) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) WebClient(org.apache.cxf.jaxrs.client.WebClient) Date(java.util.Date) URL(java.net.URL) Test(org.junit.Test)

Aggregations

TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)15 Test (org.junit.Test)8 Filter (org.opengis.filter.Filter)8 BBoxSpatialFilter (org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter)7 PolygonSpatialFilter (org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter)7 HashMap (java.util.HashMap)5 Date (java.util.Date)4 DuringImpl (org.geotools.filter.temporal.DuringImpl)4 Period (org.opengis.temporal.Period)4 SpatialDistanceFilter (ddf.catalog.impl.filter.SpatialDistanceFilter)3 SpatialFilter (ddf.catalog.impl.filter.SpatialFilter)3 DefaultInstant (org.geotools.temporal.object.DefaultInstant)2 DefaultPeriod (org.geotools.temporal.object.DefaultPeriod)2 DefaultPeriodDuration (org.geotools.temporal.object.DefaultPeriodDuration)2 DefaultPosition (org.geotools.temporal.object.DefaultPosition)2 Literal (org.opengis.filter.expression.Literal)2 Instant (org.opengis.temporal.Instant)2 PeriodDuration (org.opengis.temporal.PeriodDuration)2 PropertyIsEqualToLiteral (ddf.catalog.filter.impl.PropertyIsEqualToLiteral)1 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)1