← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2035: Implemented automatic datamart for aggregated validation

 

------------------------------------------------------------
revno: 2035
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Wed 2010-09-01 12:30:03 +0200
message:
  Implemented automatic datamart for aggregated validation
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java
  dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/RunValidationAction.java
  dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/runValidation.js
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/runValidationForm.vm


--
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/validation/ValidationRuleService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java	2010-08-31 11:40:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java	2010-09-01 10:30:03 +0000
@@ -47,8 +47,25 @@
     // ValidationRule business logic
     // -------------------------------------------------------------------------
 
+    /**
+     * Validates AggregatedDataValues.
+     * 
+     * @param startDate the start date.
+     * @param endDate the end date.
+     * @param sources a collection of Sources.
+     * @return a collection of ValidationResults for each validation violation. 
+     */
     Collection<ValidationResult> validateAggregate( Date startDate, Date endDate, Collection<? extends Source> sources );
-    
+
+    /**
+     * Validate AggregatedDataValues.
+     * 
+     * @param startDate the start date.
+     * @param endDate the end date.
+     * @param sources a collection of Sources.
+     * @param group a group of ValidationRules.
+     * @return a collection of ValidationResults for each validation violation. 
+     */
     public Collection<ValidationResult> validateAggregate( Date startDate, Date endDate, Collection<? extends Source> sources, ValidationRuleGroup group );
     
     /**
@@ -57,8 +74,6 @@
      * @param startDate the start date.
      * @param endDate the end date.
      * @param sources a collection of Sources.
-     * @param aggregate indicates whether aggregated or raw data should be used
-     *        to evaluate the validation expression.
      * @return a collection of ValidationResults for each validation violation. 
      */
     Collection<ValidationResult> validate( Date startDate, Date endDate, Collection<? extends Source> sources );
@@ -70,8 +85,6 @@
      * @param endDate the end date.
      * @param sources a collection of Sources.
      * @param group a group of ValidationRules.
-     * @param aggregate indicates whether aggregated or raw data should be used
-     *        to evaluate the validation expression.
      * @return a collection of ValidationResults for each validation violation. 
      */
     Collection<ValidationResult> validate( Date startDate, Date endDate, Collection<? extends Source> sources, ValidationRuleGroup group );
@@ -132,9 +145,10 @@
     ValidationRule getValidationRule( int id );
 
     /**
+     * Get the ValidationRules with the corresponding identifiers.
      * 
-     * @param identifiers
-     * @return
+     * @param identifiers the collection of identifiers.
+     * @return a collection of validation rules.
      */
     Collection<ValidationRule> getValidationRules( Collection<Integer> identifiers );
     
@@ -152,8 +166,21 @@
      */
     ValidationRule getValidationRuleByName( String name );
     
+    /**
+     * Get the validation rules which are associated with the given data elements.
+     * 
+     * @param dataElements the collection of data elements.
+     * @return a collection of validation rules.
+     */
     Collection<ValidationRule> getValidationRulesByDataElements( Collection<DataElement> dataElements );
     
+    /**
+     * Get all data elements associated with any validation rule.
+     * 
+     * @return a collection of data elements.
+     */
+    Collection<DataElement> getDataElementsInValidationRules();
+    
     // -------------------------------------------------------------------------
     // ValidationRuleGroup
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java	2010-09-01 07:28:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java	2010-09-01 10:30:03 +0000
@@ -217,6 +217,19 @@
         return validateInternal( period, source, getRelevantValidationRules( dataSet.getDataElements() ), false );
     }
 
+    public Collection<DataElement> getDataElementsInValidationRules()
+    {
+        Set<DataElement> dataElements = new HashSet<DataElement>();
+        
+        for ( ValidationRule rule : getAllValidationRules() )
+        {
+            dataElements.addAll( rule.getLeftSide().getDataElementsInExpression() );
+            dataElements.addAll( rule.getRightSide().getDataElementsInExpression() );
+        }
+        
+        return dataElements;
+    }
+    
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/RunValidationAction.java'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/RunValidationAction.java	2010-09-01 06:14:47 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/RunValidationAction.java	2010-09-01 10:30:03 +0000
@@ -30,14 +30,19 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.datamart.DataMartService;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.oust.manager.SelectionTreeManager;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.util.SessionUtils;
 import org.hisp.dhis.validation.ValidationResult;
 import org.hisp.dhis.validation.ValidationRuleGroup;
@@ -46,6 +51,8 @@
 
 import com.opensymphony.xwork2.ActionSupport;
 
+import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
+
 /**
  * @author Margrethe Store
  * @author Lars Helge Overland
@@ -90,6 +97,20 @@
         this.organisationUnitService = organisationUnitService;
     }
 
+    private DataMartService dataMartService;
+
+    public void setDataMartService( DataMartService dataMartService )
+    {
+        this.dataMartService = dataMartService;
+    }
+
+    private PeriodService periodService;
+
+    public void setPeriodService( PeriodService periodService )
+    {
+        this.periodService = periodService;
+    }
+
     // -------------------------------------------------------------------------
     // Input/output
     // -------------------------------------------------------------------------
@@ -144,6 +165,13 @@
         this.aggregate = aggregate;
     }
 
+    private boolean doDataMart;
+
+    public void setDoDataMart( boolean doDataMart )
+    {
+        this.doDataMart = doDataMart;
+    }
+
     // -------------------------------------------------------------------------
     // Execute
     // -------------------------------------------------------------------------
@@ -155,6 +183,18 @@
         if ( aggregate ) // Aggregate data source
         {
             Collection<OrganisationUnit> organisationUnits = unit.getChildren();
+
+            if ( doDataMart )
+            {
+                log.info( "Generating datamart" );
+                
+                Collection<Period> periods = periodService.getPeriodsBetweenDates( format.parseDate( startDate ), format.parseDate( endDate ) );
+                
+                Collection<DataElement> dataElements = validationRuleService.getDataElementsInValidationRules();
+                
+                dataMartService.export( getIdentifiers( DataElement.class, dataElements ), new HashSet<Integer>(), 
+                    getIdentifiers( Period.class, periods ), getIdentifiers( OrganisationUnit.class, organisationUnits ) );
+            }
             
             if ( validationRuleGroupId == -1 )
             {

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/META-INF/dhis/beans.xml	2010-06-29 00:24:10 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/META-INF/dhis/beans.xml	2010-09-01 10:30:03 +0000
@@ -221,6 +221,12 @@
     <property name="organisationUnitService">
       <ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
     </property>
+	<property name="dataMartService">
+	  <ref bean="org.hisp.dhis.datamart.DataMartService"/>
+	</property>
+	<property name="periodService">
+	  <ref bean="org.hisp.dhis.period.PeriodService"/>
+	</property>
   </bean>
   
   <bean id="org.hisp.dhis.validationrule.action.GetValidationResultDetailsAction"

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties	2010-08-31 11:40:23 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties	2010-09-01 10:30:03 +0000
@@ -173,3 +173,6 @@
 use_aggregated_data = Use aggregated data
 aggregate_data_info = Immediate children of the selected organisation unit will be included.
 captured_data_info = All children of the selected organisation unit will be included.
+get_updated_data = Get updated aggregated data
+use_existing_data = Use existing aggregated data
+method = Method
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/runValidation.js'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/runValidation.js	2010-08-31 11:40:23 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/runValidation.js	2010-09-01 10:30:03 +0000
@@ -23,7 +23,8 @@
         var url = 'runValidationAction.action?startDate=' + getFieldValue( 'startDate' ) +
         	'&endDate=' + getFieldValue( 'endDate' ) + 
         	'&validationRuleGroupId=' + $( '#validationRuleGroupId' ).val() +
-        	'&aggregate=' + getListValue( 'aggregate' );
+        	'&aggregate=' + getListValue( 'aggregate' ) +
+        	'&doDataMart=' + getListValue( 'doDataMart' );
         	
 		$.get( url, function( data ) {
 			$( "div#analysisInput" ).hide();
@@ -57,12 +58,14 @@
 {
 	var aggregate = getListValue( 'aggregate' );
 	
-	if ( aggregate == "true" )
+	if ( aggregate == 'true' )
 	{
-		$( "span#info" ).html( i18n_aggregate_data_info );
+		$( 'span#info' ).html( i18n_aggregate_data_info );
+		$( '#doDataMart' ).removeAttr( 'disabled' );
 	}
 	else
 	{		
-		$( "span#info" ).html( i18n_captured_data_info );
+		$( 'span#info' ).html( i18n_captured_data_info );
+		$( '#doDataMart' ).attr( 'disabled', 'disabled' );
 	}
 }

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/runValidationForm.vm'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/runValidationForm.vm	2010-09-01 06:14:47 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/runValidationForm.vm	2010-09-01 10:30:03 +0000
@@ -45,6 +45,17 @@
     	</td>
     </tr>
     <tr>
+    	<td>
+    		<label for="doDataMart">$i18n.getString( "method" )</label>
+	    </td>
+    	<td>
+			<select id="doDataMart" name="doDataMart" style="width:20em" disabled="disabled">
+				<option value="true">$i18n.getString( "get_updated_data" )</a>
+				<option value="false">$i18n.getString( "use_existing_data" )</a>
+			</select>
+		</td>
+	</tr>
+    <tr>
     	<td colspan="2"><span id="info">$i18n.getString( "captured_data_info" )</span></td>
     </tr>
     <tr>