=== 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 2013-10-15 07:35:25 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2013-10-15 12:12:59 +0000 @@ -82,8 +82,7 @@ private GenericIdentifiableObjectStore validationRuleGroupStore; - public void setValidationRuleGroupStore( - GenericIdentifiableObjectStore validationRuleGroupStore ) + public void setValidationRuleGroupStore( GenericIdentifiableObjectStore validationRuleGroupStore ) { this.validationRuleGroupStore = validationRuleGroupStore; } @@ -139,8 +138,9 @@ log.info( "Validate startDate=" + startDate + " endDate=" + endDate + " sources[" + sources.size() + "]" ); Collection periods = periodService.getPeriodsBetweenDates( startDate, endDate ); Collection rules = getAllValidationRules(); + return Validator.validate( sources, periods, rules, ValidationRunType.INTERACTIVE, null, - constantService, expressionService, periodService, dataValueService ); + constantService, expressionService, periodService, dataValueService ); } public Collection validate( Date startDate, Date endDate, Collection sources, @@ -149,8 +149,9 @@ log.info( "Validate startDate=" + startDate + " endDate=" + endDate + " sources[" + sources.size() + "] group=" + group.getName() ); Collection periods = periodService.getPeriodsBetweenDates( startDate, endDate ); Collection rules = group.getMembers(); + return Validator.validate( sources, periods, rules, ValidationRunType.INTERACTIVE, null, - constantService, expressionService, periodService, dataValueService ); + constantService, expressionService, periodService, dataValueService ); } public Collection validate( Date startDate, Date endDate, OrganisationUnit source ) @@ -160,8 +161,9 @@ Collection rules = getAllValidationRules(); Collection sources = new HashSet(); sources.add( source ); + return Validator.validate( sources, periods, rules, ValidationRunType.INTERACTIVE, null, - constantService, expressionService, periodService, dataValueService ); + constantService, expressionService, periodService, dataValueService ); } public Collection validate( DataSet dataSet, Period period, OrganisationUnit source ) @@ -172,6 +174,7 @@ periods.add( period ); Collection rules = null; + if ( DataSet.TYPE_CUSTOM.equals( dataSet.getDataSetType() ) ) { rules = getRulesForDataSet( dataSet ); @@ -183,8 +186,9 @@ Collection sources = new HashSet(); sources.add( source ); + return Validator.validate( sources, periods, rules, ValidationRunType.INTERACTIVE, null, - constantService, expressionService, periodService, dataValueService ); + constantService, expressionService, periodService, dataValueService ); } // ------------------------------------------------------------------------- @@ -244,9 +248,9 @@ { validationRuleOperands.clear(); validationRuleOperands.addAll( expressionService.getOperandsInExpression( - rule.getLeftSide().getExpression() ) ); + rule.getLeftSide().getExpression() ) ); validationRuleOperands.addAll( expressionService.getOperandsInExpression( - rule.getRightSide().getExpression() ) ); + rule.getRightSide().getExpression() ) ); if ( operands.containsAll( validationRuleOperands ) ) { === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/Validator.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/Validator.java 2013-10-15 07:35:25 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/Validator.java 2013-10-15 12:12:59 +0000 @@ -72,19 +72,19 @@ ConstantService constantService, ExpressionService expressionService, PeriodService periodService, DataValueService dataValueService) { ValidationRunContext context = ValidationRunContext.getNewValidationRunContext( sources, periods, rules, - constantService.getConstantMap(), ValidationRunType.ALERT, lastAlertRun, - expressionService, periodService, dataValueService); + constantService.getConstantMap(), ValidationRunType.ALERT, lastAlertRun, + expressionService, periodService, dataValueService); int threadPoolSize = getThreadPoolSize( context ); ExecutorService executor = Executors.newFixedThreadPool( threadPoolSize ); for ( OrganisationUnitExtended sourceX : context.getSourceXs() ) { - if ( sourceX.getToBeValidated() ) - { - Runnable worker = new ValidatorThread( sourceX, context ); - executor.execute( worker ); - } + if ( sourceX.getToBeValidated() ) + { + Runnable worker = new ValidatorThread( sourceX, context ); + executor.execute( worker ); + } } executor.shutdown(); @@ -97,6 +97,7 @@ { executor.shutdownNow(); } + return context.getValidationResults(); } @@ -114,6 +115,7 @@ { threadPoolSize--; } + if ( threadPoolSize > context.getCountOfSourcesToValidate() ) { threadPoolSize = context.getCountOfSourcesToValidate(); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/scheduling/MonitoringTask.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/scheduling/MonitoringTask.java 2013-10-14 20:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/scheduling/MonitoringTask.java 2013-10-15 12:12:59 +0000 @@ -148,6 +148,7 @@ private void alertRun() { // Find all the rules belonging to groups that will send alerts to user roles. + Set rules = getAlertRules(); Collection sources = organisationUnitService.getAllOrganisationUnits(); @@ -182,9 +183,11 @@ private Set getAlertRules() { Set rules = new HashSet(); + for ( ValidationRuleGroup validationRuleGroup : validationRuleService.getAllValidationRuleGroups() ) { - Set userRolesToAlert = validationRuleGroup.getUserAuthorityGroupsToAlert(); + Set userRolesToAlert = validationRuleGroup.getUserAuthorityGroupsToAlert(); + if ( userRolesToAlert != null && !userRolesToAlert.isEmpty() ) { rules.addAll( validationRuleGroup.getMembers() ); @@ -290,37 +293,38 @@ { Map> userRulesMap = getUserRulesMap(); - Map, Set> messageMap = new HashMap, Set>(); - - for ( User user : userRulesMap.keySet() ) - { - // For each user who receives alerts, find the subset of results - // from this run. - Collection userRules = userRulesMap.get( user ); - List userResults = new ArrayList(); - - for ( ValidationResult result : results ) - { - if ( userRules.contains( result.getValidationRule() ) ) - { - userResults.add( result ); - } - } - - // Group this user with any other users who have the same subset - // of results. - if ( !userResults.isEmpty() ) - { - Set messageReceivers = messageMap.get( userResults ); - if ( messageReceivers == null ) - { - messageReceivers = new HashSet(); - messageMap.put( userResults, messageReceivers ); - } - messageReceivers.add( user ); - } - } - return messageMap; + Map, Set> messageMap = new HashMap, Set>(); + + for ( User user : userRulesMap.keySet() ) + { + // For users receiving alerts, find the subset of results from run. + + Collection userRules = userRulesMap.get( user ); + List userResults = new ArrayList(); + + for ( ValidationResult result : results ) + { + if ( userRules.contains( result.getValidationRule() ) ) + { + userResults.add( result ); + } + } + + // Group this user with other users having the same result subset. + + if ( !userResults.isEmpty() ) + { + Set messageReceivers = messageMap.get( userResults ); + if ( messageReceivers == null ) + { + messageReceivers = new HashSet(); + messageMap.put( userResults, messageReceivers ); + } + messageReceivers.add( user ); + } + } + + return messageMap; } /** @@ -332,32 +336,34 @@ */ private Map> getUserRulesMap() { - Map> userRulesMap = new HashMap>(); - - for ( ValidationRuleGroup validationRuleGroup : validationRuleService.getAllValidationRuleGroups() ) - { - Collection userRolesToAlert = validationRuleGroup.getUserAuthorityGroupsToAlert(); - if ( userRolesToAlert != null && !userRolesToAlert.isEmpty() ) - { - for ( UserAuthorityGroup role : userRolesToAlert ) - { - for ( UserCredentials userCredentials : role.getMembers() ) - { - User user = userCredentials.getUser(); - Set userRules = userRulesMap.get( user ); - if ( userRules == null ) - { - userRules = new HashSet(); - userRulesMap.put( user, userRules ); - } - userRules.addAll( validationRuleGroup.getMembers() ); - } - } - } - } - return userRulesMap; + Map> userRulesMap = new HashMap>(); + + for ( ValidationRuleGroup validationRuleGroup : validationRuleService.getAllValidationRuleGroups() ) + { + Collection userRolesToAlert = validationRuleGroup.getUserAuthorityGroupsToAlert(); + + if ( userRolesToAlert != null && !userRolesToAlert.isEmpty() ) + { + for ( UserAuthorityGroup role : userRolesToAlert ) + { + for ( UserCredentials userCredentials : role.getMembers() ) + { + User user = userCredentials.getUser(); + Set userRules = userRulesMap.get( user ); + if ( userRules == null ) + { + userRules = new HashSet(); + userRulesMap.put( user, userRules ); + } + userRules.addAll( validationRuleGroup.getMembers() ); + } + } + } + } + + return userRulesMap; } - + /** * Generate and send an alert message containing a list of validation * results to a set of users. @@ -375,9 +381,9 @@ Map importanceCountMap = countTheResultsByImportanceType( results ); String subject = "DHIS alerts as of " + dateTimeFormatter.format( alertRunStart ) + " - priority High " - + (importanceCountMap.get( "high" ) == null ? 0 : importanceCountMap.get( "high" )) + ", Medium " - + (importanceCountMap.get( "medium" ) == null ? 0 : importanceCountMap.get( "medium" )) + ", Low " - + (importanceCountMap.get( "low" ) == null ? 0 : importanceCountMap.get( "low" )); + + ( importanceCountMap.get( "high" ) == null ? 0 : importanceCountMap.get( "high" ) ) + ", Medium " + + ( importanceCountMap.get( "medium" ) == null ? 0 : importanceCountMap.get( "medium" ) ) + ", Low " + + ( importanceCountMap.get( "low" ) == null ? 0 : importanceCountMap.get( "low" ) ); messageBuilder .append( "" ) @@ -413,9 +419,9 @@ } messageBuilder - .append( "" ) - .append( "" ) - .append( "" ); + .append( "" ) + .append( "" ) + .append( "" ); String messageText = messageBuilder.toString();