Java Code Examples for org.apache.cxf.jaxrs.ext.search.ConditionType#LESS_OR_EQUALS

The following examples show how to use org.apache.cxf.jaxrs.ext.search.ConditionType#LESS_OR_EQUALS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LuceneQueryVisitor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Query createRangeQuery(Class<?> cls, String name, Object value, ConditionType type) {

        boolean minInclusive = type == ConditionType.GREATER_OR_EQUALS || type == ConditionType.EQUALS;
        boolean maxInclusive = type == ConditionType.LESS_OR_EQUALS || type == ConditionType.EQUALS;

        if (String.class.isAssignableFrom(cls) || Number.class.isAssignableFrom(cls)) {
            Query query = null;

            if (Double.class.isAssignableFrom(cls)) {
                query = createDoubleRangeQuery(name, value, type, minInclusive, maxInclusive);
            } else if (Float.class.isAssignableFrom(cls)) {
                query = createFloatRangeQuery(name, value, type, minInclusive, maxInclusive);
            } else if (Long.class.isAssignableFrom(cls)) {
                query = createLongRangeQuery(name, value, type, minInclusive, maxInclusive);
            } else {
                query = createIntRangeQuery(name, value, type, minInclusive, maxInclusive);
            }

            return query;
        } else if (Date.class.isAssignableFrom(cls)) {
            final Date date = getValue(Date.class, getFieldTypeConverter(), value.toString());
            final String luceneDateValue = getString(Date.class, getFieldTypeConverter(), date);

            if (type == ConditionType.LESS_THAN || type == ConditionType.LESS_OR_EQUALS) {
                return TermRangeQuery.newStringRange(name, null, luceneDateValue, minInclusive, maxInclusive);
            }
            return TermRangeQuery.newStringRange(name, luceneDateValue,
                DateTools.dateToString(new Date(), Resolution.MILLISECOND), minInclusive, maxInclusive);
        } else {
            return null;
        }
    }
 
Example 2
Source File: LuceneQueryVisitor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private< N > N getMin(final ConditionType type, final N value) {
    return type == ConditionType.LESS_THAN || type == ConditionType.LESS_OR_EQUALS ? null : value;
}
 
Example 3
Source File: ODataParser.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Object visitBinary(BinaryExpression binaryExpression, BinaryOperator operator,
        Object leftSide, Object rightSide) {

    // AND / OR operate on search conditions
    if (operator == BinaryOperator.AND || operator == BinaryOperator.OR) {
        if (leftSide instanceof SearchCondition && rightSide instanceof SearchCondition) {
            final List< SearchCondition< T > > conditions = new ArrayList<>(2);
            conditions.add((SearchCondition< T >)leftSide);
            conditions.add((SearchCondition< T >)rightSide);

            if (operator == BinaryOperator.AND) {
                return new AndSearchCondition< T >(conditions);
            } else if (operator == BinaryOperator.OR) {
                return new OrSearchCondition< T >(conditions);
            }
        } else {
            throw new SearchParseException(
                "Unsupported binary operation arguments (SearchCondition expected): "
                    + leftSide + ", " + rightSide);
        }
    }

    // Property could be either on left side (Name eq 'Tom') or
    // right side ('Tom' eq Name)
    TypedValue value = null;
    TypedProperty property = null;

    if (leftSide instanceof TypedProperty && rightSide instanceof TypedValue) {
        property = (TypedProperty)leftSide;
        value = (TypedValue)rightSide;
    } else if (rightSide instanceof TypedProperty && leftSide instanceof TypedValue) {
        property = (TypedProperty)rightSide;
        value = (TypedValue)leftSide;
    } else {
        throw new SearchParseException(
            "Unsupported binary operation arguments (TypedValue or TypedProperty expected): "
                + leftSide + ", " + rightSide);
    }

    ConditionType conditionType = null;
    switch (operator) {
    case EQ:
        conditionType = ConditionType.EQUALS;
        break;
    case NE:
        conditionType = ConditionType.NOT_EQUALS;
        break;
    case LT:
        conditionType = ConditionType.LESS_THAN;
        break;
    case LE:
        conditionType = ConditionType.LESS_OR_EQUALS;
        break;
    case GT:
        conditionType = ConditionType.GREATER_THAN;
        break;
    case GE:
        conditionType = ConditionType.GREATER_OR_EQUALS;
        break;
    default:
        throw new SearchParseException("Unsupported binary operation: " + operator);
    }

    Object typedValue = null;
    // If property type and value type are compatible, just use them
    if (property.typeInfo.getWrappedTypeClass().isAssignableFrom(value.typeClass)) {
        typedValue = value.value;
    } else { // Property type and value type are not compatible and convert / cast are required
        String valueStr = value.literal;
        if (isDecodeQueryValues()) {
            valueStr = UrlUtils.urlDecode(valueStr);
        }
        typedValue = parseType(property.propertyName, null, null, property.propertyName,
            property.typeInfo, valueStr);
    }

    final CollectionCheckInfo checkInfo = property.typeInfo.getCollectionCheckInfo();
    if (checkInfo != null) {
        return new CollectionCheckCondition< T >(property.propertyName, typedValue,
            property.typeInfo.getGenericType(), conditionType, condition, checkInfo);
    }

    return new PrimitiveSearchCondition< T >(property.propertyName, typedValue,
        property.typeInfo.getGenericType(), conditionType, condition);
}