/** * Adds grid columns for each organisation unit level. */ @SuppressWarnings( "unchecked" ) private void addHierarchyColumns( Grid grid, int ouIdColumnIndex ) { Map<Object, List<?>> ancestorMap = (Map<Object, List<?>>) grid.getInternalMetaData().get( AnalyticsMetaDataKey.ORG_UNIT_ANCESTORS.getKey() ); Assert.notEmpty( ancestorMap, "Ancestor map cannot be null or empty when show hierarchy is enabled" ); int newColumns = ancestorMap.values().stream().mapToInt( List::size ).max().orElseGet( () -> 0 ); List<GridHeader> headers = new ArrayList<>(); for ( int i = 0; i < newColumns; i++ ) { int level = i + 1; String name = String.format( "Org unit level %d", level ); String column = String.format( "orgunitlevel%d", level ); headers.add( new GridHeader( name, column, ValueType.TEXT, String.class.getName(), false, true ) ); } grid.addHeaders( ouIdColumnIndex, headers ); grid.addAndPopulateColumnsBefore( ouIdColumnIndex, ancestorMap, newColumns ); }
@Override public void populateSqlViewGrid( Grid grid, String sql ) { SqlRowSet rs = readOnlyJdbcTemplate.queryForRowSet( sql ); int maxLimit = (Integer) systemSettingManager.getSystemSetting( SettingKey.SQL_VIEW_MAX_LIMIT ); log.debug( "Get view SQL: " + sql + ", max limit: " + maxLimit ); grid.addHeaders( rs ); grid.addRows( rs, maxLimit ); }