use of org.geotools.filter.LiteralExpressionImpl in project ddf by codice.
the class OpenSearchQueryTest method verifyEqualsFilter.
private void verifyEqualsFilter(Filter filter, String expectedPropertyName, String expectedValue) {
assertTrue(filter instanceof IsEqualsToImpl);
IsEqualsToImpl equalsFilter = (IsEqualsToImpl) filter;
AttributeExpressionImpl expression1 = (AttributeExpressionImpl) equalsFilter.getExpression1();
LOGGER.debug("propertyName = {}", expression1.getPropertyName());
assertEquals(expectedPropertyName, expression1.getPropertyName());
LiteralExpressionImpl expression2 = (LiteralExpressionImpl) equalsFilter.getExpression2();
LOGGER.debug("version to search for = {}", expression2.getValue());
assertEquals(expectedValue, expression2.getValue());
}
use of org.geotools.filter.LiteralExpressionImpl in project ddf by codice.
the class SubscriptionFilterVisitor method visit.
/**
* During filter maps to a Temporal (Absolute and Modified) search criteria.
*/
@Override
public Object visit(During filter, Object data) {
LOGGER.debug("ENTERING: During filter");
AttributeExpressionImpl temporalTypeAttribute = (AttributeExpressionImpl) filter.getExpression1();
String temporalType = temporalTypeAttribute.getPropertyName();
LiteralExpressionImpl timePeriodLiteral = (LiteralExpressionImpl) filter.getExpression2();
Object literal = timePeriodLiteral.getValue();
Predicate returnPredicate = null;
if (literal instanceof Period) {
Period timePeriod = (Period) literal;
// Extract the start and end dates from the OGC TOverlaps filter
Date start = timePeriod.getBeginning().getPosition().getDate();
Date end = timePeriod.getEnding().getPosition().getDate();
LOGGER.debug("time period lowerBound = {}", start);
LOGGER.debug("time period upperBound = {}", end);
LOGGER.debug("EXITING: (temporal) filter");
returnPredicate = new TemporalPredicate(start, end, DateType.getDateType(temporalType));
// CREATE RELATIVE
} else if (literal instanceof PeriodDuration) {
DefaultPeriodDuration duration = (DefaultPeriodDuration) literal;
long offset = duration.getTimeInMillis();
LOGGER.debug("EXITING: (temporal) filter");
returnPredicate = new TemporalPredicate(offset, DateType.getDateType(temporalType));
}
LOGGER.debug("temporalType: {}", temporalType);
LOGGER.debug("Temporal Predicate: {}", returnPredicate);
LOGGER.debug("EXITING: During filter");
return returnPredicate;
}
use of org.geotools.filter.LiteralExpressionImpl in project ddf by codice.
the class SubscriptionFilterVisitor method visit.
/**
* PropertyIsEqualTo filter maps to a Type/Version(s) and Entry search criteria.
*/
@Override
public Object visit(PropertyIsEqualTo filter, Object data) {
LOGGER.debug("ENTERING: PropertyIsEqualTo filter");
// TODO: consider if the contentType parameters are invalid (i.e. anything where type is
// null)
AttributeExpressionImpl exp1 = (AttributeExpressionImpl) filter.getExpression1();
String propertyName = exp1.getPropertyName();
LiteralExpressionImpl exp2 = (LiteralExpressionImpl) filter.getExpression2();
Predicate predicate = null;
if (Metacard.ID.equals(propertyName)) {
String entryId = (String) exp2.getValue();
LOGGER.debug("entry id for new entry predicate: {}", entryId);
predicate = new EntryPredicate(entryId);
} else if (Metacard.CONTENT_TYPE.equals(propertyName)) {
String typeValue = (String) exp2.getValue();
predicate = new ContentTypePredicate(typeValue, null);
} else if (Metacard.CONTENT_TYPE_VERSION.equals(propertyName)) {
String versionValue = (String) exp2.getValue();
predicate = new ContentTypePredicate(null, versionValue);
} else if (Metacard.RESOURCE_URI.equals(propertyName)) {
URI productUri = null;
if (exp2.getValue() instanceof URI) {
productUri = (URI) exp2.getValue();
predicate = new EntryPredicate(productUri);
} else {
try {
productUri = new URI((String) exp2.getValue());
predicate = new EntryPredicate(productUri);
} catch (URISyntaxException e) {
LOGGER.debug("URI Syntax exception creating EntryPredicate", e);
throw new UnsupportedOperationException("Could not create a URI object from the given ResourceURI.", e);
}
}
}
LOGGER.debug("EXITING: PropertyIsEqualTo filter");
return predicate;
}
use of org.geotools.filter.LiteralExpressionImpl in project ddf by codice.
the class CswRecordMapperFilterVisitor method convertGeometryExpressionToEpsg4326.
private static void convertGeometryExpressionToEpsg4326(Expression expression) {
if (expression instanceof LiteralExpressionImpl) {
LiteralExpressionImpl literalExpression = (LiteralExpressionImpl) expression;
Object valueObj = literalExpression.getValue();
if (valueObj instanceof Geometry) {
Geometry geometry = (Geometry) valueObj;
Object userDataObj = geometry.getUserData();
if (userDataObj instanceof CoordinateReferenceSystem) {
CoordinateReferenceSystem sourceCRS = (CoordinateReferenceSystem) userDataObj;
Geometry convertedGeometry = null;
try {
convertedGeometry = GeospatialUtil.transformToEPSG4326LonLatFormat(geometry, sourceCRS);
literalExpression.setValue(convertedGeometry);
} catch (GeoFormatException e) {
LOGGER.debug("Unable to convert geometry {} to EPSG:4326 format", valueObj, e);
}
}
}
}
}
use of org.geotools.filter.LiteralExpressionImpl in project ddf by codice.
the class CatalogFeatureQueryableTest method testQuery.
@Test
public void testQuery() throws UnsupportedQueryException, SourceUnavailableException, FederationException, FeatureQueryException {
final ArgumentCaptor<QueryRequest> requestArgument = ArgumentCaptor.forClass(QueryRequest.class);
QueryResponse queryResponse = getMockQueryResponse();
when(catalogFramework.query(any())).thenReturn(queryResponse);
List<SimpleFeature> results = catalogFeatureQueryable.query(COUNTRY_CODE, "PCL1", 1);
verify(catalogFramework, atLeastOnce()).query(requestArgument.capture());
SimpleFeature result = results.get(0);
Geometry geometry = (Geometry) result.getDefaultGeometry();
assertThat(geometry.getNumPoints(), is(WKT_NUM_POINTS));
assertThat(geometry.getGeometryType(), is(WKT_TYPE));
QueryImpl query = (QueryImpl) requestArgument.getValue().getQuery();
Filter filter = query.getFilter();
And and = (And) filter;
List<Filter> filters = and.getChildren();
assertThat(filters, hasSize(3));
List<String> attributes = new ArrayList<>();
List<String> values = new ArrayList<>();
for (Filter compFilter : filters) {
String attribute;
String value;
if (compFilter instanceof IsEqualsToImpl) {
IsEqualsToImpl equals = (IsEqualsToImpl) compFilter;
AttributeExpressionImpl attributeExpression = (AttributeExpressionImpl) equals.getExpression1();
attribute = attributeExpression.getPropertyName();
LiteralExpressionImpl literalExpression = (LiteralExpressionImpl) equals.getExpression2();
value = (String) literalExpression.getValue();
} else {
LikeFilterImpl likeFilter = (LikeFilterImpl) compFilter;
AttributeExpressionImpl literalExpression = (AttributeExpressionImpl) likeFilter.getExpression();
attribute = literalExpression.getPropertyName();
value = likeFilter.getLiteral();
}
attributes.add(attribute);
values.add(value);
}
assertThat(attributes, hasSize(3));
assertThat(attributes, hasItems(Location.COUNTRY_CODE, Core.METACARD_TAGS, Core.METACARD_TAGS));
assertThat(values, hasSize(3));
assertThat(values, hasItems(COUNTRY_CODE, GAZETTEER_METACARD_TAG, GeoCodingConstants.COUNTRY_TAG));
}
Aggregations