Search in sources :

Example 31 with FilterFactoryImpl

use of org.geotools.filter.FilterFactoryImpl in project ddf by codice.

the class SolrProviderCreate method testCreateOperation.

/**
 * Testing that if we create a record, it is truly ingested and we can retrieve all the fields we
 * intend to be retrievable.
 */
@Test
public void testCreateOperation() throws IngestException, UnsupportedQueryException {
    deleteAll(provider);
    MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
    create(metacard, provider);
    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>"));
    assertTrue(!mResult.getMetadata().isEmpty());
    assertFalse(mResult.getCreatedDate().after(new Date()));
    assertFalse(mResult.getModifiedDate().after(new Date()));
    assertEquals(metacard.getEffectiveDate(), mResult.getEffectiveDate());
    assertEquals(metacard.getExpirationDate(), mResult.getExpirationDate());
    assertTrue(Arrays.equals(metacard.getThumbnail(), mResult.getThumbnail()));
    assertEquals(metacard.getLocation(), mResult.getLocation());
    assertEquals(MASKED_ID, mResult.getSourceId());
    // --- Simple KEYWORD SEARCH
    filter = filterFactory.like(filterFactory.property(Metacard.METADATA), MockMetacard.DEFAULT_TITLE, DEFAULT_TEST_WILDCARD, DEFAULT_TEST_SINGLE_WILDCARD, DEFAULT_TEST_ESCAPE, false);
    query = new QueryImpl(filter);
    query.setStartIndex(1);
    sourceResponse = provider.query(new QueryRequestImpl(query));
    results = sourceResponse.getResults();
    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());
    assertTrue(!mResult.getMetadata().isEmpty());
    assertFalse(mResult.getCreatedDate().after(new Date()));
    assertFalse(mResult.getModifiedDate().after(new Date()));
    assertEquals(metacard.getEffectiveDate(), mResult.getEffectiveDate());
    assertEquals(metacard.getExpirationDate(), mResult.getExpirationDate());
    assertTrue(Arrays.equals(metacard.getThumbnail(), mResult.getThumbnail()));
    assertEquals(metacard.getLocation(), mResult.getLocation());
    assertEquals(MASKED_ID, mResult.getSourceId());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) FilterFactory(org.opengis.filter.FilterFactory) Date(java.util.Date) Result(ddf.catalog.data.Result) SolrProviderTest(ddf.catalog.source.solr.SolrProviderTest) Test(org.junit.Test)

Example 32 with FilterFactoryImpl

use of org.geotools.filter.FilterFactoryImpl in project ddf by codice.

the class SourceIdFilterVisitorTest method testVisitorContainsSourceIds.

@Test
public void testVisitorContainsSourceIds() {
    Filter filter = buildFilter(SOURCE_IDS);
    filter.accept(sourceIdFilter, new FilterFactoryImpl());
    List<String> result = sourceIdFilter.getSourceIds();
    assertThat(result, containsInAnyOrder(SOURCE_IDS.toArray()));
}
Also used : Filter(org.opengis.filter.Filter) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) Test(org.junit.Test)

Example 33 with FilterFactoryImpl

use of org.geotools.filter.FilterFactoryImpl in project ddf by codice.

the class TestQueryImpl method testSetFilterWithNullFilter.

@Test(expected = IllegalArgumentException.class)
public void testSetFilterWithNullFilter() {
    FilterFactory filterFactory = new FilterFactoryImpl();
    // Dummy filter copied from another test
    Filter filter1 = filterFactory.like(filterFactory.property(Metacard.METADATA), "million", DEFAULT_TEST_WILDCARD, DEFAULT_TEST_SINGLE_WILDCARD, "^", false);
    Filter filter2 = null;
    QueryImpl qi = new QueryImpl(filter1);
    assertEquals(filter1, qi.getFilter());
    qi.setFilter(filter2);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 34 with FilterFactoryImpl

use of org.geotools.filter.FilterFactoryImpl in project ddf by codice.

the class SolrProviderTest method testCreateOperation.

/**
     * Testing that if we create a record, it is truly ingested and we can retrieve all the fields
     * we intend to be retrievable.
     *
     * @throws IngestException
     * @throws UnsupportedQueryException
     */
@Test
public void testCreateOperation() throws IngestException, UnsupportedQueryException {
    deleteAllIn(provider);
    MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
    create(metacard);
    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>"));
    assertTrue(!mResult.getMetadata().isEmpty());
    assertFalse(mResult.getCreatedDate().after(new Date()));
    assertFalse(mResult.getModifiedDate().after(new Date()));
    assertEquals(metacard.getEffectiveDate(), mResult.getEffectiveDate());
    assertEquals(metacard.getExpirationDate(), mResult.getExpirationDate());
    assertTrue(Arrays.equals(metacard.getThumbnail(), mResult.getThumbnail()));
    assertEquals(metacard.getLocation(), mResult.getLocation());
    assertEquals(MASKED_ID, mResult.getSourceId());
    // --- Simple KEYWORD SEARCH
    filter = filterFactory.like(filterFactory.property(Metacard.METADATA), MockMetacard.DEFAULT_TITLE, DEFAULT_TEST_WILDCARD, DEFAULT_TEST_SINGLE_WILDCARD, DEFAULT_TEST_ESCAPE, false);
    query = new QueryImpl(filter);
    query.setStartIndex(1);
    sourceResponse = provider.query(new QueryRequestImpl(query));
    results = sourceResponse.getResults();
    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());
    assertTrue(!mResult.getMetadata().isEmpty());
    assertFalse(mResult.getCreatedDate().after(new Date()));
    assertFalse(mResult.getModifiedDate().after(new Date()));
    assertEquals(metacard.getEffectiveDate(), mResult.getEffectiveDate());
    assertEquals(metacard.getExpirationDate(), mResult.getExpirationDate());
    assertTrue(Arrays.equals(metacard.getThumbnail(), mResult.getThumbnail()));
    assertEquals(metacard.getLocation(), mResult.getLocation());
    assertEquals(MASKED_ID, mResult.getSourceId());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) FilterFactory(org.opengis.filter.FilterFactory) Date(java.util.Date) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 35 with FilterFactoryImpl

use of org.geotools.filter.FilterFactoryImpl in project ddf by codice.

the class SolrProviderTest method testTemporalDuring.

@Test
public void testTemporalDuring() throws Exception {
    deleteAllIn(provider);
    Metacard metacard = new MockMetacard(Library.getFlagstaffRecord());
    List<Metacard> list = Arrays.asList(metacard);
    /** CREATE **/
    create(list);
    /** 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();
    CommonQueryBuilder queryBuilder = new CommonQueryBuilder();
    QueryImpl query = queryBuilder.during(Metacard.MODIFIED, startDT.toDate(), endDT.toDate());
    query.setStartIndex(1);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(1, sourceResponse.getResults().size());
    for (Result content : sourceResponse.getResults()) {
        String term = FLAGSTAFF_QUERY_PHRASE;
        LOGGER.debug("RESULT returned: {}", content);
        String metadata = content.getMetacard().getMetadata();
        assertTrue("Testing if contents has term [" + term + "]", ALL_RESULTS != metadata.indexOf(term));
    }
    /** 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());
    for (Result content : sourceResponse.getResults()) {
        String term = FLAGSTAFF_QUERY_PHRASE;
        LOGGER.debug("RESULT returned: {}", content);
        String metadata = content.getMetacard().getMetadata();
        assertTrue("Testing if contents has term [" + term + "]", ALL_RESULTS != metadata.indexOf(term));
    }
    provider.isAvailable();
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) FilterFactory(org.opengis.filter.FilterFactory) DateTime(org.joda.time.DateTime) DefaultPeriodDuration(org.geotools.temporal.object.DefaultPeriodDuration) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) Test(org.junit.Test)

Aggregations

FilterFactoryImpl (org.geotools.filter.FilterFactoryImpl)58 Test (org.junit.Test)50 FilterFactory (org.opengis.filter.FilterFactory)42 Filter (org.opengis.filter.Filter)39 QueryImpl (ddf.catalog.operation.impl.QueryImpl)35 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)33 SourceResponse (ddf.catalog.operation.SourceResponse)21 Metacard (ddf.catalog.data.Metacard)18 SolrProviderTest (ddf.catalog.source.solr.SolrProviderTest)17 Date (java.util.Date)12 ArrayList (java.util.ArrayList)11 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)9 QueryResponse (ddf.catalog.operation.QueryResponse)9 Result (ddf.catalog.data.Result)8 CreateResponse (ddf.catalog.operation.CreateResponse)8 QueryRequest (ddf.catalog.operation.QueryRequest)8 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)8 Calendar (java.util.Calendar)6 DateTime (org.joda.time.DateTime)6 Ignore (org.junit.Ignore)6