Search in sources :

Example 41 with FilterFactoryImpl

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

the class TestPubSubOgcFilter method testContextualEvaluate.

@Test
@Ignore
public void testContextualEvaluate() throws TransformerException {
    FilterFactory filterFactory = new FilterFactoryImpl();
    Filter filter = filterFactory.like(filterFactory.literal("abcdef"), "abcdef");
    printFilter(filter);
    assertTrue(filter.evaluate(null));
    Filter filter2 = filterFactory.like(filterFactory.literal("123456"), "123456abc");
    assertFalse(filter2.evaluate(null));
}
Also used : Filter(org.opengis.filter.Filter) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) FilterFactory(org.opengis.filter.FilterFactory) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 42 with FilterFactoryImpl

use of org.geotools.filter.FilterFactoryImpl in project incubator-rya by apache.

the class GeoWaveFeatureReaderTest method testBBOX.

@Test
public void testBBOX() throws IllegalArgumentException, NoSuchElementException, IOException {
    final FilterFactoryImpl factory = new FilterFactoryImpl();
    final Query query = new Query("GeoWaveFeatureReaderTest", factory.bbox("", -180, -90, 180, 90, "EPSG:4326"), new String[] { "geometry", "pid" });
    final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
    int count = 0;
    while (reader.hasNext()) {
        final SimpleFeature feature = reader.next();
        assertTrue(fids.contains(feature.getID()));
        count++;
    }
    assertTrue(count > 0);
}
Also used : Query(org.geotools.data.Query) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 43 with FilterFactoryImpl

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

the class CswRecordMapperFilterVisitorTest method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    factory = new FilterFactoryImpl();
    attrExpr = factory.property(new NameImpl(new QName(CswConstants.DUBLIN_CORE_SCHEMA, UNMAPPED_PROPERTY, CswConstants.DUBLIN_CORE_NAMESPACE_PREFIX)));
    created = new AttributeExpressionImpl(new NameImpl(new QName(CswConstants.DUBLIN_CORE_SCHEMA, Core.CREATED, CswConstants.DUBLIN_CORE_NAMESPACE_PREFIX)));
    attributeRegistry = new AttributeRegistryImpl();
    attributeRegistry.registerMetacardType(CswQueryFactoryTest.getCswMetacardType());
    visitor = new CswRecordMapperFilterVisitor(DEFAULT_CSW_RECORD_MAP, attributeRegistry);
}
Also used : NameImpl(org.geotools.feature.NameImpl) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) QName(javax.xml.namespace.QName) AttributeRegistryImpl(ddf.catalog.data.impl.AttributeRegistryImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) BeforeClass(org.junit.BeforeClass)

Example 44 with FilterFactoryImpl

use of org.geotools.filter.FilterFactoryImpl 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);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FilterFactory(org.opengis.filter.FilterFactory) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(org.geotools.filter.SortByImpl) TreeSet(java.util.TreeSet) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) SolrProviderTest(ddf.catalog.source.solr.SolrProviderTest) Test(org.junit.Test)

Example 45 with FilterFactoryImpl

use of org.geotools.filter.FilterFactoryImpl 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"));
}
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) SolrProviderTest(ddf.catalog.source.solr.SolrProviderTest) 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