=== modified 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 2013-05-23 08:46:12 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultDimensionService.java 2013-05-23 10:55:23 +0000 @@ -225,91 +225,96 @@ String dimensionId = dimension.getDimension(); - List uids = getUids( dimension.getItems() ); + List items = dimension.getItems(); - 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(); - Set periods = new HashSet(); + if ( items != null ) + { + List uids = getUids( items ); - for ( String isoPeriod : uids ) - { - if ( RelativePeriodEnum.contains( isoPeriod ) ) - { - enums.add( RelativePeriodEnum.valueOf( isoPeriod ) ); - } - else - { - Period period = PeriodType.getPeriodFromIsoString( isoPeriod ); + 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(); + Set periods = new HashSet(); - if ( period != null ) + for ( String isoPeriod : uids ) + { + if ( RelativePeriodEnum.contains( isoPeriod ) ) { - periods.add( period ); + enums.add( RelativePeriodEnum.valueOf( isoPeriod ) ); } - } - } - - object.setRelatives( new RelativePeriods().setRelativePeriodsFromEnums( enums ) ); - object.setPeriods( periodService.reloadPeriods( new ArrayList( periods ) ) ); - } - else if ( ORGANISATIONUNIT.equals( type ) ) - { - List ous = new ArrayList(); - - 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 - { - OrganisationUnit unit = identifiableObjectManager.get( OrganisationUnit.class, ou ); + else + { + Period period = PeriodType.getPeriodFromIsoString( isoPeriod ); - if ( unit != null ) - { - ous.add( unit ); - } - } - } - - object.setOrganisationUnits( ous ); - } - 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 ) ); + if ( period != null ) + { + periods.add( period ); + } + } + } + + object.setRelatives( new RelativePeriods().setRelativePeriodsFromEnums( enums ) ); + object.setPeriods( periodService.reloadPeriods( new ArrayList( periods ) ) ); + } + else if ( ORGANISATIONUNIT.equals( type ) ) + { + List ous = new ArrayList(); + + 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 + { + OrganisationUnit unit = identifiableObjectManager.get( OrganisationUnit.class, ou ); + + if ( unit != null ) + { + ous.add( unit ); + } + } + } + + object.setOrganisationUnits( ous ); + } + 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 ) ); + } } } }