CategoryOptionGroupResolver implements
    ExpressionResolver { @Override @Transactional( readOnly = true ) public String resolve( String expression ) { Set<DimensionalItemId> dimItemIds = expressionService.getExpressionDimensionalItemIds( expression, INDICATOR_EXPRESSION ); List<String> resolvedOperands = new ArrayList<>(); if ( isDataElementOperand( dimItemIds ) ) { DimensionalItemId dimensionalItemId = dimItemIds.stream().findFirst().get(); String dataElementUid = dimensionalItemId.getId0(); resolvedOperands .addAll( evaluate( dataElementUid, dimensionalItemId.getId1(), dimensionalItemId.getId2() ) ); resolvedOperands.addAll( evaluate( dataElementUid, dimensionalItemId.getId2(), null ) ); } if ( resolvedOperands.isEmpty() ) { resolvedOperands.add( expression ); } return Joiner.on( "+" ).join( resolvedOperands ); } CategoryOptionGroupResolver( CategoryOptionGroupStore categoryOptionGroupStore, CategoryOptionComboStore categoryOptionComboStore,
        ExpressionService expressionService ); @Override @Transactional( readOnly = true ) String resolve( String expression );  }
@Test public void verifySecondElementIsCogThirdElementIsAoc() { DimensionalItemId dimensionalItemId = new DimensionalItemId( DimensionItemType.DATA_ELEMENT_OPERAND, elem1, elem2, elem3 ); CategoryOptionGroup categoryOptionGroup = createCategoryOptionGroup( 'A' ); String exp = createIndicatorExp(); when( expressionService.getExpressionDimensionalItemIds( exp, INDICATOR_EXPRESSION ) ) .thenReturn( Sets.newHashSet( dimensionalItemId ) ); when( categoryOptionGroupStore.getByUid( elem2 ) ).thenReturn( categoryOptionGroup ); List<CategoryOptionCombo> cocs = beanRandomizer.randomObjects( CategoryOptionCombo.class, COCS_IN_COG ); when( categoryOptionComboStore.getCategoryOptionCombosByGroupUid( categoryOptionGroup.getUid() ) ) .thenReturn( cocs ); when( categoryOptionComboStore.getByUid( elem3 ) ) .thenReturn( beanRandomizer.randomObject( CategoryOptionCombo.class ) ); String expression = resolver.resolve( exp ); List<String> expressionList = Arrays.asList( expression.split( "\\+" ) ); assertEquals( COCS_IN_COG, expressionList.size() ); collectionsHaveIdenticalValuesIgnoreOrder( expressionList, buildExpectedExpression( elem1, cocs, elem3 ) ); }
@Test public void verifySecondElementIsCogThirdElementIsCog() { DimensionalItemId dimensionalItemId = new DimensionalItemId( DimensionItemType.DATA_ELEMENT_OPERAND, elem1, elem2, elem3 ); CategoryOptionGroup categoryOptionGroup1 = createCategoryOptionGroup( 'A' ); CategoryOptionGroup categoryOptionGroup2 = createCategoryOptionGroup( 'B' ); String exp = createIndicatorExp(); when( expressionService.getExpressionDimensionalItemIds( exp, INDICATOR_EXPRESSION ) ) .thenReturn( Sets.newHashSet( dimensionalItemId ) ); when( categoryOptionGroupStore.getByUid( elem2 ) ).thenReturn( categoryOptionGroup1 ); when( categoryOptionGroupStore.getByUid( elem3 ) ).thenReturn( categoryOptionGroup2 ); List<CategoryOptionCombo> cocs1 = beanRandomizer.randomObjects( CategoryOptionCombo.class, COCS_IN_COG ); List<CategoryOptionCombo> cocs2 = beanRandomizer.randomObjects( CategoryOptionCombo.class, COCS_IN_COG ); when( categoryOptionComboStore.getCategoryOptionCombosByGroupUid( categoryOptionGroup1.getUid() ) ) .thenReturn( cocs1 ); when( categoryOptionComboStore.getCategoryOptionCombosByGroupUid( categoryOptionGroup2.getUid() ) ) .thenReturn( cocs2 ); String expression = resolver.resolve( exp ); List<String> expressionList = Arrays.asList( expression.split( "\\+" ) ); assertEquals( COCS_IN_COG * 2, expressionList.size() ); collectionsHaveIdenticalValuesIgnoreOrder( expressionList, buildExpectedExpression( elem1, cocs1, cocs2 ) ); }
@Test public void verifySecondElementIsCocThirdElementIsCog() { DimensionalItemId dimensionalItemId = new DimensionalItemId( DimensionItemType.DATA_ELEMENT_OPERAND, elem1, elem2, elem3 ); CategoryOptionGroup categoryOptionGroup1 = createCategoryOptionGroup( 'A' ); String exp = createIndicatorExp(); when( expressionService.getExpressionDimensionalItemIds( exp, INDICATOR_EXPRESSION ) ) .thenReturn( Sets.newHashSet( dimensionalItemId ) ); when( categoryOptionGroupStore.getByUid( elem3 ) ).thenReturn( categoryOptionGroup1 ); List<CategoryOptionCombo> cocs1 = beanRandomizer.randomObjects( CategoryOptionCombo.class, COCS_IN_COG ); when( categoryOptionComboStore.getCategoryOptionCombosByGroupUid( categoryOptionGroup1.getUid() ) ) .thenReturn( cocs1 ); String expression = resolver.resolve( exp ); List<String> expressionList = Arrays.asList( expression.split( "\\+" ) ); assertEquals( COCS_IN_COG , expressionList.size() ); collectionsHaveIdenticalValuesIgnoreOrder( expressionList, buildExpectedExpression( elem1, elem2, cocs1 ) ); }
@Test public void verifySecondElementIsCocThirdElementIsAoc() { DimensionalItemId dimensionalItemId = new DimensionalItemId( DimensionItemType.DATA_ELEMENT_OPERAND, elem1, elem2, elem3 ); String exp = createIndicatorExp(); when( expressionService.getExpressionDimensionalItemIds( exp, INDICATOR_EXPRESSION ) ) .thenReturn( Sets.newHashSet( dimensionalItemId ) ); String expression = resolver.resolve( exp ); List<String> expressionList = Arrays.asList( expression.split( "\\+" ) ); assertEquals( 1 , expressionList.size() ); collectionsHaveIdenticalValuesIgnoreOrder( expressionList, Lists.newArrayList( exp ) ); }
@Test public void verifyExpressionIsNotDataElementOperand() { DimensionalItemId dimensionalItemId = new DimensionalItemId( DimensionItemType.DATA_ELEMENT, elem1 ); String exp = "#{" + elem1 + "}"; when( expressionService.getExpressionDimensionalItemIds( exp, INDICATOR_EXPRESSION ) ) .thenReturn( Sets.newHashSet( dimensionalItemId ) ); String expression = resolver.resolve( exp ); List<String> expressionList = Arrays.asList( expression.split( "\\+" ) ); assertEquals( 1 , expressionList.size() ); collectionsHaveIdenticalValuesIgnoreOrder( expressionList, Lists.newArrayList( exp ) ); }