← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9773: removed name uniqueness for reportTable

 

------------------------------------------------------------
revno: 9773
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-02-08 14:18:39 +0700
message:
  removed name uniqueness for reportTable
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/ReportTableImporter.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/reporttable/hibernate/ReportTable.hbm.xml
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ValidateTableAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js


--
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/reporttable/ReportTable.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2012-11-14 09:14:44 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2013-02-08 07:18:39 +0000
@@ -929,18 +929,6 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public int hashCode()
-    {
-        final int PRIME = 31;
-
-        int result = 1;
-
-        result = PRIME * result + ((name == null) ? 0 : name.hashCode());
-
-        return result;
-    }
-
-    @Override
     public boolean equals( Object object )
     {
         if ( this == object )

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java	2012-11-13 18:52:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java	2013-02-08 07:18:39 +0000
@@ -32,6 +32,7 @@
 
 import java.util.Collection;
 import java.util.Date;
+import java.util.List;
 
 /**
  * @author Lars Helge Overland
@@ -87,7 +88,7 @@
      *
      * @return a Collection of ReportTables.
      */
-    Collection<ReportTable> getAllReportTables();
+    List<ReportTable> getAllReportTables();
 
     /**
      * Retrieves ReportTables with the given identifiers.
@@ -103,40 +104,40 @@
      * @param name the name of the ReportTable.
      * @return the ReportTable.
      */
-    ReportTable getReportTableByName( String name );
+    List<ReportTable> getReportTableByName( String name );
 
     /**
      * Instantiates and populates a Grid populated with data from the ReportTable
      * with the given identifier.
      *
-     * @param uid the ReportTable unique identifier.
-     * @param format the I18nFormat.
-     * @param reportingPeriod the reporting date.
+     * @param uid                 the ReportTable unique identifier.
+     * @param format              the I18nFormat.
+     * @param reportingPeriod     the reporting date.
      * @param organisationUnitUid the organisation unit uid.
      * @return a Grid.
      */
     Grid getReportTableGrid( String uid, I18nFormat format, Date reportingPeriod, String organisationUnitUid );
 
     Grid getReportTableGrid( int reportTableId, I18nFormat format, Date reportingPeriod, String organisationUnitUid );
-    
+
     /**
-     * Instantiates and populates a Grid populated with data from the given 
+     * Instantiates and populates a Grid populated with data from the given
      * ReportTable.
-     * 
-     * @param reportTable the ReportTable.
-     * @param format the I18nFormat.
-     * @param reportingPeriod the reporting date.
+     *
+     * @param reportTable         the ReportTable.
+     * @param format              the I18nFormat.
+     * @param reportingPeriod     the reporting date.
      * @param organisationUnitUid the organisation unit uid.
-     * @param minimal indicates whether to include visible columns only in the Grid.
+     * @param minimal             indicates whether to include visible columns only in the Grid.
      * @return a Grid.
      */
     Grid getReportTableGrid( ReportTable reportTable, I18nFormat format, Date reportingPeriod, String organisationUnitUid, boolean minimal );
-    
+
     ReportTable getReportTable( String uid, String mode );
-    
-    Collection<ReportTable> getReportTablesBetween( int first, int max );
-
-    Collection<ReportTable> getReportTablesBetweenByName( String name, int first, int max );
+
+    List<ReportTable> getReportTablesBetween( int first, int max );
+
+    List<ReportTable> getReportTablesBetweenByName( String name, int first, int max );
 
     int getReportTableCount();
 

=== 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	2013-02-08 05:10:24 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2013-02-08 07:18:39 +0000
@@ -510,16 +510,14 @@
         executeSql( "ALTER TABLE organisationunit DROP CONSTRAINT organisationunit_name_key" );
         executeSql( "ALTER TABLE orgunitgroup ADD CONSTRAINT orgunitgroup_name_key UNIQUE (name)" );
         executeSql( "ALTER TABLE orgunitgroupset ADD CONSTRAINT orgunitgroupset_name_key UNIQUE (name)" );
-
         executeSql( "ALTER TABLE indicator DROP CONSTRAINT indicator_name_key" );
         executeSql( "ALTER TABLE indicator DROP CONSTRAINT indicator_shortname_key" );
         executeSql( "ALTER TABLE indicatorgroup DROP CONSTRAINT indicatorgroup_name_key" );
         executeSql( "ALTER TABLE indicatorgroupset DROP CONSTRAINT indicatorgroupset_name_key" );
-
         executeSql( "ALTER TABLE dataset DROP CONSTRAINT dataset_name_key" );
         executeSql( "ALTER TABLE dataset DROP CONSTRAINT dataset_shortname_key" );
-
         executeSql( "ALTER TABLE document DROP CONSTRAINT document_name_key" );
+        executeSql( "ALTER TABLE reporttable DROP CONSTRAINT reporttable_name_key" );
 
         log.info( "Tables updated" );
     }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/ReportTableImporter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/ReportTableImporter.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/ReportTableImporter.java	2013-02-08 07:18:39 +0000
@@ -39,6 +39,8 @@
 import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.reporttable.ReportTableService;
 
+import java.util.List;
+
 /**
  * @author Lars Helge Overland
  * @version $Id$
@@ -47,28 +49,28 @@
     extends AbstractImporter<ReportTable> implements Importer<ReportTable>
 {
     protected ReportTableService reportTableService;
-    
+
     protected DataElementService dataElementService;
-    
+
     protected DataElementCategoryService categoryService;
-    
+
     protected IndicatorService indicatorService;
-    
+
     protected DataSetService dataSetService;
-    
+
     protected PeriodService periodService;
-    
+
     protected OrganisationUnitService organisationUnitService;
 
     public ReportTableImporter()
     {
     }
-    
+
     public ReportTableImporter( ReportTableService reportTableService )
     {
         this.reportTableService = reportTableService;
     }
-    
+
     @Override
     public void importObject( ReportTable object, ImportParams params )
     {
@@ -86,7 +88,7 @@
     {
         match.setName( object.getName() );
         match.setRegression( object.isRegression() );
-        
+
         match.setDoIndicators( match.isDoIndicators() );
         match.setDoPeriods( match.isDoPeriods() );
         match.setDoUnits( match.isDoUnits() );
@@ -98,18 +100,19 @@
         match.getRelatives().setMonthsLastYear( object.getRelatives().isMonthsLastYear() );
         match.getRelatives().setQuartersLastYear( object.getRelatives().isQuartersLastYear() );
         match.getRelatives().setLastYear( object.getRelatives().isLastYear() );
-        
+
         match.getReportParams().setParamReportingMonth( object.getReportParams().isParamReportingMonth() );
         match.getReportParams().setParamParentOrganisationUnit( object.getReportParams().isParamParentOrganisationUnit() );
         match.getReportParams().setParamOrganisationUnit( object.getReportParams().isParamOrganisationUnit() );
-        
+
         reportTableService.saveReportTable( match );
     }
 
     @Override
     protected ReportTable getMatching( ReportTable object )
     {
-        return reportTableService.getReportTableByName( object.getName() );
+        List<ReportTable> reportTableByName = reportTableService.getReportTableByName( object.getName() );
+        return reportTableByName.isEmpty() ? null : reportTableByName.get( 0 );
     }
 
     @Override
@@ -123,7 +126,7 @@
         {
             return false;
         }
-        
+
         if ( object.isDoIndicators() != existing.isDoIndicators() )
         {
             return false;
@@ -136,7 +139,7 @@
         {
             return false;
         }
-                
+
         return true;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2013-01-14 21:35:56 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java	2013-02-08 07:18:39 +0000
@@ -27,24 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.reporttable.ReportTable.ORGANISATION_UNIT_IS_PARENT_COLUMN_NAME;
-import static org.hisp.dhis.reporttable.ReportTable.PARAM_ORGANISATIONUNIT_COLUMN_NAME;
-import static org.hisp.dhis.reporttable.ReportTable.PRETTY_COLUMNS;
-import static org.hisp.dhis.reporttable.ReportTable.REPORTING_MONTH_COLUMN_NAME;
-import static org.hisp.dhis.reporttable.ReportTable.SPACE;
-import static org.hisp.dhis.reporttable.ReportTable.TOTAL_COLUMN_NAME;
-import static org.hisp.dhis.reporttable.ReportTable.TOTAL_COLUMN_PRETTY_NAME;
-import static org.hisp.dhis.reporttable.ReportTable.columnEncode;
-import static org.hisp.dhis.reporttable.ReportTable.getColumnName;
-import static org.hisp.dhis.reporttable.ReportTable.getIdentifier;
-import static org.hisp.dhis.reporttable.ReportTable.getPrettyColumnName;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -67,6 +49,14 @@
 import org.hisp.dhis.system.util.FilterUtils;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import static org.hisp.dhis.reporttable.ReportTable.*;
+
 /**
  * @author Lars Helge Overland
  * @version $Id$
@@ -128,7 +118,7 @@
     public Grid getReportTableGrid( String uid, I18nFormat format, Date reportingPeriod, String organisationUnitUid )
     {
         ReportTable reportTable = getReportTable( uid );
-        
+
         return getReportTableGrid( reportTable, format, reportingPeriod, organisationUnitUid, false );
     }
 
@@ -136,10 +126,10 @@
     public Grid getReportTableGrid( int reportTableId, I18nFormat format, Date reportingPeriod, String organisationUnitUid )
     {
         ReportTable reportTable = getReportTable( reportTableId );
-        
+
         return getReportTableGrid( reportTable, format, reportingPeriod, organisationUnitUid, false );
     }
-    
+
     @Override
     public Grid getReportTableGrid( ReportTable reportTable, I18nFormat format, Date reportingPeriod, String organisationUnitUid, boolean minimal )
     {
@@ -159,10 +149,10 @@
         {
             return reportService.getReport( uid ).getReportTable();
         }
-        
+
         return null;
     }
-    
+
     // -------------------------------------------------------------------------
     // Persistence
     // -------------------------------------------------------------------------
@@ -205,17 +195,17 @@
         } );
     }
 
-    public Collection<ReportTable> getAllReportTables()
+    public List<ReportTable> getAllReportTables()
     {
         return reportTableStore.getAll();
     }
 
-    public ReportTable getReportTableByName( String name )
+    public List<ReportTable> getReportTableByName( String name )
     {
-        return reportTableStore.getByName( name );
+        return reportTableStore.getAllEqName( name );
     }
 
-    public Collection<ReportTable> getReportTablesBetweenByName( String name, int first, int max )
+    public List<ReportTable> getReportTablesBetweenByName( String name, int first, int max )
     {
         return reportTableStore.getAllLikeNameOrderedName( name, first, max );
     }
@@ -230,7 +220,7 @@
         return reportTableStore.getCountLikeName( name );
     }
 
-    public Collection<ReportTable> getReportTablesBetween( int first, int max )
+    public List<ReportTable> getReportTablesBetween( int first, int max )
     {
         return reportTableStore.getAllOrderedName( first, max );
     }
@@ -250,14 +240,14 @@
      * @return a report table.
      */
     private ReportTable initDynamicMetaObjects( ReportTable reportTable, Date reportingPeriod,
-                                                String organisationUnitUid, I18nFormat format )
+        String organisationUnitUid, I18nFormat format )
     {
         // ---------------------------------------------------------------------
         // Reporting period report parameter / current reporting period
         // ---------------------------------------------------------------------
 
         log.info( "Running report table: " + reportTable.getName() );
-        
+
         if ( reportTable.getReportParams() != null && reportTable.getReportParams().isParamReportingMonth() )
         {
             reportTable.setRelativePeriods( periodService.reloadPeriods( reportTable.getRelatives().getRelativePeriods(
@@ -297,7 +287,7 @@
         // Parent organisation unit report parameter
         // ---------------------------------------------------------------------
 
-        if ( reportTable.getReportParams() != null && 
+        if ( reportTable.getReportParams() != null &&
             reportTable.getReportParams().isParamParentOrganisationUnit() )
         {
             OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitUid );
@@ -313,7 +303,7 @@
         // Organisation unit report parameter
         // ---------------------------------------------------------------------
 
-        if ( reportTable.getReportParams() != null && 
+        if ( reportTable.getReportParams() != null &&
             reportTable.getReportParams().isParamOrganisationUnit() )
         {
             OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitUid );
@@ -358,7 +348,7 @@
             {
                 grid.addHeader( new GridHeader( PRETTY_COLUMNS.get( column ), column, Integer.class.getName(), true, true ) );
             }
-    
+
             for ( String column : reportTable.getIndexUidColumns() ) // Index uid columns
             {
                 grid.addHeader( new GridHeader( PRETTY_COLUMNS.get( column ), column, String.class.getName(), true, true ) );
@@ -376,12 +366,12 @@
             {
                 grid.addHeader( new GridHeader( PRETTY_COLUMNS.get( column ), column, String.class.getName(), true, true ) );
             }
-    
+
             for ( String column : reportTable.getIndexDescriptionColumns() ) // Index description columns
             {
                 grid.addHeader( new GridHeader( PRETTY_COLUMNS.get( column ), column, String.class.getName(), true, true ) );
             }
-    
+
             grid.addHeader( new GridHeader( PRETTY_COLUMNS.get( REPORTING_MONTH_COLUMN_NAME ), REPORTING_MONTH_COLUMN_NAME,
                 String.class.getName(), true, true ) );
             grid.addHeader( new GridHeader( PRETTY_COLUMNS.get( PARAM_ORGANISATIONUNIT_COLUMN_NAME ),
@@ -392,7 +382,7 @@
 
         final int startColumnIndex = grid.getHeaders().size();
         final int numberOfColumns = reportTable.getColumns().size();
-        
+
         for ( List<NameableObject> column : reportTable.getColumns() )
         {
             grid.addHeader( new GridHeader( getPrettyColumnName( column ), getColumnName( column ), Double.class
@@ -428,7 +418,7 @@
                 {
                     grid.addValue( object.getId() );
                 }
-    
+
                 for ( NameableObject object : row ) // Index uid columns
                 {
                     grid.addValue( object.getUid() );
@@ -446,17 +436,17 @@
                 {
                     grid.addValue( object.getCode() );
                 }
-    
+
                 for ( NameableObject object : row ) // Index description columns
                 {
                     grid.addValue( object.getDescription() );
                 }
-    
+
                 grid.addValue( reportTable.getReportingPeriodName() );
                 grid.addValue( reportTable.getParentOrganisationUnitName() );
                 grid.addValue( isCurrentParent( row ) ? YES : NO );
             }
-            
+
             for ( List<NameableObject> column : reportTable.getColumns() ) // Values
             {
                 grid.addValue( map.get( getIdentifier( row, column ) ) );
@@ -485,7 +475,7 @@
         {
             addRegressionToGrid( grid, startColumnIndex, numberOfColumns );
         }
-        
+
         if ( reportTable.isCumulative() )
         {
             addCumulativesToGrid( grid, startColumnIndex, numberOfColumns );
@@ -511,9 +501,9 @@
     /**
      * Adds columns with regression values to the given grid.
      *
-     * @param grid the grid.
+     * @param grid             the grid.
      * @param startColumnIndex the index of the first data column.
-     * @param numberOfColumns the number of data columns.
+     * @param numberOfColumns  the number of data columns.
      */
     private Grid addRegressionToGrid( Grid grid, int startColumnIndex, int numberOfColumns )
     {
@@ -526,23 +516,23 @@
 
         return grid;
     }
-    
+
     /**
      * Adds columns with cumulative values to the given grid.
-     * 
-     * @param grid the grid.
+     *
+     * @param grid             the grid.
      * @param startColumnIndex the index of the first data column.
-     * @param numberOfColumns the number of data columns.
+     * @param numberOfColumns  the number of data columns.
      */
     private Grid addCumulativesToGrid( Grid grid, int startColumnIndex, int numberOfColumns )
     {
         for ( int i = 0; i < numberOfColumns; i++ )
         {
             int columnIndex = i + startColumnIndex;
-            
+
             grid.addCumulativeColumn( columnIndex, true );
         }
-        
+
         return grid;
     }
 

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/reporttable/hibernate/ReportTable.hbm.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/reporttable/hibernate/ReportTable.hbm.xml	2013-02-07 10:25:34 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/reporttable/hibernate/ReportTable.hbm.xml	2013-02-08 07:18:39 +0000
@@ -15,7 +15,7 @@
     </id>
     &identifiableProperties;
 
-    <property name="name" column="name" not-null="true" unique="true" length="230" />
+    <property name="name" column="name" not-null="true" unique="false" length="230" />
 
     <property name="regression" />
 

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ValidateTableAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ValidateTableAction.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ValidateTableAction.java	2013-02-08 07:18:39 +0000
@@ -27,12 +27,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.opensymphony.xwork2.Action;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.reporttable.ReportTableService;
 
-import com.opensymphony.xwork2.Action;
-
 /**
  * @author Lars Helge Overland
  * @version $Id$
@@ -75,7 +74,7 @@
     {
         this.name = name;
     }
-    
+
     // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
@@ -110,14 +109,16 @@
                 return INPUT;
             }
 
-            ReportTable match = reportTableService.getReportTableByName( name );
+            /*
+            ReportTable match = reportTableService.getReportTableByName( name ).get( 0 );
 
-            if ( match != null && ( id == null || match.getId() != id ) )
+            if ( match != null && (id == null || match.getId() != id) )
             {
                 message = i18n.getString( "name_in_use" );
 
                 return INPUT;
             }
+            */
         }
 
         message = i18n.getString( "ok" );

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js	2012-11-07 13:38:42 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/table.js	2013-02-08 07:18:39 +0000
@@ -38,7 +38,7 @@
 
     selectAllById( "selectedPeriods" );
     selectAllById( "selectedOrganisationUnits" );
-    
+
     if ( isNotEmpty( "selectedOrganisationUnitGroups" ) )
     {
         selectAllById( "selectedOrganisationUnitGroups" );
@@ -108,7 +108,7 @@
 
 function organisationUnitReportParamsChecked()
 {
-    return ( isChecked( "paramGrandParentOrganisationUnit" ) 
+    return ( isChecked( "paramGrandParentOrganisationUnit" )
     	|| isChecked( "paramParentOrganisationUnit" ) || isChecked( "paramOrganisationUnit" ) );
 }
 
@@ -170,7 +170,7 @@
 
         disable( "doOrganisationUnits" );
         disable( "doPeriods" );
-    } 
+    }
     else
     {
         enable( "doOrganisationUnits" );