Search in sources :

Example 46 with FilterFactory

use of org.opengis.filter.FilterFactory 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 47 with FilterFactory

use of org.opengis.filter.FilterFactory 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 48 with FilterFactory

use of org.opengis.filter.FilterFactory 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)

Example 49 with FilterFactory

use of org.opengis.filter.FilterFactory in project ddf by codice.

the class SolrProviderTest method testCreateOperationWithSourceId.

@Test
public void testCreateOperationWithSourceId() throws IngestException, UnsupportedQueryException {
    deleteAllIn(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);
    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"));
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) CreateResponse(ddf.catalog.operation.CreateResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Date(java.util.Date) DateTime(org.joda.time.DateTime) FilterFactory(org.opengis.filter.FilterFactory) 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)

Example 50 with FilterFactory

use of org.opengis.filter.FilterFactory in project ddf by codice.

the class SolrProviderTest method testContextualSimpleWithLogicOperators.

@Test
public void testContextualSimpleWithLogicOperators() throws Exception {
    deleteAllIn(provider);
    MockMetacard m = new MockMetacard(Library.getTampaRecord());
    m.setTitle("Tampa");
    List<Metacard> list = Arrays.asList((Metacard) new MockMetacard(Library.getFlagstaffRecord()), m);
    assertEquals(2, create(list).getCreatedMetacards().size());
    /** CONTEXTUAL QUERY - AND negative **/
    String wildcard = DEFAULT_TEST_WILDCARD;
    String singleChar = DEFAULT_TEST_SINGLE_WILDCARD;
    String escape = DEFAULT_TEST_ESCAPE;
    FilterFactory filterFactory = new FilterFactoryImpl();
    Filter filter = filterFactory.and(filterFactory.like(filterFactory.property(Metacard.METADATA), FLAGSTAFF_QUERY_PHRASE, wildcard, singleChar, escape, false), filterFactory.like(filterFactory.property(Metacard.METADATA), TAMPA_QUERY_PHRASE, wildcard, singleChar, escape, false));
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Flagstaff and Tampa", 0, sourceResponse.getResults().size());
    /** CONTEXTUAL QUERY - AND positive **/
    filter = filterFactory.and(filterFactory.like(filterFactory.property(Metacard.METADATA), FLAGSTAFF_QUERY_PHRASE, wildcard, singleChar, escape, false), filterFactory.like(filterFactory.property(Metacard.METADATA), AIRPORT_QUERY_PHRASE, wildcard, singleChar, escape, false));
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Flagstaff and Airport", ONE_HIT, sourceResponse.getResults().size());
    /** CONTEXTUAL QUERY - OR positive **/
    filter = filterFactory.or(filterFactory.like(filterFactory.property(Metacard.METADATA), FLAGSTAFF_QUERY_PHRASE, wildcard, singleChar, escape, false), filterFactory.like(filterFactory.property(Metacard.METADATA), TAMPA_QUERY_PHRASE, wildcard, singleChar, escape, false));
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Flagstaff OR Tampa", 2, sourceResponse.getResults().size());
    /** CONTEXTUAL QUERY - AND / OR positive **/
    filter = filterFactory.or(filterFactory.and(filterFactory.like(filterFactory.property(Metacard.METADATA), AIRPORT_QUERY_PHRASE, wildcard, singleChar, escape, false), filterFactory.like(filterFactory.property(Metacard.METADATA), "AZ", wildcard, singleChar, escape, false)), filterFactory.like(filterFactory.property(Metacard.METADATA), FLAGSTAFF_QUERY_PHRASE, wildcard, singleChar, escape, false));
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Failed: (Airport AND AZ) or Flagstaff", ONE_HIT, sourceResponse.getResults().size());
    /** COMPLEX CONTEXTUAL QUERY **/
    filter = filterFactory.and(filterFactory.like(filterFactory.property(Metacard.METADATA), AIRPORT_QUERY_PHRASE, wildcard, singleChar, escape, false), filterFactory.and(filterFactory.like(filterFactory.property(Metacard.METADATA), "AZ", wildcard, singleChar, escape, false), filterFactory.or(filterFactory.like(filterFactory.property(Metacard.METADATA), FLAGSTAFF_QUERY_PHRASE, wildcard, singleChar, escape, false), filterFactory.like(filterFactory.property(Metacard.METADATA), TAMPA_QUERY_PHRASE, wildcard, singleChar, escape, false))));
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("(Airport AND (AZ AND (Flagstaff OR TAMPA)))", ONE_HIT, sourceResponse.getResults().size());
    /** CONTEXTUAL QUERY - NOT positive **/
    filter = filterFactory.and(filterFactory.like(filterFactory.property(Metacard.METADATA), FLAGSTAFF_QUERY_PHRASE, wildcard, singleChar, escape, false), filterFactory.not(filterFactory.like(filterFactory.property(Metacard.METADATA), TAMPA_QUERY_PHRASE, wildcard, singleChar, escape, false)));
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Did not find Flagstaff NOT Tampa", ONE_HIT, sourceResponse.getResults().size());
    /** CONTEXTUAL QUERY - NOT negative **/
    filter = filterFactory.and(filterFactory.like(filterFactory.property(Metacard.METADATA), FLAGSTAFF_QUERY_PHRASE, wildcard, singleChar, escape, false), filterFactory.not(filterFactory.like(filterFactory.property(Metacard.METADATA), AIRPORT_QUERY_PHRASE, wildcard, singleChar, escape, false)));
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Wrongly found Flagstaff NOT Airport", 0, sourceResponse.getResults().size());
    /** CONTEXTUAL QUERY - Single NOT positive **/
    filter = filterFactory.not(filterFactory.like(filterFactory.property(Metacard.METADATA), TAMPA_QUERY_PHRASE, wildcard, singleChar, escape, false));
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Did not find Flagstaff", ONE_HIT, sourceResponse.getResults().size());
    assertTrue(sourceResponse.getResults().get(0).getMetacard().getMetadata().contains(FLAGSTAFF_QUERY_PHRASE));
    /** CONTEXTUAL QUERY - NOT multi **/
    LinkedList<Filter> filters = new LinkedList<Filter>();
    filters.add(filterFactory.like(filterFactory.property(Metacard.METADATA), FLAGSTAFF_QUERY_PHRASE, wildcard, singleChar, escape, false));
    filters.add(filterFactory.not(filterFactory.like(filterFactory.property(Metacard.METADATA), TAMPA_QUERY_PHRASE, wildcard, singleChar, escape, false)));
    filters.add(filterFactory.not(filterFactory.like(filterFactory.property(Metacard.METADATA), "Pennsylvania", wildcard, singleChar, escape, false)));
    filter = filterFactory.and(filters);
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Did not find Flagstaff NOT Tampa", ONE_HIT, sourceResponse.getResults().size());
    /** CONTEXTUAL QUERY - AND / OR **/
    filter = filterFactory.or(filterFactory.and(filterFactory.like(filterFactory.property(Metacard.METADATA), AIRPORT_QUERY_PHRASE, wildcard, singleChar, escape, false), filterFactory.like(filterFactory.property(Metacard.METADATA), "AZ", wildcard, singleChar, escape, false)), filterFactory.or(filterFactory.like(filterFactory.property(Metacard.METADATA), FLAGSTAFF_QUERY_PHRASE, wildcard, singleChar, escape, false), filterFactory.like(filterFactory.property(Metacard.METADATA), "AZ", wildcard, singleChar, escape, false)));
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Failed: ( Airport )  AND  ( AZ )  OR  ( Flagstaff )  OR  ( AZ ) ", ONE_HIT, sourceResponse.getResults().size());
    /** CONTEXTUAL QUERY - OR Then NOT **/
    filter = filterFactory.or(filterFactory.like(filterFactory.property(Metacard.METADATA), FLAGSTAFF_QUERY_PHRASE, wildcard, singleChar, escape, false), filterFactory.and(filterFactory.like(filterFactory.property(Metacard.METADATA), "AZ", wildcard, singleChar, escape, false), filterFactory.not(filterFactory.like(filterFactory.property(Metacard.METADATA), TAMPA_QUERY_PHRASE, wildcard, singleChar, escape, false))));
    sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Failed: ( Flagstaff )  OR  ( AZ )  NOT  (  ( Tampa )  )  ", ONE_HIT, sourceResponse.getResults().size());
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) FilterFactory(org.opengis.filter.FilterFactory) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

FilterFactory (org.opengis.filter.FilterFactory)88 Test (org.junit.Test)72 FilterFactoryImpl (org.geotools.filter.FilterFactoryImpl)42 Filter (org.opengis.filter.Filter)38 QueryImpl (ddf.catalog.operation.impl.QueryImpl)33 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)30 Expression (org.opengis.filter.expression.Expression)24 SourceResponse (ddf.catalog.operation.SourceResponse)21 ArrayList (java.util.ArrayList)18 Metacard (ddf.catalog.data.Metacard)17 SolrProviderTest (ddf.catalog.source.solr.SolrProviderTest)17 ContrastEnhancement (org.geotools.styling.ContrastEnhancement)12 SelectedChannelType (org.geotools.styling.SelectedChannelType)12 Date (java.util.Date)11 StyleFactoryImpl (org.geotools.styling.StyleFactoryImpl)11 ChannelSelection (org.geotools.styling.ChannelSelection)10 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)8 Result (ddf.catalog.data.Result)8 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)8 QueryResponse (ddf.catalog.operation.QueryResponse)8