Search in sources :

Example 6 with DefaultPeriodDuration

use of org.geotools.temporal.object.DefaultPeriodDuration in project ddf by codice.

the class SolrProviderTest method testTemporalDuring.

@Test
public void testTemporalDuring() throws Exception {
    deleteAllIn(provider);
    Metacard metacard = new MockMetacard(Library.getFlagstaffRecord());
    List<Metacard> list = Arrays.asList(metacard);
    /** CREATE **/
    create(list);
    /** TEMPORAL QUERY - DURING FILTER (Period) - AKA ABSOLUTE **/
    FilterFactory filterFactory = new FilterFactoryImpl();
    int minutes = 3;
    DateTime startDT = new DateTime().plusMinutes(ALL_RESULTS * minutes);
    DateTime endDT = new DateTime();
    CommonQueryBuilder queryBuilder = new CommonQueryBuilder();
    QueryImpl query = queryBuilder.during(Metacard.MODIFIED, startDT.toDate(), endDT.toDate());
    query.setStartIndex(1);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(1, sourceResponse.getResults().size());
    for (Result content : sourceResponse.getResults()) {
        String term = FLAGSTAFF_QUERY_PHRASE;
        LOGGER.debug("RESULT returned: {}", content);
        String metadata = content.getMetacard().getMetadata();
        assertTrue("Testing if contents has term [" + term + "]", ALL_RESULTS != metadata.indexOf(term));
    }
    /** TEMPORAL QUERY - DURING FILTER (Duration) - AKA RELATIVE **/
    DefaultPeriodDuration duration = new DefaultPeriodDuration(minutes * MINUTES_IN_MILLISECONDS);
    Filter filter = filterFactory.during(filterFactory.property(Metacard.MODIFIED), filterFactory.literal(duration));
    query = new QueryImpl(filter);
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(1, sourceResponse.getResults().size());
    for (Result content : sourceResponse.getResults()) {
        String term = FLAGSTAFF_QUERY_PHRASE;
        LOGGER.debug("RESULT returned: {}", content);
        String metadata = content.getMetacard().getMetadata();
        assertTrue("Testing if contents has term [" + term + "]", ALL_RESULTS != metadata.indexOf(term));
    }
    provider.isAvailable();
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) FilterFactory(org.opengis.filter.FilterFactory) DateTime(org.joda.time.DateTime) DefaultPeriodDuration(org.geotools.temporal.object.DefaultPeriodDuration) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) Test(org.junit.Test)

Aggregations

DefaultPeriodDuration (org.geotools.temporal.object.DefaultPeriodDuration)6 Date (java.util.Date)5 Period (org.opengis.temporal.Period)5 PeriodDuration (org.opengis.temporal.PeriodDuration)3 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)2 Filter (org.opengis.filter.Filter)2 Literal (org.opengis.filter.expression.Literal)2 Metacard (ddf.catalog.data.Metacard)1 Result (ddf.catalog.data.Result)1 FilterDelegate (ddf.catalog.filter.FilterDelegate)1 PropertyIsEqualToLiteral (ddf.catalog.filter.impl.PropertyIsEqualToLiteral)1 FuzzyFunction (ddf.catalog.impl.filter.FuzzyFunction)1 SourceResponse (ddf.catalog.operation.SourceResponse)1 QueryImpl (ddf.catalog.operation.impl.QueryImpl)1 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)1 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)1 ContextualPredicate (ddf.catalog.pubsub.predicate.ContextualPredicate)1 EntryPredicate (ddf.catalog.pubsub.predicate.EntryPredicate)1 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)1 Predicate (ddf.catalog.pubsub.predicate.Predicate)1