=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationResult.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationResult.java 2013-10-09 05:16:53 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationResult.java 2013-10-11 09:16:32 +0000 @@ -35,7 +35,6 @@ /** * @author Margrethe Store - * @version $Id: ValidationResult.java 5277 2008-05-27 15:48:42Z larshelg $ */ public class ValidationResult implements Serializable, Comparable @@ -152,43 +151,43 @@ public int compareTo( ValidationResult other ) { - if ( source.getName().compareTo( other.source.getName() ) != 0 ) - { - return source.getName().compareTo( other.source.getName() ); - } - else if ( period.getStartDate().compareTo( other.period.getStartDate() ) != 0 ) - { - return period.getStartDate().compareTo( other.period.getStartDate() ); - } - else if ( source.getName().compareTo( other.source.getName() ) != 0 ) - { - return source.getName().compareTo( other.source.getName() ); - } - else if ( period.getStartDate().compareTo( other.period.getStartDate() ) != 0 ) - { - return period.getStartDate().compareTo( other.period.getStartDate() ); - } - else if ( period.getEndDate().compareTo( other.period.getEndDate() ) != 0 ) - { - return period.getEndDate().compareTo( other.period.getEndDate() ); - } - else if ( validationRule.getImportance().compareTo( other.validationRule.getImportance() ) != 0 ) - { - return validationImportanceOrder( validationRule.getImportance() ) - - validationImportanceOrder( other.validationRule.getImportance() ); - } - else - { - return validationRule.getLeftSide().getDescription() - .compareTo( other.validationRule.getLeftSide().getDescription() ); - } + if ( source.getName().compareTo( other.source.getName() ) != 0 ) + { + return source.getName().compareTo( other.source.getName() ); + } + else if ( period.getStartDate().compareTo( other.period.getStartDate() ) != 0 ) + { + return period.getStartDate().compareTo( other.period.getStartDate() ); + } + else if ( source.getName().compareTo( other.source.getName() ) != 0 ) + { + return source.getName().compareTo( other.source.getName() ); + } + else if ( period.getStartDate().compareTo( other.period.getStartDate() ) != 0 ) + { + return period.getStartDate().compareTo( other.period.getStartDate() ); + } + else if ( period.getEndDate().compareTo( other.period.getEndDate() ) != 0 ) + { + return period.getEndDate().compareTo( other.period.getEndDate() ); + } + else if ( validationRule.getImportance().compareTo( other.validationRule.getImportance() ) != 0 ) + { + return validationImportanceOrder( validationRule.getImportance() ) + - validationImportanceOrder( other.validationRule.getImportance() ); + } + else + { + return validationRule.getLeftSide().getDescription() + .compareTo( other.validationRule.getLeftSide().getDescription() ); + } } - - private int validationImportanceOrder ( String importance ) + + private int validationImportanceOrder( String importance ) { - return ( importance.equals("high") ? 0 : importance.equals("medium") ? 1 : 2 ); + return ( importance.equals( "high" ) ? 0 : importance.equals( "medium" ) ? 1 : 2 ); } - + @Override public String toString() { === 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-09 05:16:53 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java 2013-10-11 09:16:32 +0000 @@ -562,46 +562,42 @@ // Construct the text of the message. messageBuilder - .append( "\n" ) - .append( "\n" ) - .append( "\n" ) - .append( "\n" ) - .append( subject ) - .append( "\n" ) - .append( "
\n" ) - .append( "\n" ) - .append( " \n" ) - .append( " \n" ) - .append( " \n" ) - .append( " \n" ) - .append( " \n" ) - .append( " \n" ) - .append( " \n" ) - .append( " \n" ) - .append( " \n" ) - .append( " \n" ); + .append( "" ) + .append( "" ).append( "" ) + .append( "" ).append( subject ).append( "
" ) + .append( "
Organisation UnitPeriodImportanceLeft side descriptionValueOperatorValueRight side description
" ) + .append( "" ) + .append( "" ) + .append( "" ) + .append( "" ) + .append( "" ) + .append( "" ) + .append( "" ) + .append( "" ) + .append( "" ) + .append( "" ); for ( ValidationResult result : results ) { ValidationRule rule = result.getValidationRule(); messageBuilder - .append( " \n" ) - .append( " \n" ); + .append( "" ) + .append( "" ); } messageBuilder - .append( "
Organisation UnitPeriodImportanceLeft side descriptionValueOperatorValueRight side description
" ).append( result.getSource().getName() ).append( "<\td>\n" ) - .append( " " ).append( result.getPeriod().getName() ).append( "<\td>\n" ) - .append( " " ).append( rule.getImportance() ).append( "<\td>\n" ) - .append( " " ).append( rule.getLeftSide().getDescription() ).append( "<\td>\n" ) - .append( " " ).append( result.getLeftsideValue() ).append( "<\td>\n" ) - .append( " " ).append( rule.getOperator().toString() ).append( "<\td>\n" ) - .append( " " ).append( result.getRightsideValue() ).append( "<\td>\n" ) - .append( " " ).append( rule.getRightSide().getDescription() ).append( "<\td>\n" ) - .append( "
" ).append( result.getSource().getName() ).append( "<\td>" ) + .append( "" ).append( result.getPeriod().getName() ).append( "<\td>" ) + .append( "" ).append( rule.getImportance() ).append( "<\td>" ) + .append( "" ).append( rule.getLeftSide().getDescription() ).append( "<\td>" ) + .append( "" ).append( result.getLeftsideValue() ).append( "<\td>" ) + .append( "" ).append( rule.getOperator().toString() ).append( "<\td>" ) + .append( "" ).append( result.getRightsideValue() ).append( "<\td>" ) + .append( "" ).append( rule.getRightSide().getDescription() ).append( "<\td>" ) + .append( "
\n" ) - .append( "\n" ) - .append( "\n" ); + .append( "" ) + .append( "" ) + .append( "" ); String messageText = messageBuilder.toString(); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidationRuleExtended.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidationRuleExtended.java 2013-10-09 05:16:53 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidationRuleExtended.java 2013-10-11 09:16:32 +0000 @@ -33,39 +33,41 @@ */ /** - * Holds information for each validation rule that is needed during - * a validation run (either interactive or an alert run). + * Holds information for each validation rule that is needed during a validation + * run (either interactive or an alert run). * - * By computing these values once at the start of a validation run, we avoid - * the overhead of having to compute them during the processing of every + * By computing these values once at the start of a validation run, we avoid the + * overhead of having to compute them during the processing of every * organisation unit. For some of these properties this is also important * because they should be copied from Hibernate lazy collections before the - * multithreaded part of the run starts, otherwise the threads may not be - * able to access these values. + * multithreaded part of the run starts, otherwise the threads may not be able + * to access these values. * * @author Jim Grace */ -public class ValidationRuleExtended { - - private ValidationRule rule; - - private Collection allowedPastPeriodTypes; - - public ValidationRuleExtended( ValidationRule rule, Collection allowedPastPeriodTypes ) - { - this.rule = rule; - this.allowedPastPeriodTypes = allowedPastPeriodTypes; - } +public class ValidationRuleExtended +{ + private ValidationRule rule; + + private Collection allowedPastPeriodTypes; + + public ValidationRuleExtended( ValidationRule rule, Collection allowedPastPeriodTypes ) + { + this.rule = rule; + this.allowedPastPeriodTypes = allowedPastPeriodTypes; + } // ------------------------------------------------------------------------- // Set and get methods - // ------------------------------------------------------------------------- - - public ValidationRule getRule() { - return rule; - } - - public Collection getAllowedPastPeriodTypes() { - return allowedPastPeriodTypes; - } + // ------------------------------------------------------------------------- + + public ValidationRule getRule() + { + return rule; + } + + public Collection getAllowedPastPeriodTypes() + { + return allowedPastPeriodTypes; + } } === 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-09 05:16:53 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidationRunContext.java 2013-10-11 09:16:32 +0000 @@ -53,16 +53,14 @@ * or an alert run.) 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 run. All of these values are stored in this single "context" object - * to allow a single object reference for each of the scheduled tasks. (This - * also reduces the amount of memory needed to queue all the multi-threaded - * tasks.) + * Some of the values are precalculated collections, to save CPU time during the + * run. All of these values are stored in this single "context" object to allow + * a single object reference for each of the scheduled tasks. (This also reduces + * the amount of memory needed to queue all the multi-threaded tasks.) * - * For some of these properties this is also important because they should - * be copied from Hibernate lazy collections before the multithreaded part - * of the run starts, otherwise the threads may not be able to access these - * values. + * For some of these properties this is also important because they should be + * copied from Hibernate lazy collections before the multithreaded part of the + * run starts, otherwise the threads may not be able to access these values. * * @author Jim Grace */ @@ -79,30 +77,30 @@ private Map ruleXMap; private Collection sourceXs; - + private Collection validationResults; private ExpressionService expressionService; - + private PeriodService periodService; - + private DataValueService dataValueService; - + private ValidationRunContext() { } - + public String toString() { 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 constantMap", "[" + constantMap.size() + "]" ) - .append( "\n ruleXMap", "[" + ruleXMap.size() + "]" ) + .append( "\n PeriodTypeExtendedMap", (Arrays.toString( periodTypeExtendedMap.entrySet().toArray() )) ) + .append( "\n runType", runType ).append( "\n lastAlertRun", lastAlertRun ) + .append( "\n constantMap", "[" + constantMap.size() + "]" ) + .append( "\n ruleXMap", "[" + ruleXMap.size() + "]" ) .append( "\n sourceXs", Arrays.toString( sourceXs.toArray() ) ) .append( "\n validationResults", Arrays.toString( validationResults.toArray() ) ).toString(); } - + /** * Creates and fills a new context object for a validation run. * @@ -113,9 +111,10 @@ * @param lastAlertRun (for ALERT runs) date of previous alert 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, DataValueService dataValueService ) + public static ValidationRunContext getNewValidationRunContext( Collection sources, + Collection periods, Collection rules, Map constantMap, + ValidationRunType runType, Date lastAlertRun, ExpressionService expressionService, PeriodService periodService, + DataValueService dataValueService ) { ValidationRunContext context = new ValidationRunContext(); context.runType = runType; @@ -131,7 +130,7 @@ context.initialize( sources, periods, rules ); return context; } - + /** * Initializes context values based on sources, periods and rules * @@ -139,7 +138,8 @@ * @param periods * @param rules */ - private void initialize( Collection sources, Collection periods, Collection rules ) + private void initialize( Collection sources, Collection periods, + Collection rules ) { // Group the periods by period type. for ( Period period : periods ) @@ -151,9 +151,10 @@ for ( ValidationRule rule : rules ) { // Find the period type extended for this rule - PeriodTypeExtended periodTypeX = getOrCreatePeriodTypeExtended( rule.getPeriodType() ); - periodTypeX.getRules().add( rule ); // Add this rule to the period type ext. - + PeriodTypeExtended periodTypeX = getOrCreatePeriodTypeExtended( rule.getPeriodType() ); + periodTypeX.getRules().add( rule ); // Add this rule to the period + // type ext. + if ( rule.getCurrentDataElements() != null ) { // Add this rule's data elements to the period extended. @@ -161,11 +162,11 @@ } // Add the allowed period types for rule's current data elements: periodTypeX.getAllowedPeriodTypes().addAll( - getAllowedPeriodTypesForDataElements( rule.getCurrentDataElements(), rule.getPeriodType() ) ); - + getAllowedPeriodTypesForDataElements( rule.getCurrentDataElements(), rule.getPeriodType() ) ); + // Add the ValidationRuleExtended - Collection allowedPastPeriodTypes = - getAllowedPeriodTypesForDataElements( rule.getPastDataElements(), rule.getPeriodType() ); + Collection allowedPastPeriodTypes = getAllowedPeriodTypesForDataElements( + rule.getPastDataElements(), rule.getPeriodType() ); ValidationRuleExtended ruleX = new ValidationRuleExtended( rule, allowedPastPeriodTypes ); ruleXMap.put( rule, ruleX ); } @@ -191,8 +192,8 @@ .getDataElementsInDataSetsByPeriodType(); for ( PeriodTypeExtended periodTypeX : periodTypeExtendedMap.values() ) { - Collection sourceDataElements = sourceDataElementsByPeriodType - .get( periodTypeX.getPeriodType() ); + Collection sourceDataElements = sourceDataElementsByPeriodType.get( periodTypeX + .getPeriodType() ); if ( sourceDataElements != null ) { periodTypeX.getSourceDataElements().put( source, sourceDataElements ); @@ -239,62 +240,71 @@ Collection allowedPeriodTypes = new HashSet(); if ( dataElements != null ) { - for ( DataElement dataElement : dataElements ) - { - for ( DataSet dataSet : dataElement.getDataSets() ) - { - if ( dataSet.getPeriodType().getFrequencyOrder() >= periodType.getFrequencyOrder() ) - { - allowedPeriodTypes.add( dataSet.getPeriodType() ); - } - } - } + for ( DataElement dataElement : dataElements ) + { + for ( DataSet dataSet : dataElement.getDataSets() ) + { + if ( dataSet.getPeriodType().getFrequencyOrder() >= periodType.getFrequencyOrder() ) + { + allowedPeriodTypes.add( dataSet.getPeriodType() ); + } + } + } } return allowedPeriodTypes; } // ------------------------------------------------------------------------- // Set and get methods - // ------------------------------------------------------------------------- - - public Map getPeriodTypeExtendedMap() { - return periodTypeExtendedMap; - } - - public ValidationRunType getRunType() { - return runType; - } - - public Date getLastAlertRun() { - return lastAlertRun; - } - - public Map getConstantMap() { - return constantMap; - } - - public Map getRuleXMap() { - return ruleXMap; - } - - public Collection getSourceXs() { - return sourceXs; - } - - public Collection getValidationResults() { - return validationResults; - } - - public ExpressionService getExpressionService() { - return expressionService; - } - - public PeriodService getPeriodService() { - return periodService; - } - - public DataValueService getDataValueService() { - return dataValueService; - } + // ------------------------------------------------------------------------- + + public Map getPeriodTypeExtendedMap() + { + return periodTypeExtendedMap; + } + + public ValidationRunType getRunType() + { + return runType; + } + + public Date getLastAlertRun() + { + return lastAlertRun; + } + + public Map getConstantMap() + { + return constantMap; + } + + public Map getRuleXMap() + { + return ruleXMap; + } + + public Collection getSourceXs() + { + return sourceXs; + } + + public Collection getValidationResults() + { + return validationResults; + } + + public ExpressionService getExpressionService() + { + return expressionService; + } + + public PeriodService getPeriodService() + { + return periodService; + } + + public DataValueService getDataValueService() + { + return dataValueService; + } } -