← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19921: Analytics tables. Making sure to ignore duplicate analytics tables. Might happen for non-iso cale...

 

------------------------------------------------------------
revno: 19921
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-09-01 11:22:27 +0200
message:
  Analytics tables. Making sure to ignore duplicate analytics tables. Might happen for non-iso calendars.
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTable.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java
  dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/AnalyticsTableTest.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-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTable.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTable.java	2015-02-24 13:57:25 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTable.java	2015-09-01 09:22:27 +0000
@@ -125,12 +125,6 @@
         return program != null;
     }
 
-    @Override
-    public String toString()
-    {
-        return getTableName();
-    }
-
     // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------
@@ -174,4 +168,84 @@
     {
         this.program = program;
     }
+
+    // -------------------------------------------------------------------------
+    // hashCode, equals, toString
+    // -------------------------------------------------------------------------
+
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ( ( baseName == null ) ? 0 : baseName.hashCode() );
+        result = prime * result + ( ( period == null ) ? 0 : period.hashCode() );
+        result = prime * result + ( ( program == null ) ? 0 : program.hashCode() );
+        return result;
+    }
+
+    @Override
+    public boolean equals( Object object )
+    {
+        if ( this == object )
+        {
+            return true;
+        }
+        
+        if ( object == null )
+        {
+            return false;
+        }
+        
+        if ( getClass() != object.getClass() )
+        {
+            return false;
+        }
+        
+        AnalyticsTable other = (AnalyticsTable) object;
+        
+        if ( baseName == null )
+        {
+            if ( other.baseName != null )
+            {
+                return false;
+            }
+        }
+        else if ( !baseName.equals( other.baseName ) )
+        {
+            return false;
+        }
+        
+        if ( period == null )
+        {
+            if ( other.period != null )
+            {
+                return false;
+            }
+        }
+        else if ( !period.equals( other.period ) )
+        {
+            return false;
+        }
+        
+        if ( program == null )
+        {
+            if ( other.program != null )
+            {
+                return false;
+            }
+        }
+        else if ( !program.equals( other.program ) )
+        {
+            return false;
+        }
+        
+        return true;
+    }
+
+    @Override
+    public String toString()
+    {
+        return getTableName();
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2015-08-27 15:28:24 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractJdbcTableManager.java	2015-09-01 09:22:27 +0000
@@ -46,6 +46,7 @@
 import org.hisp.dhis.common.CodeGenerator;
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.commons.collection.ListUtils;
+import org.hisp.dhis.commons.collection.UniqueArrayList;
 import org.hisp.dhis.commons.timer.SystemTimer;
 import org.hisp.dhis.commons.timer.Timer;
 import org.hisp.dhis.dataapproval.DataApprovalLevelService;
@@ -147,7 +148,8 @@
     
     private List<AnalyticsTable> getTables( List<Integer> dataYears )
     {
-        List<AnalyticsTable> tables = new ArrayList<>();
+        List<AnalyticsTable> tables = new UniqueArrayList<>();
+        
         Calendar calendar = PeriodType.getCalendar();
 
         Collections.sort( dataYears );

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java	2015-08-31 04:38:16 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcEventAnalyticsTableManager.java	2015-09-01 09:22:27 +0000
@@ -43,6 +43,7 @@
 import org.hisp.dhis.calendar.Calendar;
 import org.hisp.dhis.common.ValueType;
 import org.hisp.dhis.commons.collection.ListUtils;
+import org.hisp.dhis.commons.collection.UniqueArrayList;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
@@ -84,7 +85,7 @@
     
     private List<AnalyticsTable> getTables( List<Integer> dataYears )
     {
-        List<AnalyticsTable> tables = new ArrayList<>();
+        List<AnalyticsTable> tables = new UniqueArrayList<>();
         Calendar calendar = PeriodType.getCalendar();
 
         Collections.sort( dataYears );

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/AnalyticsTableTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/AnalyticsTableTest.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/AnalyticsTableTest.java	2015-09-01 09:22:27 +0000
@@ -30,7 +30,10 @@
 
 import static org.junit.Assert.assertEquals;
 
+import java.util.List;
+
 import org.hisp.dhis.analytics.AnalyticsTable;
+import org.hisp.dhis.commons.collection.UniqueArrayList;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.YearlyPeriodType;
 import org.hisp.dhis.program.Program;
@@ -43,7 +46,7 @@
 public class AnalyticsTableTest
 {
     @Test
-    public void test()
+    public void testGetTableName()
     {
         Program program = new Program( "ProgramA", "DescriptionA" );
         program.setUid( "UIDA" );
@@ -54,4 +57,22 @@
         
         assertEquals( "analytics_event_2014_uida", tableA.getTableName() );
     }
+    
+    @Test
+    public void testEquals()
+    {
+        Period periodA = new YearlyPeriodType().createPeriod( new DateTime( 2014, 1, 1, 0, 0 ).toDate() );
+        Period periodB = new YearlyPeriodType().createPeriod( new DateTime( 2015, 1, 1, 0, 0 ).toDate() );
+        
+        AnalyticsTable tableA = new AnalyticsTable( "analytics", null, periodA );
+        AnalyticsTable tableB = new AnalyticsTable( "analytics", null, periodA );
+        AnalyticsTable tableC = new AnalyticsTable( "analytics", null, periodB );
+        
+        List<AnalyticsTable> uniqueList = new UniqueArrayList<>();
+        uniqueList.add( tableA );
+        uniqueList.add( tableB );
+        uniqueList.add( tableC );
+        
+        assertEquals( 2, uniqueList.size() );
+    }
 }