← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9127: Fixed optionset.

 

------------------------------------------------------------
revno: 9127
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-11-26 18:12:01 +0700
message:
  Fixed optionset.
modified:
  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/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/option/OptionServiceTest.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/option/hibernate/HibernateOptionStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java	2012-11-26 04:43:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java	2012-11-26 11:12:01 +0000
@@ -27,17 +27,12 @@
 
 package org.hisp.dhis.option.hibernate;
 
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
 import java.util.List;
 
 import org.hibernate.Query;
 import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
 import org.hisp.dhis.option.OptionSet;
 import org.hisp.dhis.option.OptionStore;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.RowMapper;
 
 /**
  * @author Chau Thu Tran
@@ -49,17 +44,6 @@
     implements OptionStore
 {
     // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private JdbcTemplate jdbcTemplate;
-
-    public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
-    {
-        this.jdbcTemplate = jdbcTemplate;
-    }
-
-    // -------------------------------------------------------------------------
     // Implementation methods
     // -------------------------------------------------------------------------
 
@@ -68,15 +52,18 @@
     public List<String> getOptions( int optionSetId, String key, Integer max )
     {
         String hql = "select option from OptionSet as optionset inner join optionset.options as option where optionset.id = :optionSetId ";
-        if( key != null )
+        if ( key != null )
         {
             hql += " and lower(option) like lower('%" + key + "%') ";
         }
-        
+
         hql += " order by index(option)";
         Query query = getQuery( hql );
         query.setInteger( "optionSetId", optionSetId );
-        query.setMaxResults( max );
+        if ( max != null )
+        {
+            query.setMaxResults( max );
+        }
         
         return query.list();
     }

=== 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	2012-11-20 09:02:06 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2012-11-26 11:12:01 +0000
@@ -285,7 +285,6 @@
   <bean id="org.hisp.dhis.option.OptionStore" class="org.hisp.dhis.option.hibernate.HibernateOptionStore">
     <property name="clazz" value="org.hisp.dhis.option.OptionSet" />
     <property name="sessionFactory" ref="sessionFactory" />
-    <property name="jdbcTemplate" ref="jdbcTemplate" />
   </bean>
 
   <bean id="org.hisp.dhis.mapping.MapStore" class="org.hisp.dhis.mapping.hibernate.HibernateMapStore">

=== 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-11-26 08:58:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/option/OptionServiceTest.java	2012-11-26 11:12:01 +0000
@@ -43,75 +43,93 @@
     extends DhisTest
 {
     private OptionService optionService;
-    
+
     private List<String> options = new ArrayList<String>();
-    
+
     private OptionSet optionSetA = new OptionSet( "OptionSetA" );
+
     private OptionSet optionSetB = new OptionSet( "OptionSetB" );
+
     private OptionSet optionSetC = new OptionSet( "OptionSetC" );
-    
+
     @Override
     public boolean emptyDatabaseAfterTest()
     {
         return true;
     }
-    
+
     @Override
     public void setUpTest()
     {
         optionService = (OptionService) getBean( OptionService.ID );
-        
+
         options.add( "OptA1" );
         options.add( "OptA2" );
         options.add( "OptB1" );
         options.add( "OptB2" );
-        
+
         optionSetA.setOptions( options );
         optionSetB.setOptions( options );
     }
-    
+
     @Test
     public void testSaveGet()
     {
         int idA = optionService.saveOptionSet( optionSetA );
         int idB = optionService.saveOptionSet( optionSetB );
         int idC = optionService.saveOptionSet( optionSetC );
-        
+
         OptionSet actualA = optionService.getOptionSet( idA );
         OptionSet actualB = optionService.getOptionSet( idB );
         OptionSet actualC = optionService.getOptionSet( idC );
-        
+
         assertEquals( optionSetA, actualA );
         assertEquals( optionSetB, actualB );
         assertEquals( optionSetC, actualC );
-        
+
         assertEquals( 4, optionSetA.getOptions().size() );
         assertEquals( 4, optionSetB.getOptions().size() );
         assertEquals( 0, optionSetC.getOptions().size() );
-        
+
         assertTrue( optionSetA.getOptions().contains( "OptA1" ) );
         assertTrue( optionSetA.getOptions().contains( "OptA2" ) );
         assertTrue( optionSetA.getOptions().contains( "OptB1" ) );
         assertTrue( optionSetA.getOptions().contains( "OptB2" ) );
     }
-    
+
     @Test
     public void testCodec()
     {
         String decoded = "Malaria Severe Under 5";
-        String encoded = "[Malaria_Severe_Under_5]"; 
-        
+        String encoded = "[Malaria_Severe_Under_5]";
+
         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, "OptA1", 10 );
-        
-        assertEquals( 1, options.size() );
+
+        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() );
     }
 }