/** * Returns a mapping between the base dimension item identifier and the * dimension item identifier defined by the given identifier scheme. * * @param objects the dimensional item objects. * @param idScheme the identifier scheme. * @return a mapping between dimension item identifiers. */ public static Map<String, String> getDimensionItemIdSchemeMap( Collection<? extends DimensionalItemObject> objects, IdScheme idScheme ) { Map<String, String> map = Maps.newHashMap(); objects.forEach( obj -> map.put( obj.getDimensionItem(), obj.getDimensionItem( IdScheme.from( idScheme ) ) ) ); return map; }
map.put( item.getDimensionItem(), new MetadataItem( item.getDisplayProperty( params.getDisplayProperty() ), includeMetadataDetails ? item : null ) );
/** * From the initial valueMap containing expression items with full * DimensionalItemObjects, makes a hash map that can be used for fast * lookup from the identifier found in the expression. This allows the * DimensionalItemObject to be identified from the expression without * the overhead of calling the IdentifiableObjectManager. * * @param valueMap the given valueMap. */ private void makeKeyValueMap( Map<DimensionalItemObject, Double> valueMap ) { keyValueMap = valueMap.entrySet().stream().collect( Collectors.toMap( e -> e.getKey().getDimensionItem(), e -> e.getValue() ) ); }
@Override public String toString() { if ( option != null ) { return option.getCode(); } else { return dimensionalItemObject.getDimensionItem(); } } }
/** * Returns an array of identifiers of the dimension items in the given list. * If no items are given or items are null, an empty array is returned. */ public static String[] getItemIdentifiers( List<DimensionItem> items ) { List<String> itemUids = new ArrayList<>(); if ( items != null && !items.isEmpty() ) { for ( DimensionItem item : items ) { itemUids.add( item != null ? item.getItem().getDimensionItem() : null ); } } return itemUids.toArray( CollectionUtils.STRING_ARR ); }
/** * Generates an identifier based on the given lists of {@link NameableObject}. Uses * the identifiers for each nameable object, sorts them and writes them out as a key. * * @param column list of dimension items representing a column. * @param row list of dimension items representing a row. * @return an identifier representing a column item and a row item. */ public static String getIdentifier( List<DimensionalItemObject> column, List<DimensionalItemObject> row ) { List<String> ids = new ArrayList<>(); List<DimensionalItemObject> dimensions = new ArrayList<>(); dimensions.addAll( column != null ? column : new ArrayList<>() ); dimensions.addAll( row != null ? row : new ArrayList<>() ); for ( DimensionalItemObject item : dimensions ) { ids.add( item.getDimensionItem() ); } Collections.sort( ids ); return StringUtils.join( ids, DIMENSION_SEP ); }
/** * Returns a string key for dimension items in the given list. The key is * a concatenation of the dimension items separated by the dimension separator. * If no items are given or items is null, an empty string is returned. */ public static String asItemKey( List<DimensionItem> items ) { StringBuilder builder = new StringBuilder(); if ( items != null && !items.isEmpty() ) { for ( DimensionItem item : items ) { builder.append( item.getItem().getDimensionItem() ).append( DIMENSION_SEP ); } builder.deleteCharAt( builder.length() - 1 ); } return builder.toString(); }
/** * Returns a mapping between dimension item identifiers and dimensional * item object for the given query. * * @param params the data query parameters. * @return a mapping between identifiers and names. */ public static Map<String, DimensionalItemObject> getDimensionalItemObjectMap( DataQueryParams params ) { List<DimensionalObject> dimensions = params.getDimensionsAndFilters(); Map<String, DimensionalItemObject> map = new HashMap<>(); for ( DimensionalObject dimension : dimensions ) { dimension.getItems().stream().forEach( i -> map.put( i.getDimensionItem(), i ) ); } return map; }
.collect( Collectors.toMap( o -> o.getUid(), o -> o ) ); Map<String, DimensionalItemObject> dxLookup = periodTypeX.getEventItems().stream() .collect( Collectors.toMap( d -> d.getDimensionItem(), d -> d ) );
String valueItem = params.getValue().getDimensionItem();
collect( Collectors.toMap( e -> e.getKey().getDimensionItem(), e -> e.getValue() ) );
Map<String, DimensionalItemObject> dimensionItemLookup = dimensionItems.stream().collect( Collectors.toMap( d -> d.getDimensionItem(), d -> d ) ); Map<String, OrganisationUnit> orgUnitLookup = orgUnits.stream().collect( Collectors.toMap( o -> o.getUid(), o -> o ) );
@Override public String getKey() { QueryKey key = new QueryKey(); key.add( getDimension() ); getItems().forEach( e -> key.add( e.getDimensionItem() ) ); return key .add( allItems ) .addIgnoreNull( legendSet ) .addIgnoreNull( aggregationType ) .addIgnoreNull( filter ).asPlainKey(); }
map.put( item.getDimensionItem(), item.getDisplayProperty( params.getDisplayProperty() ) );
/** * Generates a sub query which provides a view of the data where each row is * ranked by the execution date, latest first. The events are partitioned by * org unit and attribute option combo. A column {@code pe_rank} defines the rank. * Only data for the last 10 years relative to the period end date is included. */ private String getLastValueSubquerySql( EventQueryParams params ) { Assert.isTrue( params.hasValueDimension(), "Last value aggregation type query must have value dimension" ); Date latest = params.getLatestEndDate(); Date earliest = addYears( latest, LAST_VALUE_YEARS_OFFSET ); String valueItem = quote( params.getValue().getDimensionItem() ); List<String> columns = getLastValueSubqueryQuotedColumns( params ); String alias = getPeriodAlias( params ); String timeCol = quote( alias, params.getTimeFieldAsFieldFallback() ); String sql = "(select "; for ( String col : columns ) { sql += col + ","; } sql += "row_number() over (" + "partition by ou, ao " + "order by " + timeCol + " desc) as pe_rank " + "from " + params.getTableName() + " " + "where " + timeCol + " >= '" + getMediumDateString( earliest ) + "' " + "and " + timeCol + " <= '" + getMediumDateString( latest ) + "' " + "and " + valueItem + " is not null)"; return sql; }
grid.addValue( object.getDimensionItem() ); grid.addValue( object.getDisplayProperty( displayProperty ) ); grid.addValue( object.getCode() );