← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8826: Improved performance and set correct sort order in option set query.

 

------------------------------------------------------------
revno: 8826
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-11-01 18:15:26 +0300
message:
  Improved performance and set correct sort order in option set query.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/option/OptionServiceTest.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ShowEventWithRegistrationFormAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentSelectAction.java
  dhis-2/dhis-web/dhis-web-caseentry/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-api/src/main/java/org/hisp/dhis/option/OptionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java	2012-06-25 13:20:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java	2012-11-01 15:15:26 +0000
@@ -51,5 +51,5 @@
 
     Collection<OptionSet> getAllOptionSets();
     
-    List<String> getOptions( OptionSet optionSet, String key, Integer max  );
+    List<String> getOptions( int optionSetId, String key, Integer max  );
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java	2012-06-25 13:20:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java	2012-11-01 15:15:26 +0000
@@ -38,6 +38,6 @@
  */
 public interface OptionStore extends GenericIdentifiableObjectStore<OptionSet>
 {
-    List<String> getOptions( OptionSet optionSet, String key, Integer max  );
+    List<String> getOptions( int optionSetId, String key, Integer max  );
 }
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java	2012-06-25 13:20:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java	2012-11-01 15:15:26 +0000
@@ -27,6 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
@@ -81,8 +82,25 @@
         return optionStore.getAll();
     }
     
-    public List<String> getOptions( OptionSet optionSet, String key, Integer max  )
+    public List<String> getOptions( int optionSetId, String key, Integer max  )
     {
-        return optionStore.getOptions( optionSet, key, max );
+        List<String> options = null;
+        
+        if ( key != null || max != null )
+        {
+            // Use query as option set size might be very high
+            
+            options = optionStore.getOptions( optionSetId, key, max );
+        }
+        else
+        {
+            // Return all from object association to preserve custom order
+
+            OptionSet optionSet = getOptionSet( optionSetId );
+            
+            options = new ArrayList<String>( optionSet.getOptions() );
+        }
+        
+        return options;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java	2012-11-01 12:01:37 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java	2012-11-01 15:15:26 +0000
@@ -45,7 +45,7 @@
 {
     @SuppressWarnings("unchecked")
     @Override
-    public List<String> getOptions( OptionSet optionSet, String key, Integer max )
+    public List<String> getOptions( int optionSetId, String key, Integer max )
     {
         String hql = "select option from OptionSet os inner join os.options as option where os.id = :optionSetId";
         
@@ -57,8 +57,12 @@
         hql += " order by option";
         
         Query query = getQuery( hql );
-        query.setInteger( "optionSetId", optionSet.getId() );
-        query.setMaxResults( max );
+        query.setInteger( "optionSetId", optionSetId );
+        
+        if ( max != null )
+        {
+            query.setMaxResults( max );
+        }
         
         return query.list();
     }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/option/OptionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/option/OptionServiceTest.java	2012-02-07 18:50:24 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/option/OptionServiceTest.java	2012-11-01 15:15:26 +0000
@@ -55,9 +55,10 @@
     {
         optionService = (OptionService) getBean( OptionService.ID );
         
-        options.add( "OptionA" );
-        options.add( "OptionB" );
-        options.add( "OptionC" );
+        options.add( "OptA1" );
+        options.add( "OptA2" );
+        options.add( "OptB1" );
+        options.add( "OptB2" );
         
         optionSetA.setOptions( options );
         optionSetB.setOptions( options );
@@ -78,13 +79,14 @@
         assertEquals( optionSetB, actualB );
         assertEquals( optionSetC, actualC );
         
-        assertEquals( 3, optionSetA.getOptions().size() );
-        assertEquals( 3, optionSetB.getOptions().size() );
+        assertEquals( 4, optionSetA.getOptions().size() );
+        assertEquals( 4, optionSetB.getOptions().size() );
         assertEquals( 0, optionSetC.getOptions().size() );
         
-        assertTrue( optionSetA.getOptions().contains( "OptionA" ) );
-        assertTrue( optionSetA.getOptions().contains( "OptionB" ) );
-        assertTrue( optionSetA.getOptions().contains( "OptionC" ) );
+        assertTrue( optionSetA.getOptions().contains( "OptA1" ) );
+        assertTrue( optionSetA.getOptions().contains( "OptA2" ) );
+        assertTrue( optionSetA.getOptions().contains( "OptB1" ) );
+        assertTrue( optionSetA.getOptions().contains( "OptB2" ) );
     }
     
     @Test
@@ -96,4 +98,30 @@
         assertEquals( encoded, OptionSet.optionEncode( decoded ) );
         assertEquals( decoded, OptionSet.optionDecode( encoded ) );
     }
+    
+    @Test
+    public void testGetList()
+    {
+        int idA = optionService.saveOptionSet( optionSetA );
+        
+        List<String> options = optionService.getOptions( idA, "OptA", 10 );
+        
+        assertEquals( 2, options.size() );
+        
+        options = optionService.getOptions( idA, "OptA1", 10 );
+
+        assertEquals( 1, options.size() );
+
+        options = optionService.getOptions( idA, "OptA1", null );
+
+        assertEquals( 1, options.size() );
+
+        options = optionService.getOptions( idA, "Opt", null );
+
+        assertEquals( 4, options.size() );
+        
+        options = optionService.getOptions( idA, "Opt", 3 );
+
+        assertEquals( 3, options.size() );
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java	2012-11-01 12:01:37 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java	2012-11-01 15:15:26 +0000
@@ -27,7 +27,6 @@
 
 package org.hisp.dhis.caseentry.action.caseentry;
 
-import java.util.Collections;
 import java.util.List;
 
 import org.apache.commons.lang.StringUtils;
@@ -116,9 +115,9 @@
 
         boolean isNotModified = ( query == null && ContextUtils.isNotModified( ServletActionContext.getRequest(), ServletActionContext.getResponse(), optionSet ) );
         
-        if ( !isNotModified )
+        if ( !isNotModified && optionSet != null )
         {
-            options = optionService.getOptions( optionSet, query, MAX_OPTIONS_DISPLAYED );
+            options = optionService.getOptions( optionSet.getId(), query, MAX_OPTIONS_DISPLAYED );
         }
         
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java	2012-08-15 02:57:56 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadProgramStageInstancesAction.java	2012-11-01 15:15:26 +0000
@@ -28,7 +28,6 @@
 package org.hisp.dhis.caseentry.action.caseentry;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -39,17 +38,13 @@
 import org.hisp.dhis.program.ProgramInstance;
 import org.hisp.dhis.program.ProgramInstanceService;
 import org.hisp.dhis.program.ProgramService;
-import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStageInstance;
 import org.hisp.dhis.program.ProgramStageInstanceService;
-import org.hisp.dhis.program.comparator.ProgramStageInstanceDueDateComparator;
 
 import com.opensymphony.xwork2.Action;
 
 /**
  * @author Chau Thu Tran
- * @version $ LoadProgramStageInstancesAction.java May 7, 2011 2:31:47 PM $
- * 
  */
 public class LoadProgramStageInstancesAction
     implements Action

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ShowEventWithRegistrationFormAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ShowEventWithRegistrationFormAction.java	2012-10-11 14:31:43 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/ShowEventWithRegistrationFormAction.java	2012-11-01 15:15:26 +0000
@@ -34,7 +34,6 @@
 import java.util.List;
 import java.util.Map;
 
-import org.hisp.dhis.dataentryform.DataEntryForm;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
 import org.hisp.dhis.patient.PatientAttribute;
@@ -43,7 +42,6 @@
 import org.hisp.dhis.patient.PatientIdentifierType;
 import org.hisp.dhis.patient.PatientIdentifierTypeService;
 import org.hisp.dhis.program.Program;
-import org.hisp.dhis.program.ProgramDataEntryService;
 import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStageDataElement;
@@ -53,8 +51,6 @@
 
 /**
  * @author Chau Thu Tran
- * 
- * @version $ShowEventWithRegistrationFormAction.java Jun 26, 2012 4:41:09 PM$
  */
 public class ShowEventWithRegistrationFormAction
     implements Action
@@ -91,13 +87,6 @@
         this.programService = programService;
     }
 
-    private ProgramDataEntryService programDataEntryService;
-
-    public void setProgramDataEntryService( ProgramDataEntryService programDataEntryService )
-    {
-        this.programDataEntryService = programDataEntryService;
-    }
-
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentAction.java	2012-10-31 09:05:25 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentAction.java	2012-11-01 15:15:26 +0000
@@ -32,6 +32,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+
 import org.hisp.dhis.caseentry.state.SelectedStateManager;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.PatientAttribute;
@@ -45,13 +46,11 @@
 import org.hisp.dhis.program.ProgramInstance;
 import org.hisp.dhis.program.ProgramInstanceService;
 import org.hisp.dhis.program.ProgramStageInstance;
-import org.hisp.dhis.program.ProgramStageInstanceService;
 
 import com.opensymphony.xwork2.Action;
 
 /**
  * @author Abyot Asalefew Gizaw
- * @version $Id$
  */
 public class ProgramEnrollmentAction
     implements Action

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentSelectAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentSelectAction.java	2012-10-26 05:09:48 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ProgramEnrollmentSelectAction.java	2012-11-01 15:15:26 +0000
@@ -29,8 +29,6 @@
 import java.util.ArrayList;
 import java.util.Collection;
 
-import org.hisp.dhis.caseentry.state.SelectedStateManager;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientService;
 import org.hisp.dhis.program.Program;
@@ -72,13 +70,6 @@
         this.programInstanceService = programInstanceService;
     }
 
-    private SelectedStateManager selectedStateManager;
-
-    public void setSelectedStateManager( SelectedStateManager selectedStateManager )
-    {
-        this.selectedStateManager = selectedStateManager;
-    }
-
     // -------------------------------------------------------------------------
     // Input/Output
     // -------------------------------------------------------------------------
@@ -111,8 +102,6 @@
     public String execute()
         throws Exception
     {
-        OrganisationUnit orgunit = selectedStateManager.getSelectedOrganisationUnit();
-
         patient = patientService.getPatient( id );
 
         // Get all programs

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2012-10-31 09:05:25 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2012-11-01 15:15:26 +0000
@@ -210,8 +210,6 @@
 		<property name="patientIdentifierTypeService"
 			ref="org.hisp.dhis.patient.PatientIdentifierTypeService" />
 		<property name="programService" ref="org.hisp.dhis.program.ProgramService" />
-		<property name="programDataEntryService"
-			ref="org.hisp.dhis.program.ProgramDataEntryService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.caseentry.action.caseentry.SaveValuesAction"
@@ -553,8 +551,6 @@
 		<property name="patientService" ref="org.hisp.dhis.patient.PatientService" />
 		<property name="programService" ref="org.hisp.dhis.program.ProgramService" />
 		<property name="programInstanceService" ref="org.hisp.dhis.program.ProgramInstanceService" />
-		<property name="selectedStateManager"
-			ref="org.hisp.dhis.caseentry.state.SelectedStateManager" />
 	</bean>
 
 	<bean id="org.hisp.dhis.caseentry.action.patient.ProgramEnrollmentAction"