dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20411
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9304: Null checks
------------------------------------------------------------
revno: 9304
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-12-13 14:56:39 +0100
message:
Null checks
modified:
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/JdbcAnalyticsManager.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-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-12 15:29:04 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2012-12-13 13:56:39 +0000
@@ -41,7 +41,6 @@
public class DefaultAnalyticsService
implements AnalyticsService
{
- //TODO select from correct partition
//TODO period aggregation for multiple period types
//TODO hierarchy aggregation for org units at multiple levels
//TODO indicator aggregation
@@ -55,6 +54,8 @@
List<DataQueryParams> queries = QueryPlanner.planQuery( params, 6 );
+ t.getTime( "Planned query" );
+
List<Future<List<AggregatedDataValue>>> futures = new ArrayList<Future<List<AggregatedDataValue>>>();
List<AggregatedDataValue> values = new ArrayList<AggregatedDataValue>();
@@ -66,7 +67,12 @@
for ( Future<List<AggregatedDataValue>> future : futures )
{
- values.addAll( future.get() );
+ List<AggregatedDataValue> taskValues = future.get();
+
+ if ( taskValues != null )
+ {
+ values.addAll( taskValues );
+ }
}
t.getTime( "Got aggregated values" );
=== 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 2012-12-11 20:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java 2012-12-13 13:56:39 +0000
@@ -27,9 +27,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
import static org.hisp.dhis.system.util.TextUtils.getQuotedCommaDelimitedString;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.Future;
import org.apache.commons.logging.Log;
@@ -37,7 +39,10 @@
import org.hisp.dhis.aggregation.AggregatedDataValue;
import org.hisp.dhis.analytics.AnalyticsManager;
import org.hisp.dhis.analytics.DataQueryParams;
+import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.expression.ExpressionService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.period.PeriodType;
@@ -70,6 +75,9 @@
@Autowired
private ExpressionService expressionService;
+
+ @Autowired
+ private IdentifiableObjectManager idObjectManager;
// -------------------------------------------------------------------------
// Implementation
@@ -78,19 +86,25 @@
@Async
public Future<List<AggregatedDataValue>> getAggregatedDataValueTotals( DataQueryParams params )
{
- int level = organisationUnitService.getLevelOfOrganisationUnit( params.getOrganisationUnits().iterator().next() );
+ int level = organisationUnitService.getLevelOfOrganisationUnit( params.getOrganisationUnits().iterator().next() );
+
String periodType = PeriodType.getPeriodTypeFromIsoString( params.getPeriods().iterator().next() ).getName().toLowerCase();
+ Set<Integer> de = idObjectManager.convertToId( DataElement.class, params.getDataElements() );
+ Set<Integer> ou = idObjectManager.convertToId( OrganisationUnit.class, params.getOrganisationUnits() );
+
final String sql =
"SELECT dataelementid, 0 as categoryoptioncomboid, periodid, idlevel" + level + " as organisationunitid, SUM(value) as value " +
"FROM " + params.getTableName() + " " +
- "WHERE dataelementid IN ( " + getQuotedCommaDelimitedString( params.getDataElements() ) + " ) " +
+ "WHERE dataelementid IN ( " + getCommaDelimitedString( de ) + " ) " +
"AND " + periodType + " IN ( " + getQuotedCommaDelimitedString( params.getPeriods() ) + " ) " +
- "AND idlevel" + level + " IN ( " + getQuotedCommaDelimitedString( params.getOrganisationUnits() ) + " ) " +
+ "AND idlevel" + level + " IN ( " + getCommaDelimitedString( ou ) + " ) " +
"GROUP BY dataelementid, periodid, idlevel" + level;
log.info( sql );
- return new AsyncResult<List<AggregatedDataValue>>( jdbcTemplate.query( sql, new AggregatedDataValueRowMapper() ) );
+ List<AggregatedDataValue> values = jdbcTemplate.query( sql, new AggregatedDataValueRowMapper() );
+
+ return new AsyncResult<List<AggregatedDataValue>>( values );
}
}