← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1133: Improved performance on get*(Collection<Integer)) methods.

 

------------------------------------------------------------
revno: 1133
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Thu 2009-11-26 15:02:44 +0100
message:
  Improved performance on get*(Collection<Integer)) methods.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/DefaultDataDictionaryService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/DefaultIndicatorService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementConverter.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/olap/DefaultOlapURLService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.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/datadictionary/DefaultDataDictionaryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/DefaultDataDictionaryService.java	2009-11-12 17:59:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/DefaultDataDictionaryService.java	2009-11-26 14:02:44 +0000
@@ -27,10 +27,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
 import java.util.Collection;
 
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.hisp.dhis.system.util.Filter;
+import org.hisp.dhis.system.util.FilterUtils;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -66,21 +67,17 @@
         return dataDictionaryStore.get( id );
     }
     
-    public Collection<DataDictionary> getDataDictionaries( Collection<Integer> identifiers )
+    public Collection<DataDictionary> getDataDictionaries( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllDataDictionaries();
-        }
-        
-        Collection<DataDictionary> dictionaries = new ArrayList<DataDictionary>();
-        
-        for ( Integer id : identifiers )
-        {
-            dictionaries.add( getDataDictionary( id ) );
-        }
-        
-        return dictionaries;
+        Collection<DataDictionary> dictionaries = getAllDataDictionaries();
+        
+        return identifiers == null ? dictionaries : FilterUtils.filter( dictionaries, new Filter<DataDictionary>()
+            {
+                public boolean retain( DataDictionary object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
     
     public void deleteDataDictionary( DataDictionary dataDictionary )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java	2009-11-12 17:59:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java	2009-11-26 14:02:44 +0000
@@ -39,6 +39,8 @@
 import org.apache.commons.collections.CollectionUtils;
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.common.GenericStore;
+import org.hisp.dhis.system.util.Filter;
+import org.hisp.dhis.system.util.FilterUtils;
 import org.hisp.dhis.system.util.UUIdUtils;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -124,21 +126,17 @@
         return dataElementCategoryStore.get( id );
     }
     
-    public Collection<DataElementCategory> getDataElementCategories( Collection<Integer> identifiers )
+    public Collection<DataElementCategory> getDataElementCategories( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllDataElementCategories();
-        }
-        
-        Collection<DataElementCategory> categories = new ArrayList<DataElementCategory>();
-        
-        for ( Integer id : identifiers )
-        {
-            categories.add( getDataElementCategory( id ) );
-        }
-        
-        return categories;
+        Collection<DataElementCategory> categories = getAllDataElementCategories();
+        
+        return identifiers == null ? categories : FilterUtils.filter( categories, new Filter<DataElementCategory>()
+            {
+                public boolean retain( DataElementCategory object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );        
     }
 
     public DataElementCategory getDataElementCategoryByName( String name )
@@ -175,21 +173,17 @@
         return dataElementCategoryOptionStore.getByName( name );
     }
     
-    public Collection<DataElementCategoryOption> getDataElementCategoryOptions( Collection<Integer> identifiers )
+    public Collection<DataElementCategoryOption> getDataElementCategoryOptions( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllDataElementCategoryOptions();
-        }
-        
-        Collection<DataElementCategoryOption> categoryOptions = new ArrayList<DataElementCategoryOption>();
-        
-        for ( Integer id : identifiers )
-        {
-            categoryOptions.add( getDataElementCategoryOption( id ) );
-        }
-        
-        return categoryOptions;
+        Collection<DataElementCategoryOption> categoryOptions = getAllDataElementCategoryOptions();
+        
+        return identifiers == null ? categoryOptions : FilterUtils.filter( categoryOptions, new Filter<DataElementCategoryOption>()
+            {
+                public boolean retain( DataElementCategoryOption object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
 
     public Collection<DataElementCategoryOption> getAllDataElementCategoryOptions()
@@ -226,21 +220,17 @@
         return dataElementCategoryComboStore.get( id );
     }
     
-    public Collection<DataElementCategoryCombo> getDataElementCategoryCombos( Collection<Integer> identifiers )
+    public Collection<DataElementCategoryCombo> getDataElementCategoryCombos( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllDataElementCategoryCombos();
-        }
-        
-        Collection<DataElementCategoryCombo> categoryCombos = new ArrayList<DataElementCategoryCombo>();
-        
-        for ( Integer id : identifiers )
-        {
-            categoryCombos.add( getDataElementCategoryCombo( id ) );
-        }
-        
-        return categoryCombos;
+        Collection<DataElementCategoryCombo> categoryCombo = getAllDataElementCategoryCombos();
+        
+        return identifiers == null ? categoryCombo : FilterUtils.filter( categoryCombo, new Filter<DataElementCategoryCombo>()
+            {
+                public boolean retain( DataElementCategoryCombo object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
 
     public DataElementCategoryCombo getDataElementCategoryComboByName( String name )
@@ -272,22 +262,17 @@
         return dataElementCategoryOptionComboStore.get( id );
     }
 
-    public Collection<DataElementCategoryOptionCombo> getDataElementCategoryOptionCombos(
-        Collection<Integer> identifiers )
+    public Collection<DataElementCategoryOptionCombo> getDataElementCategoryOptionCombos( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllDataElementCategoryOptionCombos();
-        }
-
-        Collection<DataElementCategoryOptionCombo> categoryOptionCombos = new ArrayList<DataElementCategoryOptionCombo>();
-
-        for ( Integer id : identifiers )
-        {
-            categoryOptionCombos.add( getDataElementCategoryOptionCombo( id ) );
-        }
-
-        return categoryOptionCombos;
+        Collection<DataElementCategoryOptionCombo> categoryOptionCombos = getAllDataElementCategoryOptionCombos();
+        
+        return identifiers == null ? categoryOptionCombos : FilterUtils.filter( categoryOptionCombos, new Filter<DataElementCategoryOptionCombo>()
+            {
+                public boolean retain( DataElementCategoryOptionCombo object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
     
     public DataElementCategoryOptionCombo getDataElementCategoryOptionCombo( Collection<DataElementCategoryOption> categoryOptions )
@@ -298,7 +283,7 @@
             {
                 return categoryOptionCombo;
             }
-        } // TODO Re-implement with a Hibernate Criteria
+        }
         
         return null;
     }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java	2009-11-26 12:05:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java	2009-11-26 14:02:44 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.i18n.I18nUtils.i18n;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
@@ -41,11 +43,11 @@
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.hierarchy.HierarchyViolationException;
 import org.hisp.dhis.i18n.I18nService;
+import org.hisp.dhis.system.util.Filter;
+import org.hisp.dhis.system.util.FilterUtils;
 import org.hisp.dhis.system.util.UUIdUtils;
 import org.springframework.transaction.annotation.Transactional;
 
-import static org.hisp.dhis.i18n.I18nUtils.*;
-
 /**
  * @author Kristian Nordal
  * @version $Id: DefaultDataElementService.java 5243 2008-05-25 10:18:58Z
@@ -154,40 +156,19 @@
         return dataElements;
     }
     
-    public Collection<DataElement> getDataElements( Collection<Integer> identifiers )
-    {
-        if ( identifiers == null )
-        {
-            return getAllDataElements();
-        }
-        
-        Collection<DataElement> objects = new ArrayList<DataElement>();
-        
-        for ( Integer id : identifiers )
-        {
-            objects.add( getDataElement( id ) );
-        }
-        
-        return objects;
-    }
-    
-    public Collection<CalculatedDataElement> getCalculatedDataElements( Collection<Integer> identifiers )
-    {
-        if ( identifiers == null )
-        {
-            return getAllCalculatedDataElements();
-        }
-        
-        Collection<CalculatedDataElement> objects = new ArrayList<CalculatedDataElement>();
-        
-        for ( Integer id : identifiers )
-        {
-            objects.add( (CalculatedDataElement)getDataElement( id ) );
-        }
-        
-        return objects;
-    }
-    
+    public Collection<DataElement> getDataElements( final Collection<Integer> identifiers )
+    {
+        Collection<DataElement> dataElements = getAllDataElements();
+        
+        return identifiers == null ? dataElements : FilterUtils.filter( dataElements, new Filter<DataElement>()
+            {
+                public boolean retain( DataElement dataElement )
+                {
+                    return identifiers.contains( dataElement.getId() );
+                }
+            } );
+    }
+
     public Collection<DataElement> getNonCalculatedDataElements( Collection<Integer> identifiers )
     {
         if ( identifiers == null )
@@ -277,6 +258,19 @@
         return i18n( i18nService, dataElementStore.getAllCalculatedDataElements() );
     }
 
+    public Collection<CalculatedDataElement> getCalculatedDataElements( final Collection<Integer> identifiers )
+    {
+        Collection<CalculatedDataElement> dataElements = getAllCalculatedDataElements();
+        
+        return identifiers == null ? dataElements : FilterUtils.filter( dataElements, new Filter<CalculatedDataElement>()
+            {
+                public boolean retain( CalculatedDataElement dataElement )
+                {
+                    return identifiers.contains( dataElement.getId() );
+                }
+            } );
+    }
+    
     public CalculatedDataElement getCalculatedDataElementByDataElement( DataElement dataElement )
     {
         return i18n( i18nService, dataElementStore.getCalculatedDataElementByDataElement( dataElement ) );
@@ -368,12 +362,12 @@
     
     public Map<Integer, String> getCalculatedDataElementExpressionMap( Collection<Integer> identifiers )
     {
+        Collection<CalculatedDataElement> dataElements = getCalculatedDataElements( identifiers );
+
         Map<Integer, String> map = new HashMap<Integer, String>();
         
-        for ( Integer id : identifiers )
-        {
-            CalculatedDataElement element = (CalculatedDataElement) getDataElement( id );
-            
+        for ( CalculatedDataElement element : dataElements )
+        {            
             map.put( element.getId(), element.getExpression().getExpression() );
         }
         
@@ -417,21 +411,17 @@
         return i18n( i18nService, dataElementGroupStore.get( id ) );
     }
     
-    public Collection<DataElementGroup> getDataElementGroups( Collection<Integer> identifiers )
+    public Collection<DataElementGroup> getDataElementGroups( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllDataElementGroups();
-        }
-        
-        Collection<DataElementGroup> groups = new ArrayList<DataElementGroup>();
-        
-        for ( Integer id : identifiers )
-        {
-            groups.add( getDataElementGroup( id ) );
-        }
-        
-        return groups;
+        Collection<DataElementGroup> groups = getAllDataElementGroups();
+
+        return identifiers == null ? groups : FilterUtils.filter( groups, new Filter<DataElementGroup>()
+        {
+            public boolean retain( DataElementGroup object )
+            {
+                return identifiers.contains( object.getId() );
+            }
+        } );
     }
 
     public DataElementGroup getDataElementGroup( String uuid )
@@ -508,20 +498,16 @@
         return i18n( i18nService, dataElementGroupSetStore.getAll() );
     }
 
-    public Collection<DataElementGroupSet> getDataElementGroupSets( Collection<Integer> identifiers )
+    public Collection<DataElementGroupSet> getDataElementGroupSets( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllDataElementGroupSets();
-        }
-        
-        Collection<DataElementGroupSet> groupSets = new ArrayList<DataElementGroupSet>();
-        
-        for ( Integer id : identifiers )
-        {
-            groupSets.add( getDataElementGroupSet( id ) );
-        }
-        
-        return groupSets;
+        Collection<DataElementGroupSet> groupSets = getAllDataElementGroupSets();
+        
+        return identifiers == null ? groupSets : FilterUtils.filter( groupSets, new Filter<DataElementGroupSet>()
+            {
+                public boolean retain( DataElementGroupSet object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java	2009-11-12 17:59:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java	2009-11-26 14:02:44 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.i18n.I18nUtils.i18n;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -37,10 +39,10 @@
 import org.hisp.dhis.i18n.I18nService;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.source.Source;
+import org.hisp.dhis.system.util.Filter;
+import org.hisp.dhis.system.util.FilterUtils;
 import org.springframework.transaction.annotation.Transactional;
 
-import static org.hisp.dhis.i18n.I18nUtils.*;
-
 /**
  * @author Lars Helge Overland
  * @version $Id: DefaultDataSetService.java 6255 2008-11-10 16:01:24Z larshelg $
@@ -181,21 +183,17 @@
         return i18n( i18nService, dataSetStore.getDataSetsByPeriodType( periodType ) );
     }
     
-    public Collection<DataSet> getDataSets( Collection<Integer> identifiers )
+    public Collection<DataSet> getDataSets( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllDataSets();
-        }        
-        
-        Collection<DataSet> objects = new ArrayList<DataSet>();
-        
-        for ( Integer id : identifiers )
-        {
-            objects.add( getDataSet( id ) );
-        }
-        
-        return objects;
+        Collection<DataSet> dataSets = getAllDataSets();
+        
+        return identifiers == null ? dataSets : FilterUtils.filter( dataSets, new Filter<DataSet>()
+            {
+                public boolean retain( DataSet object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
 
     public List<DataSet> getAvailableDataSets()

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/DefaultIndicatorService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/DefaultIndicatorService.java	2009-11-12 17:59:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/DefaultIndicatorService.java	2009-11-26 14:02:44 +0000
@@ -27,18 +27,19 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
+import static org.hisp.dhis.i18n.I18nUtils.i18n;
+
 import java.util.Collection;
 import java.util.Date;
 import java.util.Iterator;
 
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.i18n.I18nService;
+import org.hisp.dhis.system.util.Filter;
+import org.hisp.dhis.system.util.FilterUtils;
 import org.hisp.dhis.system.util.UUIdUtils;
 import org.springframework.transaction.annotation.Transactional;
 
-import static org.hisp.dhis.i18n.I18nUtils.*;
-
 /**
  * @author Lars Helge Overland
  * @version $Id$
@@ -137,21 +138,17 @@
         return i18n( i18nService, indicatorStore.getAllIndicators() );
     }
     
-    public Collection<Indicator> getIndicators( Collection<Integer> identifiers )
+    public Collection<Indicator> getIndicators( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllIndicators();
-        }
-        
-        Collection<Indicator> objects = new ArrayList<Indicator>();
-        
-        for ( Integer id : identifiers )
-        {
-            objects.add( getIndicator( id ) );
-        }
-        
-        return objects;
+        Collection<Indicator> indicators = getAllIndicators();
+        
+        return identifiers == null ? indicators : FilterUtils.filter( indicators, new Filter<Indicator>()
+            {
+                public boolean retain( Indicator object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
     
     public Indicator getIndicatorByName( String name )
@@ -211,21 +208,17 @@
         return i18n( i18nService, indicatorTypeStore.get( id ) );
     }
     
-    public Collection<IndicatorType> getIndicatorTypes( Collection<Integer> identifiers )
+    public Collection<IndicatorType> getIndicatorTypes( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllIndicatorTypes();
-        }
-        
-        Collection<IndicatorType> types = new ArrayList<IndicatorType>();
-        
-        for ( Integer id : identifiers )
-        {
-            types.add( getIndicatorType( id ) );
-        }
-        
-        return types;
+        Collection<IndicatorType> types = getAllIndicatorTypes();
+        
+        return identifiers == null ? types : FilterUtils.filter( types, new Filter<IndicatorType>()
+            {
+                public boolean retain( IndicatorType object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
     
     public Collection<IndicatorType> getAllIndicatorTypes()
@@ -275,21 +268,17 @@
         return i18n( i18nService, indicatorGroupStore.get( id ) );
     }
     
-    public Collection<IndicatorGroup> getIndicatorGroups( Collection<Integer> identifiers )
+    public Collection<IndicatorGroup> getIndicatorGroups( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllIndicatorGroups();
-        }
-        
-        Collection<IndicatorGroup> groups = new ArrayList<IndicatorGroup>();
-        
-        for ( Integer id : identifiers )
-        {
-            groups.add( getIndicatorGroup( id ) );
-        }
-        
-        return groups;
+        Collection<IndicatorGroup> groups = getAllIndicatorGroups();
+        
+        return identifiers == null ? groups : FilterUtils.filter( groups, new Filter<IndicatorGroup>()
+            {
+                public boolean retain( IndicatorGroup object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
     
     public IndicatorGroup getIndicatorGroup( String uuid )
@@ -368,20 +357,16 @@
         return i18n( i18nService, indicatorGroupSetStore.getAll() );
     }
     
-    public Collection<IndicatorGroupSet> getIndicatorGroupSets( Collection<Integer> identifiers )
+    public Collection<IndicatorGroupSet> getIndicatorGroupSets( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllIndicatorGroupSets();
-        }
-        
-        Collection<IndicatorGroupSet> groupSets = new ArrayList<IndicatorGroupSet>();
-        
-        for ( Integer id : identifiers )
-        {
-            groupSets.add( getIndicatorGroupSet( id ) );
-        }
-        
-        return groupSets;       
+        Collection<IndicatorGroupSet> groupSets = getAllIndicatorGroupSets();
+        
+        return identifiers == null ? groupSets : FilterUtils.filter( groupSets, new Filter<IndicatorGroupSet>()
+            {
+                public boolean retain( IndicatorGroupSet object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );     
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java	2009-11-12 17:59:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java	2009-11-26 14:02:44 +0000
@@ -32,6 +32,8 @@
 import java.util.HashSet;
 
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.hisp.dhis.system.util.Filter;
+import org.hisp.dhis.system.util.FilterUtils;
 import org.hisp.dhis.system.util.UUIdUtils;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -90,21 +92,17 @@
         return organisationUnitGroupStore.get( id );
     }
     
-    public Collection<OrganisationUnitGroup> getOrganisationUnitGroups( Collection<Integer> identifiers )
+    public Collection<OrganisationUnitGroup> getOrganisationUnitGroups( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllOrganisationUnitGroups();
-        }
-        
-        Collection<OrganisationUnitGroup> groups = new ArrayList<OrganisationUnitGroup>();
-        
-        for ( Integer id : identifiers )
-        {
-            groups.add( getOrganisationUnitGroup( id ) );
-        }
-        
-        return groups;
+        Collection<OrganisationUnitGroup> objects = getAllOrganisationUnitGroups();
+        
+        return identifiers == null ? objects : FilterUtils.filter( objects, new Filter<OrganisationUnitGroup>()
+            {
+                public boolean retain( OrganisationUnitGroup object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
 
     public OrganisationUnitGroup getOrganisationUnitGroup( String uuid )
@@ -146,21 +144,17 @@
         return organisationUnitGroupSetStore.get( id );
     }
     
-    public Collection<OrganisationUnitGroupSet> getOrganisationUnitGroupSets( Collection<Integer> identifiers )
+    public Collection<OrganisationUnitGroupSet> getOrganisationUnitGroupSets( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllOrganisationUnitGroupSets();
-        }
-        
-        Collection<OrganisationUnitGroupSet> groupSets = new ArrayList<OrganisationUnitGroupSet>();
-        
-        for ( Integer id : identifiers )
-        {
-            groupSets.add( getOrganisationUnitGroupSet( id ) );
-        }
-        
-        return groupSets;
+        Collection<OrganisationUnitGroupSet> objects = getAllOrganisationUnitGroupSets();
+        
+        return identifiers == null ? objects : FilterUtils.filter( objects, new Filter<OrganisationUnitGroupSet>()
+            {
+                public boolean retain( OrganisationUnitGroupSet object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
 
     public OrganisationUnitGroupSet getOrganisationUnitGroupSetByName( String name )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2009-11-12 17:59:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2009-11-26 14:02:44 +0000
@@ -42,6 +42,8 @@
 import org.hisp.dhis.hierarchy.HierarchyViolationException;
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitLevelComparator;
 import org.hisp.dhis.source.SourceStore;
+import org.hisp.dhis.system.util.Filter;
+import org.hisp.dhis.system.util.FilterUtils;
 import org.hisp.dhis.system.util.UUIdUtils;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -142,21 +144,17 @@
         return sourceStore.getAllSources();
     }
     
-    public Collection<OrganisationUnit> getOrganisationUnits( Collection<Integer> identifiers )
+    public Collection<OrganisationUnit> getOrganisationUnits( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllOrganisationUnits();
-        }
-        
-        Collection<OrganisationUnit> objects = new ArrayList<OrganisationUnit>();
-        
-        for ( Integer id : identifiers )
-        {
-            objects.add( getOrganisationUnit( id ) );
-        }
-        
-        return objects;
+        Collection<OrganisationUnit> objects = getAllOrganisationUnits();
+        
+        return identifiers == null ? objects : FilterUtils.filter( objects, new Filter<OrganisationUnit>()
+            {
+                public boolean retain( OrganisationUnit object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
 
     public OrganisationUnit getOrganisationUnit( String uuid )
@@ -482,21 +480,17 @@
         return organisationUnitStore.getOrganisationUnitLevel( id );
     }
     
-    public Collection<OrganisationUnitLevel> getOrganisationUnitLevels( Collection<Integer> identifiers )
+    public Collection<OrganisationUnitLevel> getOrganisationUnitLevels( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getOrganisationUnitLevels();
-        }
-        
-        Collection<OrganisationUnitLevel> levels = new ArrayList<OrganisationUnitLevel>();
-        
-        for ( Integer id : identifiers )
-        {
-            levels.add( getOrganisationUnitLevel( id ) );
-        }
-        
-        return levels;
+        Collection<OrganisationUnitLevel> objects = getOrganisationUnitLevels();
+        
+        return identifiers == null ? objects : FilterUtils.filter( objects, new Filter<OrganisationUnitLevel>()
+            {
+                public boolean retain( OrganisationUnitLevel object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
     
     public void deleteOrganisationUnitLevel( OrganisationUnitLevel level )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java	2009-06-10 22:25:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java	2009-11-26 14:02:44 +0000
@@ -37,6 +37,8 @@
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.source.Source;
 import org.hisp.dhis.system.util.DateUtils;
+import org.hisp.dhis.system.util.Filter;
+import org.hisp.dhis.system.util.FilterUtils;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -87,21 +89,17 @@
         return periodStore.getAllPeriods();
     }
 
-    public Collection<Period> getPeriods( Collection<Integer> identifiers )
+    public Collection<Period> getPeriods( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllPeriods();
-        }
-
-        Collection<Period> objects = new ArrayList<Period>();
-
-        for ( Integer id : identifiers )
-        {
-            objects.add( getPeriod( id ) );
-        }
-
-        return objects;
+        Collection<Period> periods = getAllPeriods();
+        
+        return identifiers == null ? periods : FilterUtils.filter( periods, new Filter<Period>()
+            {
+                public boolean retain( Period object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
 
     public Collection<Period> getPeriodsByPeriodType( PeriodType periodType )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java	2009-10-27 15:12:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java	2009-11-26 14:02:44 +0000
@@ -29,7 +29,6 @@
 
 import static org.hisp.dhis.system.util.MathUtils.expressionIsTrue;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
@@ -42,6 +41,8 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.source.Source;
+import org.hisp.dhis.system.util.Filter;
+import org.hisp.dhis.system.util.FilterUtils;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -272,21 +273,17 @@
         return validationRuleStore.get( id );
     }
     
-    public Collection<ValidationRule> getValidationRules( Collection<Integer> identifiers )
+    public Collection<ValidationRule> getValidationRules( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllValidationRules();
-        }
-        
-        Collection<ValidationRule> rules = new ArrayList<ValidationRule>();
-        
-        for ( Integer id : identifiers )
-        {
-            rules.add( getValidationRule( id ) );
-        }
-        
-        return rules;
+        Collection<ValidationRule> objects = getAllValidationRules();
+        
+        return identifiers == null ? objects : FilterUtils.filter( objects, new Filter<ValidationRule>()
+            {
+                public boolean retain( ValidationRule object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
 
     public ValidationRule getValidationRuleByName( String name )

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementConverter.java	2009-11-26 10:38:53 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementConverter.java	2009-11-26 14:02:44 +0000
@@ -44,6 +44,7 @@
 import org.hisp.dhis.importexport.converter.AbstractDataElementConverter;
 import org.hisp.dhis.importexport.mapping.NameMappingUtil;
 import org.hisp.dhis.system.util.DateUtils;
+import org.hisp.dhis.system.util.TimeUtils;
 
 /**
  * @author Lars Helge Overland
@@ -111,8 +112,11 @@
 
     public void write( XMLWriter writer, ExportParams params )
     {
+        TimeUtils.start();
         Collection<DataElement> elements = dataElementService.getNonCalculatedDataElements( params.getDataElements() );
-
+        TimeUtils.markHMS( "Got de" );
+        TimeUtils.stop();
+        
         if ( elements != null && elements.size() > 0 )
         {
             writer.openElement( COLLECTION_NAME );

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/olap/DefaultOlapURLService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/olap/DefaultOlapURLService.java	2009-10-27 15:12:01 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/olap/DefaultOlapURLService.java	2009-11-26 14:02:44 +0000
@@ -27,10 +27,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
 import java.util.Collection;
 
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.hisp.dhis.system.util.Filter;
+import org.hisp.dhis.system.util.FilterUtils;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -89,21 +90,17 @@
         return olapURLStore.get( id );
     }
     
-    public Collection<OlapURL> getOlapURLs( Collection<Integer> identifiers )
+    public Collection<OlapURL> getOlapURLs( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllOlapURLs();
-        }
-        
-        Collection<OlapURL> urls = new ArrayList<OlapURL>();
-        
-        for ( Integer id : identifiers )
-        {
-            urls.add( getOlapURL( id ) );
-        }
-        
-        return urls;
+        Collection<OlapURL> objects = getAllOlapURLs();
+        
+        return identifiers == null ? objects : FilterUtils.filter( objects, new Filter<OlapURL>()
+            {
+                public boolean retain( OlapURL object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
     
     public void deleteOlapURL( OlapURL olapURL )

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2009-11-23 17:17:04 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2009-11-26 14:02:44 +0000
@@ -67,6 +67,8 @@
 import org.hisp.dhis.reporttable.ReportTableService;
 import org.hisp.dhis.reporttable.jdbc.ReportTableManager;
 import org.hisp.dhis.system.grid.Grid;
+import org.hisp.dhis.system.util.Filter;
+import org.hisp.dhis.system.util.FilterUtils;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -487,21 +489,17 @@
     }
 
     @Transactional
-    public Collection<ReportTable> getReportTables( Collection<Integer> identifiers )
+    public Collection<ReportTable> getReportTables( final Collection<Integer> identifiers )
     {
-        if ( identifiers == null )
-        {
-            return getAllReportTables();
-        }
-        
-        Collection<ReportTable> tables = new ArrayList<ReportTable>();
-        
-        for ( Integer id : identifiers )
-        {
-            tables.add( getReportTable( id ) );
-        }
-        
-        return tables;
+        Collection<ReportTable> objects = getAllReportTables();
+        
+        return identifiers == null ? objects : FilterUtils.filter( objects, new Filter<ReportTable>()
+            {
+                public boolean retain( ReportTable object )
+                {
+                    return identifiers.contains( object.getId() );
+                }
+            } );
     }
 
     @Transactional