/** * Creates a field criteria for the given node and operator. * * @param node The comparison node to extract selector and argument from. * @param operator The (Morphia) operator to create criteria for. * @return A field criteria for the given comparison. * @throws RSQLValidationException If the node contains more or less than one argument, or a * matching field for the selector cannot be found. */ protected Criteria createCriteria(ComparisonNode node, FilterOperator operator) { MappedFieldPath mfp = resolveFieldPath(node.getSelector()); Object mappedValue = convertToMappedValue(node.getArguments(), mfp, !node.getOperator().isMultiValue()); return new SimpleFieldCriteria(mfp.getFieldPath(), operator, mappedValue); }
/** * Converts the argument(s) to the target type (specified by {@code MappedFieldPath}) and then to * a Mongo object. * * @param arguments Single or multiple arguments in a list. * @param mfp The mapped field path. * @param singleValue Whether a single argument is expected. * @return An argument(s) converted to Mongo value. * @throws cz.jirutka.rsql.mongodb.morphia.RSQLArgumentFormatException */ protected Object convertToMappedValue( List<String> arguments, MappedFieldPath mfp, boolean singleValue) { Object value = singleValue ? converter.convert(arguments.get(0), mfp.getTargetValueType()) : converter.convert(arguments, mfp.getTargetValueType()); return mapper.toMongoObject(mfp.getMappedField(), null, value); }