dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20515
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9389: Impl method getDataElementsByAggregationLevel(int)
------------------------------------------------------------
revno: 9389
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-12-22 13:26:34 +0100
message:
Impl method getDataElementsByAggregationLevel(int)
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTableManager.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java
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/DataElementStoreTest.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-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2012-10-18 13:04:28 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2012-12-22 12:26:34 +0000
@@ -260,8 +260,22 @@
*/
Collection<DataElement> getDataElementsWithDataSets();
+ /**
+ * Returns all DataElements which are assigned to any of the given DataSets.
+ *
+ * @param dataSets the collection of DataSets.
+ * @return all DataElements which are assigned to any of the given DataSets.
+ */
Collection<DataElement> getDataElementsByDataSets( Collection<DataSet> dataSets );
+ /**
+ * Returns all DataElements which have the given aggregation level assigned.
+ *
+ * @param aggregationLevel the aggregation level.
+ * @return all DataElements which have the given aggregation level assigned.
+ */
+ Collection<DataElement> getDataElementsByAggregationLevel( int aggregationLevel );
+
Collection<DataElement> getDataElementsLikeName( String name );
Collection<DataElement> getDataElementsBetween( int first, int max );
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java 2012-07-20 07:04:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java 2012-12-22 12:26:34 +0000
@@ -152,7 +152,21 @@
*/
Collection<DataElement> getDataElementsWithDataSets();
+ /**
+ * Returns all DataElements which are assigned to any of the given DataSets.
+ *
+ * @param dataSets the collection of DataSets.
+ * @return all DataElements which are assigned to any of the given DataSets.
+ */
Collection<DataElement> getDataElementsByDataSets( Collection<DataSet> dataSets );
+
+ /**
+ * Returns all DataElements which have the given aggregation level assigned.
+ *
+ * @param aggregationLevel the aggregation level.
+ * @return all DataElements which have the given aggregation level assigned.
+ */
+ Collection<DataElement> getDataElementsByAggregationLevel( int aggregationLevel );
Map<Integer, Set<Integer>> getDataElementCategoryOptionCombos();
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTableManager.java 2012-12-11 01:38:43 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTableManager.java 2012-12-22 12:26:34 +0000
@@ -94,11 +94,12 @@
Date getLatestData();
/**
- * Checks whether the given table has no rows, if so drops the table.
+ * Checks whether the given table has no rows, if so drops the table. Returns
+ * true if the table was empty and pruned, if not false.
*
* @param tableName the name of the table to prune.
*/
- void pruneTable( String tableName );
+ boolean pruneTable( String tableName );
/**
* Drops the given table.
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2012-12-21 16:50:36 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2012-12-22 12:26:34 +0000
@@ -50,6 +50,8 @@
{
private static final String VALUE_HEADER_NAME = "Value";
+ //TODO aggregation levels
+ // add org unit level as column in tables
//TODO indicator aggregation
//TODO category sub-totals and totals
//TODO use data mart when query can be satisfied
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java 2012-12-17 16:58:29 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java 2012-12-22 12:26:34 +0000
@@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.Date;
+import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Future;
@@ -57,8 +58,8 @@
// -------------------------------------------------------------------------
//TODO generateOrganisationUnitStructures
- //TODO generateOrganisationUnitGroupSetTable
- //TODO generatePeriodStructure
+ // generateOrganisationUnitGroupSetTable
+ // generatePeriodStructure
@Async
public Future<?> update()
@@ -116,9 +117,6 @@
for ( List<String> tablePage : tablePages )
{
- System.out.println();
- System.out.println(tablePage);
-
List<Future<?>> futures = new ArrayList<Future<?>>();
for ( String table : tablePage )
@@ -134,9 +132,14 @@
public void pruneTables( List<String> tables )
{
- for ( String table : tables )
+ Iterator<String> iterator = tables.iterator();
+
+ while ( iterator.hasNext() )
{
- tableManager.pruneTable( table );
+ if ( tableManager.pruneTable( iterator.next() ) )
+ {
+ iterator.remove();
+ }
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java 2012-12-17 16:58:29 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java 2012-12-22 12:26:34 +0000
@@ -285,7 +285,7 @@
return jdbcTemplate.queryForObject( sql, Date.class );
}
- public void pruneTable( String tableName )
+ public boolean pruneTable( String tableName )
{
final String sqlCount = "select count(*) from " + tableName;
@@ -300,7 +300,11 @@
executeSilently( sqlDrop );
log.info( "Drop SQL: " + sqlDrop );
+
+ return true;
}
+
+ return false;
}
public void dropTable( String tableName )
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2012-10-18 13:04:28 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2012-12-22 12:26:34 +0000
@@ -324,6 +324,11 @@
return i18n( i18nService, dataElementStore.getDataElementsByDataSets( dataSets ) );
}
+ public Collection<DataElement> getDataElementsByAggregationLevel( int aggregationLevel )
+ {
+ return i18n( i18nService, dataElementStore.getDataElementsByAggregationLevel( aggregationLevel ) );
+ }
+
public Map<Integer, Set<Integer>> getDataElementCategoryOptionCombos()
{
return dataElementStore.getDataElementCategoryOptionCombos();
=== 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 2012-07-20 07:04:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2012-12-22 12:26:34 +0000
@@ -216,6 +216,14 @@
ConversionUtils.getIdentifiers( DataSet.class, dataSets ) ).list();
}
+ @SuppressWarnings( "unchecked" )
+ public Collection<DataElement> getDataElementsByAggregationLevel( int aggregationLevel )
+ {
+ String hql = "from DataElement de join de.aggregationLevels al where al = :aggregationLevel";
+
+ return getQuery( hql ).setInteger( "aggregationLevel", aggregationLevel ).list();
+ }
+
public Map<Integer, Set<Integer>> getDataElementCategoryOptionCombos()
{
final String sql = "select de.dataelementid, coc.categoryoptioncomboid from dataelement de " +
@@ -246,6 +254,7 @@
public Collection<DataElement> get( DataSet dataSet, String key, Integer max )
{
String hql = "select dataElement from DataSet dataSet inner join dataSet.dataElements as dataElement where dataSet.id = :dataSetId ";
+
if( key != null )
{
hql += " and lower(dataElement.name) like lower('%" + key + "%') ";
=== 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 2012-11-20 17:04:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementStoreTest.java 2012-12-22 12:26:34 +0000
@@ -403,6 +403,39 @@
}
@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 );
+
+ Collection<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()
{
DataElement dataElementA = createDataElement( 'A' );