dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20716
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9611: Impl table manager class for data set completeness target / sources. Will be used as denominator ...
------------------------------------------------------------
revno: 9611
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-01-25 12:33:17 +0200
message:
Impl table manager class for data set completeness target / sources. Will be used as denominator when calculating completeness.
added:
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTargetTableManager.java
modified:
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-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/PartitionUtils.java
dhis-2/dhis-services/dhis-service-analytics/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ResourceTableController.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/AnalyticsTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTableManager.java 2013-01-17 17:49:13 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsTableManager.java 2013-01-25 10:33:17 +0000
@@ -32,6 +32,8 @@
import java.util.List;
import java.util.concurrent.Future;
+import org.hisp.dhis.period.Period;
+
public interface AnalyticsTableManager
{
public static final String TABLE_TEMP_SUFFIX = "_temp";
@@ -77,10 +79,9 @@
* The data range is based on the start date of the data value row.
*
* @param tableName the name of the analytics table.
- * @param startDate the start date for the data value row start date
- * @param endDate the end date for the data value row end date
+ * @param period the data period for which to populate the table.
*/
- Future<?> populateTableAsync( String tableName, Date startDate, Date endDate );
+ Future<?> populateTableAsync( String tableName, Period period );
/**
* Returns a list of string arrays in where the first index holds the database
=== 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 2013-01-22 07:59:25 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2013-01-25 10:33:17 +0000
@@ -208,7 +208,7 @@
}
// ---------------------------------------------------------------------
- // Data sets
+ // Data sets / completeness
// ---------------------------------------------------------------------
if ( params.getDataSets() != null && !params.getDataSets().isEmpty() )
=== 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-01-17 17:49:13 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java 2013-01-25 10:33:17 +0000
@@ -140,7 +140,7 @@
{
Period period = PartitionUtils.getPeriod( table );
- futures.add( tableManager.populateTableAsync( table, period.getStartDate(), period.getEndDate() ) );
+ futures.add( tableManager.populateTableAsync( table, period ) );
}
ConcurrentUtils.waitForCompletion( futures );
=== 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-01-17 17:49:13 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java 2013-01-25 10:33:17 +0000
@@ -40,6 +40,7 @@
import org.hisp.dhis.dataelement.DataElementGroupSet;
import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
+import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.system.util.DateUtils;
import org.springframework.scheduling.annotation.Async;
@@ -93,8 +94,11 @@
}
@Async
- public Future<?> populateTableAsync( String tableName, Date startDate, Date endDate )
+ public Future<?> populateTableAsync( String tableName, Period period )
{
+ Date startDate = period.getStartDate();
+ Date endDate = period.getEndDate();
+
populateTable( tableName, startDate, endDate, "cast(dv.value as double precision)", "int" );
populateTable( tableName, startDate, endDate, "1" , "bool" );
@@ -123,7 +127,7 @@
select += col[2] + ",";
}
- select = select.replace( "organisationunitid", "sourceid" ); // Legacy fix
+ select = select.replace( "organisationunitid", "sourceid" ); // Legacy fix TODO remove
select +=
valueExpression + " * ps.daysno as value, " +
=== 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-01-17 17:49:13 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTableManager.java 2013-01-25 10:33:17 +0000
@@ -35,6 +35,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
+import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.system.util.DateUtils;
import org.springframework.scheduling.annotation.Async;
@@ -68,10 +69,10 @@
}
@Async
- public Future<?> populateTableAsync( String tableName, Date startDate, Date endDate )
+ public Future<?> populateTableAsync( String tableName, Period period )
{
- final String start = DateUtils.getMediumDateString( startDate );
- final String end = DateUtils.getMediumDateString( endDate );
+ final String start = DateUtils.getMediumDateString( period.getStartDate() );
+ final String end = DateUtils.getMediumDateString( period.getEndDate() );
String insert = "insert into " + tableName + " (";
@@ -89,7 +90,7 @@
select += col[2] + ",";
}
- select = select.replace( "organisationunitid", "sourceid" ); // Legacy fix
+ select = select.replace( "organisationunitid", "sourceid" ); // Legacy fix TODO remove
select +=
"cdr.date as date " +
@@ -142,9 +143,9 @@
columns.add( col );
}
- String[] de = { "ds", "character(11) not null", "ds.uid" };
+ String[] ds = { "ds", "character(11) not null", "ds.uid" };
- columns.add( de );
+ columns.add( ds );
return columns;
}
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcCompletenessTargetTableManager.java 2013-01-25 10:33:17 +0000
@@ -0,0 +1,147 @@
+package org.hisp.dhis.analytics.table;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.Future;
+
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
+import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
+import org.hisp.dhis.period.Period;
+import org.springframework.scheduling.annotation.Async;
+
+public class JdbcCompletenessTargetTableManager
+ extends AbstractJdbcTableManager
+{
+ public String getTableName()
+ {
+ return "completenesstarget";
+ }
+
+ public void createTable( String tableName )
+ {
+ final String sqlDrop = "drop table " + tableName;
+
+ executeSilently( sqlDrop );
+
+ String sqlCreate = "create table " + tableName + " (";
+
+ for ( String[] col : getDimensionColumns() )
+ {
+ sqlCreate += col[0] + " " + col[1] + ",";
+ }
+
+ sqlCreate = sqlCreate.substring( 0, sqlCreate.length() - 1 ) + ")";
+
+ log.info( "Create SQL: " + sqlCreate );
+
+ executeSilently( sqlCreate );
+ }
+
+ @Async
+ public Future<?> populateTableAsync( String tableName, Period period )
+ {
+ String sql = "insert into " + tableName + " (";
+
+ for ( String[] col : getDimensionColumns() )
+ {
+ sql += col[0] + ",";
+ }
+
+ sql = sql.substring( 0, sql.length() - 1 );
+
+ sql += ") select ";
+
+ for ( String[] col : getDimensionColumns() )
+ {
+ sql += col[2] + ",";
+ }
+
+ sql = sql.substring( 0, sql.length() - 1 ) + " ";
+
+ sql +=
+ "from datasetsource dss " +
+ "left join dataset ds on dss.datasetid=ds.datasetid " +
+ "left join _orgunitstructure ous on dss.sourceid=ous.organisationunitid " +
+ "left join _organisationunitgroupsetstructure ougs on dss.sourceid=ougs.organisationunitid";
+
+ log.info( "Populate SQL: "+ sql );
+
+ jdbcTemplate.execute( sql );
+
+ return null;
+ }
+
+ public List<String[]> getDimensionColumns()
+ {
+ List<String[]> columns = new ArrayList<String[]>();
+
+ Collection<OrganisationUnitGroupSet> orgUnitGroupSets =
+ organisationUnitGroupService.getCompulsoryOrganisationUnitGroupSets();
+
+ Collection<OrganisationUnitLevel> levels =
+ organisationUnitService.getOrganisationUnitLevels();
+
+ for ( OrganisationUnitGroupSet groupSet : orgUnitGroupSets )
+ {
+ String[] col = { groupSet.getUid(), "character(11)", "ougs." + groupSet.getUid() };
+ columns.add( col );
+ }
+
+ for ( OrganisationUnitLevel level : levels )
+ {
+ String column = PREFIX_ORGUNITLEVEL + level.getLevel();
+ String[] col = { column, "character(11)", "ous." + column };
+ columns.add( col );
+ }
+
+ String[] ds = { "ds", "character(11) not null", "ds.uid" };
+
+ columns.add( ds );
+
+ return columns;
+ }
+
+ public Date getEarliestData()
+ {
+ return null; // Not relevant
+ }
+
+ public Date getLatestData()
+ {
+ return null; // Not relevant
+ }
+
+ public void applyAggregationLevels( String tableName, Collection<String> dataElements, int aggregationLevel )
+ {
+ // Not relevant
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/PartitionUtils.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/PartitionUtils.java 2013-01-17 17:49:13 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/PartitionUtils.java 2013-01-25 10:33:17 +0000
@@ -28,6 +28,7 @@
*/
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
@@ -47,9 +48,14 @@
public static List<String> getTempTableNames( Date earliest, Date latest, String tableName )
{
- if ( earliest == null || latest == null || earliest.after( latest ) )
- {
- throw new IllegalArgumentException( "Earliest or latest date invalid: " + earliest + ", " + latest );
+ if ( earliest == null || latest == null )
+ {
+ return new ArrayList<String>( Arrays.asList( tableName + AnalyticsTableManager.TABLE_TEMP_SUFFIX ) );
+ }
+
+ if ( earliest.after( latest ) )
+ {
+ throw new IllegalArgumentException( "Earliest date is after latest: " + earliest + ", " + latest );
}
List<String> tables = new ArrayList<String>();
@@ -79,7 +85,7 @@
{
if ( tableName == null || tableName.indexOf( SEP ) == -1 )
{
- throw new IllegalArgumentException( "Illegal table name: " + tableName );
+ return null;
}
String[] split = tableName.split( SEP );
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/resources/META-INF/dhis/beans.xml 2013-01-17 17:49:13 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/resources/META-INF/dhis/beans.xml 2013-01-25 10:33:17 +0000
@@ -6,6 +6,8 @@
<bean id="org.hisp.dhis.analytics.CompletenessTableManager" class="org.hisp.dhis.analytics.table.JdbcCompletenessTableManager" />
+ <bean id="org.hisp.dhis.analytics.CompletenessTargetTableManager" class="org.hisp.dhis.analytics.table.JdbcCompletenessTargetTableManager" />
+
<bean id="org.hisp.dhis.analytics.AnalyticsTableService" class="org.hisp.dhis.analytics.table.DefaultAnalyticsTableService">
<property name="tableManager" ref="org.hisp.dhis.analytics.AnalyticsTableManager" />
</bean>
@@ -14,6 +16,10 @@
<property name="tableManager" ref="org.hisp.dhis.analytics.CompletenessTableManager" />
</bean>
+ <bean id="org.hisp.dhis.analytics.CompletenessTargetTableService" class="org.hisp.dhis.analytics.table.DefaultAnalyticsTableService">
+ <property name="tableManager" ref="org.hisp.dhis.analytics.CompletenessTargetTableManager" />
+ </bean>
+
<bean id="org.hisp.dhis.analytics.AnalyticsManager" class="org.hisp.dhis.analytics.data.JdbcAnalyticsManager" />
<bean id="org.hisp.dhis.analytics.AnalyticsService" class="org.hisp.dhis.analytics.data.DefaultAnalyticsService" />
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java 2013-01-22 07:59:25 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AnalyticsController.java 2013-01-25 10:33:17 +0000
@@ -62,8 +62,6 @@
@Autowired
private I18nManager i18nManager;
- //TODO URL only requests
-
// -------------------------------------------------------------------------
// Resources
// -------------------------------------------------------------------------
@@ -164,13 +162,13 @@
if ( !params.dimensionsAsFilters().isEmpty() )
{
- ContextUtils.conflictResponse( response, "Dimensions cannot also be specified as filters: " + params.dimensionsAsFilters() );
+ ContextUtils.conflictResponse( response, "Dimensions cannot be specified as dimension and filter simultaneously: " + params.dimensionsAsFilters() );
return false;
}
if ( !params.hasPeriods() )
{
- ContextUtils.conflictResponse( response, "Periods must be specified as dimension or filter" );
+ ContextUtils.conflictResponse( response, "At least one period must be specified as dimension or filter" );
return false;
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ResourceTableController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ResourceTableController.java 2013-01-17 17:49:13 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ResourceTableController.java 2013-01-25 10:33:17 +0000
@@ -55,6 +55,9 @@
@Resource(name="org.hisp.dhis.analytics.CompletenessTableService")
private AnalyticsTableService completenessTableService;
+ @Resource(name="org.hisp.dhis.analytics.CompletenessTargetTableService")
+ private AnalyticsTableService completenessTargetTableService;
+
@Autowired
private ResourceTableService resourceTableService;
@@ -78,6 +81,15 @@
ContextUtils.okResponse( response, "Initiated completeness table update" );
}
+
+ @RequestMapping( value = "/completenessTarget", method = RequestMethod.PUT )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_DATA_MART_ADMIN')" )
+ public void completenessTarget( HttpServletResponse response )
+ {
+ completenessTargetTableService.update();
+
+ ContextUtils.okResponse( response, "Initiated completeness target table update" );
+ }
@RequestMapping( method = RequestMethod.PUT )
@PreAuthorize( "hasRole('ALL') or hasRole('F_PERFORM_MAINTENANCE')" )