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