Search in sources :

Example 1 with DuringImpl

use of org.geotools.filter.temporal.DuringImpl in project ddf by codice.

the class OpenSearchQueryTest method verifyTemporalFilter.

private void verifyTemporalFilter(Filter filter, String expectedStartDate, String expectedEndDate, boolean reformatDates) throws Exception {
    DuringImpl duringFilter = (DuringImpl) filter;
    // The TOverlaps temporal range is wrapped in a <Literal> element, so have to
    // get expression as literal and then evaluate it to get the
    // temporal data.
    // Example:
    // <ogc:TOverlaps>
    // <ogc:PropertyName>modifiedDate</ogc:PropertyName>
    // <ogc:Literal>Period:
    // begin:Instant:
    // position:Position:
    // position:Tue Oct 04 05:48:27 MST 2011
    //
    //
    // end:Instant:
    // position:Position:
    // position:Tue Oct 04 06:18:27 MST 2011
    //
    //
    // </ogc:Literal>
    // </ogc:TOverlaps>
    Literal literalWrapper = (Literal) duringFilter.getExpression2();
    // Luckily we know what type the temporal expression should be, so we can cast it
    Period period = (Period) literalWrapper.evaluate(null);
    // Extract the start and end dates from the filter
    Date start = period.getBeginning().getPosition().getDate();
    Date end = period.getEnding().getPosition().getDate();
    if (reformatDates) {
        String formattedStartDate = reformatDate(start);
        String formattedEndDate = reformatDate(end);
        LOGGER.debug("startDate = {}", formattedStartDate);
        LOGGER.debug("endDate = {}", formattedEndDate);
        assertEquals(expectedStartDate, formattedStartDate);
        assertEquals(expectedEndDate, formattedEndDate);
    } else {
        assertEquals(expectedStartDate, start.toString());
        assertEquals(expectedEndDate, end.toString());
    }
}
Also used : DuringImpl(org.geotools.filter.temporal.DuringImpl) Literal(org.opengis.filter.expression.Literal) Period(org.opengis.temporal.Period) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 DuringImpl (org.geotools.filter.temporal.DuringImpl)1 Literal (org.opengis.filter.expression.Literal)1 Period (org.opengis.temporal.Period)1