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.");
}
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations