← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12579: Validation. Code style.

 

------------------------------------------------------------
revno: 12579
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-10-11 11:16:32 +0200
message:
  Validation. Code style.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationResult.java
  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/ValidationRuleExtended.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidationRunContext.java


--
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/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<ValidationResult>
@@ -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( "<html>\n" )
-        	.append( "<head>\n" )
-            .append( "</head>\n" )
-            .append( "<body>\n" )
-            .append( subject )
-            .append( "\n" )
-            .append( "<br />\n" )
-            .append( "<table>\n" )
-            .append( " <tr>\n" )
-            .append( "  <th>Organisation Unit</th>\n" )
-            .append( "  <th>Period</th>\n" )
-            .append( "  <th>Importance</th>\n" )
-            .append( "  <th>Left side description</th>\n" )
-            .append( "  <th>Value</th>\n" )
-            .append( "  <th>Operator</th>\n" )
-            .append( "  <th>Value</th>\n" )
-            .append( "  <th>Right side description</th>\n" )
-            .append( " </tr>\n" );
+            .append( "<html>" )
+            .append( "<head>" ).append( "</head>" )
+            .append( "<body>" ).append( subject ).append( "<br />" )
+            .append( "<table>" )
+            .append( "<tr>" )
+            .append( "<th>Organisation Unit</th>" )
+            .append( "<th>Period</th>" )
+            .append( "<th>Importance</th>" )
+            .append( "<th>Left side description</th>" )
+            .append( "<th>Value</th>" )
+            .append( "<th>Operator</th>" )
+            .append( "<th>Value</th>" )
+            .append( "<th>Right side description</th>" )
+            .append( "</tr>" );
 
         for ( ValidationResult result : results )
         {
             ValidationRule rule = result.getValidationRule();
 
             messageBuilder
-            	.append( " <tr>\n" )
-            	.append( "  <td>" ).append( result.getSource().getName() ).append( "<\td>\n" )
-                .append( "  <td>" ).append( result.getPeriod().getName() ).append( "<\td>\n" )
-                .append( "  <td>" ).append( rule.getImportance() ).append( "<\td>\n" )
-                .append( "  <td>" ).append( rule.getLeftSide().getDescription() ).append( "<\td>\n" )
-                .append( "  <td>" ).append( result.getLeftsideValue() ).append( "<\td>\n" )
-                .append( "  <td>" ).append( rule.getOperator().toString() ).append( "<\td>\n" )
-                .append( "  <td>" ).append( result.getRightsideValue() ).append( "<\td>\n" )
-                .append( "  <td>" ).append( rule.getRightSide().getDescription() ).append( "<\td>\n" )
-                .append( " </tr>\n" );
+            	.append( "<tr>" )
+            	.append( "<td>" ).append( result.getSource().getName() ).append( "<\td>" )
+                .append( "<td>" ).append( result.getPeriod().getName() ).append( "<\td>" )
+                .append( "<td>" ).append( rule.getImportance() ).append( "<\td>" )
+                .append( "<td>" ).append( rule.getLeftSide().getDescription() ).append( "<\td>" )
+                .append( "<td>" ).append( result.getLeftsideValue() ).append( "<\td>" )
+                .append( "<td>" ).append( rule.getOperator().toString() ).append( "<\td>" )
+                .append( "<td>" ).append( result.getRightsideValue() ).append( "<\td>" )
+                .append( "<td>" ).append( rule.getRightSide().getDescription() ).append( "<\td>" )
+                .append( "</tr>" );
         }
 
         messageBuilder
-        	.append( "</table>\n" )
-        	.append( "</body>\n" )
-        	.append( "</html>\n" );
+        	.append( "</table>" )
+        	.append( "</body>" )
+        	.append( "</html>" );
 
         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<PeriodType> allowedPastPeriodTypes;
-
-	public ValidationRuleExtended( ValidationRule rule, Collection<PeriodType> allowedPastPeriodTypes )
-	{
-		this.rule = rule;
-		this.allowedPastPeriodTypes = allowedPastPeriodTypes;
-	}
+public class ValidationRuleExtended
+{
+    private ValidationRule rule;
+
+    private Collection<PeriodType> allowedPastPeriodTypes;
+
+    public ValidationRuleExtended( ValidationRule rule, Collection<PeriodType> allowedPastPeriodTypes )
+    {
+        this.rule = rule;
+        this.allowedPastPeriodTypes = allowedPastPeriodTypes;
+    }
 
     // -------------------------------------------------------------------------
     // Set and get methods
-    // -------------------------------------------------------------------------  
-
-	public ValidationRule getRule() {
-		return rule;
-	}
-
-	public Collection<PeriodType> getAllowedPastPeriodTypes() {
-		return allowedPastPeriodTypes;
-	}
+    // -------------------------------------------------------------------------
+
+    public ValidationRule getRule()
+    {
+        return rule;
+    }
+
+    public Collection<PeriodType> 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<ValidationRule, ValidationRuleExtended> ruleXMap;
 
     private Collection<OrganisationUnitExtended> sourceXs;
-    
+
     private Collection<ValidationResult> 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<OrganisationUnit> sources, Collection<Period> periods,
-        Collection<ValidationRule> rules, Map<String, Double> constantMap, ValidationRunType runType, Date lastAlertRun,
-        ExpressionService expressionService, PeriodService periodService, DataValueService dataValueService )
+    public static ValidationRunContext getNewValidationRunContext( Collection<OrganisationUnit> sources,
+        Collection<Period> periods, Collection<ValidationRule> rules, Map<String, Double> 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<OrganisationUnit> sources, Collection<Period> periods, Collection<ValidationRule> rules )
+    private void initialize( Collection<OrganisationUnit> sources, Collection<Period> periods,
+        Collection<ValidationRule> 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<PeriodType> allowedPastPeriodTypes =
-            		getAllowedPeriodTypesForDataElements( rule.getPastDataElements(), rule.getPeriodType() );
+            Collection<PeriodType> 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<DataElement> sourceDataElements = sourceDataElementsByPeriodType
-                    .get( periodTypeX.getPeriodType() );
+                Collection<DataElement> sourceDataElements = sourceDataElementsByPeriodType.get( periodTypeX
+                    .getPeriodType() );
                 if ( sourceDataElements != null )
                 {
                     periodTypeX.getSourceDataElements().put( source, sourceDataElements );
@@ -239,62 +240,71 @@
         Collection<PeriodType> allowedPeriodTypes = new HashSet<PeriodType>();
         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<PeriodType, PeriodTypeExtended> getPeriodTypeExtendedMap() {
-		return periodTypeExtendedMap;
-	}
-
-	public ValidationRunType getRunType() {
-		return runType;
-	}
-
-	public Date getLastAlertRun() {
-		return lastAlertRun;
-	}
-
-	public Map<String, Double> getConstantMap() {
-		return constantMap;
-	}
-
-	public Map<ValidationRule, ValidationRuleExtended> getRuleXMap() {
-		return ruleXMap;
-	}
-
-	public Collection<OrganisationUnitExtended> getSourceXs() {
-		return sourceXs;
-	}
-
-	public Collection<ValidationResult> getValidationResults() {
-		return validationResults;
-	}
-
-	public ExpressionService getExpressionService() {
-		return expressionService;
-	}
-
-	public PeriodService getPeriodService() {
-		return periodService;
-	}
-
-	public DataValueService getDataValueService() {
-		return dataValueService;
-	}
+    // -------------------------------------------------------------------------
+
+    public Map<PeriodType, PeriodTypeExtended> getPeriodTypeExtendedMap()
+    {
+        return periodTypeExtendedMap;
+    }
+
+    public ValidationRunType getRunType()
+    {
+        return runType;
+    }
+
+    public Date getLastAlertRun()
+    {
+        return lastAlertRun;
+    }
+
+    public Map<String, Double> getConstantMap()
+    {
+        return constantMap;
+    }
+
+    public Map<ValidationRule, ValidationRuleExtended> getRuleXMap()
+    {
+        return ruleXMap;
+    }
+
+    public Collection<OrganisationUnitExtended> getSourceXs()
+    {
+        return sourceXs;
+    }
+
+    public Collection<ValidationResult> getValidationResults()
+    {
+        return validationResults;
+    }
+
+    public ExpressionService getExpressionService()
+    {
+        return expressionService;
+    }
+
+    public PeriodService getPeriodService()
+    {
+        return periodService;
+    }
+
+    public DataValueService getDataValueService()
+    {
+        return dataValueService;
+    }
 }
-