← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17263: Data approval, moved database query for approval level out of loop

 

------------------------------------------------------------
revno: 17263
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-10-24 13:45:30 +0200
message:
  Data approval, moved database query for approval level out of loop
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.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-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java	2014-10-23 08:30:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java	2014-10-24 11:45:30 +0000
@@ -117,6 +117,8 @@
      */
     List<DataApprovalLevel> getAllDataApprovalLevels();
     
+    Map<Integer, DataApprovalLevel> getDataApprovalLevelMap();
+    
     List<DataApprovalLevel> getUserDataApprovalLevels();
 
     /**

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2014-09-01 06:16:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2014-10-24 11:45:30 +0000
@@ -61,7 +61,8 @@
 public abstract class PeriodType
     implements Serializable
 {
-    // cache for speeding up period lookup, uses calendar.name() + periodType.getName() + date.getTime() as key
+    // Cache for period lookup, uses calendar.name() + periodType.getName() + date.getTime() as key
+    
     private static Cache<String, Period> periodCache = CacheBuilder.newBuilder()
         .expireAfterAccess( 5, TimeUnit.MINUTES )
         .initialCapacity( 10000 )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java	2014-10-24 10:49:02 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java	2014-10-24 11:45:30 +0000
@@ -36,7 +36,10 @@
 import java.util.Map;
 import java.util.Set;
 
+import com.google.common.base.Function;
 import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
 import org.apache.commons.collections.CollectionUtils;
 import org.hisp.dhis.dataelement.CategoryOptionGroup;
 import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
@@ -268,6 +271,19 @@
 
         return dataApprovalLevels;
     }
+    
+    public Map<Integer, DataApprovalLevel> getDataApprovalLevelMap()
+    {
+        List<DataApprovalLevel> levels = dataApprovalLevelStore.getAllDataApprovalLevels();
+        
+        return Maps.uniqueIndex( levels, new Function<DataApprovalLevel, Integer>()
+        {
+            public Integer apply( DataApprovalLevel level )
+            {
+                return level.getLevel();
+            }            
+        } );
+    }
 
     @Override
     public List<DataApprovalLevel> getUserDataApprovalLevels()

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java	2014-10-24 10:44:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java	2014-10-24 11:45:30 +0000
@@ -28,6 +28,17 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.system.util.CollectionUtils.asSet;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.dataapproval.exceptions.DataApprovalException;
@@ -60,17 +71,6 @@
 import org.hisp.dhis.user.User;
 import org.springframework.transaction.annotation.Transactional;
 
-import static org.hisp.dhis.system.util.CollectionUtils.asSet;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
 /**
  * @author Jim Grace
  */

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java	2014-10-24 10:44:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java	2014-10-24 11:45:30 +0000
@@ -30,6 +30,7 @@
 
 import java.util.Date;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 
 import org.hibernate.Criteria;
@@ -243,6 +244,8 @@
 
         DataElementCategoryOptionCombo defaultOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
         
+        Map<Integer, DataApprovalLevel> levelMap = dataApprovalLevelService.getDataApprovalLevelMap();
+        
         Set<DataApproval> userDataApprovals = new HashSet<>();
 
         while ( rowSet.next() )
@@ -264,7 +267,7 @@
 
             DataElementCategoryOptionCombo attributeOptionCombo = categoryService.getDataElementCategoryOptionCombo( attributeOptionComboId );
             Period period = periodService.getPeriod( periodId );
-            DataApprovalLevel dataApprovalLevel = ( level == null ? null : dataApprovalLevelService.getDataApprovalLevelByLevelNumber( level ) );
+            DataApprovalLevel dataApprovalLevel = ( level == null ? null : levelMap.get( level ) );
             OrganisationUnit orgUnit = ( orgUnitId == null ? null : organisationUnitService.getOrganisationUnit( orgUnitId ) );
 
             //TODO: currently special cased for PEFPAR's requirements. Can we make it more generic?