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 ); }  static Function<Root<?>, Order> getOrders( CriteriaBuilder builder, String field ); static Predicate stringPredicateCaseSensitive( CriteriaBuilder builder,
        Expression<String> expressionPath, Object objectValue, StringSearchMode searchMode ); static Predicate stringPredicateIgnoreCase( CriteriaBuilder builder,
        Expression<String> expressionPath, Object objectValue, StringSearchMode searchMode ); static Predicate getPredicate( CriteriaBuilder builder, Property property, Path<?> path, String operator, String value ); @Nullable static String createOrderExpression( @Nullable List<org.hisp.dhis.query.Order> orders, @Nullable String alias ); @Nullable static String createSelectOrderExpression( @Nullable List<org.hisp.dhis.query.Order> orders, @Nullable String alias ); static final String HIBERNATE_CACHEABLE_HINT; }
@Test public void createSelectOrderExpressionNull() { Assert.assertNull( JpaQueryUtils.createSelectOrderExpression( null, null ) ); }
@Test public void createSelectOrderExpressionNoPersistent() { final Property property = new Property(); property.setName( "valueTest" ); property.setSimple( true ); property.setPersisted( false ); Assert.assertNull( JpaQueryUtils.createSelectOrderExpression( Collections.singletonList( new Order( property, Direction.ASCENDING ) ), null ) ); }
@Test public void createSelectOrderExpression() { final Property property1 = new Property(); property1.setName( "value1" ); property1.setSimple( true ); property1.setPersisted( true ); property1.setKlass( String.class ); final Property property2 = new Property(); property2.setName( "value2" ); property2.setSimple( true ); property2.setPersisted( false ); final Property property3 = new Property(); property3.setName( "value3" ); property3.setSimple( true ); property3.setKlass( Integer.class ); property3.setPersisted( true ); final Property property4 = new Property(); property4.setName( "value4" ); property4.setSimple( true ); property4.setPersisted( true ); property4.setKlass( String.class ); final Property property5 = new Property(); property5.setName( "value5" ); property5.setSimple( true ); property5.setPersisted( true ); Assert.assertEquals( "lower(value1),lower(value4)", JpaQueryUtils.createSelectOrderExpression( Arrays.asList( new Order( property1, Direction.ASCENDING ).ignoreCase(), new Order( property2, Direction.ASCENDING ), new Order( property3, Direction.ASCENDING ).ignoreCase(), new Order( property4, Direction.ASCENDING ).ignoreCase(), new Order( property5, Direction.DESCENDING ) ), null ) ); }
@Test public void createSelectOrderExpressionSingle() { final Property property1 = new Property(); property1.setName( "value1" ); property1.setSimple( true ); property1.setKlass( String.class ); property1.setPersisted( true ); Assert.assertEquals( "lower(value1)", JpaQueryUtils.createSelectOrderExpression( Collections.singletonList( new Order( property1, Direction.ASCENDING ).ignoreCase() ), null ) ); }
@Test public void createSelectOrderExpressionAlias() { final Property property1 = new Property(); property1.setName( "value1" ); property1.setSimple( true ); property1.setKlass( String.class ); property1.setPersisted( true ); Assert.assertEquals( "lower(x.value1)", JpaQueryUtils.createSelectOrderExpression( Collections.singletonList( new Order( property1, Direction.ASCENDING ).ignoreCase() ), "x" ) ); }