=== 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 validateAggregate( Date startDate, Date endDate, Collection 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 validateAggregate( Date startDate, Date endDate, Collection 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 validate( Date startDate, Date endDate, Collection 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 validate( Date startDate, Date endDate, Collection 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 getValidationRules( Collection 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 getValidationRulesByDataElements( Collection dataElements ); + /** + * Get all data elements associated with any validation rule. + * + * @return a collection of data elements. + */ + Collection 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 getDataElementsInValidationRules() + { + Set dataElements = new HashSet(); + + 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 organisationUnits = unit.getChildren(); + + if ( doDataMart ) + { + log.info( "Generating datamart" ); + + Collection periods = periodService.getPeriodsBetweenDates( format.parseDate( startDate ), format.parseDate( endDate ) ); + + Collection dataElements = validationRuleService.getDataElementsInValidationRules(); + + dataMartService.export( getIdentifiers( DataElement.class, dataElements ), new HashSet(), + 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 @@ + + + + + + + + + + + + + + $i18n.getString( "captured_data_info" )