Search in sources :

Example 1 with PeriodDuration

use of org.opengis.temporal.PeriodDuration 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 2 with PeriodDuration

use of org.opengis.temporal.PeriodDuration in project ddf by codice.

the class SubscriptionFilterVisitor method visit.

/**
 * During filter maps to a Temporal (Absolute and Modified) search criteria.
 */
@Override
public Object visit(During filter, Object data) {
    LOGGER.debug("ENTERING: During filter");
    AttributeExpressionImpl temporalTypeAttribute = (AttributeExpressionImpl) filter.getExpression1();
    String temporalType = temporalTypeAttribute.getPropertyName();
    LiteralExpressionImpl timePeriodLiteral = (LiteralExpressionImpl) filter.getExpression2();
    Object literal = timePeriodLiteral.getValue();
    Predicate returnPredicate = null;
    if (literal instanceof Period) {
        Period timePeriod = (Period) literal;
        // Extract the start and end dates from the OGC TOverlaps filter
        Date start = timePeriod.getBeginning().getPosition().getDate();
        Date end = timePeriod.getEnding().getPosition().getDate();
        LOGGER.debug("time period lowerBound = {}", start);
        LOGGER.debug("time period upperBound = {}", end);
        LOGGER.debug("EXITING: (temporal) filter");
        returnPredicate = new TemporalPredicate(start, end, DateType.getDateType(temporalType));
    // CREATE RELATIVE
    } else if (literal instanceof PeriodDuration) {
        DefaultPeriodDuration duration = (DefaultPeriodDuration) literal;
        long offset = duration.getTimeInMillis();
        LOGGER.debug("EXITING: (temporal) filter");
        returnPredicate = new TemporalPredicate(offset, DateType.getDateType(temporalType));
    }
    LOGGER.debug("temporalType: {}", temporalType);
    LOGGER.debug("Temporal Predicate: {}", returnPredicate);
    LOGGER.debug("EXITING: During filter");
    return returnPredicate;
}
Also used : TemporalPredicate(ddf.catalog.pubsub.predicate.TemporalPredicate) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) 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) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) EntryPredicate(ddf.catalog.pubsub.predicate.EntryPredicate) TemporalPredicate(ddf.catalog.pubsub.predicate.TemporalPredicate) ContextualPredicate(ddf.catalog.pubsub.predicate.ContextualPredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate)

Example 3 with PeriodDuration

use of org.opengis.temporal.PeriodDuration in project ddf by codice.

the class TwitterFilterVisitor method handleTemporal.

private void handleTemporal(BinaryTemporalOperator filter) {
    Literal literalWrapper = (Literal) filter.getExpression2();
    LOGGER.debug("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) 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)

Aggregations

Date (java.util.Date)3 DefaultPeriodDuration (org.geotools.temporal.object.DefaultPeriodDuration)3 Period (org.opengis.temporal.Period)3 PeriodDuration (org.opengis.temporal.PeriodDuration)3 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)2 Literal (org.opengis.filter.expression.Literal)2 PropertyIsEqualToLiteral (ddf.catalog.filter.impl.PropertyIsEqualToLiteral)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 TemporalPredicate (ddf.catalog.pubsub.predicate.TemporalPredicate)1 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)1 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)1