use of org.opengis.filter.FilterFactory in project ddf by codice.
the class CatalogFrameworkImplTest method testPostQueryStopExecution.
@Test(expected = FederationException.class)
public void testPostQueryStopExecution() throws UnsupportedQueryException, FederationException, SourceUnavailableException {
BundleContext context = null;
FilterFactory filterFactory = new FilterFactoryImpl();
Filter filter = filterFactory.like(filterFactory.property(Metacard.METADATA), "goodyear", "*", "?", "/", false);
QueryRequest request = new QueryRequestImpl(new QueryImpl(filter));
SourceResponseImpl sourceResponse = new SourceResponseImpl(request, new ArrayList<Result>());
QueryResponseImpl queryResponse = new QueryResponseImpl(sourceResponse, "anyId");
CatalogProvider provider = mock(CatalogProvider.class);
when(provider.query(isA(QueryRequest.class))).thenReturn(sourceResponse);
FederationStrategy federationStrategy = mock(FederationStrategy.class);
when(federationStrategy.federate(isA(List.class), isA(QueryRequest.class))).thenReturn(queryResponse);
PostQueryPlugin stopQueryPlugin = new PostQueryPlugin() {
@Override
public QueryResponse process(QueryResponse input) throws PluginExecutionException, StopProcessingException {
throw new StopProcessingException("Testing that the framework will stop the query.");
}
};
FrameworkProperties props = new FrameworkProperties();
props.setCatalogProviders(Collections.singletonList((CatalogProvider) provider));
props.setBundleContext(context);
props.setPostQuery(Arrays.asList(stopQueryPlugin));
props.setFederationStrategy(federationStrategy);
props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
props.setFilterBuilder(new GeotoolsFilterBuilder());
CatalogFrameworkImpl framework = createFramework(props);
framework.query(request);
}
use of org.opengis.filter.FilterFactory in project ddf by codice.
the class CatalogFrameworkQueryTest method testDuringQuery.
@Test
public void testDuringQuery() {
List<Metacard> metacards = new ArrayList<Metacard>();
MetacardImpl newCard1 = new MetacardImpl();
newCard1.setId(null);
Calendar duringStart = Calendar.getInstance();
Calendar card1Exp = Calendar.getInstance();
card1Exp.add(Calendar.YEAR, 1);
Calendar duringEnd1 = Calendar.getInstance();
duringEnd1.add(Calendar.YEAR, 2);
Calendar card2Exp = Calendar.getInstance();
card2Exp.add(Calendar.YEAR, 3);
Calendar duringEnd2 = Calendar.getInstance();
duringEnd2.add(Calendar.YEAR, 4);
newCard1.setExpirationDate(card1Exp.getTime());
metacards.add(newCard1);
MetacardImpl newCard2 = new MetacardImpl();
newCard2.setId(null);
newCard2.setExpirationDate(card2Exp.getTime());
metacards.add(newCard2);
String mcId1 = null;
String mcId2 = null;
CreateResponse createResponse = null;
try {
createResponse = framework.create(new CreateRequestImpl(metacards, null));
} catch (IngestException e1) {
LOGGER.error("Failure", e1);
fail();
} catch (SourceUnavailableException e1) {
LOGGER.error("Failure", e1);
fail();
}
assertEquals(createResponse.getCreatedMetacards().size(), metacards.size());
for (Metacard curCard : createResponse.getCreatedMetacards()) {
if (curCard.getExpirationDate().equals(card1Exp.getTime())) {
mcId1 = curCard.getId();
} else {
mcId2 = curCard.getId();
}
assertNotNull(curCard.getId());
}
FilterFactory filterFactory = new FilterFactoryImpl();
Period duringPeriod = new DefaultPeriod(new DefaultInstant(new DefaultPosition(duringStart.getTime())), new DefaultInstant(new DefaultPosition(duringEnd1.getTime())));
QueryImpl query = new QueryImpl(filterFactory.during(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(duringPeriod)));
QueryRequest queryReq = new QueryRequestImpl(query, false);
try {
QueryResponse response = framework.query(queryReq);
assertEquals("Expecting return 1 result.", 1, response.getHits());
assertEquals("During filter should return metacard[" + mcId1 + "]", mcId1, response.getResults().get(0).getMetacard().getId());
} catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
LOGGER.error("Failure", e);
fail();
}
duringPeriod = new DefaultPeriod(new DefaultInstant(new DefaultPosition(card1Exp.getTime())), new DefaultInstant(new DefaultPosition(duringEnd2.getTime())));
query = new QueryImpl(filterFactory.during(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(duringPeriod)));
queryReq = new QueryRequestImpl(query, false);
try {
QueryResponse response = framework.query(queryReq);
assertEquals("During filter should return 1 result", 1, response.getHits());
assertEquals("During filter should return metacard[" + mcId2 + "]", mcId2, response.getResults().get(0).getMetacard().getId());
} catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
LOGGER.error("Failure", e);
fail();
}
duringPeriod = new DefaultPeriod(new DefaultInstant(new DefaultPosition(duringStart.getTime())), new DefaultInstant(new DefaultPosition(duringEnd2.getTime())));
query = new QueryImpl(filterFactory.during(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(duringPeriod)));
queryReq = new QueryRequestImpl(query, false);
try {
QueryResponse response = framework.query(queryReq);
assertEquals("During filter should return 2 result", 2, response.getHits());
} catch (UnsupportedQueryException | SourceUnavailableException | FederationException e) {
LOGGER.error("Failure", e);
fail();
}
}
use of org.opengis.filter.FilterFactory in project ddf by codice.
the class SolrProviderSorting method testStartIndexWithSorting.
@Test
public void testStartIndexWithSorting() throws Exception {
deleteAll(provider);
List<Metacard> metacards = new ArrayList<>();
DateTime dt = new DateTime(1985, 1, 1, 1, 1, 1, 1, DateTimeZone.UTC);
TreeSet<Date> calculatedDates = new TreeSet<>();
for (int j = 0; j < 10; j++) {
for (int i = 0; i < 100; i = i + 10) {
MetacardImpl metacard = new MockMetacard(Library.getFlagstaffRecord());
// ingest sporadically the effective dates so the default return
// order won't be ordered
Date calculatedDate = dt.plusDays(100 - i + 10 - j).toDate();
calculatedDates.add(calculatedDate);
metacard.setEffectiveDate(calculatedDate);
metacards.add(metacard);
}
}
// The TreeSet will sort them, the array will give me access to everyone
// without an iterator
Date[] dates = new Date[calculatedDates.size()];
calculatedDates.toArray(dates);
// CREATE
CreateResponse response = create(metacards, provider);
LOGGER.info("CREATED {} records.", response.getCreatedMetacards().size());
FilterFactory filterFactory = new FilterFactoryImpl();
// STARTINDEX=2, MAXSIZE=20
int maxSize = 20;
int startIndex = 2;
SortByImpl sortBy = new SortByImpl(filterFactory.property(Metacard.EFFECTIVE), org.opengis.filter.sort.SortOrder.ASCENDING);
QueryImpl query = query(Metacard.CONTENT_TYPE, MockMetacard.DEFAULT_TYPE, startIndex, maxSize, sortBy);
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(maxSize, sourceResponse.getResults().size());
assertSorting(dates, startIndex, sourceResponse);
// STARTINDEX=20, MAXSIZE=5
// a match-all queryByProperty
maxSize = 5;
startIndex = 20;
sortBy = new SortByImpl(filterFactory.property(Metacard.EFFECTIVE), org.opengis.filter.sort.SortOrder.ASCENDING);
query = query(Metacard.CONTENT_TYPE, MockMetacard.DEFAULT_TYPE, startIndex, maxSize, sortBy);
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(maxSize, sourceResponse.getResults().size());
assertSorting(dates, startIndex, sourceResponse);
// STARTINDEX=80, MAXSIZE=20
// a match-all queryByProperty
maxSize = 20;
startIndex = 80;
sortBy = new SortByImpl(filterFactory.property(Metacard.EFFECTIVE), org.opengis.filter.sort.SortOrder.ASCENDING);
query = query(Metacard.CONTENT_TYPE, MockMetacard.DEFAULT_TYPE, startIndex, maxSize, sortBy);
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(maxSize, sourceResponse.getResults().size());
assertSorting(dates, startIndex, sourceResponse);
// STARTINDEX=1, MAXSIZE=100
// a match-all queryByProperty
maxSize = 100;
startIndex = 1;
sortBy = new SortByImpl(filterFactory.property(Metacard.EFFECTIVE), org.opengis.filter.sort.SortOrder.ASCENDING);
query = query(Metacard.CONTENT_TYPE, MockMetacard.DEFAULT_TYPE, startIndex, maxSize, sortBy);
sourceResponse = provider.query(new QueryRequestImpl(query));
assertEquals(maxSize, sourceResponse.getResults().size());
assertSorting(dates, startIndex, sourceResponse);
}
use of org.opengis.filter.FilterFactory in project ddf by codice.
the class SolrProviderCreate method testCreateOperationWithSourceId.
@Test
public void testCreateOperationWithSourceId() throws IngestException, UnsupportedQueryException {
deleteAll(provider);
MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
String id = UUID.randomUUID().toString();
metacard.setId(id);
metacard.setSourceId("ddfChild");
Date oneDayAgo = new DateTime().minusDays(1).toDate();
metacard.setCreatedDate(oneDayAgo);
metacard.setExpirationDate(oneDayAgo);
metacard.setEffectiveDate(oneDayAgo);
metacard.setModifiedDate(oneDayAgo);
CreateResponse createResponse = create(metacard, provider);
Metacard createdMetacard = createResponse.getCreatedMetacards().get(0);
assertNotNull(createdMetacard.getId());
assertEquals(MockMetacard.DEFAULT_TITLE, createdMetacard.getTitle());
assertEquals(MockMetacard.DEFAULT_LOCATION, createdMetacard.getLocation());
assertEquals(MockMetacard.DEFAULT_TYPE, createdMetacard.getContentTypeName());
assertEquals(MockMetacard.DEFAULT_VERSION, createdMetacard.getContentTypeVersion());
assertNotNull(createdMetacard.getMetadata());
assertThat(createdMetacard.getMetadata(), containsString("<title>Flagstaff Chamber of Commerce</title>"));
assertThat(createdMetacard.getMetadata().isEmpty(), is(not(true)));
assertThat(createdMetacard.getCreatedDate(), is(oneDayAgo));
assertThat(createdMetacard.getModifiedDate(), is(oneDayAgo));
assertThat(createdMetacard.getEffectiveDate(), is(oneDayAgo));
assertThat(createdMetacard.getExpirationDate(), is(oneDayAgo));
assertTrue(Arrays.equals(metacard.getThumbnail(), createdMetacard.getThumbnail()));
assertEquals(metacard.getLocation(), createdMetacard.getLocation());
assertThat(createdMetacard.getSourceId(), is(metacard.getSourceId()));
// --------------------
FilterFactory filterFactory = new FilterFactoryImpl();
// SIMPLE TITLE SEARCH
Filter filter = filterFactory.like(filterFactory.property(Metacard.TITLE), MockMetacard.DEFAULT_TITLE, DEFAULT_TEST_WILDCARD, DEFAULT_TEST_SINGLE_WILDCARD, DEFAULT_TEST_ESCAPE, false);
QueryImpl query = new QueryImpl(filter);
query.setStartIndex(1);
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
List<Result> results = sourceResponse.getResults();
Metacard mResult = results.get(0).getMetacard();
assertEquals(1, results.size());
assertNotNull(mResult.getId());
assertEquals(MockMetacard.DEFAULT_TITLE, mResult.getTitle());
assertEquals(MockMetacard.DEFAULT_LOCATION, mResult.getLocation());
assertEquals(MockMetacard.DEFAULT_TYPE, mResult.getContentTypeName());
assertEquals(MockMetacard.DEFAULT_VERSION, mResult.getContentTypeVersion());
assertNotNull(mResult.getMetadata());
assertThat(mResult.getMetadata(), containsString("<title>Flagstaff Chamber of Commerce</title>"));
assertThat(mResult.getMetadata().isEmpty(), is(not(true)));
assertThat(mResult.getCreatedDate(), is(oneDayAgo));
assertThat(mResult.getModifiedDate(), is(oneDayAgo));
assertThat(mResult.getEffectiveDate(), is(oneDayAgo));
assertThat(mResult.getExpirationDate(), is(oneDayAgo));
assertTrue(Arrays.equals(metacard.getThumbnail(), mResult.getThumbnail()));
assertEquals(metacard.getLocation(), mResult.getLocation());
// assertThat(mResult.getSourceId(), is("ddf"));
}
use of org.opengis.filter.FilterFactory 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();
}
Aggregations