Example usage for org.springframework.context MessageSource getMessage

List of usage examples for org.springframework.context MessageSource getMessage

Introduction

In this page you can find the example usage for org.springframework.context MessageSource getMessage.

Prototype

String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException;

Source Link

Document

Try to resolve the message.

Usage

From source file:org.gvnix.web.datatables.util.DatatablesUtils.java

public static boolean checkDateFilters(String expression, MessageSource messageSource) {

    // All possible operations
    String date = "DATE";
    String year = "YEAR";
    String month = "MONTH";
    String day = "DAY";
    String between = "BETWEEN";
    String isNullOperation = ISNULL_OPE;
    String isNotNullOperation = NOTNULL_OPE;

    String datePattern = "dd/MM/yyyy";

    if (messageSource != null) {
        date = messageSource.getMessage("global.filters.operations.date.date", null,
                LocaleContextHolder.getLocale());
        year = messageSource.getMessage("global.filters.operations.date.year", null,
                LocaleContextHolder.getLocale());
        month = messageSource.getMessage("global.filters.operations.date.month", null,
                LocaleContextHolder.getLocale());
        day = messageSource.getMessage("global.filters.operations.date.day", null,
                LocaleContextHolder.getLocale());
        between = messageSource.getMessage("global.filters.operations.date.between", null,
                LocaleContextHolder.getLocale());
        isNullOperation = messageSource.getMessage(G_ISNULL_OPE, null, LocaleContextHolder.getLocale());
        isNotNullOperation = messageSource.getMessage(G_NOTNULL_OPE, null, LocaleContextHolder.getLocale());
        datePattern = messageSource.getMessage("global.filters.operations.date.pattern", null,
                LocaleContextHolder.getLocale());
    }//from   ww  w.j av a 2 s  .  c  o m

    // Getting simpleDateFormat
    DateFormat dateFormat = new SimpleDateFormat(datePattern);

    // If written expression is ISNULL operation
    Pattern isNullOperator = Pattern.compile(String.format("%s", isNullOperation));
    Matcher isNullMatcher = isNullOperator.matcher(expression);
    if (isNullMatcher.matches()) {
        return true;

    }

    // If written expression is ISNOTNULL operation
    Pattern isNotNullOperator = Pattern.compile(String.format("%s", isNotNullOperation));
    Matcher isNotNullMatcher = isNotNullOperator.matcher(expression);
    if (isNotNullMatcher.matches()) {
        return true;

    }

    // Creating regex to get DATE operator
    Pattern dateOperator = Pattern.compile(String.format("%s[(]([\\d\\/]*)[)]", date));
    Matcher dateMatcher = dateOperator.matcher(expression);

    if (dateMatcher.matches()) {
        try {
            String dateValue = dateMatcher.group(1);
            Date dateToFilter = dateFormat.parse(dateValue);

            Calendar searchCal = Calendar.getInstance();
            searchCal.setTime(dateToFilter);

            return true;
        } catch (ParseException e) {
            return false;
        }
    }

    // Creating regex to get YEAR operator
    Pattern yearOperator = Pattern.compile(String.format("%s[(]([\\d]*)[)]", year));
    Matcher yearMatcher = yearOperator.matcher(expression);

    if (yearMatcher.matches()) {
        return true;
    }

    // Creating regex to get MONTH operator
    Pattern monthOperator = Pattern.compile(String.format("%s[(]([\\d]*)[)]", month));
    Matcher monthMatcher = monthOperator.matcher(expression);

    if (monthMatcher.matches()) {
        return true;
    }

    // Creating regex to get DAY operator
    Pattern dayOperator = Pattern.compile(String.format("%s[(]([\\d]*)[)]", day));
    Matcher dayMatcher = dayOperator.matcher(expression);

    if (dayMatcher.matches()) {
        return true;
    }

    // Creating regex to get BETWEEN operator
    Pattern betweenOperator = Pattern.compile(String.format("%s[(]([\\d\\/]*);([\\d\\/]*)[)]", between));
    Matcher betweenMatcher = betweenOperator.matcher(expression);

    if (betweenMatcher.matches()) {

        String valueFrom = betweenMatcher.group(1);
        String valueTo = betweenMatcher.group(2);

        if (StringUtils.isNotBlank(valueFrom) && StringUtils.isNotBlank(valueTo)) {

            try {

                Date dateFrom = dateFormat.parse(valueFrom);
                Date dateTo = dateFormat.parse(valueTo);

                Calendar dateFromCal = Calendar.getInstance();
                dateFromCal.setTime(dateFrom);

                Calendar dateToCal = Calendar.getInstance();
                dateToCal.setTime(dateTo);

                return true;

            } catch (Exception e) {
                return false;
            }
        }

    }

    return false;
}

From source file:org.gvnix.web.datatables.util.QuerydslUtils.java

/**
 * Return like expression for {@code entityPath.fieldName}.
 * <p/>/*  ww w  .  j ava  2 s  .c  o  m*/
 * Expr: {@code entityPath.fieldName like ('%' + searchStr + '%')}
 * <p/>
 * Like operation is case insensitive.
 * 
 * @param entityPath Full path to entity and associations. For example:
 *        {@code Pet} , {@code Pet.owner}
 * @param fieldName Property name in the given entity path. For example:
 *        {@code name} in {@code Pet} entity, {@code firstName} in
 *        {@code Pet.owner} entity.
 * @param searchStr the value to find, may be null
 * @return BooleanExpression
 */
public static <T> BooleanExpression createStringExpressionWithOperators(PathBuilder<T> entityPath,
        String fieldName, String searchStr, ConversionService conversionService, MessageSource messageSource) {
    if (StringUtils.isEmpty(searchStr)) {
        return null;
    }

    // All operations
    String endsOperation = "ENDS";
    String startsOperation = "STARTS";
    String containsOperation = "CONTAINS";
    String isEmptyOperation = "ISEMPTY";
    String isNotEmptyOperation = "ISNOTEMPTY";
    String isNullOperation = OPERATOR_ISNULL;
    String isNotNullOperation = OPERATOR_NOTNULL;

    if (messageSource != null) {
        endsOperation = messageSource.getMessage("global.filters.operations.string.ends", null,
                LocaleContextHolder.getLocale());
        startsOperation = messageSource.getMessage("global.filters.operations.string.starts", null,
                LocaleContextHolder.getLocale());
        containsOperation = messageSource.getMessage("global.filters.operations.string.contains", null,
                LocaleContextHolder.getLocale());
        isEmptyOperation = messageSource.getMessage("global.filters.operations.string.isempty", null,
                LocaleContextHolder.getLocale());
        isNotEmptyOperation = messageSource.getMessage("global.filters.operations.string.isnotempty", null,
                LocaleContextHolder.getLocale());
        isNullOperation = messageSource.getMessage(G_FIL_OPE_ISNULL, null, LocaleContextHolder.getLocale());
        isNotNullOperation = messageSource.getMessage(G_FIL_OPE_NOTNULL, null, LocaleContextHolder.getLocale());
    }

    // If written expression is ENDS operation
    Pattern endsOperator = Pattern.compile(String.format("%s[(](.+)[)]$", endsOperation));
    Matcher endsMatcher = endsOperator.matcher(searchStr);

    if (endsMatcher.matches()) {
        // Getting value
        String value = endsMatcher.group(1);

        String str = "%".concat(value.toLowerCase());
        return entityPath.getString(fieldName).lower().like(str);
    }

    // If written expression is STARTS operation
    Pattern startsOperator = Pattern.compile(String.format("%s[(](.+)[)]$", startsOperation));
    Matcher startsMatcher = startsOperator.matcher(searchStr);

    if (startsMatcher.matches()) {
        // Getting value
        String value = startsMatcher.group(1);

        String str = value.toLowerCase().concat("%");
        return entityPath.getString(fieldName).lower().like(str);
    }

    // If written expression is CONTAINS operation
    Pattern containsOperator = Pattern.compile(String.format("%s[(](.+)[)]$", containsOperation));
    Matcher containsMatcher = containsOperator.matcher(searchStr);

    if (containsMatcher.matches()) {
        // Getting value
        String value = containsMatcher.group(1);

        String str = "%".concat(value.toLowerCase()).concat("%");
        return entityPath.getString(fieldName).lower().like(str);
    }

    // If written expression is ISEMPTY operation
    Pattern isEmptyOperator = Pattern.compile(String.format("%s", isEmptyOperation));
    Matcher isEmptyMatcher = isEmptyOperator.matcher(searchStr);
    if (isEmptyMatcher.matches()) {
        return entityPath.getString(fieldName).isEmpty().or(entityPath.getString(fieldName).isNull());

    }

    // If written expression is ISNOTEMPTY operation
    Pattern isNotEmptyOperator = Pattern.compile(String.format("%s", isNotEmptyOperation));
    Matcher isNotEmptyMatcher = isNotEmptyOperator.matcher(searchStr);
    if (isNotEmptyMatcher.matches()) {
        return entityPath.getString(fieldName).isNotEmpty().and(entityPath.getString(fieldName).isNotNull());

    }

    // If written expression is ISNULL operation
    Pattern isNullOperator = Pattern.compile(String.format("%s", isNullOperation));
    Matcher isNullMatcher = isNullOperator.matcher(searchStr);
    if (isNullMatcher.matches()) {
        return entityPath.getString(fieldName).isNull();

    }

    // If written expression is ISNOTNULL operation
    Pattern isNotNullOperator = Pattern.compile(String.format("%s", isNotNullOperation));
    Matcher isNotNullMatcher = isNotNullOperator.matcher(searchStr);
    if (isNotNullMatcher.matches()) {
        return entityPath.getString(fieldName).isNotNull();

    }

    // If written expression is a symbol operation expression

    // Getting expressions with symbols
    Pattern symbolOperator = Pattern.compile("[=]?(.+)");
    Matcher symbolMatcher = symbolOperator.matcher(searchStr);

    if (symbolMatcher.matches()) {

        String value = symbolMatcher.group(1);

        // operator is not necessary. Always is =
        return entityPath.getString(fieldName).lower().eq(value.toLowerCase());
    }

    return null;
}

From source file:org.gvnix.web.datatables.util.QuerydslUtils.java

/**
 * Return where clause expression for date properties, trying to parse the
 * value to find to date and comparing it to the value of the date; if the
 * value to find cannot be parsed to date, then try to cast the value to
 * string before check it./*  www .  ja va  2s  .c om*/
 * <p/>
 * <ul>
 * <li>
 * If value to find {@code searchStr} can be parsed using the patterns
 * <em>dd-MM-yyyy HH:mm:ss</em> or <em>dd-MM-yyyy HH:mm</em> or
 * <em>dd-MM-yyyy</em> to {@code searchDate}, then search by specific date:
 * <p/>
 * - Querydsl Expr: {@code entityPath.fieldName = searchDate}
 * <p/>
 * - Database operation: {@code entity.fieldName = searchDate}</li>
 * <li>
 * If value to find {@code searchStr} can be parsed using the pattern
 * <em>dd-MM</em> to {@code searchDate}, then search by specific day and
 * month:
 * <p/>
 * - Querydsl Expr:
 * {@code entityPath.fieldName.dayOfMonth() = searchDate.day and entityPath.fieldName.month() = searchDate.month}
 * <p/>
 * - Database operation:
 * {@code dayofmonth(entity.fieldName) = searchDate.day && month(entity.fieldName) = searchDate.month}
 * </li>
 * <li>
 * If value to find {@code searchStr} can be parsed using the pattern
 * <em>MM-aaaa</em> to {@code searchDate}, then obtain the first day of the
 * month for that year and the last day of the month for that year and check
 * that value is into between theses values:
 * <p/>
 * - Querydsl Expr:
 * {@code entityPath.fieldName.between(searchDate.firstDayOfMonth, searchDate.lastDayOfMonth)}
 * <p/>
 * - Database operation:
 * {@code entity.fieldName between searchDate.firstDayOfMonth and searchDate.lastDayOfMonth}
 * </li>
 * <li>
 * If value to find cannot be parsed as date, then try to cast the value to
 * string before check it:
 * <p/>
 * - Querydsl Expr:
 * {@code entityPath.fieldName.stringValue() like ('%' + searchStr + '%')}
 * <p/>
 * - Database operation:
 * {@code str(entity.fieldName) like ('%' + searchStr + '%')}
 * <p/>
 * Note that like operation is case sensitive.</li>
 * </ul>
 * 
 * @param entityPath Full path to entity and associations. For example:
 *        {@code Pet} , {@code Pet.owner}
 * @param fieldName Property name in the given entity path. For example:
 *        {@code weight} in {@code Pet} entity, {@code age} in
 *        {@code Pet.owner} entity.
 * @param searchStr the value to find, may be null
 * @return PredicateOperation
 */
public static <T, C extends java.lang.Comparable<?>> BooleanExpression createDateExpressionWithOperators(
        PathBuilder<T> entityPath, String fieldName, Class<C> fieldType, String searchStr,
        ConversionService conversionService, MessageSource messageSource, String datePattern) {
    if (StringUtils.isEmpty(searchStr)) {
        return null;
    }

    DatePath<C> dateExpression = entityPath.getDate(fieldName, fieldType);

    // Getting simpleDateFormat
    DateFormat dateFormat = new SimpleDateFormat(datePattern);

    // All possible operations
    String date = "DATE";
    String year = "YEAR";
    String month = "MONTH";
    String day = "DAY";
    String between = "BETWEEN";
    String isNullOperation = OPERATOR_ISNULL;
    String isNotNullOperation = OPERATOR_NOTNULL;

    if (messageSource != null) {
        date = messageSource.getMessage("global.filters.operations.date.date", null,
                LocaleContextHolder.getLocale());
        year = messageSource.getMessage("global.filters.operations.date.year", null,
                LocaleContextHolder.getLocale());
        month = messageSource.getMessage("global.filters.operations.date.month", null,
                LocaleContextHolder.getLocale());
        day = messageSource.getMessage("global.filters.operations.date.day", null,
                LocaleContextHolder.getLocale());
        between = messageSource.getMessage("global.filters.operations.date.between", null,
                LocaleContextHolder.getLocale());
        isNullOperation = messageSource.getMessage(G_FIL_OPE_ISNULL, null, LocaleContextHolder.getLocale());
        isNotNullOperation = messageSource.getMessage(G_FIL_OPE_NOTNULL, null, LocaleContextHolder.getLocale());
    }

    // If written expression is ISNULL operation
    Pattern isNullOperator = Pattern.compile(String.format("%s", isNullOperation));
    Matcher isNullMatcher = isNullOperator.matcher(searchStr);
    if (isNullMatcher.matches()) {
        return dateExpression.isNull();

    }

    // If written expression is ISNOTNULL operation
    Pattern isNotNullOperator = Pattern.compile(String.format("%s", isNotNullOperation));
    Matcher isNotNullMatcher = isNotNullOperator.matcher(searchStr);
    if (isNotNullMatcher.matches()) {
        return dateExpression.isNotNull();

    }

    // Creating regex to get DATE operator
    Pattern dateOperator = Pattern.compile(String.format("%s[(]([\\d\\/]*)[)]", date));
    Matcher dateMatcher = dateOperator.matcher(searchStr);

    if (dateMatcher.matches()) {
        try {
            String dateValue = dateMatcher.group(1);
            Date dateToFilter = dateFormat.parse(dateValue);

            Calendar searchCal = Calendar.getInstance();
            searchCal.setTime(dateToFilter);

            return dateExpression.eq(conversionService.convert(searchCal, fieldType));

        } catch (ParseException e) {
            return null;
        }
    }

    // Creating regex to get YEAR operator
    Pattern yearOperator = Pattern.compile(String.format("%s[(]([\\d]*)[)]", year));
    Matcher yearMatcher = yearOperator.matcher(searchStr);

    if (yearMatcher.matches()) {

        String value = yearMatcher.group(1);

        return dateExpression.year().eq(Integer.parseInt(value));
    }

    // Creating regex to get MONTH operator
    Pattern monthOperator = Pattern.compile(String.format("%s[(]([\\d]*)[)]", month));
    Matcher monthMatcher = monthOperator.matcher(searchStr);

    if (monthMatcher.matches()) {

        String value = monthMatcher.group(1);

        return dateExpression.month().eq(Integer.parseInt(value));
    }

    // Creating regex to get DAY operator
    Pattern dayOperator = Pattern.compile(String.format("%s[(]([\\d]*)[)]", day));
    Matcher dayMatcher = dayOperator.matcher(searchStr);

    if (dayMatcher.matches()) {

        String value = dayMatcher.group(1);

        return dateExpression.dayOfMonth().eq(Integer.parseInt(value));
    }

    // Creating regex to get BETWEEN operator
    Pattern betweenOperator = Pattern.compile(String.format("%s[(]([\\d\\/]*);([\\d\\/]*)[)]", between));
    Matcher betweenMatcher = betweenOperator.matcher(searchStr);

    if (betweenMatcher.matches()) {

        String valueFrom = betweenMatcher.group(1);
        String valueTo = betweenMatcher.group(2);

        if (StringUtils.isNotBlank(valueFrom) && StringUtils.isNotBlank(valueTo)) {

            try {

                Date dateFrom = dateFormat.parse(valueFrom);
                Date dateTo = dateFormat.parse(valueTo);

                Calendar dateFromCal = Calendar.getInstance();
                dateFromCal.setTime(dateFrom);

                Calendar dateToCal = Calendar.getInstance();
                dateToCal.setTime(dateTo);

                return dateExpression.between(conversionService.convert(dateFromCal, fieldType),
                        conversionService.convert(dateToCal, fieldType));

            } catch (Exception e) {
                return null;
            }
        }

    }

    return null;
}

From source file:org.gvnix.web.datatables.util.QuerydslUtils.java

/**
 * Utility for constructing where clause expressions.
 * /*from  ww w. j  av a  2s . c  o  m*/
 * @param entityPath Full path to entity and associations. For example:
 *        {@code Pet} , {@code Pet.owner}
 * @param fieldName Property name in the given entity path. For example:
 *        {@code name} in {@code Pet} entity, {@code firstName} in
 *        {@code Pet.owner} entity.
 * @param fieldType Property value {@code Class}
 * @param searchStr the value to find, may be null
 * @return Predicate
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T> Predicate createExpression(PathBuilder<T> entityPath, String fieldName, String searchStr,
        ConversionService conversionService, MessageSource messageSource) {

    TypeDescriptor descriptor = getTypeDescriptor(fieldName, entityPath);
    if (descriptor == null) {
        throw new IllegalArgumentException(
                String.format("Can't found field '%s' on entity '%s'", fieldName, entityPath.getType()));
    }
    Class<?> fieldType = descriptor.getType();

    // Check for field type in order to delegate in custom-by-type
    // create expression method
    if (String.class == fieldType) {
        return createStringExpressionWithOperators(entityPath, fieldName, searchStr, conversionService,
                messageSource);
    } else if (Boolean.class == fieldType || boolean.class == fieldType) {
        return createBooleanExpressionWithOperators(entityPath, fieldName, searchStr, conversionService,
                messageSource);
    } else if (Number.class.isAssignableFrom(fieldType) || NUMBER_PRIMITIVES.contains(fieldType)) {
        return createNumberExpressionGenericsWithOperators(entityPath, fieldName, descriptor, searchStr,
                conversionService, messageSource);
    } else if (Date.class.isAssignableFrom(fieldType) || Calendar.class.isAssignableFrom(fieldType)) {
        String datePattern = "dd/MM/yyyy";
        if (messageSource != null) {
            datePattern = messageSource.getMessage("global.filters.operations.date.pattern", null,
                    LocaleContextHolder.getLocale());
        }
        BooleanExpression expression = createDateExpressionWithOperators(entityPath, fieldName,
                (Class<Date>) fieldType, searchStr, conversionService, messageSource, datePattern);
        return expression;
    }

    else if (fieldType.isEnum()) {
        return createEnumExpression(entityPath, fieldName, searchStr, (Class<? extends Enum>) fieldType);
    }
    return null;
}

From source file:org.gvnix.web.datatables.util.DatatablesUtils.java

public static boolean checkNumericFilters(String expression, MessageSource messageSource) {
    if (NumberUtils.isNumber(expression)) {
        return true;
    } else {/*from w  w  w  .  j  a v a 2s . c  om*/
        // Getting expressions with symbols
        Pattern symbolOperator = Pattern.compile("([!=><][=>]?)([-]?[\\d.,]*)");
        Matcher symbolMatcher = symbolOperator.matcher(expression);

        if (symbolMatcher.matches()) {

            String symbolExpression = symbolMatcher.group(1);
            String value = symbolMatcher.group(2);

            if (!StringUtils.isBlank(value)) {
                if (symbolExpression.equals("=") || symbolExpression.equals("==")) {
                    return true;
                } else if (symbolExpression.equals(">") || symbolExpression.equals(">>")) {
                    return true;
                } else if (symbolExpression.equals("<")) {
                    return true;
                } else if (symbolExpression.equals(">=")) {
                    return true;
                } else if (symbolExpression.equals("<=")) {
                    return true;
                } else if (symbolExpression.equals("!=") || symbolExpression.equals("<>")) {
                    return true;
                }
            }
        }

        // Get all operations
        String isNullOperation = ISNULL_OPE;
        String isNotNullOperation = NOTNULL_OPE;
        String betweenOperation = "BETWEEN";

        if (messageSource != null) {
            isNullOperation = messageSource.getMessage(G_ISNULL_OPE, null, LocaleContextHolder.getLocale());
            isNotNullOperation = messageSource.getMessage(G_NOTNULL_OPE, null, LocaleContextHolder.getLocale());
            betweenOperation = messageSource.getMessage("global.filters.operations.number.between", null,
                    LocaleContextHolder.getLocale());
        }

        // If written function is BETWEEN function
        Pattern betweenFunctionOperator = Pattern
                .compile(String.format("%s[(]([-]?[\\d.,]*);([-]?[\\d.,]*)[)]", betweenOperation));
        Matcher betweenFunctionMatcher = betweenFunctionOperator.matcher(expression);

        if (betweenFunctionMatcher.matches()) {
            // Getting valueFrom and valueTo
            String valueFrom = betweenFunctionMatcher.group(1);
            String valueTo = betweenFunctionMatcher.group(2);
            if (!StringUtils.isBlank(valueFrom) && !StringUtils.isBlank(valueTo)) {
                return true;
            }
        }

        // If written expression is ISNULL operation
        Pattern isNullOperator = Pattern.compile(String.format("%s", isNullOperation));
        Matcher isNullMatcher = isNullOperator.matcher(expression);
        if (isNullMatcher.matches()) {
            return true;

        }

        // If written expression is ISNOTNULL operation
        Pattern isNotNullOperator = Pattern.compile(String.format("%s", isNotNullOperation));
        Matcher isNotNullMatcher = isNotNullOperator.matcher(expression);
        if (isNotNullMatcher.matches()) {
            return true;

        }
    }
    return false;
}

From source file:org.gvnix.web.datatables.util.QuerydslUtils.java

/**
 * This method returns the query expression based on String expression
 * user-written./*from w  w  w.j av a  2s .c om*/
 * 
 * Expression can be "=", ">", "<", ">=", "<=", "<>", "!=",
 * "ENTRENUMERO(n1;n2)"
 * 
 * @param searchStr
 * @return
 */
@SuppressWarnings("unchecked")
public static <T, N extends java.lang.Number & java.lang.Comparable<?>> BooleanExpression getNumericFilterExpression(
        PathBuilder<T> entityPath, String fieldName, Class<N> fieldType, TypeDescriptor descriptor,
        String searchStr, ConversionService conversionService, MessageSource messageSource) {

    if (StringUtils.isEmpty(searchStr)) {
        return null;
    }

    TypeDescriptor strDesc = STRING_TYPE_DESCRIPTOR;

    NumberPath<N> numberExpression = entityPath.getNumber(fieldName, fieldType);

    // If written expression is a symbol operation expression

    // Getting expressions with symbols
    Pattern symbolOperator = Pattern.compile("([!=><][=>]?)([-]?[\\d.,]*)");
    Matcher symbolMatcher = symbolOperator.matcher(searchStr);

    if (symbolMatcher.matches()) {

        String symbolExpression = symbolMatcher.group(1);
        String value = symbolMatcher.group(2);

        if (!StringUtils.isBlank(value)) {

            Object valueConverted = conversionService.convert(value, strDesc, descriptor);

            if (symbolExpression.equals("=") || symbolExpression.equals("==")) {
                return numberExpression.eq((N) valueConverted);
            } else if (symbolExpression.equals(">") || symbolExpression.equals(">>")) {
                return numberExpression.gt((N) valueConverted);
            } else if (symbolExpression.equals("<")) {
                return numberExpression.lt((N) valueConverted);
            } else if (symbolExpression.equals(">=")) {
                return numberExpression.goe((N) valueConverted);
            } else if (symbolExpression.equals("<=")) {
                return numberExpression.loe((N) valueConverted);
            } else if (symbolExpression.equals("!=") || symbolExpression.equals("<>")) {
                return numberExpression.ne((N) valueConverted);
            }
        }
    }

    // Get all operations
    String isNullOperation = OPERATOR_ISNULL;
    String isNotNullOperation = OPERATOR_NOTNULL;
    String betweenOperation = "BETWEEN";

    if (messageSource != null) {
        isNullOperation = messageSource.getMessage(G_FIL_OPE_ISNULL, null, LocaleContextHolder.getLocale());
        isNotNullOperation = messageSource.getMessage(G_FIL_OPE_NOTNULL, null, LocaleContextHolder.getLocale());
        betweenOperation = messageSource.getMessage("global.filters.operations.number.between", null,
                LocaleContextHolder.getLocale());
    }

    // If written function is BETWEEN function
    Pattern betweenFunctionOperator = Pattern
            .compile(String.format("%s[(]([-]?[\\d.,]*);([-]?[\\d.,]*)[)]", betweenOperation));
    Matcher betweenFunctionMatcher = betweenFunctionOperator.matcher(searchStr);

    if (betweenFunctionMatcher.matches()) {
        // Getting valueFrom and valueTo
        String valueFrom = betweenFunctionMatcher.group(1);
        String valueTo = betweenFunctionMatcher.group(2);

        Object valueFromConverted = conversionService.convert(valueFrom, strDesc, descriptor);
        Object valueToConverted = conversionService.convert(valueTo, strDesc, descriptor);

        if (!StringUtils.isBlank(valueFrom) && !StringUtils.isBlank(valueTo)) {
            return numberExpression.between((N) valueFromConverted, (N) valueToConverted);
        }
    }

    // If written expression is ISNULL operation
    Pattern isNullOperator = Pattern.compile(String.format("%s", isNullOperation));
    Matcher isNullMatcher = isNullOperator.matcher(searchStr);
    if (isNullMatcher.matches()) {
        return numberExpression.isNull();

    }

    // If written expression is ISNOTNULL operation
    Pattern isNotNullOperator = Pattern.compile(String.format("%s", isNotNullOperation));
    Matcher isNotNullMatcher = isNotNullOperator.matcher(searchStr);
    if (isNotNullMatcher.matches()) {
        return numberExpression.isNotNull();

    }

    return null;
}

From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.util.AwsCredentialUtil.java

public static AWSCredentials getAWSCredentials(String awsAccessKey, String awsSecretKey, String roleARN) {
    AWSCredentials awsCredentials;/*from w w w  .j a  v a  2  s. co  m*/
    if (isNotEmpty(awsAccessKey) && isNotEmpty(awsSecretKey)) {
        awsCredentials = new BasicAWSCredentials(awsAccessKey.trim(), awsSecretKey.trim());

        // Use user long-term credentials to call the
        // AWS Security Token Service (STS) AssumeRole API, specifying
        // the ARN for the role -RO-role in amazon account.
        if (isNotEmpty(roleARN)) {
            AWSSecurityTokenServiceClient stsClient = new AWSSecurityTokenServiceClient(awsCredentials);

            AssumeRoleRequest assumeRequest = new AssumeRoleRequest().withRoleArn(roleARN.trim())
                    .withRoleSessionName("JRSRequest");

            AssumeRoleResult assumeResult = null;
            try {
                assumeResult = stsClient.assumeRole(assumeRequest);
            } catch (Exception ex) {
                logger.error(ex);
                throw new JSShowOnlyErrorMessage(ex.getMessage());
            }

            // AssumeRole returns temporary security credentials for
            // the IAM role.
            awsCredentials = new BasicSessionCredentials(assumeResult.getCredentials().getAccessKeyId(),
                    assumeResult.getCredentials().getSecretAccessKey(),
                    assumeResult.getCredentials().getSessionToken());
        }
    } else {
        //Try getting Ec2 instance credentials.
        AWSCredentialsProvider instanceCredentialsProvider = new DefaultAWSCredentialsProviderChain();
        try {
            awsCredentials = instanceCredentialsProvider.getCredentials();
        } catch (Exception ex) {
            ApplicationContext ctx = StaticApplicationContext.getApplicationContext();
            MessageSource message = ctx.getBean("messageSource", MessageSource.class);

            logger.error("Exception loading default JRS instance credentials", ex);
            throw new JSShowOnlyErrorMessage(
                    message.getMessage("aws.exception.datasource.load.default.credentials", null,
                            LocaleContextHolder.getLocale()));
        }
    }
    return awsCredentials;
}

From source file:com.jaspersoft.jasperserver.war.common.JasperServerUtil.java

public static DateFormat createCalendarDateFormat(MessageSource messages, Locale locale) {
    String pattern = messages.getMessage("date.format", null, locale);
    return new SimpleDateFormat(pattern);
}

From source file:com.jaspersoft.jasperserver.war.common.JasperServerUtil.java

public static DateFormat createCalendarDateTimeFormat(MessageSource messages, Locale locale) {
    String pattern = messages.getMessage("datetime.format", null, locale);
    return new SimpleDateFormat(pattern);
}

From source file:com.jaspersoft.jasperserver.war.common.JasperServerUtil.java

public static DateFormat createCalendarTimeFormat(MessageSource messages, Locale locale) {
    String pattern = messages.getMessage("time.format", null, locale);
    return new SimpleDateFormat(pattern);
}