use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition in project hale by halestudio.
the class TestCqlToMappingConditionTranslator method testTranslateSimpleEquality.
/**
* Test that generates model RIF from a simple CQL query comprising an
* equality test against a named property.
*
* @throws CQLException
* if any errors occurred parsing the CQL string
* @throws TranslationException
* if any errors occurred during the translation
*/
@Test
public void testTranslateSimpleEquality() throws CQLException, TranslationException {
// $NON-NLS-1$
String cqlPredicate = "ATTR1='17'";
ModelMappingCondition result = digester.translate(CQL.toFilter(cqlPredicate));
assertNotNull(result);
assertNotNull(result.getRoot());
assertThat(result.getRoot(), is(instanceOf(EqualToNode.class)));
EqualToNode node = (EqualToNode) result.getRoot();
assertNotNull(node.getLeft());
assertNotNull(node.getRight());
// $NON-NLS-1$
assertThat(node.getLeft().getPropertyName(), is(equalTo("ATTR1")));
// $NON-NLS-1$
assertThat(node.getRight().getLiteralValue().toString(), is(equalTo("17")));
}
use of com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition in project hale by halestudio.
the class CqlToMappingConditionTranslator method translate.
/**
* {@inheritDoc}
*/
@Override
public ModelMappingCondition translate(Filter source) throws TranslationException {
ModelMappingCondition filter = new ModelMappingCondition();
FilterNode root = null;
if (isLogical(source)) {
LogicFilterImpl logicFilter = (LogicFilterImpl) source;
root = factory.createLogicNode(logicFilter);
List<?> children = logicFilter.getChildren();
for (Object child : children) {
createNode(root, (Filter) child);
}
} else // if it's a comparison filter we assume we are at the start of the tree
if (isComparison(source)) {
CompareFilterImpl compare = (CompareFilterImpl) source;
AbstractComparisonNode cn = factory.createComparisonNode(compare);
cn.setLeft(getLeftContents((AttributeExpressionImpl) compare.getExpression1()));
cn.setRight(getRightContents(compare.getExpression2()));
root = cn;
} else // likewise if it's a geometric filter
if (isGeometric(source)) {
GeometryFilterImpl geometric = (GeometryFilterImpl) source;
AbstractGeometricNode gn = factory.createGeometricNode(geometric);
gn.setLeft(getLeftContents((AttributeExpressionImpl) geometric.getExpression1()));
gn.setRight(getRightContents(geometric.getExpression2()));
setGeometricOperationSpecifics(gn, geometric);
root = gn;
}
filter.setRoot(root);
return filter;
}
Aggregations