← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14511: Fixed bug - Error in TableAlterator

 

------------------------------------------------------------
revno: 14511
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-03-28 15:30:22 +0700
message:
  Fixed bug - Error in TableAlterator
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.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/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2014-03-28 07:24:57 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2014-03-28 08:30:22 +0000
@@ -28,6 +28,13 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import org.amplecode.quick.BatchHandler;
 import org.amplecode.quick.BatchHandlerFactory;
 import org.amplecode.quick.StatementHolder;
@@ -37,22 +44,11 @@
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.jdbc.StatementBuilder;
 import org.hisp.dhis.jdbc.batchhandler.RelativePeriodsBatchHandler;
-import org.hisp.dhis.option.OptionService;
-import org.hisp.dhis.option.OptionSet;
 import org.hisp.dhis.period.RelativePeriods;
 import org.hisp.dhis.system.startup.AbstractStartupRoutine;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.sql.ResultSet;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 /**
  * @author Lars Helge Overland
  */
@@ -717,35 +713,10 @@
         upgradeDataValuesWithAttributeOptionCombo();
         upgradeMapViewsToAnalyticalObject();
         
-        removeNullOptionSet();
-
         log.info( "Tables updated" );
     }
 
-    private OptionService optionService;
-
-    private void removeNullOptionSet()
-    {
-        Collection<OptionSet> optionSets = optionService.getAllOptionSets();
-        for ( OptionSet optionSet : optionSets )
-        {
-            boolean flag = false;
-            Iterator<String> iterOption = optionSet.getOptions().iterator();
-            while ( iterOption.hasNext() )
-            {
-                if ( iterOption.next() == null )
-                {
-                    iterOption.remove();
-                    flag = true;
-                }
-            }
-            if ( flag )
-            {
-                optionService.updateOptionSet( optionSet );
-            }
-
-        }
-    }
+  
 
     private void upgradeDataValuesWithAttributeOptionCombo()
     {

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java	2014-03-20 15:05:57 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/startup/TableAlteror.java	2014-03-28 08:30:22 +0000
@@ -31,6 +31,7 @@
 import java.sql.ResultSet;
 import java.sql.Statement;
 import java.util.Collection;
+import java.util.Iterator;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -44,6 +45,8 @@
 import org.hisp.dhis.dataentryform.DataEntryForm;
 import org.hisp.dhis.dataentryform.DataEntryFormService;
 import org.hisp.dhis.jdbc.StatementBuilder;
+import org.hisp.dhis.option.OptionService;
+import org.hisp.dhis.option.OptionSet;
 import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStageService;
 import org.hisp.dhis.system.startup.AbstractStartupRoutine;
@@ -104,6 +107,9 @@
     @Autowired
     private StatementBuilder statementBuilder;
 
+    @Autowired
+    private OptionService optionService;
+
     // -------------------------------------------------------------------------
     // Action Implementation
     // -------------------------------------------------------------------------
@@ -287,16 +293,41 @@
             + "where trackedentityattribute.mandatory is not null" );
         executeSql( "ALTER TABLE trackedentityattribute DROP COLUMN mandatory" );
 
-        executeSql( "update datavalue set storedby='aggregated_from_tracker' where storedby='DHIS-System'");
-        
+        executeSql( "update datavalue set storedby='aggregated_from_tracker' where storedby='DHIS-System'" );
+
         executeSql( "ALTER TABLE trackedentityattribute DROP COLUMN groupBy" );
-        
+
+        removeNullOptionSet();
+
     }
 
     // -------------------------------------------------------------------------
     // Supporting methods
     // -------------------------------------------------------------------------
 
+    private void removeNullOptionSet()
+    {
+        Collection<OptionSet> optionSets = optionService.getAllOptionSets();
+        for ( OptionSet optionSet : optionSets )
+        {
+            boolean flag = false;
+            Iterator<String> iterOption = optionSet.getOptions().iterator();
+            while ( iterOption.hasNext() )
+            {
+                if ( iterOption.next() == null )
+                {
+                    iterOption.remove();
+                    flag = true;
+                }
+            }
+            if ( flag )
+            {
+                optionService.updateOptionSet( optionSet );
+            }
+
+        }
+    }
+
     private void updateProgramAttributes()
     {
         String autoIncrVal = statementBuilder.getAutoIncrementValue();