DimensionalObjectUtils { 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; }  static List<DimensionalObject> getCopies( List<DimensionalObject> dimensions ); static List<String> getDimensions( Collection<DimensionalObject> dimensions ); static NameableObject[][] getItemArray( List<DimensionalObject> dimensions ); @SafeVarargs static Map<T, T> asMap( final T... elements ); static String getDimensionFromParam( String param ); static List<String> getDimensionItemsFromParam( String param ); static List<String> getItemsFromParam( String param ); static boolean anyDimensionHasItems( Collection<DimensionalObject> dimensions ); static String getValueFromKeywordParam( String param ); static String getUidFromGroupParam( String param ); static void setDimensionItemsForFilters( DimensionalObject dimension, Grid grid, boolean naForNull ); static String getPrettyFilter( String filter ); static boolean isCompositeDimensionalObject( String expression ); static String getFirstIdentifer( String compositeItem ); static String getSecondIdentifer( String compositeItem ); static boolean isWildCard( String identifier ); static List<DimensionalItemObject> getList( DimensionalItemObject... objects ); static List<DimensionalItemObject> asList( Collection<? extends DimensionalItemObject> collection ); static List<DimensionalObject> asDimensionalObjectList( Collection<? extends DimensionalObject> collection ); @SuppressWarnings("unchecked") static List<T> asTypedList( Collection<DimensionalItemObject> collection ); static List<DimensionalItemObject> getDimensionalItemObjects( Collection<?> values, boolean naForNull ); static List<String> getDimensionalItemIds( Collection<DimensionalItemObject> objects ); static Set<DimensionalItemObject> getDataElements( Collection<DataElementOperand> operands ); static Set<DimensionalItemObject> getCategoryOptionCombos( Collection<DataElementOperand> operands ); static Set<DimensionalItemObject> getAttributeOptionCombos( Collection<DataElementOperand> operands ); static Map<String, String> getDimensionItemIdSchemeMap( Collection<? extends DimensionalItemObject> objects, IdScheme idScheme ); static Map<String, String> getDataElementOperandIdSchemeMap( Collection<DataElementOperand> dataElementOperands, IdScheme idScheme ); static String getDimensionItem( String uid, ReportingRateMetric metric ); static List<DimensionalItemObject> replaceOperandTotalsWithDataElements( List<DimensionalItemObject> items ); static String getKey( List<DimensionalItemObject> column, List<DimensionalItemObject> row ); static Map<String, Object> getSortedKeysMap( Map<String, Object> valueMap ); static String sortKey( String key ); static String getKey( List<DimensionalItemObject> objects ); static String getName( List<DimensionalItemObject> objects ); static Map<DimensionalItemObject, Double> convertToDimItemValueMap(
        List<DimensionItemObjectValue> dimensionItemObjectValues ); static final String COMPOSITE_DIM_OBJECT_ESCAPED_SEP; static final String COMPOSITE_DIM_OBJECT_PLAIN_SEP; static final String TITLE_ITEM_SEP; static final String NULL_REPLACEMENT; static final String NAME_SEP; static final String COL_SEP; }
@Test public void testGetUidMapIsSchemeCode() { DataElement deA = new DataElement( "NameA" ); DataElement deB = new DataElement( "NameB" ); DataElement deC = new DataElement( "NameC" ); deA.setUid( "A123456789A" ); deB.setUid( "A123456789B" ); deC.setUid( "A123456789C" ); deA.setCode( "CodeA" ); deB.setCode( "CodeB" ); deC.setCode( null ); List<DataElement> elements = Lists.newArrayList( deA, deB, deC ); Map<String, String> map = DimensionalObjectUtils.getDimensionItemIdSchemeMap( elements, IdScheme.CODE ); assertEquals( 3, map.size() ); assertEquals( "CodeA", map.get( "A123456789A" ) ); assertEquals( "CodeB", map.get( "A123456789B" ) ); assertEquals( null, map.get( "A123456789C" ) ); }
@Test public void testGetUidMapIsSchemeCodeCompositeObject() { Program prA = new Program(); prA.setUid( "P123456789A" ); prA.setCode( "PCodeA" ); DataElement deA = new DataElement( "NameA" ); DataElement deB = new DataElement( "NameB" ); deA.setUid( "D123456789A" ); deB.setUid( "D123456789B" ); deA.setCode( "DCodeA" ); deB.setCode( "DCodeB" ); ProgramDataElementDimensionItem pdeA = new ProgramDataElementDimensionItem( prA, deA ); ProgramDataElementDimensionItem pdeB = new ProgramDataElementDimensionItem( prA, deB ); List<ProgramDataElementDimensionItem> elements = Lists.newArrayList( pdeA, pdeB ); Map<String, String> map = DimensionalObjectUtils.getDimensionItemIdSchemeMap( elements, IdScheme.CODE ); assertEquals( 2, map.size() ); assertEquals( "PCodeA.DCodeA", map.get( "P123456789A.D123456789A" ) ); assertEquals( "PCodeA.DCodeB", map.get( "P123456789A.D123456789B" ) ); }
@Test public void testGetUidMapIsSchemeAttribute() { DataElement deA = new DataElement( "DataElementA" ); DataElement deB = new DataElement( "DataElementB" ); DataElement deC = new DataElement( "DataElementC" ); deA.setUid( "A123456789A" ); deB.setUid( "A123456789B" ); deC.setUid( "A123456789C" ); Attribute atA = new Attribute( "AttributeA", ValueType.INTEGER ); atA.setUid( "ATTR123456A" ); AttributeValue avA = new AttributeValue( "AttributeValueA", atA ); AttributeValue avB = new AttributeValue( "AttributeValueB", atA ); deA.setAttributeValues( Sets.newHashSet( avA ) ); deB.setAttributeValues( Sets.newHashSet( avB ) ); List<DataElement> elements = Lists.newArrayList( deA, deB, deC ); String scheme = IdScheme.ATTR_ID_SCHEME_PREFIX + atA.getUid(); IdScheme idScheme = IdScheme.from( scheme ); Map<String, String> map = DimensionalObjectUtils.getDimensionItemIdSchemeMap( elements, idScheme ); assertEquals( 3, map.size() ); assertEquals( "AttributeValueA", map.get( "A123456789A" ) ); assertEquals( "AttributeValueB", map.get( "A123456789B" ) ); assertEquals( null, map.get( "A123456789C" ) ); }