Search in sources :

Example 51 with FilterFactory

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

the class SolrProviderTest method testCreateMultivaluedAttribute.

/**
     * Tests that multivalued attributes are stored and returned
     *
     * @throws UnsupportedQueryException
     * @throws IngestException
     */
@Test
public void testCreateMultivaluedAttribute() throws UnsupportedQueryException, IngestException {
    deleteAllIn(provider);
    FilterFactory filterFactory = new FilterFactoryImpl();
    MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
    List<Serializable> a = new ArrayList<>();
    a.add("sample-validator");
    a.add("sample-validator2");
    AttributeImpl attribute = new AttributeImpl(Validation.VALIDATION_WARNINGS, a);
    metacard.setAttribute(attribute);
    create(metacard);
    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();
    assertThat(mResult.getAttribute(Validation.VALIDATION_WARNINGS).getValues().size(), is(2));
}
Also used : Serializable(java.io.Serializable) SourceResponse(ddf.catalog.operation.SourceResponse) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) FilterFactory(org.opengis.filter.FilterFactory) Result(ddf.catalog.data.Result) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) Test(org.junit.Test)

Example 52 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) BBoxSpatialFilter(org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter) PolygonSpatialFilter(org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter) Filter(org.opengis.filter.Filter) 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 53 with FilterFactory

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

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

the class SLDUtilsTest method testFindRule.

@Test
public void testFindRule() {
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    sld.layers().add(DefaultSymbols.createNewNamedLayer());
    sld.layers().add(namedLayer);
    String expectedNamedLayer = "namedLayer";
    namedLayer.setName(expectedNamedLayer);
    Style style = DefaultSymbols.createNewStyle();
    String expectedStyleLayer = "style";
    style.setName(expectedStyleLayer);
    namedLayer.addStyle(DefaultSymbols.createNewStyle());
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedFeatureTypeStyleLayer = "feature type style";
    fts.setName(expectedFeatureTypeStyleLayer);
    style.featureTypeStyles().add(DefaultSymbols.createNewFeatureTypeStyle());
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    fts.rules().add(DefaultSymbols.createNewRule());
    fts.rules().add(rule);
    String expectedRule = "rule";
    rule.setName(expectedRule);
    String expectedSymbolizer = "text symbolizer";
    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    symbolizer.setName(expectedSymbolizer);
    rule.symbolizers().add(DefaultSymbols.createDefaultPolygonSymbolizer());
    rule.symbolizers().add(symbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
    symbolizer.setFont(font);
    DuplicatingStyleVisitor duplicate = new DuplicatingStyleVisitor();
    duplicate.visit(sld);
    StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicate.getCopy();
    Rule actualRule = SLDUtils.findRule(sld, rule, sldCopy);
    assertNotNull(actualRule);
    assertEquals(rule.getName(), actualRule.getName());
    actualRule = SLDUtils.findRule(sld, null, sldCopy);
    assertNull(actualRule);
    actualRule = SLDUtils.findRule(sld, rule, null);
    assertNull(actualRule);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) DuplicatingStyleVisitor(org.geotools.styling.visitor.DuplicatingStyleVisitor) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) FilterFactory(org.opengis.filter.FilterFactory) Font(org.geotools.styling.Font) Test(org.junit.Test)

Example 55 with FilterFactory

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

the class SLDUtilsTest method testFindSymbolizer.

@Test
public void testFindSymbolizer() {
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
    sld.layers().add(DefaultSymbols.createNewNamedLayer());
    sld.layers().add(namedLayer);
    String expectedNamedLayer = "namedLayer";
    namedLayer.setName(expectedNamedLayer);
    Style style = DefaultSymbols.createNewStyle();
    String expectedStyleLayer = "style";
    style.setName(expectedStyleLayer);
    namedLayer.addStyle(DefaultSymbols.createNewStyle());
    namedLayer.addStyle(style);
    FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
    String expectedFeatureTypeStyleLayer = "feature type style";
    fts.setName(expectedFeatureTypeStyleLayer);
    style.featureTypeStyles().add(DefaultSymbols.createNewFeatureTypeStyle());
    style.featureTypeStyles().add(fts);
    Rule rule = DefaultSymbols.createNewRule();
    fts.rules().add(DefaultSymbols.createNewRule());
    fts.rules().add(rule);
    String expectedRule = "rule";
    rule.setName(expectedRule);
    String expectedSymbolizer = "text symbolizer";
    TextSymbolizer symbolizer = DefaultSymbols.createDefaultTextSymbolizer();
    symbolizer.setName(expectedSymbolizer);
    rule.symbolizers().add(DefaultSymbols.createDefaultPolygonSymbolizer());
    rule.symbolizers().add(symbolizer);
    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Font font = styleFactory.createFont(ff.literal("abc"), ff.literal("normal"), ff.literal("normal"), ff.literal(10));
    symbolizer.setFont(font);
    DuplicatingStyleVisitor duplicate = new DuplicatingStyleVisitor();
    duplicate.visit(sld);
    StyledLayerDescriptor sldCopy = (StyledLayerDescriptor) duplicate.getCopy();
    Symbolizer actualSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, sldCopy);
    assertNotNull(actualSymbolizer);
    assertEquals(symbolizer.getLabel().toString(), ((TextSymbolizer) actualSymbolizer).getLabel().toString());
    actualSymbolizer = SLDUtils.findSymbolizer(sld, null, sldCopy);
    assertNull(actualSymbolizer);
    actualSymbolizer = SLDUtils.findSymbolizer(sld, symbolizer, null);
    assertNull(actualSymbolizer);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) TextSymbolizer(org.geotools.styling.TextSymbolizer) StyleFactoryImpl(org.geotools.styling.StyleFactoryImpl) DuplicatingStyleVisitor(org.geotools.styling.visitor.DuplicatingStyleVisitor) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer) FilterFactory(org.opengis.filter.FilterFactory) Font(org.geotools.styling.Font) Symbolizer(org.geotools.styling.Symbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) TextSymbolizer(org.geotools.styling.TextSymbolizer) 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