dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #22140
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10624: Compulsory data elements, upgraded ui to use uids
------------------------------------------------------------
revno: 10624
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-04-18 15:39:33 +0200
message:
Compulsory data elements, upgraded ui to use uids
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/compulsory/GetCompulsoryDataElementsAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/compulsoryDataElementsForm.vm
--
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/dataelement/DataElementOperand.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java 2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java 2013-04-18 13:39:33 +0000
@@ -210,10 +210,36 @@
*
* @return the id.
*/
+ @Deprecated
public String getPersistedId()
{
return dataElement.getId() + SEPARATOR + categoryOptionCombo.getId();
}
+
+ /**
+ * Returns the operand expression which is on the format #{de-uid.coc-uid} .
+ *
+ * @return the operand expression.
+ */
+ public String getOperandExpression()
+ {
+ String expression = null;
+
+ if ( dataElementId != null )
+ {
+ String coc = optionComboId != null ? SEPARATOR + optionComboId : "";
+
+ expression = "#{" + dataElementId + coc + "}";
+ }
+ else if ( dataElement != null )
+ {
+ String coc = categoryOptionCombo != null ? SEPARATOR + categoryOptionCombo.getUid() : "";
+
+ expression = "#{" + dataElement.getUid() + coc + "}";
+ }
+
+ return expression;
+ }
/**
* Returns a database-friendly name.
@@ -304,7 +330,7 @@
/**
* Generates a DataElementOperand based on the given formula. The formula
- * needs to be on the form "[<dataelementid>.<categoryoptioncomboid>]".
+ * needs to be on the form "#{<dataelementid>.<categoryoptioncomboid>}".
*
* @param expression the formula.
* @return a DataElementOperand.
@@ -520,6 +546,18 @@
}
DataElementOperand other = (DataElementOperand) object;
+
+ if ( dataElement == null )
+ {
+ if ( other.dataElement != null )
+ {
+ return false;
+ }
+ }
+ else if ( !dataElement.equals( other.dataElement ) )
+ {
+ return false;
+ }
if ( categoryOptionCombo == null )
{
@@ -533,18 +571,6 @@
return false;
}
- if ( dataElement == null )
- {
- if ( other.dataElement != null )
- {
- return false;
- }
- }
- else if ( !dataElement.equals( other.dataElement ) )
- {
- return false;
- }
-
if ( dataElementId == null )
{
if ( other.dataElementId != null )
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java 2013-03-25 11:13:05 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java 2013-04-18 13:39:33 +0000
@@ -63,6 +63,7 @@
import org.hisp.dhis.system.util.MathUtils;
import org.hisp.dhis.system.util.SqlHelper;
import org.hisp.dhis.system.util.TextUtils;
+import org.hisp.dhis.system.util.Timer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -112,7 +113,7 @@
sql += getGroupByClause( params );
- log.info( sql );
+ log.debug( sql );
Map<String, Double> map = null;
@@ -300,8 +301,12 @@
{
Map<String, Double> map = new HashMap<String, Double>();
+ Timer t = new Timer().start();
+
SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
+ t.getTime( "Analytics SQL: " + sql );
+
while ( rowSet.next() )
{
Double value = rowSet.getDouble( VALUE_ID );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java 2013-04-18 10:37:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java 2013-04-18 13:39:33 +0000
@@ -27,20 +27,17 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import org.amplecode.quick.StatementHolder;
-import org.amplecode.quick.StatementManager;
+import java.sql.SQLException;
+import java.util.UUID;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.system.startup.AbstractStartupRoutine;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Timestamp;
-import java.util.Date;
-import java.util.UUID;
+import org.hisp.dhis.system.util.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.BadSqlGrammarException;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.support.rowset.SqlRowSet;
/**
* @author bobj
@@ -62,111 +59,125 @@
// Dependencies
// -------------------------------------------------------------------------
- private StatementManager statementManager;
-
- public void setStatementManager( StatementManager statementManager )
- {
- this.statementManager = statementManager;
- }
+ @Autowired
+ private JdbcTemplate jdbcTemplate;
// -------------------------------------------------------------------------
// Execute
// -------------------------------------------------------------------------
- @Transactional
- @Override
public void execute()
throws SQLException
{
- StatementHolder holder = statementManager.getHolder();
-
- Statement dummyStatement = holder.getStatement();
-
- Statement statement = null;
-
- try
- {
- Connection conn = dummyStatement.getConnection();
-
- statement = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE );
-
- for ( String table : tables )
- {
- try
- {
- int count = 0;
-
- ResultSet resultSet = statement.executeQuery( "SELECT * from " + table + " WHERE uid IS NULL" );
-
- while ( resultSet.next() )
- {
- ++count;
- resultSet.updateString( "uid", CodeGenerator.generateCode() );
- resultSet.updateRow();
- }
-
- if ( count > 0 )
- {
- log.info( count + " uids updated on " + table );
- }
-
- count = 0;
-
- Timestamp now = new Timestamp( new Date().getTime() );
-
- resultSet = statement.executeQuery( "SELECT * from " + table + " WHERE lastUpdated IS NULL" );
-
- while ( resultSet.next() )
- {
- ++count;
- resultSet.updateTimestamp( "lastUpdated", now );
- resultSet.updateRow();
- }
-
- resultSet = statement.executeQuery( "SELECT * from " + table + " WHERE created IS NULL" );
-
- while ( resultSet.next() )
- {
- ++count;
- resultSet.updateTimestamp( "created", resultSet.getTimestamp( "lastUpdated" ) );
- resultSet.updateRow();
- }
-
- if ( count > 0 )
- {
- log.info( count + " timestamps updated on " + table );
- }
- }
- catch ( SQLException ex )
- {
- log.info( "Problem updating " + table + ": ", ex );
- }
- }
- }
- finally
- {
- if ( statement != null )
- {
- statement.close();
- }
- }
-
+ for ( String table : tables )
+ {
+ try
+ {
+ log.debug( "Checking table: " + table );
+
+ int count = 0;
+
+ SqlRowSet resultSet = jdbcTemplate.queryForRowSet( "SELECT * from " + table + " WHERE uid IS NULL" );
+
+ while ( resultSet.next() )
+ {
+ ++count;
+ String idColumn = table + "id";
+ int id = resultSet.getInt( idColumn );
+ String sql = "update " + table + " set uid = '" + CodeGenerator.generateCode() + "' where " + idColumn + " = " + id;
+ jdbcTemplate.update( sql );
+ }
+
+ if ( count > 0 )
+ {
+ log.info( count + " uids set on " + table );
+ }
+
+ count = 0;
+
+ resultSet = jdbcTemplate.queryForRowSet( "SELECT * from " + table + " WHERE lastUpdated IS NULL" );
+
+ String timestamp = DateUtils.getLongDateString();
+
+ while ( resultSet.next() )
+ {
+ ++count;
+ String idColumn = table + "id";
+ int id = resultSet.getInt( idColumn );
+ String sql = "update " + table + " set lastupdated = '" + timestamp + "' where " + idColumn + " = " + id;
+ jdbcTemplate.update( sql );
+ }
+
+ if ( count > 0 )
+ {
+ log.info( count + " last updated set on " + table );
+ }
+
+ count = 0;
+
+ resultSet = jdbcTemplate.queryForRowSet( "SELECT * from " + table + " WHERE created IS NULL" );
+
+ while ( resultSet.next() )
+ {
+ ++count;
+ String idColumn = table + "id";
+ int id = resultSet.getInt( idColumn );
+ String sql = "update " + table + " set created = '" + timestamp + "' where " + idColumn + " = " + id;
+ jdbcTemplate.update( sql );
+ }
+
+ if ( count > 0 )
+ {
+ log.info( count + " timestamps set on " + table );
+ }
+ }
+ catch ( BadSqlGrammarException ex )
+ {
+ log.error( "Problem updating " + table + ": ", ex );
+ }
+ }
+
+ log.debug( "Identifiable properties updated" );
+
createUidConstraints();
+ log.debug( "Identifiable constraints updated" );
+
+ createOrgUnitUuids();
+
+ log.debug( "Organisation unit uuids updated" );
+ }
+
+ private void createUidConstraints()
+ {
+ for ( String table : tables )
+ {
+ try
+ {
+ final String sql = "ALTER TABLE " + table + " ADD CONSTRAINT " + table + "_uid_key UNIQUE(uid)";
+ jdbcTemplate.execute( sql );
+ }
+ catch ( BadSqlGrammarException ex )
+ {
+ log.debug( "Could not create uid constraint on table " + table +
+ ", might already be created or column contains duplicates", ex );
+ }
+ }
+ }
+
+ private void createOrgUnitUuids()
+ {
try
{
- Connection conn = dummyStatement.getConnection();
-
- statement = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE );
-
- ResultSet resultSet = statement.executeQuery( "SELECT * from organisationunit WHERE uuid IS NULL" );
+ SqlRowSet resultSet = jdbcTemplate.queryForRowSet( "SELECT * from organisationunit WHERE uuid IS NULL" );
int count = 0;
while ( resultSet.next() )
{
++count;
- resultSet.updateString( "uuid", UUID.randomUUID().toString() );
- resultSet.updateRow();
+ int id = resultSet.getInt( "organisationunitid" );
+ String sql = "update organisationunit set uuid = '" + UUID.randomUUID().toString() + "' where organisationunitid = " + id;
+ jdbcTemplate.update( sql );
}
if ( count > 0 )
@@ -174,39 +185,9 @@
log.info( count + " UUIDs updated on organisationunit" );
}
}
- catch ( SQLException ex )
- {
- log.info( "Problem updating organisationunit: ", ex );
- }
- finally
- {
- if ( statement != null )
- {
- statement.close();
- }
- }
- }
-
- private void createUidConstraints()
- {
- for ( String table : tables )
- {
- StatementHolder holder = statementManager.getHolder();
-
- try
- {
- final String sql = "ALTER TABLE " + table + " ADD CONSTRAINT " + table + "_uid_key UNIQUE(uid)";
- holder.executeUpdate( sql, true );
- }
- catch ( Exception ex )
- {
- log.debug( "Could not create uid constraint on table " + table +
- ", might already be created or column contains duplicates", ex );
- }
- finally
- {
- holder.close();
- }
+ catch ( BadSqlGrammarException ex )
+ {
+ log.debug( "Problem updating organisationunit: ", ex );
}
}
}
=== 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 2013-04-02 15:45:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2013-04-18 13:39:33 +0000
@@ -734,7 +734,6 @@
</bean>
<bean id="org.hisp.dhis.common.IdentityPopulator" class="org.hisp.dhis.common.IdentityPopulator">
- <property name="statementManager" ref="statementManager" />
<property name="name" value="IdentityPopulator" />
<property name="runlevel" value="2" />
<property name="skipInTests" value="true" />
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/compulsory/GetCompulsoryDataElementsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/compulsory/GetCompulsoryDataElementsAction.java 2012-07-20 07:04:42 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/compulsory/GetCompulsoryDataElementsAction.java 2013-04-18 13:39:33 +0000
@@ -29,7 +29,6 @@
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import org.hisp.dhis.dataelement.DataElementCategoryService;
@@ -108,21 +107,9 @@
selectedOperands = new ArrayList<DataElementOperand>( dataSet.getCompulsoryDataElementOperands() );
- availableOperands = new ArrayList<DataElementOperand>( dataElementCategoryService.getOperands( dataSet
- .getDataElements() ) );
-
- for ( DataElementOperand selectedOperand : selectedOperands )
- {
- Iterator<DataElementOperand> availableIter = availableOperands.iterator();
-
- while ( availableIter.hasNext() )
- {
- if ( selectedOperand.getPersistedId().equals( availableIter.next().getOperandId() ) )
- {
- availableIter.remove();
- }
- }
- }
+ availableOperands = new ArrayList<DataElementOperand>( dataElementCategoryService.getOperands( dataSet.getDataElements() ) );
+
+ availableOperands.removeAll( selectedOperands );
Collections.sort( availableOperands, new DataElementOperandNameComparator() );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/compulsoryDataElementsForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/compulsoryDataElementsForm.vm 2011-03-18 14:20:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/compulsoryDataElementsForm.vm 2013-04-18 13:39:33 +0000
@@ -20,7 +20,7 @@
<td>
<select id="availableOperands" name="availableOperands" size="15" style="width:325px" multiple="multiple" ondblclick="moveSelectedById( 'availableOperands', 'selectedOperands' )">
#foreach( $operand in $availableOperands )
- <option value="${operand.operandId}">$encoder.htmlEncode( $!operand.operandName )</option>
+ <option value="${operand.operandExpression}">$encoder.htmlEncode( $!operand.operandName )</option>
#end
</select>
</td>
@@ -32,7 +32,7 @@
<td>
<select id="selectedOperands" name="selectedOperands" size="15" style="width:325px" multiple="multiple" ondblclick="moveSelectedById( 'selectedOperands', 'availableOperands' )">
#foreach( $operand in $selectedOperands )
- <option value="${operand.persistedId}">$encoder.htmlEncode( $!operand.getPrettyName() )</option>
+ <option value="${operand.operandExpression}">$encoder.htmlEncode( $!operand.getPrettyName() )</option>
#end
</select>
</td>