← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18624: Data entry form service, cache for option combos

 

------------------------------------------------------------
revno: 18624
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-03-19 01:30:31 +0100
message:
  Data entry form service, cache for option combos
modified:
  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/resources/META-INF/dhis/beans.xml


--
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/dataentryform/DefaultDataEntryFormService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2015-02-19 09:18:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2015-03-19 00:30:31 +0000
@@ -43,15 +43,17 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
-import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.indicator.IndicatorService;
+import org.hisp.dhis.system.callable.IdentifiableObjectCallable;
+import org.hisp.dhis.system.util.CachingMap;
 import org.hisp.dhis.system.util.Filter;
 import org.hisp.dhis.system.util.FilterUtils;
 import org.springframework.transaction.annotation.Transactional;
@@ -81,11 +83,11 @@
         this.dataEntryFormStore = dataEntryFormStore;
     }
 
-    private DataElementCategoryService categoryService;
+    private IdentifiableObjectManager idObjectManager;
 
-    public void setCategoryService( DataElementCategoryService categoryService )
+    public void setIdObjectManager( IdentifiableObjectManager idObjectManager )
     {
-        this.categoryService = categoryService;
+        this.idObjectManager = idObjectManager;
     }
 
     private DataElementService dataElementService;
@@ -192,6 +194,11 @@
         {
             return null;
         }
+
+        CachingMap<String, DataElementCategoryOptionCombo> optionComboMap = new CachingMap<>();
+        
+        IdentifiableObjectCallable<DataElementCategoryOptionCombo> optionComboCallabel = 
+            new IdentifiableObjectCallable<DataElementCategoryOptionCombo>( idObjectManager, DataElementCategoryOptionCombo.class, null );
         
         StringBuffer sb = new StringBuffer();
 
@@ -214,8 +221,10 @@
                 DataElement dataElement = dataElementService.getDataElement( dataElementId );
 
                 String optionComboId = identifierMatcher.group( 2 );
-                DataElementCategoryOptionCombo categegoryOptionCombo = categoryService.getDataElementCategoryOptionCombo( optionComboId );
-                String optionComboName = categegoryOptionCombo != null ? escapeHtml3( categegoryOptionCombo.getName() ) : "[ " + i18n.getString( "cat_option_combo_not_exist" ) + " ]";
+
+                DataElementCategoryOptionCombo categoryOptionCombo = optionComboMap.get( optionComboId, optionComboCallabel.setUid( optionComboId ) );
+
+                String optionComboName = categoryOptionCombo != null ? escapeHtml3( categoryOptionCombo.getName() ) : "[ " + i18n.getString( "cat_option_combo_not_exist" ) + " ]";
 
                 StringBuilder title = dataElement != null ?
                     new StringBuilder( "title=\"" ).append( dataElementId ).append( " - " ).
@@ -277,14 +286,19 @@
         // Inline javascript/html to add to HTML before output
         // ---------------------------------------------------------------------
 
+        Map<String, DataElement> dataElementMap = getDataElementMap( dataSet );
+
+        CachingMap<String, DataElementCategoryOptionCombo> optionComboMap = new CachingMap<>();
+        
+        IdentifiableObjectCallable<DataElementCategoryOptionCombo> optionComboCallabel = 
+            new IdentifiableObjectCallable<DataElementCategoryOptionCombo>( idObjectManager, DataElementCategoryOptionCombo.class, null );
+        
         int i = 1;
 
         StringBuffer sb = new StringBuffer();
 
         Matcher inputMatcher = INPUT_PATTERN.matcher( htmlCode );
 
-        Map<String, DataElement> dataElementMap = getDataElementMap( dataSet );
-
         while ( inputMatcher.find() )
         {
             // -----------------------------------------------------------------
@@ -309,8 +323,7 @@
                     return i18n.getString( "dataelement_with_id" ) + ": " + dataElementId + " " + i18n.getString( "does_not_exist" );
                 }
 
-                DataElementCategoryOptionCombo categoryOptionCombo = categoryService
-                    .getDataElementCategoryOptionCombo( optionComboId );
+                DataElementCategoryOptionCombo categoryOptionCombo = optionComboMap.get( optionComboId, optionComboCallabel.setUid( optionComboId ) );
 
                 if ( categoryOptionCombo == null )
                 {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2015-03-16 15:02:40 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2015-03-19 00:30:31 +0000
@@ -492,7 +492,7 @@
     <property name="dataEntryFormStore" ref="org.hisp.dhis.dataentryform.DataEntryFormStore" />
     <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
     <property name="indicatorService" ref="org.hisp.dhis.indicator.IndicatorService" />
-    <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
+    <property name="idObjectManager" ref="org.hisp.dhis.common.IdentifiableObjectManager" />
   </bean>
 
   <bean id="org.hisp.dhis.expression.ExpressionService" class="org.hisp.dhis.expression.DefaultExpressionService">