use of ddf.catalog.impl.filter.TemporalFilter in project ddf by codice.
the class MockQuery method addTemporalFilter.
public void addTemporalFilter(TemporalFilter temporalFilter) {
if (temporalFilter != null) {
// t1.start < timeType instance < t1.end
Instant startInstant = new DefaultInstant(new DefaultPosition(temporalFilter.getStartDate()));
Instant endInstant = new DefaultInstant(new DefaultPosition(temporalFilter.getEndDate()));
Period period = new DefaultPeriod(startInstant, endInstant);
Filter filter = FILTER_FACTORY.during(FILTER_FACTORY.property(MODIFIED_DATE), FILTER_FACTORY.literal(period));
filters.add(filter);
this.filter = getFilter();
}
}
use of ddf.catalog.impl.filter.TemporalFilter 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);
}
}
use of ddf.catalog.impl.filter.TemporalFilter in project ddf by codice.
the class OpenSearchQuery method addTemporalFilter.
public void addTemporalFilter(TemporalFilter temporalFilter) {
String methodName = "addTemporalFilter";
if (temporalFilter != null) {
// t1.start < timeType instance < t1.end
Instant startInstant = new DefaultInstant(new DefaultPosition(temporalFilter.getStartDate()));
Instant endInstant = new DefaultInstant(new DefaultPosition(temporalFilter.getEndDate()));
Period period = new DefaultPeriod(startInstant, endInstant);
Filter filter = FILTER_FACTORY.during(FILTER_FACTORY.property(Metacard.MODIFIED), FILTER_FACTORY.literal(period));
LOGGER.debug("Adding temporal filter");
filters.add(filter);
}
}
use of ddf.catalog.impl.filter.TemporalFilter in project ddf by codice.
the class OpenSearchQuery method addTemporalFilter.
public void addTemporalFilter(String dateStart, String dateEnd, String dateOffset) {
String methodName = "addTemporalFilter";
TemporalFilter temporalFilter = null;
// a temporal filter can be created
if ((dateStart != null && !dateStart.trim().isEmpty()) || (dateEnd != null && !dateEnd.trim().isEmpty())) {
temporalFilter = new TemporalFilter(dateStart, dateEnd);
} else if (dateOffset != null && !dateOffset.trim().isEmpty()) {
temporalFilter = new TemporalFilter(Long.parseLong(dateOffset));
}
addTemporalFilter(temporalFilter);
}
use of ddf.catalog.impl.filter.TemporalFilter in project ddf by codice.
the class OpenSearchQueryTest method testTemporalFilterModifiedSearch.
@Test
public void testTemporalFilterModifiedSearch() throws Exception {
// 30 minutes
String dateOffset = "1800000";
TemporalFilter temporalFilter = new TemporalFilter(Long.parseLong(dateOffset));
LOGGER.debug(temporalFilter.toString());
OpenSearchQuery query = new OpenSearchQuery(null, 0, 10, "relevance", "desc", 30000, FILTER_BUILDER);
query.addTemporalFilter(temporalFilter);
Filter filter = query.getFilter();
// String filterXml = getFilterAsXml( filter );
VerificationVisitor verificationVisitor = new VerificationVisitor();
filter.accept(verificationVisitor, null);
HashMap<String, FilterStatus> map = (HashMap<String, FilterStatus>) verificationVisitor.getMap();
printFilterStatusMap(map);
List<Filter> filters = getFilters(map, DuringImpl.class.getName());
assertEquals(1, filters.size());
verifyTemporalFilter(filters.get(0), temporalFilter.getStartDate().toString(), temporalFilter.getEndDate().toString(), false);
}
Aggregations