@Test public void testPostProcessWithSortConstraints() { String query = "query"; DataRow parameters = mock( DataRow.class ); TableModel tableModel = mock( TableModel.class ); doReturn( 2 ).when( tableModel ).getRowCount(); doReturn( 1 ).when( tableModel ).getColumnCount(); List<Object> querySort = new ArrayList<Object>(); doReturn( querySort ).when( parameters ).get( DataFactory.QUERY_SORT ); TableModel result = factory.postProcess( query, parameters, tableModel ); assertThat( result, is( equalTo( tableModel ) ) ); querySort.add( "val_0" ); SortConstraint sortConstraint = new SortConstraint( "field", true ); querySort.add( sortConstraint ); SortConstraint emptySortConstraint = new SortConstraint( "", true ); querySort.add( emptySortConstraint ); SortConstraint columnSortConstraint = new SortConstraint( ClassicEngineBoot.INDEX_COLUMN_PREFIX + "0", true ); querySort.add( columnSortConstraint ); doReturn( querySort ).when( parameters ).get( DataFactory.QUERY_SORT ); doReturn( "test_column_name" ).when( tableModel ).getColumnName( 0 ); result = factory.postProcess( query, parameters, tableModel ); assertThat( result, is( not( equalTo( tableModel ) ) ) ); assertThat( result, is( instanceOf( SortingTableModel.class ) ) ); }
protected TableModel postProcess( final String query, final DataRow parameters, final TableModel tableModel ) { if ( tableModel == null ) { logger.debug( "No data, therefore no sorting." ); return null; } if ( tableModel.getRowCount() == 1 || tableModel.getColumnCount() == 0 ) { logger.debug( "Empty data, therefore no sorting." ); return tableModel; } Object o = parameters.get( DataFactory.QUERY_SORT ); if ( ( o instanceof List<?> ) == false ) { logger.debug( "Sort constraints are not in list format." ); return tableModel; } List<SortConstraint> sort = validate( (List<?>) o ); List<SortConstraint> resolvedConstraints = resolveColumnAliases( tableModel, sort ); if ( resolvedConstraints.isEmpty() ) { logger.debug( "Resolved sort constraints are empty." ); return tableModel; } return sort( tableModel, resolvedConstraints ); }
SortingDataFactory extends CompoundDataFactory { protected TableModel postProcess( final String query, final DataRow parameters, final TableModel tableModel ) { if ( tableModel == null ) { logger.debug( "No data, therefore no sorting." ); return null; } if ( tableModel.getRowCount() == 1 || tableModel.getColumnCount() == 0 ) { logger.debug( "Empty data, therefore no sorting." ); return tableModel; } Object o = parameters.get( DataFactory.QUERY_SORT ); if ( ( o instanceof List<?> ) == false ) { logger.debug( "Sort constraints are not in list format." ); return tableModel; } List<SortConstraint> sort = validate( (List<?>) o ); List<SortConstraint> resolvedConstraints = resolveColumnAliases( tableModel, sort ); if ( resolvedConstraints.isEmpty() ) { logger.debug( "Resolved sort constraints are empty." ); return tableModel; } return sort( tableModel, resolvedConstraints ); } }
SortingDataFactory extends CompoundDataFactory { protected TableModel postProcess( final String query, final DataRow parameters, final TableModel tableModel ) { if ( tableModel == null ) { logger.debug( "No data, therefore no sorting." ); return null; } if ( tableModel.getRowCount() == 1 || tableModel.getColumnCount() == 0 ) { logger.debug( "Empty data, therefore no sorting." ); return tableModel; } Object o = parameters.get( DataFactory.QUERY_SORT ); if ( ( o instanceof List<?> ) == false ) { logger.debug( "Sort constraints are not in list format." ); return tableModel; } List<SortConstraint> sort = validate( (List<?>) o ); List<SortConstraint> resolvedConstraints = resolveColumnAliases( tableModel, sort ); if ( resolvedConstraints.isEmpty() ) { logger.debug( "Resolved sort constraints are empty." ); return tableModel; } return sort( tableModel, resolvedConstraints ); } SortingDataFactory( final DataFactory parent, final PerformanceMonitorContext performanceMonitorContext ); }
SortingDataFactory extends CompoundDataFactory { protected TableModel postProcess( final String query, final DataRow parameters, final TableModel tableModel ) { if ( tableModel == null ) { logger.debug( "No data, therefore no sorting." ); return null; } if ( tableModel.getRowCount() == 1 || tableModel.getColumnCount() == 0 ) { logger.debug( "Empty data, therefore no sorting." ); return tableModel; } Object o = parameters.get( DataFactory.QUERY_SORT ); if ( ( o instanceof List<?> ) == false ) { logger.debug( "Sort constraints are not in list format." ); return tableModel; } List<SortConstraint> sort = validate( (List<?>) o ); List<SortConstraint> resolvedConstraints = resolveColumnAliases( tableModel, sort ); if ( resolvedConstraints.isEmpty() ) { logger.debug( "Resolved sort constraints are empty." ); return tableModel; } return sort( tableModel, resolvedConstraints ); } SortingDataFactory( final DataFactory parent, final PerformanceMonitorContext performanceMonitorContext );  }
SortingDataFactory extends CompoundDataFactory { protected TableModel postProcess( final String query, final DataRow parameters, final TableModel tableModel ) { if ( tableModel == null ) { logger.debug( "No data, therefore no sorting." ); return null; } if ( tableModel.getRowCount() == 1 || tableModel.getColumnCount() == 0 ) { logger.debug( "Empty data, therefore no sorting." ); return tableModel; } Object o = parameters.get( DataFactory.QUERY_SORT ); if ( ( o instanceof List<?> ) == false ) { logger.debug( "Sort constraints are not in list format." ); return tableModel; } List<SortConstraint> sort = validate( (List<?>) o ); List<SortConstraint> resolvedConstraints = resolveColumnAliases( tableModel, sort ); if ( resolvedConstraints.isEmpty() ) { logger.debug( "Resolved sort constraints are empty." ); return tableModel; } return sort( tableModel, resolvedConstraints ); } SortingDataFactory( final DataFactory parent, final PerformanceMonitorContext performanceMonitorContext );   }