Search in sources :

Example 1 with AbstractComparisonNode

use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.AbstractComparisonNode in project hale by halestudio.

the class CqlToMappingConditionTranslator method createNode.

private FilterNode createNode(FilterNode parent, Filter child) {
    FilterNode childNode = null;
    if (isLogical(child)) {
        LogicFilterImpl logicFilter = (LogicFilterImpl) child;
        childNode = factory.createLogicNode(logicFilter);
        List<?> children = logicFilter.getChildren();
        for (Object c : children) {
            createNode(childNode, (Filter) c);
        }
    } else if (isComparison(child)) {
        AbstractComparisonNode comparisonNode = null;
        if (LikeFilterImpl.class.isAssignableFrom(child.getClass())) {
            LikeFilterImpl like = (LikeFilterImpl) child;
            comparisonNode = factory.createComparisonNode(like);
            comparisonNode.setLeft(getLeftContents((AttributeExpressionImpl) like.getExpression()));
            LeafNode node = new LeafNode();
            node.setLiteralValue(LiteralValue.getNew(like.getLiteral()));
            comparisonNode.setRight(node);
        } else {
            CompareFilterImpl compare = (CompareFilterImpl) child;
            comparisonNode = factory.createComparisonNode(compare);
            comparisonNode.setLeft(getLeftContents((AttributeExpressionImpl) compare.getExpression1()));
            comparisonNode.setRight(getRightContents(compare.getExpression2()));
        }
        childNode = comparisonNode;
    } else if (isGeometric(child)) {
        childNode = factory.createGeometricNode((GeometryFilterImpl) child);
    }
    if (parent != null) {
        parent.addChild(childNode);
    }
    return childNode;
}
Also used : CompareFilterImpl(org.geotools.filter.CompareFilterImpl) LikeFilterImpl(org.geotools.filter.LikeFilterImpl) FilterNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode) LeafNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.terminal.LeafNode) LogicFilterImpl(org.geotools.filter.LogicFilterImpl) GeometryFilterImpl(org.geotools.filter.GeometryFilterImpl) AbstractComparisonNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.AbstractComparisonNode)

Example 2 with AbstractComparisonNode

use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.AbstractComparisonNode 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)

Example 3 with AbstractComparisonNode

use of com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.AbstractComparisonNode in project hale by halestudio.

the class ModelAlignmentToModelRifTranslator method buildRifMappingCondition.

private ModelRifMappingCondition buildRifMappingCondition(ModelSentence sentence, AbstractFilterNode node) {
    ModelRifMappingCondition rifCondition = new ModelRifMappingCondition();
    if (node != null) {
        // logical ones
        if (node.isLogical()) {
            for (FilterNode child : node.getChildren()) {
                AbstractFilterNode childNode = (AbstractFilterNode) child;
                rifCondition.addChild(buildRifMappingCondition(sentence, childNode));
            }
            if (node.getNodeType().equals(AND_NODE)) {
                rifCondition.setLogicalType(LogicalType.AND);
            } else if (node.getNodeType().equals(OR_NODE)) {
                rifCondition.setLogicalType(LogicalType.OR);
            } else if (node.getNodeType().equals(NOT_NODE)) {
                rifCondition.setLogicalType(LogicalType.NOT);
                rifCondition.setNegated(true);
            }
        } else // comparison ones
        if (node.isComparison()) {
            AbstractComparisonNode cnode = (AbstractComparisonNode) node;
            if (node.getNodeType().equals(EQUAL_TO_NODE)) {
                EqualToNode equalNode = (EqualToNode) node;
                // work out if it's a string or a numeric equality test
                rifCondition.setOperator(STRING_EQUALS);
                if (equalNode.getRight().isNumeric()) {
                    rifCondition.setOperator(NUMBER_EQUALS);
                }
            } else // less-than comparisons
            if (node.getNodeType().equals(GREATER_THAN_NODE)) {
                rifCondition.setOperator(NUMBER_GREATER_THAN);
            } else if (node.getNodeType().equals(LESS_THAN_NODE)) {
                rifCondition.setOperator(NUMBER_LESS_THAN);
            } else if (node.getNodeType().equals(LIKE_NODE)) {
                rifCondition.setOperator(STRING_CONTAINS);
            }
            rifCondition.setLeft(getContents(sentence, cnode.getLeft()));
            rifCondition.setLiteralClass(cnode.getRight().getLiteralValue().getValueClass());
            rifCondition.setLiteralValue(cnode.getRight().getLiteralValue().toString());
            rifCondition.setRight(getContents(sentence, cnode.getRight()));
        } else // geometric ones
        if (node.isGeometric()) {
        // TODO add this
        }
    }
    return rifCondition;
}
Also used : EqualToNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode) AbstractFilterNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.AbstractFilterNode) ModelRifMappingCondition(com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelRifMappingCondition) FilterNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode) AbstractFilterNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.AbstractFilterNode) AbstractComparisonNode(com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.AbstractComparisonNode)

Aggregations

FilterNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.FilterNode)3 AbstractComparisonNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.AbstractComparisonNode)3 CompareFilterImpl (org.geotools.filter.CompareFilterImpl)2 GeometryFilterImpl (org.geotools.filter.GeometryFilterImpl)2 LogicFilterImpl (org.geotools.filter.LogicFilterImpl)2 ModelMappingCondition (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelMappingCondition)1 ModelRifMappingCondition (com.onespatial.jrc.tns.oml_to_rif.model.rif.ModelRifMappingCondition)1 AbstractFilterNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.AbstractFilterNode)1 EqualToNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.comparison.EqualToNode)1 AbstractGeometricNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.nonterminal.geometric.AbstractGeometricNode)1 LeafNode (com.onespatial.jrc.tns.oml_to_rif.model.rif.filter.terminal.LeafNode)1 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)1 LikeFilterImpl (org.geotools.filter.LikeFilterImpl)1