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));
}
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);
}
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));
}
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);
}
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);
}
Aggregations