Search in sources :

Example 76 with FilterFactory

use of org.opengis.filter.FilterFactory in project sldeditor by robward-scisys.

the class MultipleFontTest method testParseList.

/**
 * Test method for {@link com.sldeditor.tool.batchupdatefont.MultipleFont#parseList(java.util.List)}. Test method for
 * {@link com.sldeditor.tool.batchupdatefont.MultipleFont#getFont()}.
 */
@Test
public void testParseList() {
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    List<Font> entries = new ArrayList<Font>();
    MultipleFont testObj = new MultipleFont();
    testObj.parseList(null);
    assertNotNull(testObj.getFont());
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    String originalFontname = "Serif";
    String originalFontStyle = "normal";
    String originalFontWeight = "normal";
    int originalFontSize = 24;
    Font font = styleFactory.createFont(ff.literal(originalFontname), ff.literal(originalFontStyle), ff.literal(originalFontWeight), ff.literal(originalFontSize));
    entries.add(font);
    testObj.parseList(entries);
    Font actualFont = testObj.getFont();
    assertNotNull(actualFont.getSize());
    assertNotNull(actualFont.getStyle());
    assertNotNull(actualFont.getWeight());
    assertTrue(!actualFont.getFamily().isEmpty());
    // 2nd font is completely different
    String newFontname = "Serif2";
    String newFontStyle = "italic";
    String newFontWeight = "bold";
    int newFontSize = 25;
    Font font2 = styleFactory.createFont(ff.literal(newFontname), ff.literal(newFontStyle), ff.literal(newFontWeight), ff.literal(newFontSize));
    entries.add(font2);
    testObj.parseList(entries);
    actualFont = testObj.getFont();
    assertNull(actualFont.getSize());
    assertNull(actualFont.getStyle());
    assertNull(actualFont.getWeight());
    assertTrue(actualFont.getFamily().isEmpty());
    // Change family, style, weight and size
    entries.clear();
    entries.add(font);
    Font font3 = styleFactory.createFont(ff.literal(originalFontname), ff.literal(originalFontStyle), ff.literal(originalFontWeight), ff.literal(originalFontSize));
    entries.add(font3);
    testObj.parseList(entries);
    actualFont = testObj.getFont();
    assertNotNull(actualFont.getSize());
    assertNotNull(actualFont.getStyle());
    assertNotNull(actualFont.getWeight());
    assertTrue(!actualFont.getFamily().isEmpty());
}
Also used : StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) ArrayList(java.util.ArrayList) MultipleFont(com.sldeditor.tool.batchupdatefont.MultipleFont) Font(org.geotools.styling.Font) MultipleFont(com.sldeditor.tool.batchupdatefont.MultipleFont) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 77 with FilterFactory

use of org.opengis.filter.FilterFactory in project incubator-rya by apache.

the class GeoWaveGeoIndexer method deleteStatements.

private void deleteStatements(final Collection<RyaStatement> ryaStatements) throws IOException {
    // create a feature collection
    final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
    for (final RyaStatement ryaStatement : ryaStatements) {
        final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
        // if the predicate list is empty, accept all predicates.
        // Otherwise, make sure the predicate is on the "valid" list
        final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
        if (isValidPredicate && (statement.getObject() instanceof Literal)) {
            try {
                final SimpleFeature feature = createFeature(featureType, statement);
                featureCollection.add(feature);
            } catch (final ParseException e) {
                logger.warn("Error getting geo from statement: " + statement.toString(), e);
            }
        }
    }
    // remove this feature collection from the store
    if (!featureCollection.isEmpty()) {
        final Set<Identifier> featureIds = new HashSet<Identifier>();
        final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null);
        final Set<String> stringIds = DataUtilities.fidSet(featureCollection);
        for (final String id : stringIds) {
            featureIds.add(filterFactory.featureId(id));
        }
        final String filterString = stringIds.stream().collect(Collectors.joining("','", "'", "'"));
        Filter filter = null;
        try {
            filter = ECQL.toFilter(GEO_ID_ATTRIBUTE + " IN (" + filterString + ")", filterFactory);
        } catch (final CQLException e) {
            logger.error("Unable to generate filter for deleting the statement.", e);
        }
        featureStore.removeFeatures(filter);
    }
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) SimpleFeature(org.opengis.feature.simple.SimpleFeature) FilterFactory(org.opengis.filter.FilterFactory) Identifier(org.opengis.filter.identity.Identifier) Filter(org.opengis.filter.Filter) Literal(org.openrdf.model.Literal) ParseException(com.vividsolutions.jts.io.ParseException) CQLException(org.geotools.filter.text.cql2.CQLException) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) HashSet(java.util.HashSet)

Example 78 with FilterFactory

use of org.opengis.filter.FilterFactory 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);
}
Also used : TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.endpoint.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) BBoxSpatialFilter(org.codice.ddf.opensearch.endpoint.query.filter.BBoxSpatialFilter) Calendar(java.util.Calendar) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) SimpleDateFormat(java.text.SimpleDateFormat) FilterFactory(org.opengis.filter.FilterFactory) Date(java.util.Date) FilterTransformer(org.geotools.filter.FilterTransformer) Test(org.junit.Test)

Example 79 with FilterFactory

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

the class CatalogFrameworkQueryTest method testAfterQuery.

@Test
public void testAfterQuery() throws Exception {
    Calendar afterCal = Calendar.getInstance();
    Calendar card1Exp = Calendar.getInstance();
    card1Exp.add(Calendar.YEAR, 1);
    Calendar card2Exp = Calendar.getInstance();
    card2Exp.add(Calendar.YEAR, 3);
    List<Metacard> metacards = new ArrayList<Metacard>();
    MetacardImpl newCard1 = new MetacardImpl();
    newCard1.setId(null);
    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;
    createResponse = framework.create(new CreateRequestImpl(metacards, null));
    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();
    Instant afterInstant = new DefaultInstant(new DefaultPosition(afterCal.getTime()));
    QueryImpl query = new QueryImpl(filterFactory.after(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(afterInstant)));
    QueryRequest queryReq = new QueryRequestImpl(query, false);
    try {
        QueryResponse response = framework.query(queryReq);
        LOGGER.info("Response:{}", response);
        assertEquals("Expecting return 2 results.", 2, response.getHits());
    } catch (UnsupportedQueryException e) {
        LOGGER.error("Failure!!!", e);
        fail();
    } catch (FederationException e) {
        fail();
    }
    afterInstant = new DefaultInstant(new DefaultPosition(card1Exp.getTime()));
    query = new QueryImpl(filterFactory.after(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(afterInstant)));
    queryReq = new QueryRequestImpl(query, false);
    try {
        QueryResponse response = framework.query(queryReq);
        assertEquals("After filter should return 1 result", 1, response.getHits());
        assertEquals("After filter should return metacard[" + mcId2 + "]", mcId2, response.getResults().get(0).getMetacard().getId());
    } catch (UnsupportedQueryException e) {
        fail();
    } catch (FederationException e) {
        fail();
    }
    afterInstant = new DefaultInstant(new DefaultPosition(card2Exp.getTime()));
    query = new QueryImpl(filterFactory.after(filterFactory.property(Metacard.EXPIRATION), filterFactory.literal(afterInstant)));
    queryReq = new QueryRequestImpl(query, false);
    try {
        QueryResponse response = framework.query(queryReq);
        assertEquals("After filter should return 0 results.", 0, response.getHits());
    } catch (UnsupportedQueryException e) {
        fail();
    } catch (FederationException e) {
        fail();
    }
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) CreateResponse(ddf.catalog.operation.CreateResponse) Calendar(java.util.Calendar) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Instant(org.opengis.temporal.Instant) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) DefaultInstant(org.geotools.temporal.object.DefaultInstant) FederationException(ddf.catalog.federation.FederationException) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FilterFactory(org.opengis.filter.FilterFactory) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) DefaultPosition(org.geotools.temporal.object.DefaultPosition) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) Test(org.junit.Test)

Example 80 with FilterFactory

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

the class CatalogFrameworkImplTest method testInjectsAttributesOnQuery.

@Test
public void testInjectsAttributesOnQuery() throws Exception {
    final Metacard original = new MetacardImpl();
    final String id = framework.create(new CreateRequestImpl(Collections.singletonList(original), null)).getCreatedMetacards().get(0).getId();
    final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl("new attribute", true, true, false, false, BasicTypes.DOUBLE_TYPE);
    stubMetacardInjection(injectAttribute);
    final FilterFactory filterFactory = new FilterFactoryImpl();
    final Filter filter = filterFactory.equals(filterFactory.property(Metacard.ID), filterFactory.literal(id));
    final QueryRequest request = new QueryRequestImpl(new QueryImpl(filter));
    final QueryResponse response = framework.query(request);
    final Metacard queryMetacard = response.getResults().get(0).getMetacard();
    final MetacardType originalMetacardType = original.getMetacardType();
    final MetacardType queryMetacardType = queryMetacard.getMetacardType();
    assertThat(originalMetacardType.getName(), is(queryMetacardType.getName()));
    final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
    expectedAttributeDescriptors.add(injectAttribute);
    assertThat(queryMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FilterFactory(org.opengis.filter.FilterFactory) MetacardType(ddf.catalog.data.MetacardType) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) HashSet(java.util.HashSet) 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