dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #39471
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19984: minor, update data element store/service to use valueType for queries
------------------------------------------------------------
revno: 19984
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-09-04 12:55:14 +0700
message:
minor, update data element store/service to use valueType for queries
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java
dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.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/dataelement/hibernate/HibernateDataElementStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2015-09-03 04:31:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2015-09-04 05:55:14 +0000
@@ -44,10 +44,7 @@
import org.hisp.dhis.dataelement.DataElementStore;
import org.hisp.dhis.dataset.DataSet;
import org.springframework.jdbc.BadSqlGrammarException;
-import org.springframework.jdbc.core.RowCallbackHandler;
-import java.sql.ResultSet;
-import java.sql.SQLException;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
@@ -79,12 +76,12 @@
@SuppressWarnings( "unchecked" )
public List<DataElement> getAggregateableDataElements()
{
- Set<String> types = new HashSet<>();
-
- types.add( DataElement.VALUE_TYPE_INT );
- types.add( DataElement.VALUE_TYPE_BOOL );
-
- return getCriteria( Restrictions.in( "type", types ) ).list();
+ Set<ValueType> valueTypes = new HashSet<>();
+
+ valueTypes.addAll( ValueType.NUMERIC_TYPES );
+ valueTypes.add( ValueType.BOOLEAN );
+
+ return getCriteria( Restrictions.in( "valueType", valueTypes ) ).list();
}
@Override
@@ -173,7 +170,7 @@
{
Criteria criteria = getCriteria();
criteria.add( Restrictions.eq( "zeroIsSignificant", zeroIsSignificant ) );
- criteria.add( Restrictions.eq( "type", DataElement.VALUE_TYPE_INT ) );
+ criteria.add( Restrictions.in( "valueType", ValueType.NUMERIC_TYPES ) );
return criteria.list();
}
@@ -235,17 +232,11 @@
try
{
- jdbcTemplate.query( sql, new RowCallbackHandler()
- {
- @Override
- public void processRow( ResultSet rs )
- throws SQLException
- {
- String de = rs.getString( 1 );
- String coc = rs.getString( 2 );
+ jdbcTemplate.query( sql, rs -> {
+ String de = rs.getString( 1 );
+ String coc = rs.getString( 2 );
- map.putValue( de, coc );
- }
+ map.putValue( de, coc );
} );
}
catch ( BadSqlGrammarException ex )
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java 2015-09-03 04:42:52 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementServiceTest.java 2015-09-04 05:55:14 +0000
@@ -262,6 +262,11 @@
dataElementC.setType( DataElement.VALUE_TYPE_STRING );
dataElementD.setType( DataElement.VALUE_TYPE_INT );
+ dataElementA.setValueType( ValueType.INTEGER );
+ dataElementB.setValueType( ValueType.BOOLEAN );
+ dataElementC.setValueType( ValueType.TEXT );
+ dataElementD.setValueType( ValueType.INTEGER );
+
dataElementService.addDataElement( dataElementA );
dataElementService.addDataElement( dataElementB );
dataElementService.addDataElement( dataElementC );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java 2015-09-03 04:31:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java 2015-09-04 05:55:14 +0000
@@ -28,22 +28,20 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.period.MonthlyPeriodType;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.*;
+
/**
* @author Torgeir Lorange Ostby
* @version $Id: DataElementStoreTest.java 5742 2008-09-26 11:37:35Z larshelg $
@@ -53,10 +51,10 @@
{
@Autowired
private DataElementStore dataElementStore;
-
+
@Autowired
private DataSetService dataSetService;
-
+
// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@@ -195,7 +193,7 @@
DataElement dataElementC = dataElementStore.getByShortName( "DataElementShortC" );
assertNull( dataElementC );
}
-
+
@Test
public void testGetAllDataElements()
{
@@ -232,12 +230,17 @@
DataElement dataElementB = createDataElement( 'B' );
DataElement dataElementC = createDataElement( 'C' );
DataElement dataElementD = createDataElement( 'D' );
-
+
dataElementA.setType( DataElement.VALUE_TYPE_INT );
dataElementB.setType( DataElement.VALUE_TYPE_BOOL );
dataElementC.setType( DataElement.VALUE_TYPE_STRING );
dataElementD.setType( DataElement.VALUE_TYPE_INT );
+ dataElementA.setValueType( ValueType.INTEGER );
+ dataElementB.setValueType( ValueType.BOOLEAN );
+ dataElementC.setValueType( ValueType.TEXT );
+ dataElementD.setValueType( ValueType.INTEGER );
+
dataElementStore.save( dataElementA );
dataElementStore.save( dataElementB );
dataElementStore.save( dataElementC );
@@ -257,10 +260,8 @@
@Test
public void testGetDataElementsByAggregationOperator()
{
- assertEquals( 0, dataElementStore.getDataElementsByAggregationOperator(
- DataElement.AGGREGATION_OPERATOR_AVERAGE_SUM ).size() );
- assertEquals( 0, dataElementStore.getDataElementsByAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM )
- .size() );
+ assertEquals( 0, dataElementStore.getDataElementsByAggregationOperator( DataElement.AGGREGATION_OPERATOR_AVERAGE_SUM ).size() );
+ assertEquals( 0, dataElementStore.getDataElementsByAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM ).size() );
DataElement dataElementA = createDataElement( 'A' );
dataElementA.setAggregationOperator( DataElement.AGGREGATION_OPERATOR_AVERAGE_SUM );
@@ -276,12 +277,10 @@
dataElementStore.save( dataElementC );
dataElementStore.save( dataElementD );
- assertEquals( 1, dataElementStore.getDataElementsByAggregationOperator(
- DataElement.AGGREGATION_OPERATOR_AVERAGE_SUM ).size() );
- assertEquals( 3, dataElementStore.getDataElementsByAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM )
- .size() );
+ assertEquals( 1, dataElementStore.getDataElementsByAggregationOperator( DataElement.AGGREGATION_OPERATOR_AVERAGE_SUM ).size() );
+ assertEquals( 3, dataElementStore.getDataElementsByAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM ).size() );
}
-
+
@Test
public void testGetDataElementsByDomainType()
{
@@ -289,7 +288,7 @@
assertEquals( 0, dataElementStore.getDataElementsByDomainType( DataElementDomain.TRACKER ).size() );
DataElement dataElementA = createDataElement( 'A' );
- dataElementA.setDomainType( DataElementDomain.AGGREGATE);
+ dataElementA.setDomainType( DataElementDomain.AGGREGATE );
DataElement dataElementB = createDataElement( 'B' );
dataElementB.setDomainType( DataElementDomain.TRACKER );
DataElement dataElementC = createDataElement( 'C' );
@@ -310,50 +309,50 @@
public void testGetDataElementAggregationLevels()
{
List<Integer> aggregationLevels = Arrays.asList( 3, 5 );
-
+
DataElement dataElementA = createDataElement( 'A' );
dataElementA.setAggregationLevels( aggregationLevels );
-
+
int idA = dataElementStore.save( dataElementA );
-
+
assertNotNull( dataElementStore.get( idA ).getAggregationLevels() );
assertEquals( 2, dataElementStore.get( idA ).getAggregationLevels().size() );
assertEquals( aggregationLevels, dataElementStore.get( idA ).getAggregationLevels() );
}
-
+
@Test
public void testGetDataElementsByAggregationLevel()
{
DataElement dataElementA = createDataElement( 'A' );
DataElement dataElementB = createDataElement( 'B' );
DataElement dataElementC = createDataElement( 'C' );
-
+
dataElementA.getAggregationLevels().addAll( Arrays.asList( 3, 5 ) );
dataElementB.getAggregationLevels().addAll( Arrays.asList( 4, 5 ) );
dataElementStore.save( dataElementA );
dataElementStore.save( dataElementB );
dataElementStore.save( dataElementC );
-
+
List<DataElement> dataElements = dataElementStore.getDataElementsByAggregationLevel( 2 );
-
+
assertEquals( 0, dataElements.size() );
-
+
dataElements = dataElementStore.getDataElementsByAggregationLevel( 3 );
-
+
assertEquals( 1, dataElements.size() );
dataElements = dataElementStore.getDataElementsByAggregationLevel( 4 );
-
+
assertEquals( 1, dataElements.size() );
-
+
dataElements = dataElementStore.getDataElementsByAggregationLevel( 5 );
-
+
assertEquals( 2, dataElements.size() );
assertTrue( dataElements.contains( dataElementA ) );
assertTrue( dataElements.contains( dataElementB ) );
}
-
+
@Test
public void testGetDataElementsZeroIsSignificant()
{
@@ -364,17 +363,17 @@
dataElementA.setZeroIsSignificant( true );
dataElementB.setZeroIsSignificant( true );
-
+
dataElementStore.save( dataElementA );
dataElementStore.save( dataElementB );
dataElementStore.save( dataElementC );
dataElementStore.save( dataElementD );
-
+
List<DataElement> dataElements = dataElementStore.getDataElementsByZeroIsSignificant( true );
-
+
assertTrue( equals( dataElements, dataElementA, dataElementB ) );
}
-
+
@Test
public void testGetDataElements()
{
@@ -384,32 +383,32 @@
DataElement dataElementD = createDataElement( 'D' );
DataElement dataElementE = createDataElement( 'E' );
DataElement dataElementF = createDataElement( 'F' );
-
+
dataElementStore.save( dataElementA );
dataElementStore.save( dataElementB );
dataElementStore.save( dataElementC );
dataElementStore.save( dataElementD );
dataElementStore.save( dataElementE );
dataElementStore.save( dataElementF );
-
+
DataSet dataSetA = createDataSet( 'A', new MonthlyPeriodType() );
DataSet dataSetB = createDataSet( 'B', new MonthlyPeriodType() );
-
+
dataSetA.getDataElements().add( dataElementA );
dataSetA.getDataElements().add( dataElementC );
dataSetA.getDataElements().add( dataElementF );
dataSetB.getDataElements().add( dataElementD );
dataSetB.getDataElements().add( dataElementF );
-
+
dataSetService.addDataSet( dataSetA );
dataSetService.addDataSet( dataSetB );
-
+
List<DataSet> dataSets = new ArrayList<>();
dataSets.add( dataSetA );
dataSets.add( dataSetB );
-
+
List<DataElement> dataElements = dataElementStore.getDataElementsByDataSets( dataSets );
-
+
assertNotNull( dataElements );
assertEquals( 4, dataElements.size() );
assertTrue( dataElements.contains( dataElementA ) );
=== modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java'
--- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java 2015-09-03 08:15:09 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java 2015-09-04 05:55:14 +0000
@@ -353,7 +353,7 @@
dataElement.setCode( "DataElementCode" + uniqueCharacter );
dataElement.setDescription( "DataElementDescription" + uniqueCharacter );
dataElement.setType( DataElement.VALUE_TYPE_INT );
- dataElement.setValueType( ValueType.NUMBER );
+ dataElement.setValueType( ValueType.INTEGER );
dataElement.setDomainType( DataElementDomain.AGGREGATE );
dataElement.setAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM );