Search in sources :

Example 11 with ModelMappingCondition

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")));
}
Also used : EqualToNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode) ModelMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition) Test(org.junit.Test)

Example 12 with ModelMappingCondition

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;
}
Also used : AbstractGeometricNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.geometric.AbstractGeometricNode) CompareFilterImpl(org.geotools.filter.CompareFilterImpl) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) FilterNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode) LogicFilterImpl(org.geotools.filter.LogicFilterImpl) ModelMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition) GeometryFilterImpl(org.geotools.filter.GeometryFilterImpl) AbstractComparisonNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.AbstractComparisonNode)

Aggregations

ModelMappingCondition (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition)12 Test (org.junit.Test)8 EqualToNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode)5 LessThanNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.LessThanNode)5 GreaterThanNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.GreaterThanNode)3 AndNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.AndNode)3 FilterNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode)2 ModelAttributeMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell)1 ModelStaticAssignmentCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell)1 ModelSentence (com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelSentence)1 AbstractFilterNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.AbstractFilterNode)1 AbstractComparisonNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.AbstractComparisonNode)1 AbstractGeometricNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.geometric.AbstractGeometricNode)1 WithinNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.geometric.WithinNode)1 NotNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.NotNode)1 OrNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.logical.OrNode)1 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)1 CompareFilterImpl (org.geotools.filter.CompareFilterImpl)1 GeometryFilterImpl (org.geotools.filter.GeometryFilterImpl)1 LogicFilterImpl (org.geotools.filter.LogicFilterImpl)1