← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10955: Null check

 

------------------------------------------------------------
revno: 10955
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-05-23 12:55:23 +0200
message:
  Null check
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultDimensionService.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== 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<String> uids = getUids( dimension.getItems() );
+            List<IdentifiableObject> 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<RelativePeriodEnum> enums = new ArrayList<RelativePeriodEnum>();                
-                Set<Period> periods = new HashSet<Period>();
+            if ( items != null )
+            {
+                List<String> 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<RelativePeriodEnum> enums = new ArrayList<RelativePeriodEnum>();                
+                    Set<Period> periods = new HashSet<Period>();
                     
-                        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<Period>( periods ) ) );
-            }
-            else if ( ORGANISATIONUNIT.equals( type ) )
-            {
-                List<OrganisationUnit> ous = new ArrayList<OrganisationUnit>();
-                
-                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<Period>( periods ) ) );
+                }
+                else if ( ORGANISATIONUNIT.equals( type ) )
+                {
+                    List<OrganisationUnit> ous = new ArrayList<OrganisationUnit>();
+                    
+                    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 ) );
+                }
             }
         }
     }