dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #00183
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 54: Giving feedback to user when too many dataelements are selected for data mart export.
------------------------------------------------------------
revno: 54
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Fri 2009-03-13 12:51:35 +0100
message:
Giving feedback to user when too many dataelements are selected for data mart export.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/jdbc/StatementManager.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/CrossTabService.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/DefaultCrossTabService.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/CrossTabStore.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/JDBCCrossTabStore.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java
dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/configuration/DefaultJDBCConfigurationProvider.java
dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statement/JDBCStatementManager.java
dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java
dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java
dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java
dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties
dhis-2/dhis-web/dhis-web-datamart/src/main/java/org/hisp/dhis/datamart/action/ValidateDataMartExportAction.java
dhis-2/dhis-web/dhis-web-datamart/src/main/resources/org/hisp/dhis/datamart/i18n_module.properties
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/jdbc/StatementBuilder.java 2009-03-13 11:51:35 +0000
@@ -230,4 +230,11 @@
* @return a delete datavalue statement.
*/
String getDeleteZeroDataValues();
+
+ /**
+ * Returns the maximum number of columns in a table.
+ *
+ * @return the maximum number of columns in a table.
+ */
+ int getMaximumNumberOfColumns();
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/jdbc/StatementManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/jdbc/StatementManager.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/jdbc/StatementManager.java 2009-03-13 11:51:35 +0000
@@ -73,4 +73,11 @@
* Closes the statement object and the internal database connection.
*/
void destroyInternal();
+
+ /**
+ * Gets the current StatementBuilder.
+ *
+ * @return the current StatementBuilder.
+ */
+ StatementBuilder getStatementBuilder();
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/CrossTabService.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/CrossTabService.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/CrossTabService.java 2009-03-13 11:51:35 +0000
@@ -48,4 +48,6 @@
void trimCrossTabTable( Collection<Operand> emptyOperands );
Map<Operand, Integer> getOperandIndexMap( Collection<Operand> operands );
+
+ int validateCrossTabTable( Collection<Operand> operands );
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/DefaultCrossTabService.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/DefaultCrossTabService.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/DefaultCrossTabService.java 2009-03-13 11:51:35 +0000
@@ -214,6 +214,11 @@
return operandMap;
}
+
+ public int validateCrossTabTable( Collection<Operand> operands )
+ {
+ return crossTabStore.validateCrossTabTable( operands );
+ }
// -------------------------------------------------------------------------
// Supportive methods
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/CrossTabStore.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/CrossTabStore.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/CrossTabStore.java 2009-03-13 11:51:35 +0000
@@ -27,6 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -49,4 +50,6 @@
Map<Integer, String> getCrossTabTableColumns();
void dropCrossTabColumn( String columnName );
+
+ int validateCrossTabTable( Collection<Operand> operands );
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/JDBCCrossTabStore.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/JDBCCrossTabStore.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/crosstab/jdbc/JDBCCrossTabStore.java 2009-03-13 11:51:35 +0000
@@ -29,10 +29,13 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.dataelement.Operand;
import org.hisp.dhis.jdbc.StatementHolder;
import org.hisp.dhis.jdbc.StatementManager;
@@ -44,6 +47,8 @@
public class JDBCCrossTabStore
implements CrossTabStore
{
+ private static final Log log = LogFactory.getLog( JDBCCrossTabStore.class );
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -63,6 +68,8 @@
{
final StatementHolder holder = statementManager.getHolder();
+ log.info( operands != null ? "Number of crosstab columns: " + ( 2 + operands.size() ) : "No operands selected" );
+
try
{
final StringBuffer sql = new StringBuffer( "CREATE TABLE datavaluecrosstab ( " );
@@ -162,4 +169,11 @@
holder.close();
}
}
+
+ public int validateCrossTabTable( final Collection<Operand> operands )
+ {
+ int maxColumns = statementManager.getStatementBuilder().getMaximumNumberOfColumns();
+
+ return ( operands != null && operands.size() > maxColumns ) ? operands.size() - maxColumns : 0;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/impl/DefaultDataMartService.java 2009-03-13 11:51:35 +0000
@@ -174,9 +174,9 @@
public int export( final Collection<Integer> dataElementIds, final Collection<Integer> indicatorIds,
final Collection<Integer> periodIds, final Collection<Integer> organisationUnitIds )
- {
+ {
int count = 0;
-
+
log.info( "Export process started" );
TimeUtils.start();
@@ -193,8 +193,6 @@
log.info( "Deleted existing aggregated data: " + TimeUtils.getHMS() );
- setMessage( "crosstabulating_data" );
-
// ---------------------------------------------------------------------
// Crosstabulate data
// ---------------------------------------------------------------------
@@ -213,7 +211,24 @@
final Collection<Operand> allDataElementOperands = categoryOptionComboService.getOperands( dataElementService.getDataElements( allDataElementIds ) );
final Collection<Operand> dataElementInIndicatorOperands = categoryOptionComboService.getOperands( dataElementService.getDataElements( dataElementInIndicatorIds ) );
final Collection<Operand> dataElementInCalculatedDataElementOperands = categoryOptionComboService.getOperands( dataElementService.getDataElements( dataElementInCalculatedDataElementIds ) );
-
+
+ // ---------------------------------------------------------------------
+ // Validate crosstabtable
+ // ---------------------------------------------------------------------
+
+ if ( crossTabService.validateCrossTabTable( allDataElementOperands ) != 0 )
+ {
+ int excess = crossTabService.validateCrossTabTable( allDataElementOperands );
+
+ log.warn( "Cannot crosstabulate since the number of data elements exceeded maximum columns: " + excess );
+
+ setMessage( "could_not_export_too_many_data_elements" );
+
+ return 0;
+ }
+
+ setMessage( "crosstabulating_data" );
+
final Collection<Operand> emptyOperands = crossTabService.populateCrossTabTable( allDataElementOperands, getIntersectingIds( periodIds ),
getIdsWithChildren( organisationUnitIds ) );
=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/configuration/DefaultJDBCConfigurationProvider.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/configuration/DefaultJDBCConfigurationProvider.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/configuration/DefaultJDBCConfigurationProvider.java 2009-03-13 11:51:35 +0000
@@ -28,10 +28,10 @@
*/
import org.hibernate.cfg.Configuration;
+import org.hisp.dhis.hibernate.HibernateConfigurationProvider;
import org.hisp.dhis.jdbc.JDBCConfiguration;
import org.hisp.dhis.jdbc.JDBCConfigurationProvider;
import org.hisp.dhis.jdbc.StatementDialect;
-import org.hisp.dhis.hibernate.HibernateConfigurationProvider;
/**
* @author Lars Helge Overland
=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statement/JDBCStatementManager.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statement/JDBCStatementManager.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statement/JDBCStatementManager.java 2009-03-13 11:51:35 +0000
@@ -32,8 +32,10 @@
import org.hisp.dhis.jdbc.JDBCConfiguration;
import org.hisp.dhis.jdbc.JDBCConfigurationProvider;
+import org.hisp.dhis.jdbc.StatementBuilder;
import org.hisp.dhis.jdbc.StatementHolder;
import org.hisp.dhis.jdbc.StatementManager;
+import org.hisp.dhis.jdbc.factory.StatementBuilderFactory;
/**
* @author Lars Helge Overland
@@ -125,6 +127,11 @@
internalHolderTag.remove();
}
}
+
+ public StatementBuilder getStatementBuilder()
+ {
+ return StatementBuilderFactory.createStatementBuilder( configurationProvider.getConfiguration().getDialect() );
+ }
// -------------------------------------------------------------------------
// Supportive methods
=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/H2StatementBuilder.java 2009-03-13 11:51:35 +0000
@@ -265,4 +265,9 @@
return sql;
}
+
+ public int getMaximumNumberOfColumns()
+ {
+ return 1580; // TODO verify
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/MySQLStatementBuilder.java 2009-03-13 11:51:35 +0000
@@ -262,4 +262,9 @@
return sql;
}
+
+ public int getMaximumNumberOfColumns()
+ {
+ return 720;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/statementbuilder/PostgreSQLStatementBuilder.java 2009-03-13 11:51:35 +0000
@@ -41,6 +41,8 @@
public class PostgreSQLStatementBuilder
extends AbstractStatementBuilder
{
+ public static final int MAX_COLUMS = 1580; // TODO verify
+
private static final String AUTO_INCREMENT = "nextval('hibernate_sequence')";
// -------------------------------------------------------------------------
@@ -273,4 +275,9 @@
return sql;
}
+
+ public int getMaximumNumberOfColumns()
+ {
+ return 1580; // TODO verify
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties 2009-03-13 07:11:28 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties 2009-03-13 11:51:35 +0000
@@ -52,7 +52,7 @@
dhis-web-reports = NRHM Reports
dhis-web-dashboard-integration = Dashboard
dhis-web-jforum-integration = Forum
-dhis-web-dataentry-national = Linelisting DataEntry
+dhis-web-dataentry-national = Linelisting Data Entry
dhis-web-validationrule-local-in = Validation Analysis
#-- Common --------------------------------------------------------------------#
=== modified file 'dhis-2/dhis-web/dhis-web-datamart/src/main/java/org/hisp/dhis/datamart/action/ValidateDataMartExportAction.java'
--- dhis-2/dhis-web/dhis-web-datamart/src/main/java/org/hisp/dhis/datamart/action/ValidateDataMartExportAction.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-datamart/src/main/java/org/hisp/dhis/datamart/action/ValidateDataMartExportAction.java 2009-03-13 11:51:35 +0000
@@ -75,7 +75,7 @@
{
this.name = name;
}
-
+
// -------------------------------------------------------------------------
// Output
// -------------------------------------------------------------------------
@@ -120,6 +120,8 @@
}
}
+
+
return SUCCESS;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-datamart/src/main/resources/org/hisp/dhis/datamart/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-datamart/src/main/resources/org/hisp/dhis/datamart/i18n_module.properties 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-datamart/src/main/resources/org/hisp/dhis/datamart/i18n_module.properties 2009-03-13 11:51:35 +0000
@@ -65,4 +65,5 @@
generate_data_mart= Generate data mart
add_to_dashboard = Add to dashboard
confirm_add_to_dashboard = Are you sure you want to add this data mart export to the dashboard?
-export_to_datamart = Export to data mart
\ No newline at end of file
+export_to_datamart = Export to data mart
+could_not_export_too_many_data_elements = Could not export because too many data elements were selected
\ No newline at end of file
--
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.