class JpaQueryUtils {

    @Nullable
    public static String createSelectOrderExpression( @Nullable List<org.hisp.dhis.query.Order> orders, @Nullable String alias )
    {
        if ( orders == null )
        {
            return null;
        }

        return StringUtils.defaultIfEmpty( orders.stream().filter( o -> o.isPersisted() && isIgnoreCase( o ) ).map( o -> {
            final StringBuilder sb = new StringBuilder( "lower(" );

            if ( alias != null )
            {
                sb.append( alias ).append( '.' );
            }

            sb.append( o.getProperty().getName() ).append( ')' );

            return sb.toString();
        } ).collect( Collectors.joining( "," ) ), null );
    }

}