QueryUtils { @Nonnull public static List<Order> convertOrderStrings( @Nullable Collection<String> orders, @Nonnull Schema schema ) { if ( orders == null ) { return Collections.emptyList(); } final Map<String, Order> result = new LinkedHashMap<>(); for ( String o : orders ) { String[] split = o.split( ":" ); String direction = "asc"; if ( split.length < 1 ) { continue; } else if ( split.length == 2 ) { direction = split[1].toLowerCase(); } String propertyName = split[0]; Property property = schema.getProperty( propertyName ); if ( result.containsKey( propertyName ) || !schema.haveProperty( propertyName ) || !validProperty( property ) || !validDirection( direction ) ) { continue; } result.put( propertyName, Order.from( direction, property ) ); } return new ArrayList<>( result.values() ); }  static T parseValue( Class<T> klass, Object objectValue ); @SuppressWarnings( "unchecked" ) static T parseValue( Class<T> klass, Class<?> secondaryKlass, Object objectValue ); @SuppressWarnings( { "unchecked", "rawtypes" } ) static T getEnumValue( Class<T> klass, String value ); static Object parseValue( String value ); static String parseSelectFields( List<String> fields ); static String convertCollectionValue( String value ); static String parseFilterOperator( String operator, String value ); @Nonnull static List<Order> convertOrderStrings( @Nullable Collection<String> orders, @Nonnull Schema schema ); static T getSingleResult( TypedQuery<T> query );  }
@Test public void testConvertOrderStringsNull() { Assert.assertEquals( Collections.emptyList(), QueryUtils.convertOrderStrings( null, schema ) ); }
@Test public void testConvertOrderStrings() { List<Order> orders = QueryUtils.convertOrderStrings( Arrays.asList( "value1:asc", "value2:asc", "value3:iasc", "value4:desc", "value5:idesc", "value6:xdesc", "value7" ), schema ); Assert.assertEquals( 5, orders.size() ); Assert.assertEquals( orders.get( 0 ), Order.from( "asc", schema.getProperty( "value1" ) ) ); Assert.assertEquals( orders.get( 1 ), Order.from( "iasc", schema.getProperty( "value3" ) ) ); Assert.assertEquals( orders.get( 2 ), Order.from( "desc", schema.getProperty( "value4" ) ) ); Assert.assertEquals( orders.get( 3 ), Order.from( "idesc", schema.getProperty( "value5" ) ) ); Assert.assertEquals( orders.get( 4 ), Order.from( "asc", schema.getProperty( "value7" ) ) ); }