=== added directory 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension' === added file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java' --- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java 2014-03-26 18:14:37 +0000 @@ -0,0 +1,396 @@ +package org.hisp.dhis.analytics.dimension; + +/* + * Copyright (c) 2004-2014, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.common.BaseAnalyticalObject; +import org.hisp.dhis.common.DimensionService; +import org.hisp.dhis.common.DimensionType; +import org.hisp.dhis.common.DimensionalObject; +import org.hisp.dhis.common.DimensionalObjectUtils; +import org.hisp.dhis.common.IdentifiableObjectManager; +import org.hisp.dhis.common.NameableObject; +import org.hisp.dhis.dataelement.CategoryOptionGroup; +import org.hisp.dhis.dataelement.CategoryOptionGroupSet; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementCategory; +import org.hisp.dhis.dataelement.DataElementCategoryDimension; +import org.hisp.dhis.dataelement.DataElementCategoryService; +import org.hisp.dhis.dataelement.DataElementGroup; +import org.hisp.dhis.dataelement.DataElementGroupSet; +import org.hisp.dhis.dataelement.DataElementOperandService; +import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.indicator.Indicator; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitGroup; +import org.hisp.dhis.organisationunit.OrganisationUnitGroupService; +import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.period.PeriodService; +import org.hisp.dhis.period.PeriodType; +import org.hisp.dhis.period.RelativePeriodEnum; +import org.hisp.dhis.period.RelativePeriods; +import org.hisp.dhis.sharing.SharingService; +import org.hisp.dhis.system.util.UniqueArrayList; +import org.hisp.dhis.user.CurrentUserService; +import org.hisp.dhis.user.User; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.hisp.dhis.common.DimensionType.*; +import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids; +import static org.hisp.dhis.organisationunit.OrganisationUnit.*; + +/** + * @author Lars Helge Overland + */ +public class DefaultDimensionService + implements DimensionService +{ + @Autowired + private IdentifiableObjectManager identifiableObjectManager; + + @Autowired + private DataElementCategoryService categoryService; + + @Autowired + private DataElementOperandService operandService; + + @Autowired + private PeriodService periodService; + + @Autowired + private OrganisationUnitGroupService organisationUnitGroupService; + + @Autowired + private DataElementService dataElementService; + + @Autowired + private SharingService sharingService; + + @Autowired + private CurrentUserService currentUserService; + + //-------------------------------------------------------------------------- + // DimensionService implementation + //-------------------------------------------------------------------------- + + @Override + public DimensionalObject getDimension( String uid ) + { + DataElementCategory cat = identifiableObjectManager.get( DataElementCategory.class, uid ); + + if ( cat != null ) + { + return cat; + } + + DataElementGroupSet degs = identifiableObjectManager.get( DataElementGroupSet.class, uid ); + + if ( degs != null ) + { + return degs; + } + + OrganisationUnitGroupSet ougs = identifiableObjectManager.get( OrganisationUnitGroupSet.class, uid ); + + if ( ougs != null ) + { + return ougs; + } + + CategoryOptionGroupSet cogs = identifiableObjectManager.get( CategoryOptionGroupSet.class, uid ); + + if ( cogs != null ) + { + return cogs; + } + + return null; + } + + public List getCanReadDimensionItems( String uid ) + { + DimensionalObject dimension = getDimension( uid ); + + List items = new ArrayList(); + + if ( dimension != null && dimension.getItems() != null ) + { + User user = currentUserService.getCurrentUser(); + + for ( NameableObject item : dimension.getItems() ) + { + boolean canRead = sharingService.canRead( user, item ); + + if ( canRead ) + { + items.add( item ); + } + } + } + + return items; + } + + public DimensionType getDimensionType( String uid ) + { + DataElementCategory cat = identifiableObjectManager.get( DataElementCategory.class, uid ); + + if ( cat != null ) + { + return DimensionType.CATEGORY; + } + + DataElementGroupSet degs = identifiableObjectManager.get( DataElementGroupSet.class, uid ); + + if ( degs != null ) + { + return DimensionType.DATAELEMENT_GROUPSET; + } + + OrganisationUnitGroupSet ougs = identifiableObjectManager.get( OrganisationUnitGroupSet.class, uid ); + + if ( ougs != null ) + { + return DimensionType.ORGANISATIONUNIT_GROUPSET; + } + + CategoryOptionGroupSet cogs = identifiableObjectManager.get( CategoryOptionGroupSet.class, uid ); + + if ( cogs != null ) + { + return DimensionType.CATEGORYOPTION_GROUPSET; + } + + final Map dimObjectTypeMap = new HashMap(); + + dimObjectTypeMap.put( DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X ); + dimObjectTypeMap.put( DimensionalObject.INDICATOR_DIM_ID, DimensionType.INDICATOR ); + dimObjectTypeMap.put( DimensionalObject.DATAELEMENT_DIM_ID, DimensionType.DATAELEMENT ); + dimObjectTypeMap.put( DimensionalObject.DATASET_DIM_ID, DimensionType.DATASET ); + dimObjectTypeMap.put( DimensionalObject.DATAELEMENT_OPERAND_ID, DimensionType.DATAELEMENT_OPERAND ); + dimObjectTypeMap.put( DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD ); + dimObjectTypeMap.put( DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATIONUNIT ); + + return dimObjectTypeMap.get( uid ); + } + + @Override + public List getAllDimensions() + { + Collection dcs = categoryService.getDataDimensionDataElementCategories(); + Collection cogs = categoryService.getDataDimensionCategoryOptionGroupSets(); + Collection degs = dataElementService.getDataDimensionDataElementGroupSets(); + Collection ougs = organisationUnitGroupService.getDataDimensionOrganisationUnitGroupSets(); + + final List dimensions = new ArrayList(); + + dimensions.addAll( dcs ); + dimensions.addAll( cogs ); + dimensions.addAll( degs ); + dimensions.addAll( ougs ); + + return dimensions; + } + + @Override + public void mergeAnalyticalObject( BaseAnalyticalObject object ) + { + if ( object != null ) + { + object.clear(); + + if ( object.getUser() != null ) + { + object.setUser( identifiableObjectManager.get( User.class, object.getUser().getUid() ) ); + } + else + { + object.setUser( currentUserService.getCurrentUser() ); + } + + mergeDimensionalObjects( object, object.getColumns() ); + mergeDimensionalObjects( object, object.getRows() ); + mergeDimensionalObjects( object, object.getFilters() ); + } + } + + //-------------------------------------------------------------------------- + // Supportive methods + //-------------------------------------------------------------------------- + + /** + * Sets persistent objects for dimensional associations on the given + * BaseAnalyticalObject based on the given list of transient DimensionalObjects. + *

+ * Relative periods represented by enums are converted into a RelativePeriods + * object. User organisation units represented by enums are converted and + * represented by the user organisation unit persisted properties on the + * BaseAnalyticalObject. + * + * @param object the BaseAnalyticalObject to merge. + * @param dimensions the + */ + private void mergeDimensionalObjects( BaseAnalyticalObject object, List dimensions ) + { + if ( object == null || dimensions == null ) + { + return; + } + + for ( DimensionalObject dimension : dimensions ) + { + DimensionType type = getDimensionType( dimension.getDimension() ); + + String dimensionId = dimension.getDimension(); + + List items = dimension.getItems(); + + if ( items != null ) + { + List uids = getUids( items ); + + if ( INDICATOR.equals( type ) ) + { + object.getIndicators().addAll( identifiableObjectManager.getByUid( Indicator.class, uids ) ); + } + else if ( DATAELEMENT.equals( type ) ) + { + object.getDataElements().addAll( identifiableObjectManager.getByUid( DataElement.class, uids ) ); + } + else if ( DATAELEMENT_OPERAND.equals( type ) ) + { + object.getDataElementOperands().addAll( operandService.getDataElementOperandsByUid( uids ) ); + } + else if ( DATASET.equals( type ) ) + { + object.getDataSets().addAll( identifiableObjectManager.getByUid( DataSet.class, uids ) ); + } + else if ( PERIOD.equals( type ) ) + { + List enums = new ArrayList(); + List periods = new UniqueArrayList(); + + for ( String isoPeriod : uids ) + { + if ( RelativePeriodEnum.contains( isoPeriod ) ) + { + enums.add( RelativePeriodEnum.valueOf( isoPeriod ) ); + } + else + { + Period period = PeriodType.getPeriodFromIsoString( isoPeriod ); + + if ( period != null ) + { + periods.add( period ); + } + } + } + + object.setRelatives( new RelativePeriods().setRelativePeriodsFromEnums( enums ) ); + object.setPeriods( periodService.reloadPeriods( new ArrayList( periods ) ) ); + } + else if ( ORGANISATIONUNIT.equals( type ) ) + { + for ( String ou : uids ) + { + if ( KEY_USER_ORGUNIT.equals( ou ) ) + { + object.setUserOrganisationUnit( true ); + } + else if ( KEY_USER_ORGUNIT_CHILDREN.equals( ou ) ) + { + object.setUserOrganisationUnitChildren( true ); + } + else if ( KEY_USER_ORGUNIT_GRANDCHILDREN.equals( ou ) ) + { + object.setUserOrganisationUnitGrandChildren( true ); + } + else if ( ou != null && ou.startsWith( KEY_LEVEL ) ) + { + int level = DimensionalObjectUtils.getLevelFromLevelParam( ou ); + + if ( level > 0 ) + { + object.getOrganisationUnitLevels().add( level ); + } + } + else if ( ou != null && ou.startsWith( KEY_ORGUNIT_GROUP ) ) + { + String uid = DimensionalObjectUtils.getUidFromOrgUnitGroupParam( ou ); + + OrganisationUnitGroup group = identifiableObjectManager.get( OrganisationUnitGroup.class, uid ); + + if ( group != null ) + { + object.getItemOrganisationUnitGroups().add( group ); + } + } + else + { + OrganisationUnit unit = identifiableObjectManager.get( OrganisationUnit.class, ou ); + + if ( unit != null ) + { + object.getOrganisationUnits().add( unit ); + } + } + } + } + else if ( CATEGORY.equals( type ) ) + { + DataElementCategoryDimension categoryDimension = new DataElementCategoryDimension(); + categoryDimension.setDimension( categoryService.getDataElementCategory( dimensionId ) ); + categoryDimension.getItems().addAll( categoryService.getDataElementCategoryOptionsByUid( uids ) ); + + object.getCategoryDimensions().add( categoryDimension ); + } + else if ( DATAELEMENT_GROUPSET.equals( type ) ) + { + object.getDataElementGroups().addAll( identifiableObjectManager.getByUid( DataElementGroup.class, uids ) ); + } + else if ( ORGANISATIONUNIT_GROUPSET.equals( type ) ) + { + object.getOrganisationUnitGroups().addAll( identifiableObjectManager.getByUid( OrganisationUnitGroup.class, uids ) ); + } + else if ( CATEGORYOPTION_GROUPSET.equals( type ) ) + { + object.getCategoryOptionGroups().addAll( identifiableObjectManager.getByUid( CategoryOptionGroup.class, uids ) ); + } + } + } + } +} === modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-analytics/src/main/resources/META-INF/dhis/beans.xml 2014-01-30 10:13:58 +0000 +++ dhis-2/dhis-services/dhis-service-analytics/src/main/resources/META-INF/dhis/beans.xml 2014-03-26 18:14:37 +0000 @@ -50,6 +50,10 @@ + + + + === added directory 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/dimension' === added file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/dimension/DimensionServiceTest.java' --- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/dimension/DimensionServiceTest.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/dimension/DimensionServiceTest.java 2014-03-26 18:14:37 +0000 @@ -0,0 +1,240 @@ +package org.hisp.dhis.analytics.dimension; + +/* + * Copyright (c) 2004-2014, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_LEVEL; +import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_USER_ORGUNIT; +import static org.hisp.dhis.period.RelativePeriodEnum.LAST_12_MONTHS; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; + +import org.hisp.dhis.DhisSpringTest; +import org.hisp.dhis.common.BaseDimensionalObject; +import org.hisp.dhis.common.BaseNameableObject; +import org.hisp.dhis.common.DimensionService; +import org.hisp.dhis.common.DimensionalObject; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitGroup; +import org.hisp.dhis.organisationunit.OrganisationUnitGroupService; +import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet; +import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.reporttable.ReportTable; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * @author Lars Helge Overland + */ +public class DimensionServiceTest + extends DhisSpringTest +{ + private DataElement deA; + private DataElement deB; + + private Period peA; + private Period peB; + + private BaseNameableObject peLast12Months; + + private OrganisationUnit ouA; + private OrganisationUnit ouB; + private OrganisationUnit ouC; + private OrganisationUnit ouD; + private OrganisationUnit ouE; + + private BaseNameableObject ouUser; + private BaseNameableObject ouLevel2; + + private OrganisationUnitGroup ouGroupA; + private OrganisationUnitGroup ouGroupB; + private OrganisationUnitGroup ouGroupC; + + private OrganisationUnitGroupSet ouGroupSetA; + + @Autowired + private DataElementService dataElementService; + + @Autowired + private OrganisationUnitService organisationUnitService; + + @Autowired + private OrganisationUnitGroupService organisationUnitGroupService; + + @Autowired + private DimensionService dimensionService; + + @Override + public void setUpTest() + { + deA = createDataElement( 'A' ); + deB = createDataElement( 'B' ); + + dataElementService.addDataElement( deA ); + dataElementService.addDataElement( deB ); + + peA = createPeriod( "201201" ); + peB = createPeriod( "201202" ); + peLast12Months = new BaseNameableObject( LAST_12_MONTHS.toString(), LAST_12_MONTHS.toString(), LAST_12_MONTHS.toString() ); + + peA.setUid( "201201" ); + peB.setUid( "201202" ); + + ouA = createOrganisationUnit( 'A' ); + ouB = createOrganisationUnit( 'B' ); + ouC = createOrganisationUnit( 'C' ); + ouD = createOrganisationUnit( 'D' ); + ouE = createOrganisationUnit( 'E' ); + + ouB.updateParent( ouA ); + ouC.updateParent( ouA ); + ouD.updateParent( ouB ); + ouE.updateParent( ouB ); + + organisationUnitService.addOrganisationUnit( ouA ); + organisationUnitService.addOrganisationUnit( ouB ); + organisationUnitService.addOrganisationUnit( ouC ); + organisationUnitService.addOrganisationUnit( ouD ); + organisationUnitService.addOrganisationUnit( ouE ); + + String level2 = KEY_LEVEL + 2; + + ouUser = new BaseNameableObject( KEY_USER_ORGUNIT, KEY_USER_ORGUNIT, KEY_USER_ORGUNIT ); + ouLevel2 = new BaseNameableObject( level2, level2, level2 ); + + ouGroupSetA = createOrganisationUnitGroupSet( 'A' ); + + organisationUnitGroupService.addOrganisationUnitGroupSet( ouGroupSetA ); + + ouGroupA = createOrganisationUnitGroup( 'A' ); + ouGroupB = createOrganisationUnitGroup( 'B' ); + ouGroupC = createOrganisationUnitGroup( 'C' ); + + ouGroupA.setGroupSet( ouGroupSetA ); + ouGroupB.setGroupSet( ouGroupSetA ); + ouGroupC.setGroupSet( ouGroupSetA ); + + organisationUnitGroupService.addOrganisationUnitGroup( ouGroupA ); + organisationUnitGroupService.addOrganisationUnitGroup( ouGroupB ); + organisationUnitGroupService.addOrganisationUnitGroup( ouGroupC ); + + ouGroupSetA.getOrganisationUnitGroups().add( ouGroupA ); + ouGroupSetA.getOrganisationUnitGroups().add( ouGroupB ); + ouGroupSetA.getOrganisationUnitGroups().add( ouGroupC ); + + organisationUnitGroupService.updateOrganisationUnitGroupSet( ouGroupSetA ); + } + + @Test + public void testMergeAnalyticalObject() + { + ReportTable reportTable = new ReportTable(); + + reportTable.getColumns().add( new BaseDimensionalObject( DimensionalObject.DATAELEMENT_DIM_ID, Arrays.asList( deA, deB ) ) ); + reportTable.getRows().add( new BaseDimensionalObject( DimensionalObject.ORGUNIT_DIM_ID, Arrays.asList( ouA, ouB, ouC, ouD, ouE ) ) ); + reportTable.getFilters().add( new BaseDimensionalObject( DimensionalObject.PERIOD_DIM_ID, Arrays.asList( peA, peB ) ) ); + + dimensionService.mergeAnalyticalObject( reportTable ); + + assertEquals( 2, reportTable.getDataElements().size() ); + assertEquals( 2, reportTable.getPeriods().size() ); + assertEquals( 5, reportTable.getOrganisationUnits().size() ); + } + + @Test + public void testMergeAnalyticalObjectUserOrgUnit() + { + ReportTable reportTable = new ReportTable(); + + reportTable.getColumns().add( new BaseDimensionalObject( DimensionalObject.DATAELEMENT_DIM_ID, Arrays.asList( deA, deB ) ) ); + reportTable.getRows().add( new BaseDimensionalObject( DimensionalObject.ORGUNIT_DIM_ID, Arrays.asList( ouUser ) ) ); + reportTable.getFilters().add( new BaseDimensionalObject( DimensionalObject.PERIOD_DIM_ID, Arrays.asList( peA ) ) ); + + dimensionService.mergeAnalyticalObject( reportTable ); + + assertEquals( 2, reportTable.getDataElements().size() ); + assertEquals( 1, reportTable.getPeriods().size() ); + assertEquals( 0, reportTable.getOrganisationUnits().size() ); + assertTrue( reportTable.isUserOrganisationUnit() ); + } + + @Test + public void testMergeAnalyticalObjectOrgUnitLevel() + { + ReportTable reportTable = new ReportTable(); + + reportTable.getColumns().add( new BaseDimensionalObject( DimensionalObject.DATAELEMENT_DIM_ID, Arrays.asList( deA, deB ) ) ); + reportTable.getRows().add( new BaseDimensionalObject( DimensionalObject.ORGUNIT_DIM_ID, Arrays.asList( ouLevel2, ouA ) ) ); + reportTable.getFilters().add( new BaseDimensionalObject( DimensionalObject.PERIOD_DIM_ID, Arrays.asList( peA ) ) ); + + dimensionService.mergeAnalyticalObject( reportTable ); + + assertEquals( 2, reportTable.getDataElements().size() ); + assertEquals( 1, reportTable.getPeriods().size() ); + assertEquals( 1, reportTable.getOrganisationUnits().size() ); + assertEquals( Integer.valueOf( 2 ), reportTable.getOrganisationUnitLevels().get( 0 ) ); + } + + @Test + public void testMergeAnalyticalObjectRelativePeriods() + { + ReportTable reportTable = new ReportTable(); + + reportTable.getColumns().add( new BaseDimensionalObject( DimensionalObject.DATAELEMENT_DIM_ID, Arrays.asList( deA, deB ) ) ); + reportTable.getRows().add( new BaseDimensionalObject( DimensionalObject.ORGUNIT_DIM_ID, Arrays.asList( ouA, ouB, ouC, ouD, ouE ) ) ); + reportTable.getFilters().add( new BaseDimensionalObject( DimensionalObject.PERIOD_DIM_ID, Arrays.asList( peLast12Months ) ) ); + + dimensionService.mergeAnalyticalObject( reportTable ); + + assertEquals( 2, reportTable.getDataElements().size() ); + assertEquals( 0, reportTable.getPeriods().size() ); + assertTrue( reportTable.getRelatives().isLast12Months() ); + assertEquals( 5, reportTable.getOrganisationUnits().size() ); + } + + @Test + public void testMergeAnalyticalObjectOrgUnitGroupSet() + { + ReportTable reportTable = new ReportTable(); + + reportTable.getColumns().add( new BaseDimensionalObject( DimensionalObject.DATAELEMENT_DIM_ID, Arrays.asList( deA, deB ) ) ); + reportTable.getRows().add( ouGroupSetA ); + reportTable.getFilters().add( new BaseDimensionalObject( DimensionalObject.PERIOD_DIM_ID, Arrays.asList( peA, peB ) ) ); + + dimensionService.mergeAnalyticalObject( reportTable ); + + assertEquals( 2, reportTable.getDataElements().size() ); + assertEquals( 2, reportTable.getPeriods().size() ); + assertEquals( 3, reportTable.getOrganisationUnitGroups().size() ); + } +} === removed file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultDimensionService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultDimensionService.java 2014-03-21 12:20:36 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultDimensionService.java 1970-01-01 00:00:00 +0000 @@ -1,389 +0,0 @@ -package org.hisp.dhis.common; - -/* - * Copyright (c) 2004-2014, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import org.hisp.dhis.dataelement.CategoryOptionGroup; -import org.hisp.dhis.dataelement.CategoryOptionGroupSet; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementCategory; -import org.hisp.dhis.dataelement.DataElementCategoryDimension; -import org.hisp.dhis.dataelement.DataElementCategoryService; -import org.hisp.dhis.dataelement.DataElementGroup; -import org.hisp.dhis.dataelement.DataElementGroupSet; -import org.hisp.dhis.dataelement.DataElementOperandService; -import org.hisp.dhis.dataelement.DataElementService; -import org.hisp.dhis.dataset.DataSet; -import org.hisp.dhis.indicator.Indicator; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitGroup; -import org.hisp.dhis.organisationunit.OrganisationUnitGroupService; -import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet; -import org.hisp.dhis.period.Period; -import org.hisp.dhis.period.PeriodService; -import org.hisp.dhis.period.PeriodType; -import org.hisp.dhis.period.RelativePeriodEnum; -import org.hisp.dhis.period.RelativePeriods; -import org.hisp.dhis.sharing.SharingService; -import org.hisp.dhis.system.util.UniqueArrayList; -import org.hisp.dhis.user.CurrentUserService; -import org.hisp.dhis.user.User; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.hisp.dhis.common.DimensionType.*; -import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids; -import static org.hisp.dhis.organisationunit.OrganisationUnit.*; - -/** - * @author Lars Helge Overland - */ -public class DefaultDimensionService - implements DimensionService -{ - @Autowired - private IdentifiableObjectManager identifiableObjectManager; - - @Autowired - private DataElementCategoryService categoryService; - - @Autowired - private DataElementOperandService operandService; - - @Autowired - private PeriodService periodService; - - @Autowired - private OrganisationUnitGroupService organisationUnitGroupService; - - @Autowired - private DataElementService dataElementService; - - @Autowired - private SharingService sharingService; - - @Autowired - private CurrentUserService currentUserService; - - //-------------------------------------------------------------------------- - // DimensionService implementation - //-------------------------------------------------------------------------- - - @Override - public DimensionalObject getDimension( String uid ) - { - DataElementCategory cat = identifiableObjectManager.get( DataElementCategory.class, uid ); - - if ( cat != null ) - { - return cat; - } - - DataElementGroupSet degs = identifiableObjectManager.get( DataElementGroupSet.class, uid ); - - if ( degs != null ) - { - return degs; - } - - OrganisationUnitGroupSet ougs = identifiableObjectManager.get( OrganisationUnitGroupSet.class, uid ); - - if ( ougs != null ) - { - return ougs; - } - - CategoryOptionGroupSet cogs = identifiableObjectManager.get( CategoryOptionGroupSet.class, uid ); - - if ( cogs != null ) - { - return cogs; - } - - return null; - } - - public List getCanReadDimensionItems( String uid ) - { - DimensionalObject dimension = getDimension( uid ); - - List items = new ArrayList(); - - if ( dimension != null && dimension.getItems() != null ) - { - User user = currentUserService.getCurrentUser(); - - for ( NameableObject item : dimension.getItems() ) - { - boolean canRead = sharingService.canRead( user, item ); - - if ( canRead ) - { - items.add( item ); - } - } - } - - return items; - } - - public DimensionType getDimensionType( String uid ) - { - DataElementCategory cat = identifiableObjectManager.get( DataElementCategory.class, uid ); - - if ( cat != null ) - { - return DimensionType.CATEGORY; - } - - DataElementGroupSet degs = identifiableObjectManager.get( DataElementGroupSet.class, uid ); - - if ( degs != null ) - { - return DimensionType.DATAELEMENT_GROUPSET; - } - - OrganisationUnitGroupSet ougs = identifiableObjectManager.get( OrganisationUnitGroupSet.class, uid ); - - if ( ougs != null ) - { - return DimensionType.ORGANISATIONUNIT_GROUPSET; - } - - CategoryOptionGroupSet cogs = identifiableObjectManager.get( CategoryOptionGroupSet.class, uid ); - - if ( cogs != null ) - { - return DimensionType.CATEGORYOPTION_GROUPSET; - } - - final Map dimObjectTypeMap = new HashMap(); - - dimObjectTypeMap.put( DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X ); - dimObjectTypeMap.put( DimensionalObject.INDICATOR_DIM_ID, DimensionType.INDICATOR ); - dimObjectTypeMap.put( DimensionalObject.DATAELEMENT_DIM_ID, DimensionType.DATAELEMENT ); - dimObjectTypeMap.put( DimensionalObject.DATASET_DIM_ID, DimensionType.DATASET ); - dimObjectTypeMap.put( DimensionalObject.DATAELEMENT_OPERAND_ID, DimensionType.DATAELEMENT_OPERAND ); - dimObjectTypeMap.put( DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD ); - dimObjectTypeMap.put( DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATIONUNIT ); - - return dimObjectTypeMap.get( uid ); - } - - @Override - public List getAllDimensions() - { - Collection dcs = categoryService.getDataDimensionDataElementCategories(); - Collection cogs = categoryService.getDataDimensionCategoryOptionGroupSets(); - Collection degs = dataElementService.getDataDimensionDataElementGroupSets(); - Collection ougs = organisationUnitGroupService.getDataDimensionOrganisationUnitGroupSets(); - - final List dimensions = new ArrayList(); - - dimensions.addAll( dcs ); - dimensions.addAll( cogs ); - dimensions.addAll( degs ); - dimensions.addAll( ougs ); - - return dimensions; - } - - @Override - public void mergeAnalyticalObject( BaseAnalyticalObject object ) - { - if ( object != null ) - { - object.clear(); - - if ( object.getUser() != null ) - { - object.setUser( identifiableObjectManager.get( User.class, object.getUser().getUid() ) ); - } - else - { - object.setUser( currentUserService.getCurrentUser() ); - } - - mergeDimensionalObjects( object, object.getColumns() ); - mergeDimensionalObjects( object, object.getRows() ); - mergeDimensionalObjects( object, object.getFilters() ); - } - } - - //-------------------------------------------------------------------------- - // Supportive methods - //-------------------------------------------------------------------------- - - /** - * Sets persistent objects for dimensional associations on the given - * BaseAnalyticalObject based on the given list of transient DimensionalObjects. - *

- * Relative periods represented by enums are converted into a RelativePeriods - * object. User organisation units represented by enums are converted and - * represented by the user organisation unit persisted properties on the - * BaseAnalyticalObject. - * - * @param object the BaseAnalyticalObject to merge. - * @param dimensions the - */ - private void mergeDimensionalObjects( BaseAnalyticalObject object, List dimensions ) - { - if ( object == null || dimensions == null ) - { - return; - } - - for ( DimensionalObject dimension : dimensions ) - { - DimensionType type = getDimensionType( dimension.getDimension() ); - - String dimensionId = dimension.getDimension(); - - List items = dimension.getItems(); - - if ( items != null ) - { - List uids = getUids( items ); - - if ( INDICATOR.equals( type ) ) - { - object.getIndicators().addAll( identifiableObjectManager.getByUid( Indicator.class, uids ) ); - } - else if ( DATAELEMENT.equals( type ) ) - { - object.getDataElements().addAll( identifiableObjectManager.getByUid( DataElement.class, uids ) ); - } - else if ( DATAELEMENT_OPERAND.equals( type ) ) - { - object.getDataElementOperands().addAll( operandService.getDataElementOperandsByUid( uids ) ); - } - else if ( DATASET.equals( type ) ) - { - object.getDataSets().addAll( identifiableObjectManager.getByUid( DataSet.class, uids ) ); - } - else if ( PERIOD.equals( type ) ) - { - List enums = new ArrayList(); - List periods = new UniqueArrayList(); - - for ( String isoPeriod : uids ) - { - if ( RelativePeriodEnum.contains( isoPeriod ) ) - { - enums.add( RelativePeriodEnum.valueOf( isoPeriod ) ); - } - else - { - Period period = PeriodType.getPeriodFromIsoString( isoPeriod ); - - if ( period != null ) - { - periods.add( period ); - } - } - } - - object.setRelatives( new RelativePeriods().setRelativePeriodsFromEnums( enums ) ); - object.setPeriods( periodService.reloadPeriods( new ArrayList( periods ) ) ); - } - else if ( ORGANISATIONUNIT.equals( type ) ) - { - for ( String ou : uids ) - { - if ( KEY_USER_ORGUNIT.equals( ou ) ) - { - object.setUserOrganisationUnit( true ); - } - else if ( KEY_USER_ORGUNIT_CHILDREN.equals( ou ) ) - { - object.setUserOrganisationUnitChildren( true ); - } - else if ( KEY_USER_ORGUNIT_GRANDCHILDREN.equals( ou ) ) - { - object.setUserOrganisationUnitGrandChildren( true ); - } - else if ( ou != null && ou.startsWith( KEY_LEVEL ) ) - { - int level = DimensionalObjectUtils.getLevelFromLevelParam( ou ); - - if ( level > 0 ) - { - object.getOrganisationUnitLevels().add( level ); - } - } - else if ( ou != null && ou.startsWith( KEY_ORGUNIT_GROUP ) ) - { - String uid = DimensionalObjectUtils.getUidFromOrgUnitGroupParam( ou ); - - OrganisationUnitGroup group = identifiableObjectManager.get( OrganisationUnitGroup.class, uid ); - - if ( group != null ) - { - object.getItemOrganisationUnitGroups().add( group ); - } - } - else - { - OrganisationUnit unit = identifiableObjectManager.get( OrganisationUnit.class, ou ); - - if ( unit != null ) - { - object.getOrganisationUnits().add( unit ); - } - } - } - } - else if ( CATEGORY.equals( type ) ) - { - DataElementCategoryDimension categoryDimension = new DataElementCategoryDimension(); - categoryDimension.setDimension( categoryService.getDataElementCategory( dimensionId ) ); - categoryDimension.getItems().addAll( categoryService.getDataElementCategoryOptionsByUid( uids ) ); - - object.getCategoryDimensions().add( categoryDimension ); - } - else if ( DATAELEMENT_GROUPSET.equals( type ) ) - { - object.getDataElementGroups().addAll( identifiableObjectManager.getByUid( DataElementGroup.class, uids ) ); - } - else if ( ORGANISATIONUNIT_GROUPSET.equals( type ) ) - { - object.getOrganisationUnitGroups().addAll( identifiableObjectManager.getByUid( OrganisationUnitGroup.class, uids ) ); - } - else if ( CATEGORYOPTION_GROUPSET.equals( type ) ) - { - object.getCategoryOptionGroups().addAll( identifiableObjectManager.getByUid( CategoryOptionGroup.class, uids ) ); - } - } - } - } -} === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2014-03-26 11:38:14 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2014-03-26 18:14:37 +0000 @@ -774,8 +774,6 @@ - - === removed file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/DimensionServiceTest.java' --- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/DimensionServiceTest.java 2014-03-18 08:10:10 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/DimensionServiceTest.java 1970-01-01 00:00:00 +0000 @@ -1,236 +0,0 @@ -package org.hisp.dhis.common; - -/* - * Copyright (c) 2004-2014, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_LEVEL; -import static org.hisp.dhis.organisationunit.OrganisationUnit.KEY_USER_ORGUNIT; -import static org.hisp.dhis.period.RelativePeriodEnum.LAST_12_MONTHS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; - -import org.hisp.dhis.DhisSpringTest; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementService; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitGroup; -import org.hisp.dhis.organisationunit.OrganisationUnitGroupService; -import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet; -import org.hisp.dhis.organisationunit.OrganisationUnitService; -import org.hisp.dhis.period.Period; -import org.hisp.dhis.reporttable.ReportTable; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; - -/** - * @author Lars Helge Overland - */ -public class DimensionServiceTest - extends DhisSpringTest -{ - private DataElement deA; - private DataElement deB; - - private Period peA; - private Period peB; - - private BaseNameableObject peLast12Months; - - private OrganisationUnit ouA; - private OrganisationUnit ouB; - private OrganisationUnit ouC; - private OrganisationUnit ouD; - private OrganisationUnit ouE; - - private BaseNameableObject ouUser; - private BaseNameableObject ouLevel2; - - private OrganisationUnitGroup ouGroupA; - private OrganisationUnitGroup ouGroupB; - private OrganisationUnitGroup ouGroupC; - - private OrganisationUnitGroupSet ouGroupSetA; - - @Autowired - private DataElementService dataElementService; - - @Autowired - private OrganisationUnitService organisationUnitService; - - @Autowired - private OrganisationUnitGroupService organisationUnitGroupService; - - @Autowired - private DimensionService dimensionService; - - @Override - public void setUpTest() - { - deA = createDataElement( 'A' ); - deB = createDataElement( 'B' ); - - dataElementService.addDataElement( deA ); - dataElementService.addDataElement( deB ); - - peA = createPeriod( "201201" ); - peB = createPeriod( "201202" ); - peLast12Months = new BaseNameableObject( LAST_12_MONTHS.toString(), LAST_12_MONTHS.toString(), LAST_12_MONTHS.toString() ); - - peA.setUid( "201201" ); - peB.setUid( "201202" ); - - ouA = createOrganisationUnit( 'A' ); - ouB = createOrganisationUnit( 'B' ); - ouC = createOrganisationUnit( 'C' ); - ouD = createOrganisationUnit( 'D' ); - ouE = createOrganisationUnit( 'E' ); - - ouB.updateParent( ouA ); - ouC.updateParent( ouA ); - ouD.updateParent( ouB ); - ouE.updateParent( ouB ); - - organisationUnitService.addOrganisationUnit( ouA ); - organisationUnitService.addOrganisationUnit( ouB ); - organisationUnitService.addOrganisationUnit( ouC ); - organisationUnitService.addOrganisationUnit( ouD ); - organisationUnitService.addOrganisationUnit( ouE ); - - String level2 = KEY_LEVEL + 2; - - ouUser = new BaseNameableObject( KEY_USER_ORGUNIT, KEY_USER_ORGUNIT, KEY_USER_ORGUNIT ); - ouLevel2 = new BaseNameableObject( level2, level2, level2 ); - - ouGroupSetA = createOrganisationUnitGroupSet( 'A' ); - - organisationUnitGroupService.addOrganisationUnitGroupSet( ouGroupSetA ); - - ouGroupA = createOrganisationUnitGroup( 'A' ); - ouGroupB = createOrganisationUnitGroup( 'B' ); - ouGroupC = createOrganisationUnitGroup( 'C' ); - - ouGroupA.setGroupSet( ouGroupSetA ); - ouGroupB.setGroupSet( ouGroupSetA ); - ouGroupC.setGroupSet( ouGroupSetA ); - - organisationUnitGroupService.addOrganisationUnitGroup( ouGroupA ); - organisationUnitGroupService.addOrganisationUnitGroup( ouGroupB ); - organisationUnitGroupService.addOrganisationUnitGroup( ouGroupC ); - - ouGroupSetA.getOrganisationUnitGroups().add( ouGroupA ); - ouGroupSetA.getOrganisationUnitGroups().add( ouGroupB ); - ouGroupSetA.getOrganisationUnitGroups().add( ouGroupC ); - - organisationUnitGroupService.updateOrganisationUnitGroupSet( ouGroupSetA ); - } - - @Test - public void testMergeAnalyticalObject() - { - ReportTable reportTable = new ReportTable(); - - reportTable.getColumns().add( new BaseDimensionalObject( DimensionalObject.DATAELEMENT_DIM_ID, Arrays.asList( deA, deB ) ) ); - reportTable.getRows().add( new BaseDimensionalObject( DimensionalObject.ORGUNIT_DIM_ID, Arrays.asList( ouA, ouB, ouC, ouD, ouE ) ) ); - reportTable.getFilters().add( new BaseDimensionalObject( DimensionalObject.PERIOD_DIM_ID, Arrays.asList( peA, peB ) ) ); - - dimensionService.mergeAnalyticalObject( reportTable ); - - assertEquals( 2, reportTable.getDataElements().size() ); - assertEquals( 2, reportTable.getPeriods().size() ); - assertEquals( 5, reportTable.getOrganisationUnits().size() ); - } - - @Test - public void testMergeAnalyticalObjectUserOrgUnit() - { - ReportTable reportTable = new ReportTable(); - - reportTable.getColumns().add( new BaseDimensionalObject( DimensionalObject.DATAELEMENT_DIM_ID, Arrays.asList( deA, deB ) ) ); - reportTable.getRows().add( new BaseDimensionalObject( DimensionalObject.ORGUNIT_DIM_ID, Arrays.asList( ouUser ) ) ); - reportTable.getFilters().add( new BaseDimensionalObject( DimensionalObject.PERIOD_DIM_ID, Arrays.asList( peA ) ) ); - - dimensionService.mergeAnalyticalObject( reportTable ); - - assertEquals( 2, reportTable.getDataElements().size() ); - assertEquals( 1, reportTable.getPeriods().size() ); - assertEquals( 0, reportTable.getOrganisationUnits().size() ); - assertTrue( reportTable.isUserOrganisationUnit() ); - } - - @Test - public void testMergeAnalyticalObjectOrgUnitLevel() - { - ReportTable reportTable = new ReportTable(); - - reportTable.getColumns().add( new BaseDimensionalObject( DimensionalObject.DATAELEMENT_DIM_ID, Arrays.asList( deA, deB ) ) ); - reportTable.getRows().add( new BaseDimensionalObject( DimensionalObject.ORGUNIT_DIM_ID, Arrays.asList( ouLevel2, ouA ) ) ); - reportTable.getFilters().add( new BaseDimensionalObject( DimensionalObject.PERIOD_DIM_ID, Arrays.asList( peA ) ) ); - - dimensionService.mergeAnalyticalObject( reportTable ); - - assertEquals( 2, reportTable.getDataElements().size() ); - assertEquals( 1, reportTable.getPeriods().size() ); - assertEquals( 1, reportTable.getOrganisationUnits().size() ); - assertEquals( Integer.valueOf( 2 ), reportTable.getOrganisationUnitLevels().get( 0 ) ); - } - - @Test - public void testMergeAnalyticalObjectRelativePeriods() - { - ReportTable reportTable = new ReportTable(); - - reportTable.getColumns().add( new BaseDimensionalObject( DimensionalObject.DATAELEMENT_DIM_ID, Arrays.asList( deA, deB ) ) ); - reportTable.getRows().add( new BaseDimensionalObject( DimensionalObject.ORGUNIT_DIM_ID, Arrays.asList( ouA, ouB, ouC, ouD, ouE ) ) ); - reportTable.getFilters().add( new BaseDimensionalObject( DimensionalObject.PERIOD_DIM_ID, Arrays.asList( peLast12Months ) ) ); - - dimensionService.mergeAnalyticalObject( reportTable ); - - assertEquals( 2, reportTable.getDataElements().size() ); - assertEquals( 0, reportTable.getPeriods().size() ); - assertTrue( reportTable.getRelatives().isLast12Months() ); - assertEquals( 5, reportTable.getOrganisationUnits().size() ); - } - - @Test - public void testMergeAnalyticalObjectOrgUnitGroupSet() - { - ReportTable reportTable = new ReportTable(); - - reportTable.getColumns().add( new BaseDimensionalObject( DimensionalObject.DATAELEMENT_DIM_ID, Arrays.asList( deA, deB ) ) ); - reportTable.getRows().add( ouGroupSetA ); - reportTable.getFilters().add( new BaseDimensionalObject( DimensionalObject.PERIOD_DIM_ID, Arrays.asList( peA, peB ) ) ); - - dimensionService.mergeAnalyticalObject( reportTable ); - - assertEquals( 2, reportTable.getDataElements().size() ); - assertEquals( 2, reportTable.getPeriods().size() ); - assertEquals( 3, reportTable.getOrganisationUnitGroups().size() ); - } -}