=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2013-10-08 17:20:57 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2013-10-16 16:00:05 +0000 @@ -79,7 +79,7 @@ final String KEY_SCHEDULE_AGGREGATE_QUERY_BUILDER_TASK_STRATEGY = "scheduleAggregateQueryBuilderTackStrategy"; final String KEY_CONFIGURATION = "keyConfig"; final String KEY_ACCOUNT_RECOVERY = "keyAccountRecovery"; - final String KEY_LAST_ALERT_RUN = "keyLastAlertRun"; + final String KEY_LAST_MONITORING_RUN = "keyLastMonitoringRun"; final String DEFAULT_SCHEDULE_AGGREGATE_QUERY_BUILDER_TASK_STRATEGY = "lastMonth"; final String DEFAULT_FLAG = "dhis2"; === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidationRunContext.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidationRunContext.java 2013-10-16 12:39:47 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidationRunContext.java 2013-10-16 16:00:05 +0000 @@ -52,7 +52,7 @@ /** * Holds common values that are used during a validation run (either interactive - * or an alert run.) These values don't change during the multi-threaded tasks + * or scheduled.) These values don't change during the multi-threaded tasks * (except that results entries are added in a threadsafe way.) * * Some of the values are precalculated collections, to save CPU time during the @@ -74,7 +74,7 @@ private ValidationRunType runType; - private Date lastAlertRun; + private Date lastScheduledRun; private Map constantMap; @@ -100,7 +100,8 @@ { return new ToStringBuilder( this, ToStringStyle.SHORT_PREFIX_STYLE ) .append( "\n PeriodTypeExtendedMap", (Arrays.toString( periodTypeExtendedMap.entrySet().toArray() )) ) - .append( "\n runType", runType ).append( "\n lastAlertRun", lastAlertRun ) + .append( "\n runType", runType ) + .append( "\n lastScheduledRun", lastScheduledRun ) .append( "\n constantMap", "[" + constantMap.size() + "]" ) .append( "\n ruleXMap", "[" + ruleXMap.size() + "]" ) .append( "\n sourceXs", Arrays.toString( sourceXs.toArray() ) ) @@ -113,18 +114,18 @@ * @param sources organisation units for validation * @param periods periods for validation * @param rules validation rules for validation - * @param runType whether this is an INTERACTIVE or ALERT run - * @param lastAlertRun (for ALERT runs) date of previous alert run + * @param runType whether this is an INTERACTIVE or SCHEDULED run + * @param lastScheduledRun (for SCHEDULED runs) date/time of previous run * @return context object for this run */ public static ValidationRunContext getNewValidationRunContext( Collection sources, Collection periods, Collection rules, Map constantMap, - ValidationRunType runType, Date lastAlertRun, ExpressionService expressionService, PeriodService periodService, + ValidationRunType runType, Date lastScheduledRun, ExpressionService expressionService, PeriodService periodService, DataValueService dataValueService ) { ValidationRunContext context = new ValidationRunContext(); context.runType = runType; - context.lastAlertRun = lastAlertRun; + context.lastScheduledRun = lastScheduledRun; context.validationResults = new ConcurrentLinkedQueue(); // thread-safe context.periodTypeExtendedMap = new HashMap(); context.ruleXMap = new HashMap(); @@ -149,7 +150,7 @@ { addPeriodsToContext( periods ); - boolean monitoringRulesPresent = addRulesToContext ( rules ); + boolean surveillanceRulesPresent = addRulesToContext ( rules ); removeAnyUnneededPeriodTypes(); @@ -157,7 +158,7 @@ countOfSourcesToValidate = sources.size(); - if ( monitoringRulesPresent ) + if ( surveillanceRulesPresent ) { Set otherDescendants = getAllOtherDescendants( sources ); addSourcesToContext( otherDescendants, false ); @@ -182,11 +183,11 @@ * Adds validation rules to the context. * * @param rules validation rules to add - * @return true if there were some monitoring-type rules, false otherwise. + * @return true if there were some surveillance-type rules, false otherwise. */ private boolean addRulesToContext ( Collection rules ) { - boolean monitoringRulesPresent = false; + boolean surveillanceRulesPresent = false; for ( ValidationRule rule : rules ) { @@ -194,12 +195,12 @@ { if ( rule.getOrganisationUnitLevel() == null ) { - log.error( "monitoring-type validationRule '" + (rule.getName() == null ? "" : rule.getName()) + log.error( "surveillance-type validationRule '" + (rule.getName() == null ? "" : rule.getName()) + "' has no organisationUnitLevel." ); continue; // Ignore rule, avoid null reference later. } - monitoringRulesPresent = true; + surveillanceRulesPresent = true; } // Find the period type extended for this rule @@ -221,7 +222,7 @@ ValidationRuleExtended ruleX = new ValidationRuleExtended( rule, allowedPastPeriodTypes ); ruleXMap.put( rule, ruleX ); } - return monitoringRulesPresent; + return surveillanceRulesPresent; } /** @@ -242,14 +243,14 @@ /** * Finds all organisation unit descendants that are not in a given - * collection of organisation units. This is needed for monitoring-type + * collection of organisation units. This is needed for surveillance-type * rules, because the data values for the rules may need to be aggregated * from the organisation unit's descendants. * * The descendants will likely be there anyway for a run including - * monitoring-type rules, because an interactive run containing - * monitoring-type rules should select an entire subtree, and a - * scheduled alert run will contain all organisation units. But check + * surveillance-type rules, because an interactive run containing + * surveillance-type rules should select an entire subtree, and a + * scheduled monitoring run will contain all organisation units. But check * just to be sure, and find any that may be missing. This makes sure * that some of the tests will work, and may be required for some * future features to work. @@ -386,9 +387,9 @@ return runType; } - public Date getLastAlertRun() + public Date getLastScheduledRun() { - return lastAlertRun; + return lastScheduledRun; } public Map getConstantMap() === 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-16 13:46:59 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/Validator.java 2013-10-16 16:00:05 +0000 @@ -58,9 +58,9 @@ * @param sources the organisation units in which to run the validation rules * @param periods the periods of data to check * @param rules the ValidationRules to evaluate - * @param runType whether this is an INTERACTIVE or ALERT run - * @param lastAlertRun date/time of the most recent successful alerts run - * (needed only for alert run) + * @param runType whether this is an INTERACTIVE or SCHEDULED run + * @param lastScheduledRun date/time of the most recent successful + * scheduled monitoring run (needed only for scheduled runs) * @param constantService Constant Service reference * @param expressionService Expression Service reference * @param periodService Period Service reference @@ -68,11 +68,11 @@ * @return a collection of any validations that were found */ public static Collection validate( Collection sources, - Collection periods, Collection rules, ValidationRunType runType, Date lastAlertRun, + Collection periods, Collection rules, ValidationRunType runType, Date lastScheduledRun, ConstantService constantService, ExpressionService expressionService, PeriodService periodService, DataValueService dataValueService) { ValidationRunContext context = ValidationRunContext.getNewValidationRunContext( sources, periods, rules, - constantService.getConstantMap(), ValidationRunType.SCHEDULED, lastAlertRun, + constantService.getConstantMap(), ValidationRunType.SCHEDULED, lastScheduledRun, expressionService, periodService, dataValueService ); int threadPoolSize = getThreadPoolSize( context ); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidatorThread.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidatorThread.java 2013-10-16 13:46:59 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidatorThread.java 2013-10-16 16:00:05 +0000 @@ -170,7 +170,7 @@ * * @param sourceX the organisation unit extended information * @param periodTypeX the period type extended information - * @param context the alert run context + * @param context the validation run context * @param sourceDataElements all data elements collected for this * organisation unit * @return @@ -196,7 +196,7 @@ } else { - // For monitoring-type rules, include only rules for this + // For surveillance-type rules, include only rules for this // organisation's unit level. // The organisation may not be configured for the data elements // because they could be aggregated from a lower level. @@ -215,9 +215,9 @@ * Checks to see if the evaluation should go further for this * evaluationRule, after the "current" data to evaluate has been fetched. * For INTERACTIVE runs, we always go further (always return true.) For - * ALERT runs, we go further only if something has changed since the last - * successful alert run -- either the rule definition or one of the - * "current" data element / option values. + * SCHEDULED runs, we go further only if something has changed since the + * last successful scheduled run -- either the rule definition or one of + * the "current" data element / option values. * * @param lastUpdatedMap when each data value was last updated * @param rule the rule that may be evaluated @@ -231,13 +231,13 @@ if ( ValidationRunType.SCHEDULED == context.getRunType() ) { - if ( context.getLastAlertRun() != null ) // True if no previous alert run + if ( context.getLastScheduledRun() != null ) // True if no previous scheduled run { - if ( rule.getLastUpdated().before( context.getLastAlertRun() ) ) + if ( rule.getLastUpdated().before( context.getLastScheduledRun() ) ) { // Get the "current" DataElementOperands from this rule: // Left+Right sides for VALIDATION, Left side only for - // MONITORING + // SURVEILLANCE Collection deos = context.getExpressionService().getOperandsInExpression( rule.getLeftSide().getExpression() ); @@ -249,12 +249,12 @@ } // Return true if any data is more recent than the last - // ALERT run, otherwise return false. + // scheduled run, otherwise return false. evaluate = false; for ( DataElementOperand deo : deos ) { Date lastUpdated = lastUpdatedMap.get( deo ); - if ( lastUpdated != null && lastUpdated.after( context.getLastAlertRun() ) ) + if ( lastUpdated != null && lastUpdated.after( context.getLastScheduledRun() ) ) { evaluate = true; // True if new/updated data. break; @@ -310,7 +310,7 @@ Double rightSideValue = null; // If ruleType is VALIDATION, the right side is evaluated using the same - // (current) data values. If ruleType is MONITORING but there are no + // (current) data values. If ruleType is SURVEILLANCE but there are no // data elements in the right side, then it doesn't matter what data // values we use, so just supply the current data values in order to // evaluate the (constant) expression. @@ -322,7 +322,7 @@ currentValueMap, context.getConstantMap(), null ); } else - // ruleType equals MONITORING, and there are some data elements in the + // ruleType equals SURVEILLANCE, and there are some data elements in the // right side expression { CalendarPeriodType calendarPeriodType = ( CalendarPeriodType ) period.getPeriodType(); @@ -384,11 +384,11 @@ } /** - * Evaluates the right side of a monitoring-type validation rule for + * Evaluates the right side of a surveillance-type validation rule for * a given organisation unit and period, and adds the value to a list * of sample values. * - * Note that for a monitoring-type rule, evaluating the right side + * Note that for a surveillance-type rule, evaluating the right side * expression can result in sampling multiple periods and/or child * organisation units. * @@ -397,7 +397,7 @@ * @param source the organisation unit * @param allowedPeriodTypes the period types in which the data may exist * @param period the main period for the validation rule evaluation - * @param rule the monitoring-type rule being evaluated + * @param rule the surveillance-type rule being evaluated * @param sourceDataElements the data elements configured for this * organisation unit * @param context the evaluation run context @@ -434,9 +434,9 @@ /** * Finds the average right-side sample value. This is used as the right-side - * expression value to evaluate a monitoring-type rule. + * expression value to evaluate a surveillance-type rule. * - * @param rule monitoring-type rule being evaluated + * @param rule surveillance-type rule being evaluated * @param sampleValues sample values actually collected * @param annualSampleCount number of annual samples tried for * @param sequentialSampleCount number of sequential samples tried for === 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-16 13:46:59 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/scheduling/MonitoringTask.java 2013-10-16 16:00:05 +0000 @@ -123,7 +123,7 @@ try { - alertRun(); + scheduledRun(); notifier.notify( taskId, INFO, "Monitoring process done", true ); } @@ -145,7 +145,7 @@ * Evaluates all the validation rules that could generate alerts, * and sends results (if any) to users who should be notified. */ - private void alertRun() + private void scheduledRun() { // Find all the rules belonging to groups that will send alerts to user roles. @@ -153,26 +153,26 @@ Collection sources = organisationUnitService.getAllOrganisationUnits(); Set periods = getAlertPeriodsFromRules( rules ); - Date lastAlertRun = (Date) systemSettingManager.getSystemSetting( SystemSettingManager.KEY_LAST_ALERT_RUN ); + Date lastScheduledRun = (Date) systemSettingManager.getSystemSetting( SystemSettingManager.KEY_LAST_MONITORING_RUN ); // Any database changes after this moment will contribute to the next run. - Date thisAlertRun = new Date(); + Date thisScheduledRun = new Date(); - log.info( "alertRun sources[" + sources.size() + "] periods[" + periods.size() + "] rules[" + rules.size() - + "] last run " + lastAlertRun == null ? "(none)" : lastAlertRun ); + log.info( "Scheduled monitoring run sources[" + sources.size() + "] periods[" + periods.size() + "] rules[" + rules.size() + + "] last run " + lastScheduledRun == null ? "(none)" : lastScheduledRun ); Collection results = Validator.validate( sources, periods, rules, ValidationRunType.SCHEDULED, - lastAlertRun, constantService, expressionService, periodService, dataValueService ); + lastScheduledRun, constantService, expressionService, periodService, dataValueService ); - log.trace( "alertRun() results[" + results.size() + "]" ); + log.trace( "scheduledRun() results[" + results.size() + "]" ); if ( !results.isEmpty() ) { - postAlerts( results, thisAlertRun ); + postAlerts( results, thisScheduledRun ); } - systemSettingManager.saveSystemSetting( SystemSettingManager.KEY_LAST_ALERT_RUN, thisAlertRun ); + systemSettingManager.saveSystemSetting( SystemSettingManager.KEY_LAST_MONITORING_RUN, thisScheduledRun ); } /** @@ -206,9 +206,10 @@ * these periods actually exist in the database. * * TODO If the last successful daily run was more than one day ago, we might - * add some additional periods of type DailyPeriodType not to miss any alerts. + * add some additional periods of type DailyPeriodType not to miss any + * alerts. * - * @param rules the ValidationRules to be evaluated on this alert run + * @param rules the ValidationRules to be evaluated on this run * @return periods to search for new alerts */ private Set getAlertPeriodsFromRules( Set rules ) @@ -251,8 +252,8 @@ } /** - * At the end of an ALERT run, post messages to the users who want to see - * the results. + * At the end of a scheduled monitoring run, post messages to the users who + * want to see the results. * * Create one message for each set of users who receive the same * subset of results. (Not necessarily the same as the set of users who @@ -267,9 +268,9 @@ * ( target language, set of results ). * * @param validationResults the set of validation error results - * @param alertRunStart the date/time when the alert run started + * @param scheduledRunStart the date/time when this scheduled run started */ - private void postAlerts( Collection validationResults, Date alertRunStart ) + private void postAlerts( Collection validationResults, Date scheduledRunStart ) { SortedSet results = new TreeSet( validationResults ); @@ -277,7 +278,7 @@ for ( Map.Entry, Set> entry : messageMap.entrySet() ) { - sendAlertmessage( entry.getKey(), entry.getValue(), alertRunStart ); + sendAlertmessage( entry.getKey(), entry.getValue(), scheduledRunStart ); } } @@ -370,9 +371,9 @@ * * @param results results to put in this message * @param users users to receive these results - * @param alertRunStart date/time when the alert run started + * @param scheduledRunStart date/time when the scheduled run started */ - private void sendAlertmessage( List results, Set users, Date alertRunStart ) + private void sendAlertmessage( List results, Set users, Date scheduledRunStart ) { StringBuilder messageBuilder = new StringBuilder(); @@ -380,7 +381,7 @@ Map importanceCountMap = countResultsByImportanceType( results ); - String subject = "DHIS alerts as of " + dateTimeFormatter.format( alertRunStart ) + " - priority High " + String subject = "DHIS alerts as of " + dateTimeFormatter.format( scheduledRunStart ) + " - 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" ) );