dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33440
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17063: Fixed bug - Exception thrown when to run Schedule automated aggregation function.
------------------------------------------------------------
revno: 17063
committer: Tran Chau<tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-10-12 10:59:00 +0700
message:
Fixed bug - Exception thrown when to run Schedule automated aggregation function.
modified:
dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.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-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java 2014-10-11 14:27:16 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/caseaggregation/hibernate/HibernateCaseAggregationConditionStore.java 2014-10-12 03:59:00 +0000
@@ -49,6 +49,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
@@ -326,35 +327,12 @@
{
try
{
- int periodId = 0;
-
- final String selectSql = "select periodid from period where periodtypeid = ( select periodtypeid from periodtype where name='"
- + period.getPeriodType().getName()
- + "' )"
- + " and startdate='"
- + DateUtils.getMediumDateString( period.getStartDate() )
- + "' and enddate='"
- + DateUtils.getMediumDateString( period.getEndDate() ) + "'";
-
- periodId = jdbcTemplate.queryForObject( selectSql, Integer.class );
-
- if ( periodId == 0 )
- {
- final String insertSql = "insert into period (periodid, periodtypeid,startdate,enddate) " + " VALUES " + "("
- + statementBuilder.getAutoIncrementValue() + ","+ period.getPeriodType().getId() + ",'" + DateUtils.getMediumDateString( period.getStartDate() )
- + "','" + DateUtils.getMediumDateString( period.getEndDate() ) + "' )";
-
- jdbcTemplate.update( insertSql );
- }
- else
- {
- final String deleteDataValueSql = "delete from datavalue where dataelementid=" + dataElementId
- + " and categoryoptioncomboid=" + optionComboId + " and sourceid in ("
- + TextUtils.getCommaDelimitedString( orgunitIds ) + ") "
- + "and periodid = " + periodId;
- jdbcTemplate.update( deleteDataValueSql );
- }
-
+ period = periodService.reloadPeriod( period );
+ final String deleteDataValueSql = "delete from datavalue where dataelementid=" + dataElementId
+ + " and categoryoptioncomboid=" + optionComboId + " and sourceid in ("
+ + TextUtils.getCommaDelimitedString( orgunitIds ) + ") " + "and periodid = " + period.getId();
+ jdbcTemplate.update( deleteDataValueSql );
+
jdbcTemplate.update( sql );
}
@@ -1356,41 +1334,9 @@
Date endDate = calEndDate.getTime();
CalendarPeriodType periodType = (CalendarPeriodType) PeriodType.getPeriodTypeByName( periodTypeName );
- String sql = "select periodtypeid from periodtype where name='" + periodTypeName + "'";
- int periodTypeId = jdbcTemplate.queryForObject( sql, Integer.class );
-
- Collection<Period> periods = periodType.generatePeriods( startDate, endDate );
-
- for ( Period period : periods )
- {
- String start = DateUtils.getMediumDateString( period.getStartDate() );
- String end = DateUtils.getMediumDateString( period.getEndDate() );
-
- sql = "select periodid from period where periodtypeid=" + periodTypeId + " and startdate='" + start
- + "' and enddate='" + end + "'";
- Integer periodid = null;
- SqlRowSet rs = jdbcTemplate.queryForRowSet( sql );
- if ( rs.next() )
- {
- periodid = rs.getInt( "periodid" );
- }
-
- if ( periodid == null )
- {
- String insertSql = "insert into period (periodid, periodtypeid,startdate,enddate) " + " VALUES " + "("
- + statementBuilder.getAutoIncrementValue() + "," + periodTypeId + ",'" + start + "','" + end
- + "' )";
-
- jdbcTemplate.execute( insertSql );
-
- period.setId( jdbcTemplate.queryForObject( sql, Integer.class ) );
- }
- else
- {
- period.setId( periodid );
- }
- }
-
+ List<Period> periods = new ArrayList<Period>( periodType.generatePeriods( startDate, endDate ) );
+ periods = periodService.reloadPeriods(periods );
+
return periods;
}