Search in sources :

Example 1 with DefaultPeriodDuration

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

the class GeotoolsFilterAdapterImpl method visit.

public Object visit(During during, Object delegate) {
    ExpressionValues filterValues = getExpressions(during, delegate);
    // Absolute
    if (filterValues.literal instanceof Period) {
        Period period = (Period) filterValues.literal;
        Date start = period.getBeginning().getPosition().getDate();
        Date end = period.getEnding().getPosition().getDate();
        return ((FilterDelegate<?>) delegate).during(filterValues.propertyName, start, end);
    // Relative
    } else if (filterValues.literal instanceof DefaultPeriodDuration) {
        // TODO should support PeriodDuration and reconstruct the duration
        // instead of using an implementation to get the milliseconds
        DefaultPeriodDuration duration = (DefaultPeriodDuration) filterValues.literal;
        return ((FilterDelegate<?>) delegate).relative(filterValues.propertyName, duration.getTimeInMillis());
    } else {
        throw new UnsupportedOperationException("Unsupported implementation of Period or PeriodDuration for During filter.");
    }
}
Also used : FilterDelegate(ddf.catalog.filter.FilterDelegate) Period(org.opengis.temporal.Period) Date(java.util.Date) DefaultPeriodDuration(org.geotools.temporal.object.DefaultPeriodDuration)

Example 2 with DefaultPeriodDuration

use of org.geotools.temporal.object.DefaultPeriodDuration 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.valueOf(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.valueOf(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 DefaultPeriodDuration

use of org.geotools.temporal.object.DefaultPeriodDuration 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 DefaultPeriodDuration

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

the class GeotoolsBuilder method build.

//
// /**
// * @param expression the expression to set
// */
// void setExpression(Expression expression) {
// this.expression = expression;
// }
protected Filter build() {
    LOGGER.debug("BUILDING attribute = {}, operator = {}, value = {}, secondaryValue = {}", attribute, operator, value, secondaryValue);
    Filter filter = null;
    String wkt = null;
    Date date = null;
    double distance = 0;
    switch(operator) {
        case AFTER:
            date = getValue(Date.class);
            if (date != null) {
                filter = factory.after(factory.property(attribute), factory.literal(new DefaultInstant(new DefaultPosition(date))));
            }
            break;
        case BEFORE:
            date = getValue(Date.class);
            if (date != null) {
                filter = factory.before(factory.property(attribute), factory.literal(new DefaultInstant(new DefaultPosition(date))));
            }
            break;
        case BETWEEN:
            filter = factory.between(factory.property(attribute), factory.literal(value), factory.literal(secondaryValue));
            break;
        case DURING:
            Date start = getValue(Date.class);
            Date end = getSecondaryValue(Date.class);
            if (start != null && end != null) {
                DefaultPosition defaultPosition = new DefaultPosition(start);
                Instant startInstant = new DefaultInstant(defaultPosition);
                Instant endInstant = new DefaultInstant(new DefaultPosition(end));
                Period period = new DefaultPeriod(startInstant, endInstant);
                filter = factory.during(factory.property(attribute), factory.literal(period));
            }
            break;
        case DURING_RELATIVE:
            Long longValue = getValue(Long.class);
            if (null != value) {
                filter = factory.during(factory.property(attribute), factory.literal(new DefaultPeriodDuration(longValue)));
            }
            break;
        case EQ:
            filter = factory.equals(factory.property(attribute), factory.literal(value));
            break;
        case GT:
            filter = factory.greater(factory.property(attribute), factory.literal(value));
            break;
        case GTE:
            filter = factory.greaterOrEqual(factory.property(attribute), factory.literal(value));
            break;
        case LT:
            filter = factory.less(factory.property(attribute), factory.literal(value));
            break;
        case LTE:
            filter = factory.lessOrEqual(factory.property(attribute), factory.literal(value));
            break;
        case NEQ:
            filter = factory.notEqual(factory.property(attribute), factory.literal(value));
            break;
        case NULL:
            filter = factory.isNull(factory.property(attribute));
            break;
        case TOVERLAPS:
            filter = factory.toverlaps(factory.property(attribute), factory.literal(value));
            break;
        case BEYOND:
            wkt = getValue(String.class);
            distance = getSecondaryValue(Double.class);
            if (wkt != null && wkt.length() > 0) {
                filter = factory.beyond(attribute, toGeometry(wkt), distance, METERS);
            }
            break;
        case CONTAINS:
            wkt = getValue(String.class);
            if (wkt != null && wkt.length() > 0) {
                filter = factory.contains(attribute, toGeometry(wkt));
            }
            break;
        case DWITHIN:
            wkt = getValue(String.class);
            distance = getSecondaryValue(Double.class);
            if (wkt != null && wkt.length() > 0) {
                filter = factory.dwithin(attribute, toGeometry(wkt), distance, METERS);
            }
            break;
        case INTERSECTS:
            wkt = getValue(String.class);
            if (wkt != null && wkt.length() > 0) {
                filter = factory.intersects(attribute, toGeometry(wkt));
            }
            break;
        case WITHIN:
            wkt = getValue(String.class);
            if (wkt != null && wkt.length() > 0) {
                filter = factory.within(attribute, toGeometry(wkt));
            }
            break;
        case LIKE:
            filter = factory.like(factory.property(attribute), getValue(String.class), "*", "%", "'", getSecondaryValue(Boolean.class));
            break;
        case FUZZY:
            Expression expression = factory.property(attribute);
            filter = factory.like(new FuzzyFunction(Arrays.asList(expression), factory.literal(Metacard.ANY_TEXT)), getValue(String.class), "*", "%", "'", getSecondaryValue(Boolean.class));
            break;
        default:
    }
    if (filter == null) {
        throw new IllegalArgumentException("Illegal argument for operation [" + operator.name() + "]");
    }
    return filter;
}
Also used : FuzzyFunction(ddf.catalog.impl.filter.FuzzyFunction) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Instant(org.opengis.temporal.Instant) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Period(org.opengis.temporal.Period) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) Date(java.util.Date) DefaultPeriodDuration(org.geotools.temporal.object.DefaultPeriodDuration) Filter(org.opengis.filter.Filter) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) Expression(org.opengis.filter.expression.Expression) DefaultPosition(org.geotools.temporal.object.DefaultPosition)

Example 5 with DefaultPeriodDuration

use of org.geotools.temporal.object.DefaultPeriodDuration 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

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