use of org.geotools.filter.LiteralExpressionImpl in project ddf by codice.
the class CswRecordMapperFilterVisitor method visit.
@Override
public Object visit(PropertyIsGreaterThan filter, Object extraData) {
Expression expr1 = visit(filter.getExpression1(), extraData);
Expression expr2 = visit(filter.getExpression2(), expr1);
// work around since Solr Provider doesn't support greater on temporal (DDF-311)
if (isTemporalQuery(expr1, expr2)) {
// also not supported by provider (DDF-311)
//TODO: work around 1: return getFactory(extraData).after(expr1, expr2);
Object val = null;
Expression other = null;
if (expr2 instanceof Literal) {
val = ((Literal) expr2).getValue();
other = expr1;
} else if (expr1 instanceof Literal) {
val = ((Literal) expr1).getValue();
other = expr2;
}
if (val != null) {
Date orig = (Date) val;
orig.setTime(orig.getTime() + 1);
Instant start = new DefaultInstant(new DefaultPosition(orig));
Instant end = new DefaultInstant(new DefaultPosition(new Date()));
DefaultPeriod period = new DefaultPeriod(start, end);
Literal literal = getFactory(extraData).literal(period);
return getFactory(extraData).during(other, literal);
}
} else {
AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression1()).getPropertyName());
LiteralExpressionImpl typedExpression = (LiteralExpressionImpl) filter.getExpression2();
setExpressionType(type, typedExpression);
expr2 = visit((Expression) typedExpression, expr1);
}
return getFactory(extraData).greater(expr1, expr2);
}
use of org.geotools.filter.LiteralExpressionImpl in project ddf by codice.
the class CswRecordMapperFilterVisitor method visit.
@Override
public Object visit(PropertyIsBetween filter, Object extraData) {
Expression expr = visit(filter.getExpression(), extraData);
AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression()).getPropertyName());
LiteralExpressionImpl typedLowerExpression = (LiteralExpressionImpl) filter.getLowerBoundary();
setExpressionType(type, typedLowerExpression);
LiteralExpressionImpl typedUpperExpression = (LiteralExpressionImpl) filter.getUpperBoundary();
setExpressionType(type, typedUpperExpression);
Expression lower = visit((Expression) typedLowerExpression, expr);
Expression upper = visit((Expression) typedUpperExpression, expr);
return getFactory(extraData).between(expr, lower, upper);
}
use of org.geotools.filter.LiteralExpressionImpl in project ddf by codice.
the class CswRecordMapperFilterVisitor method visit.
@Override
public Object visit(PropertyIsGreaterThanOrEqualTo filter, Object extraData) {
Expression expr1 = visit(filter.getExpression1(), extraData);
Expression expr2 = visit(filter.getExpression2(), expr1);
// work around since Solr Provider doesn't support greaterOrEqual on temporal (DDF-311)
if (isTemporalQuery(expr1, expr2)) {
// also not supported by provider (DDF-311)
//TEquals tEquals = getFactory(extraData).tequals(expr1, expr2);
//After after = getFactory(extraData).after(expr1, expr2);
//return getFactory(extraData).or(tEquals, after);
Object val = null;
Expression other = null;
if (expr2 instanceof Literal) {
val = ((Literal) expr2).getValue();
other = expr1;
} else if (expr1 instanceof Literal) {
val = ((Literal) expr1).getValue();
other = expr2;
}
if (val != null) {
Date orig = (Date) val;
Instant start = new DefaultInstant(new DefaultPosition(orig));
Instant end = new DefaultInstant(new DefaultPosition(new Date()));
DefaultPeriod period = new DefaultPeriod(start, end);
Literal literal = getFactory(extraData).literal(period);
return getFactory(extraData).during(other, literal);
}
} else {
AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression1()).getPropertyName());
LiteralExpressionImpl typedExpression = (LiteralExpressionImpl) filter.getExpression2();
setExpressionType(type, typedExpression);
expr2 = visit((Expression) typedExpression, expr1);
}
return getFactory(extraData).greaterOrEqual(expr1, expr2);
}
use of org.geotools.filter.LiteralExpressionImpl in project sldeditor by robward-scisys.
the class FieldConfigPopulationTest method testExpression.
/**
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#populateField(com.sldeditor.ui.detail.config.FieldId, org.opengis.filter.expression.Expression)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#populateField(com.sldeditor.common.xml.ui.FieldIdEnum, org.opengis.filter.expression.Expression)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#getExpression(com.sldeditor.ui.detail.config.FieldId)}.
* Test method for
* {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#getExpression(com.sldeditor.common.xml.ui.FieldIdEnum)}.
*/
@Test
public void testExpression() {
FieldIdEnum fieldId = FieldIdEnum.DESCRIPTION;
GraphicPanelFieldManager fieldConfigManager = new GraphicPanelFieldManager(String.class);
FieldConfigInteger intField = new FieldConfigInteger(new FieldConfigCommonData(Geometry.class, fieldId, "label", true));
intField.createUI();
fieldConfigManager.add(fieldId, intField);
FieldConfigPopulation obj = new FieldConfigPopulation(fieldConfigManager);
int expectedValue = 1256;
StyleBuilder styleBuilder = new StyleBuilder();
Expression expression = styleBuilder.literalExpression(expectedValue);
obj.populateField(fieldId, expression);
LiteralExpressionImpl actualValue = (LiteralExpressionImpl) obj.getExpression(fieldId);
assertEquals(expectedValue, ((Integer) actualValue.getValue()).intValue());
actualValue = (LiteralExpressionImpl) obj.getExpression(fieldId);
assertEquals(expectedValue, ((Integer) actualValue.getValue()).intValue());
// This shouldn't work as it does not know about the field
FieldIdEnum wrongFieldEnum = FieldIdEnum.ELSE_FILTER;
obj.populateField(wrongFieldEnum, expression);
assertNull(obj.getExpression(wrongFieldEnum));
// Try with null
obj.populateField(fieldId, null);
}
use of org.geotools.filter.LiteralExpressionImpl in project sldeditor by robward-scisys.
the class ExpressionNode method setExpression.
/**
* Sets the expression.
*
* @param expression the expression to set
*/
public void setExpression(Expression expression) {
this.expression = expression;
if (expression instanceof LiteralExpressionImpl) {
Object value = ((LiteralExpressionImpl) expression).getValue();
if (value instanceof AttributeExpressionImpl) {
this.expression = (AttributeExpressionImpl) value;
}
}
setDisplayString();
this.removeAllChildren();
if (this.expression instanceof EnvFunction) {
EnvFunction envVarExpression = (EnvFunction) this.expression;
ExpressionNode childNode = new ExpressionNode();
childNode.setExpressionType(ExpressionTypeEnum.ENVVAR);
Expression envVarLiteral = envVarExpression.getParameters().get(0);
Class<?> dataType = Object.class;
if (envMgr != null) {
dataType = envMgr.getDataType(envVarLiteral);
}
childNode.setType(dataType);
childNode.setName(Localisation.getString(ExpressionPanelv2.class, "ExpressionPanelv2.envVar"));
childNode.setExpression(envVarLiteral);
this.insert(childNode, this.getChildCount());
} else if (this.expression instanceof FunctionExpression) {
FunctionExpression functionExpression = (FunctionExpression) this.expression;
FunctionName functionName = functionExpression.getFunctionName();
TypeManager.getInstance().setDataType(functionName.getReturn().getType());
int argCount = functionName.getArgumentCount();
if (functionName.getArgumentCount() < 0) {
argCount *= -1;
}
for (int index = 0; index < argCount; index++) {
ExpressionNode childNode = new ExpressionNode();
Parameter<?> parameter = functionName.getArguments().get(index);
childNode.setType(parameter.getType());
childNode.setName(parameter.getName());
if (index < functionExpression.getParameters().size()) {
childNode.setExpression(functionExpression.getParameters().get(index));
}
this.insert(childNode, this.getChildCount());
}
} else if (this.expression instanceof FunctionImpl) {
FunctionImpl functionExpression = (FunctionImpl) this.expression;
FunctionName functionName = functionExpression.getFunctionName();
TypeManager.getInstance().setDataType(functionName.getReturn().getType());
int maxArgument = Math.abs(functionName.getArgumentCount());
for (int index = 0; index < maxArgument; index++) {
ExpressionNode childNode = new ExpressionNode();
Parameter<?> parameter = functionName.getArguments().get(0);
childNode.setType(parameter.getType());
childNode.setName(parameter.getName());
if (index < functionExpression.getParameters().size()) {
childNode.setExpression(functionExpression.getParameters().get(index));
}
this.insert(childNode, this.getChildCount());
}
} else if (expression instanceof MathExpressionImpl) {
MathExpressionImpl mathsExpression = (MathExpressionImpl) expression;
String expressionText = Localisation.getString(ExpressionPanelv2.class, "ExpressionPanelv2.expression");
ExpressionNode childNode1 = new ExpressionNode();
childNode1.setType(Number.class);
childNode1.setName(expressionText + " 1");
childNode1.setExpression(mathsExpression.getExpression1());
this.insert(childNode1, this.getChildCount());
ExpressionNode childNode2 = new ExpressionNode();
childNode2.setType(Number.class);
childNode2.setName(expressionText + " 2");
childNode2.setExpression(mathsExpression.getExpression2());
this.insert(childNode2, this.getChildCount());
} else if (expression instanceof AttributeExpressionImpl) {
@SuppressWarnings("unused") AttributeExpressionImpl property = (AttributeExpressionImpl) expression;
// TypeManager.getInstance().setLiteralType(literal.getValue().getClass());
} else if (expression instanceof LiteralExpressionImpl) {
LiteralExpressionImpl literal = (LiteralExpressionImpl) expression;
if (literal.getValue() != null) {
TypeManager.getInstance().setDataType(literal.getValue().getClass());
}
}
}
Aggregations