← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18633: DataEntryFormService, preloading cache of option combos

 

------------------------------------------------------------
revno: 18633
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-03-19 13:24:51 +0100
message:
  DataEntryFormService, preloading cache of option combos
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js


--
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/common/IdentifiableObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java	2015-02-26 11:19:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java	2015-03-19 12:24:51 +0000
@@ -376,4 +376,26 @@
 
         return map;
     }
+
+    /**
+     * Returns a mapping between the uid and the name of the given identifiable
+     * objects.
+     *
+     * @param objects the identifiable objects.
+     * @return mapping between the uid and the name of the given objects.
+     */
+    public static <T extends IdentifiableObject> Map<String, T> getUidObjectMap( Collection<T> objects )
+    {
+        Map<String, T> map = new HashMap<>();
+
+        if ( objects != null )
+        {
+            for ( T object : objects )
+            {
+                map.put( object.getUid(), object );
+            }
+        }
+
+        return map;
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java	2015-02-26 15:21:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java	2015-03-19 12:24:51 +0000
@@ -417,6 +417,11 @@
         return aggregationLevels != null && aggregationLevels.size() > 0;
     }
 
+    public boolean hasCategoryCombo()
+    {
+        return categoryCombo != null;
+    }
+    
     /**
      * Tests whether the DataElement is associated with a
      * DataElementCategoryCombo with more than one DataElementCategory, or any

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2015-02-26 15:21:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2015-03-19 12:24:51 +0000
@@ -49,6 +49,7 @@
 import org.hisp.dhis.dataelement.DataElementCategory;
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryOption;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.dataentryform.DataEntryForm;
 import org.hisp.dhis.indicator.Indicator;
@@ -400,6 +401,21 @@
         return dataElements;
     }
 
+    public Set<DataElementCategoryOptionCombo> getDataElementOptionCombos()
+    {
+        Set<DataElementCategoryOptionCombo> optionCombos = new HashSet<>();
+        
+        for ( DataElement element : dataElements )
+        {
+            if ( element.hasCategoryCombo() )
+            {
+                optionCombos.addAll( element.getCategoryCombo().getOptionCombos() );
+            }
+        }
+        
+        return optionCombos;
+    }
+
     public int increaseVersion()
     {
         return ++version;
@@ -435,7 +451,7 @@
     {
         return categoryCombo != null && !DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME.equals( categoryCombo.getName() );
     }
-
+    
     // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2015-03-19 00:30:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2015-03-19 12:24:51 +0000
@@ -44,6 +44,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.common.IdentifiableObjectUtils;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementOperand;
@@ -287,9 +288,11 @@
         // ---------------------------------------------------------------------
 
         Map<String, DataElement> dataElementMap = getDataElementMap( dataSet );
-
+        
         CachingMap<String, DataElementCategoryOptionCombo> optionComboMap = new CachingMap<>();
         
+        optionComboMap.putAll( IdentifiableObjectUtils.getUidObjectMap( dataSet.getDataElementOptionCombos() ) );
+        
         IdentifiableObjectCallable<DataElementCategoryOptionCombo> optionComboCallabel = 
             new IdentifiableObjectCallable<DataElementCategoryOptionCombo>( idObjectManager, DataElementCategoryOptionCombo.class, null );
         

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2015-02-24 09:53:30 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js	2015-03-19 12:24:51 +0000
@@ -914,12 +914,15 @@
 
         $.safeEach( dataSetList, function( idx, item )
         {
-            addOptionById( 'selectedDataSetId', item.id, item.name );
-
-            if ( dataSetId == item.id )
-            {
-                dataSetValid = true;
-            }
+        	if ( item )
+        	{
+	            addOptionById( 'selectedDataSetId', item.id, item.name );
+	
+	            if ( dataSetId == item.id )
+	            {
+	                dataSetValid = true;
+	            }
+        	}
         } );
 
         if ( children )