use of ddf.catalog.impl.filter.TemporalFilter in project ddf by codice.
the class OpenSearchQueryTest method testOgcFilterEvaluateContextualLike.
@Test
@Ignore
public void testOgcFilterEvaluateContextualLike() throws Exception {
// String input = "abc_cat_dog_xyz";
String input = "<ns1:thing xmlns:ns1=\"http://ddf.codice.org/mynamespace\">cat</ns1:thing>";
// String searchTerm = "cat";
// List<Filter> filters = new ArrayList<Filter>();
FilterFactory filterFactory = new FilterFactoryImpl();
// Filter filter = filterFactory.like( filterFactory.property( "AnyText" ), searchTerm );
// Filter filter = filterFactory.equal( filterFactory.property( "thing" ),
// filterFactory.literal( searchTerm ), false );
// Filter filter = filterFactory.like( filterFactory.property( Query.ANY_TEXT ), searchTerm,
// "*", "?", "\\" );
// Filter filter = filterFactory.equal( filterFactory.property( Query.ANY_TEXT ),
// searchTerm, false );
// Filter filter = filterFactory.like( filterFactory.property( Query.ANY_TEXT ), searchTerm,
// "*", "?", "\\" );
Calendar.getInstance().getTime();
String startDate = "2011-10-8T05:48:27.891-07:00";
String endDate = "2011-10-10T06:18:27.581-07:00";
TemporalFilter temporalFilter = new TemporalFilter(startDate, endDate);
// WORKS Filter filter = filterFactory.between( filterFactory.literal( new Date() ),
// filterFactory.literal( temporalFilter.getStartDate() ), filterFactory.literal(
// temporalFilter.getEndDate() ) );
Filter filter = filterFactory.between(filterFactory.literal(new Date()), filterFactory.literal(temporalFilter.getStartDate()), filterFactory.literal(temporalFilter.getEndDate()));
FilterTransformer transform = new FilterTransformer();
transform.setIndentation(2);
LOGGER.debug(transform.transform(filter));
// VisualizingVisitor vv = new VisualizingVisitor() ;
// filter.accept(vv, null) ;
// vv.getMap();
boolean result = filter.evaluate(input);
LOGGER.debug("result = {}", result);
// filters.add( filter );
}
use of ddf.catalog.impl.filter.TemporalFilter in project ddf by codice.
the class OpenSearchSource method applyFilters.
private void applyFilters(OpenSearchFilterVisitor visitor, WebClient client) {
TemporalFilter temporalFilter = visitor.getTemporalSearch();
if (temporalFilter != null) {
LOGGER.debug("startDate = {}", temporalFilter.getStartDate());
LOGGER.debug("endDate = {}", temporalFilter.getEndDate());
OpenSearchSiteUtil.populateTemporal(client, temporalFilter, parameters);
}
SpatialFilter spatialFilter = visitor.getSpatialSearch();
if (spatialFilter != null) {
if (spatialFilter instanceof SpatialDistanceFilter) {
try {
OpenSearchSiteUtil.populateGeospatial(client, (SpatialDistanceFilter) spatialFilter, shouldConvertToBBox, parameters);
} catch (UnsupportedQueryException e) {
LOGGER.debug("Problem with populating geospatial criteria. ", e);
}
} else {
try {
OpenSearchSiteUtil.populateGeospatial(client, spatialFilter, shouldConvertToBBox, parameters);
} catch (UnsupportedQueryException e) {
LOGGER.debug("Problem with populating geospatial criteria. ", e);
}
}
}
if (localQueryOnly) {
client.replaceQueryParam(URL_SRC_PARAMETER, LOCAL_SEARCH_PARAMETER);
} else {
client.replaceQueryParam(URL_SRC_PARAMETER, "");
}
}
use of ddf.catalog.impl.filter.TemporalFilter 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 ddf.catalog.impl.filter.TemporalFilter in project ddf by codice.
the class OpenSearchQueryTest method testTemporalFilterModifiedSearchStringDates.
@Test
public void testTemporalFilterModifiedSearchStringDates() throws Exception {
String startDate = null;
String endDate = null;
// 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(startDate, endDate, dateOffset);
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);
}
use of ddf.catalog.impl.filter.TemporalFilter in project ddf by codice.
the class TestOpenSearchSiteUtil method populateTemporal.
@Test
public void populateTemporal() {
// TODO have actual set time strings to compare to
DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
Date start = new Date(System.currentTimeMillis() - 10000000);
Date end = new Date(System.currentTimeMillis());
StringBuilder resultStr = new StringBuilder(url);
TemporalFilter temporal = new TemporalFilter(start, end);
WebClient webClient = WebClient.create(url.toString());
OpenSearchSiteUtil.populateTemporal(webClient, temporal, Arrays.asList("q,src,mr,start,count,mt,dn,lat,lon,radius,bbox,polygon,dtstart,dtend,dateName,filter,sort".split(",")));
String urlStr = webClient.getCurrentURI().toString();
String startT = fmt.print(start.getTime());
try {
assertTrue(urlStr.indexOf(URLEncoder.encode(startT, "UTF-8")) != -1);
} catch (UnsupportedEncodingException e) {
fail(e.getMessage());
}
String endT = fmt.print(end.getTime());
try {
assertTrue(urlStr.indexOf(URLEncoder.encode(endT, "UTF-8")) != -1);
} catch (UnsupportedEncodingException e) {
fail(e.getMessage());
}
assertTrue(urlStr.indexOf(OpenSearchSiteUtil.TIME_START) != -1);
assertTrue(urlStr.indexOf(OpenSearchSiteUtil.TIME_END) != -1);
assertTrue(urlStr.indexOf(OpenSearchSiteUtil.TIME_NAME) == -1);
try {
new URL(resultStr.toString());
} catch (MalformedURLException mue) {
fail("URL is not valid: " + mue.getMessage());
}
LOGGER.info("URL after temporal population: {}", resultStr.toString());
}
Aggregations