dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21585
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10246: Analytics tables, aborting gracefull if in invalid state, eg if there are no data values in the d...
------------------------------------------------------------
revno: 10246
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-03-15 12:10:10 +0100
message:
Analytics tables, aborting gracefull if in invalid state, eg if there are no data values in the database
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/TaskId.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/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-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTargetTableManager.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/InMemoryNotifier.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/common/IdentifiableObjectManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2013-03-14 04:50:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2013-03-15 11:10:10 +0000
@@ -27,15 +27,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
-import org.hisp.dhis.common.NameableObject.NameableProperty;
-
import java.util.Collection;
import java.util.Date;
-import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
+import org.hisp.dhis.common.NameableObject.NameableProperty;
+
/**
* @author Lars Helge Overland
*/
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java 2013-03-14 10:58:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/SharingUtils.java 2013-03-15 11:10:10 +0000
@@ -27,9 +27,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import org.hisp.dhis.chart.Chart;
import org.hisp.dhis.datadictionary.DataDictionary;
-import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.document.Document;
import org.hisp.dhis.indicator.Indicator;
@@ -42,11 +46,6 @@
import org.hisp.dhis.user.UserGroup;
import org.hisp.dhis.user.UserGroupAccess;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/TaskId.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/TaskId.java 2012-04-03 22:08:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/scheduling/TaskId.java 2013-03-15 11:10:10 +0000
@@ -36,7 +36,9 @@
{
private static final String SEPARATOR = "-";
- private String id;
+ private TaskCategory category;
+
+ private User user;
public TaskId()
{
@@ -44,18 +46,26 @@
public TaskId( TaskCategory category, User user )
{
- this.id = category.toString() + SEPARATOR + user.getUserCredentials().getUsername();
+ this.category = category;
+ this.user = user;
}
public String getId()
{
+ String id = category.toString();
+
+ if ( user != null && user.getUserCredentials() != null )
+ {
+ id += SEPARATOR + user.getUserCredentials().getUsername();
+ }
+
return id;
}
@Override
public int hashCode()
{
- return id.hashCode();
+ return getId().hashCode();
}
@Override
@@ -78,12 +88,12 @@
TaskId other = (TaskId) obj;
- return id.equals( other.id );
+ return getId().equals( other.getId() );
}
@Override
public String toString()
{
- return "[" + id + "]";
+ return "[" + getId() + "]";
}
}
=== 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 2013-02-21 18:18:15 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTableManager.java 2013-03-15 11:10:10 +0000
@@ -41,6 +41,11 @@
public static final String COMPLETENESS_TARGET_TABLE_NAME = "completenesstarget";
/**
+ * Checks if the database content is in valid state for analytics table generation.
+ */
+ boolean validState();
+
+ /**
* Returns the base table name.
*/
String getTableName();
=== 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 2013-03-05 22:03:40 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java 2013-03-15 11:10:10 +0000
@@ -83,12 +83,21 @@
{
Clock clock = new Clock().startClock().logTime( "Starting update" );
+ boolean valid = tableManager.validState();
+
+ if ( !valid )
+ {
+ notifier.notify( taskId, DATAMART, "Table not valid, aborted update" );
+ return;
+ }
+
final Date threeYrsAgo = new Cal().subtract( Calendar.YEAR, 2 ).set( 1, 1 ).time();
final Date earliest = last3YearsOnly ? threeYrsAgo : tableManager.getEarliestData();
final Date latest = tableManager.getLatestData();
final String tableName = tableManager.getTableName();
final List<String> tables = PartitionUtils.getTempTableNames( earliest, latest, tableName );
- clock.logTime( "Got partition tables: " + tables + ", earliest: " + earliest + ", latest: " + latest );
+
+ clock.logTime( "Partition tables: " + tables + ", earliest: " + earliest + ", latest: " + latest + ", last 3 years: " + last3YearsOnly );
notifier.notify( taskId, DATAMART, "Creating analytics tables" );
=== 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 2013-03-07 09:42:11 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java 2013-03-15 11:10:10 +0000
@@ -71,6 +71,11 @@
//TODO use statement builder for double column type
+ public boolean validState()
+ {
+ return jdbcTemplate.queryForRowSet( "select dataelementid from datavalue limit 1" ).next();
+ }
+
public String getTableName()
{
return "analytics";
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java 2013-03-07 09:42:11 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java 2013-03-15 11:10:10 +0000
@@ -44,6 +44,11 @@
public class JdbcCompletenessTableManager
extends AbstractJdbcTableManager
{
+ public boolean validState()
+ {
+ return jdbcTemplate.queryForRowSet( "select datasetid from completedatasetregistration limit 1" ).next();
+ }
+
public String getTableName()
{
return "completeness";
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTargetTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTargetTableManager.java 2013-03-07 09:42:11 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTargetTableManager.java 2013-03-15 11:10:10 +0000
@@ -41,6 +41,11 @@
public class JdbcCompletenessTargetTableManager
extends AbstractJdbcTableManager
{
+ public boolean validState()
+ {
+ return true;
+ }
+
public String getTableName()
{
return "completenesstarget";
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/InMemoryNotifier.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/InMemoryNotifier.java 2013-03-05 19:00:51 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/notification/InMemoryNotifier.java 2013-03-15 11:10:10 +0000
@@ -49,7 +49,7 @@
{
private static final Log log = LogFactory.getLog( InMemoryNotifier.class );
- private int MAX_SIZE = 100;
+ private int MAX_SIZE = 75;
private TaskLocalList<Notification> notifications;