use of org.geotools.filter.FilterFactoryImpl in project ddf by codice.
the class SolrProviderTemporal method testTemporalDuring.
@Test
public void testTemporalDuring() throws Exception {
deleteAll(provider);
Metacard metacard = new MockMetacard(Library.getFlagstaffRecord());
List<Metacard> list = Collections.singletonList(metacard);
// CREATE
create(list, provider);
// TEMPORAL QUERY - DURING FILTER (Period) - AKA ABSOLUTE
FilterFactory filterFactory = new FilterFactoryImpl();
int minutes = 3;
DateTime startDT = new DateTime().plusMinutes(ALL_RESULTS * minutes);
DateTime endDT = new DateTime();
QueryImpl query = new QueryImpl(getFilterBuilder().attribute(Metacard.MODIFIED).is().during().dates(startDT.toDate(), endDT.toDate()));
query.setStartIndex(1);
query.setRequestsTotalResultsCount(true);
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(1, sourceResponse.getResults().size());
assertContainsTerm(sourceResponse);
// TEMPORAL QUERY - DURING FILTER (Duration) - AKA RELATIVE
DefaultPeriodDuration duration = new DefaultPeriodDuration(minutes * MINUTES_IN_MILLISECONDS);
Filter filter = filterFactory.during(filterFactory.property(Metacard.MODIFIED), filterFactory.literal(duration));
query = new QueryImpl(filter);
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(1, sourceResponse.getResults().size());
assertContainsTerm(sourceResponse);
provider.isAvailable();
}
use of org.geotools.filter.FilterFactoryImpl in project ddf by codice.
the class SolrProviderQuery method contextualLogicalComplex.
@Test
public void contextualLogicalComplex() throws UnsupportedQueryException, IngestException {
createContextualMetacards();
FilterFactory filterFactory = new FilterFactoryImpl();
Filter filter = filterFactory.and(filterFactory.like(filterFactory.property(Metacard.METADATA), Library.AIRPORT_QUERY_PHRASE, DEFAULT_TEST_WILDCARD, DEFAULT_TEST_SINGLE_WILDCARD, DEFAULT_TEST_ESCAPE, false), filterFactory.and(filterFactory.like(filterFactory.property(Metacard.METADATA), "AZ", DEFAULT_TEST_WILDCARD, DEFAULT_TEST_SINGLE_WILDCARD, DEFAULT_TEST_ESCAPE, false), filterFactory.or(filterFactory.like(filterFactory.property(Metacard.METADATA), Library.FLAGSTAFF_QUERY_PHRASE, DEFAULT_TEST_WILDCARD, DEFAULT_TEST_SINGLE_WILDCARD, DEFAULT_TEST_ESCAPE, false), filterFactory.like(filterFactory.property(Metacard.METADATA), Library.TAMPA_QUERY_PHRASE, DEFAULT_TEST_WILDCARD, DEFAULT_TEST_SINGLE_WILDCARD, DEFAULT_TEST_ESCAPE, false))));
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
assertEquals("(Airport AND (AZ AND (Flagstaff OR TAMPA)))", ONE_HIT, sourceResponse.getResults().size());
}
use of org.geotools.filter.FilterFactoryImpl in project ddf by codice.
the class SolrProviderQuery method contextualLogicalAndPositiveCase.
@Test
public void contextualLogicalAndPositiveCase() throws UnsupportedQueryException, IngestException {
createContextualMetacards();
FilterFactory filterFactory = new FilterFactoryImpl();
Filter filter = filterFactory.and(filterFactory.like(filterFactory.property(Metacard.METADATA), Library.FLAGSTAFF_QUERY_PHRASE, DEFAULT_TEST_WILDCARD, DEFAULT_TEST_SINGLE_WILDCARD, DEFAULT_TEST_ESCAPE, false), filterFactory.like(filterFactory.property(Metacard.METADATA), Library.AIRPORT_QUERY_PHRASE, DEFAULT_TEST_WILDCARD, DEFAULT_TEST_SINGLE_WILDCARD, DEFAULT_TEST_ESCAPE, false));
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
assertEquals("Flagstaff and Airport", ONE_HIT, sourceResponse.getResults().size());
}
use of org.geotools.filter.FilterFactoryImpl in project ddf by codice.
the class CswSourceTest method testAbsoluteTemporalSearchTwoRanges.
@Test
public void testAbsoluteTemporalSearchTwoRanges() throws JAXBException, UnsupportedQueryException, DatatypeConfigurationException, SAXException, IOException, SecurityServiceException {
// Setup
String expectedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n" + "<GetRecords resultType=\"results\" outputFormat=\"application/xml\"\r\n" + " outputSchema=\"http://www.opengis.net/cat/csw/2.0.2\" startPosition=\"1\"\r\n" + " maxRecords=\"10\" service=\"CSW\" version=\"2.0.2\"" + " xmlns=\"http://www.opengis.net/cat/csw/2.0.2\"" + " xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\"" + " xmlns:ogc=\"http://www.opengis.net/ogc\">\r\n" + " <Query typeNames=\"csw:Record\">\r\n" + " <ElementSetName>full</ElementSetName>\r\n" + " <Constraint version=\"1.1.0\">\r\n" + " <ogc:Filter>\r\n" + " <ogc:Or>\r\n" + " <ogc:PropertyIsBetween>\r\n" + " <ogc:PropertyName>effective</ogc:PropertyName>\r\n" + " <ogc:LowerBoundary>\r\n" + " <ogc:Literal>START1_DATE_TIME</ogc:Literal>\r\n" + " </ogc:LowerBoundary>\r\n" + " <ogc:UpperBoundary>\r\n" + " <ogc:Literal>END1_DATE_TIME</ogc:Literal>\r\n" + " </ogc:UpperBoundary>\r\n" + " </ogc:PropertyIsBetween>\r\n" + " <ogc:PropertyIsBetween>\r\n" + " <ogc:PropertyName>effective</ogc:PropertyName>\r\n" + " <ogc:LowerBoundary>\r\n" + " <ogc:Literal>START2_DATE_TIME</ogc:Literal>\r\n" + " </ogc:LowerBoundary>\r\n" + " <ogc:UpperBoundary>\r\n" + " <ogc:Literal>END2_DATE_TIME</ogc:Literal>\r\n" + " </ogc:UpperBoundary>\r\n" + " </ogc:PropertyIsBetween>\r\n" + " </ogc:Or>\r\n" + " </ogc:Filter>\r\n" + " </Constraint>\r\n" + " </Query>\r\n" + "</GetRecords>\r\n";
final int pageSize = 10;
final int numRecordsReturned = 1;
final long numRecordsMatched = 10;
setupMockContextForMetacardTypeRegistrationAndUnregistration(getDefaultContentTypes());
try {
configureMockCsw(numRecordsReturned, numRecordsMatched, CswConstants.VERSION_2_0_2);
} catch (CswException e) {
fail("Could not configure Mock Remote CSW: " + e.getMessage());
}
DateTime startDate = new DateTime(2012, 5, 1, 0, 0, 0, 0);
DateTime endDate = new DateTime(2012, 12, 31, 0, 0, 0, 0);
DateTime startDate2 = new DateTime(2013, 5, 1, 0, 0, 0, 0);
DateTime endDate2 = new DateTime(2013, 12, 31, 0, 0, 0, 0);
DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
// Load the expected start and end date time into the excepted result
// XML
expectedXml = expectedXml.replace("START1_DATE_TIME", fmt.print(startDate));
expectedXml = expectedXml.replace("END1_DATE_TIME", fmt.print(endDate));
expectedXml = expectedXml.replace("START2_DATE_TIME", fmt.print(startDate2));
expectedXml = expectedXml.replace("END2_DATE_TIME", fmt.print(endDate2));
// Single absolute time range to search across
FilterFactory filterFactory = new FilterFactoryImpl();
Filter temporalFilter1 = builder.attribute(Metacard.EFFECTIVE).is().during().dates(startDate.toDate(), endDate.toDate());
Filter temporalFilter2 = builder.attribute(Metacard.EFFECTIVE).is().during().dates(startDate2.toDate(), endDate2.toDate());
Filter temporalFilter = filterFactory.or(temporalFilter1, temporalFilter2);
QueryImpl temporalQuery = new QueryImpl(temporalFilter);
temporalQuery.setPageSize(pageSize);
AbstractCswSource cswSource = getCswSource(mockCsw, mockContext);
cswSource.setCswUrl(URL);
cswSource.setId(ID);
// Perform test
cswSource.query(getQueryRequestWithSubject(temporalQuery));
// Verify
ArgumentCaptor<GetRecordsType> captor = ArgumentCaptor.forClass(GetRecordsType.class);
try {
verify(mockCsw, atLeastOnce()).getRecords(captor.capture());
} catch (CswException e) {
fail("Could not verify Mock CSW record count " + e.getMessage());
}
GetRecordsType getRecordsType = captor.getValue();
String xml = getGetRecordsTypeAsXml(getRecordsType);
Diff xmlDiff = new Diff(expectedXml, xml);
if (!xmlDiff.similar()) {
LOGGER.error("Unexpected XML request sent");
LOGGER.error("Expected: {}", expectedXml);
LOGGER.error("Actual: {}", xml);
}
assertXMLEqual(expectedXml, xml);
}
use of org.geotools.filter.FilterFactoryImpl in project ddf by codice.
the class OpenSearchQueryTest method testOgcFilterEvaluateTemporalBetween.
@Test
public // @Ignore
void testOgcFilterEvaluateTemporalBetween() throws Exception {
FilterFactory filterFactory = new FilterFactoryImpl();
// get a calendar instance, which defaults to "now"
Calendar calendar = Calendar.getInstance();
// get a date to represent "today"
Date now = calendar.getTime();
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
String dateInRange = dateFormatter.format(now);
// set calendar time in past to create start date for temporal filter's criteria
calendar.add(Calendar.DAY_OF_YEAR, -1);
Date start = calendar.getTime();
String startDate = dateFormatter.format(start);
LOGGER.debug("startDate = {}", startDate);
// set calendar time in future to create end date for temporal filter's criteria
calendar.add(Calendar.DAY_OF_YEAR, +3);
Date end = calendar.getTime();
String endDate = dateFormatter.format(end);
LOGGER.debug("endDate = {}", endDate);
// Test date between start and end dates
Filter filter = filterFactory.between(filterFactory.literal(dateInRange), filterFactory.literal(startDate), filterFactory.literal(endDate));
FilterTransformer transform = new FilterTransformer();
transform.setIndentation(2);
LOGGER.debug(transform.transform(filter));
boolean result = filter.evaluate(null);
LOGGER.debug("result = {}", result);
assertTrue(result);
// Test date that is after end date
calendar.add(Calendar.DAY_OF_YEAR, +3);
Date outOfRange = calendar.getTime();
String outOfRangeDate = dateFormatter.format(outOfRange);
filter = filterFactory.between(filterFactory.literal(outOfRangeDate), filterFactory.literal(startDate), filterFactory.literal(endDate));
LOGGER.debug(transform.transform(filter));
result = filter.evaluate(null);
LOGGER.debug("result = {}", result);
assertFalse(result);
// Test date that is before start date
calendar.add(Calendar.DAY_OF_YEAR, -20);
Date outOfRange2 = calendar.getTime();
String outOfRangeDate2 = dateFormatter.format(outOfRange2);
filter = filterFactory.between(filterFactory.literal(outOfRangeDate2), filterFactory.literal(startDate), filterFactory.literal(endDate));
LOGGER.debug(transform.transform(filter));
result = filter.evaluate(null);
LOGGER.debug("result = {}", result);
assertFalse(result);
// Test date that is equal to start date
filter = filterFactory.between(filterFactory.literal(startDate), filterFactory.literal(startDate), filterFactory.literal(endDate));
LOGGER.debug(transform.transform(filter));
result = filter.evaluate(null);
LOGGER.debug("result = {}", result);
assertTrue(result);
// Test date that is equal to end date
filter = filterFactory.between(filterFactory.literal(endDate), filterFactory.literal(startDate), filterFactory.literal(endDate));
LOGGER.debug(transform.transform(filter));
result = filter.evaluate(null);
LOGGER.debug("result = {}", result);
assertTrue(result);
}
Aggregations