← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16148: Code style

 

------------------------------------------------------------
revno: 16148
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-07-16 13:19:08 +0200
message:
  Code style
modified:
  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/ValidationRunContext.java
  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/ValidatorThread.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-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	2014-05-27 02:41:16 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java	2014-07-16 11:19:08 +0000
@@ -228,7 +228,7 @@
         sources.add( source );
 
         return Validator.validate( sources, periods, rules, null, null,
-                constantService, expressionService, periodService, dataValueService, dataElementCategoryService, userService, currentUserService );
+            constantService, expressionService, periodService, dataValueService, dataElementCategoryService, userService, currentUserService );
     }
 
     @Override
@@ -237,7 +237,7 @@
     {
     	log.info( "Validate data set: " + dataSet.getName() + " period: " + period.getPeriodType().getName() + " "
             + period.getStartDate() + " " + period.getEndDate() + " source: " + source.getName()
-            + " attribute combo: " + ( attributeCombo == null ? "(null)" : attributeCombo.getName() ) );
+            + " attribute combo: " + ( attributeCombo == null ? "[none]" : attributeCombo.getName() ) );
 
         Collection<Period> periods = new ArrayList<Period>();
         periods.add( period );
@@ -254,12 +254,12 @@
         }
         
         log.info( "Using validation rules: " + rules.size() );
-
+        
         Collection<OrganisationUnit> sources = new HashSet<OrganisationUnit>();
         sources.add( source );
         
         return Validator.validate( sources, periods, rules, attributeCombo, null,
-                constantService, expressionService, periodService, dataValueService, dataElementCategoryService, userService, currentUserService );
+            constantService, expressionService, periodService, dataValueService, dataElementCategoryService, userService, currentUserService );
     }
 
     @Override
@@ -422,7 +422,7 @@
 
         Map<SortedSet<ValidationResult>, Set<User>> messageMap = new HashMap<SortedSet<ValidationResult>, Set<User>>();
 
-        for (Map.Entry<User, SortedSet<ValidationResult>> userResultEntry : userResults.entrySet() )
+        for ( Map.Entry<User, SortedSet<ValidationResult>> userResultEntry : userResults.entrySet() )
         {
             Set<User> users = messageMap.get( userResultEntry.getValue() );
 
@@ -432,6 +432,7 @@
 
                 messageMap.put( userResultEntry.getValue(), users );
             }
+            
             users.add( userResultEntry.getKey() );
         }
 
@@ -469,6 +470,7 @@
 
                                     userResults.put( user, resultSet );
                                 }
+                                
                                 resultSet.add( result );
                             }
                         }
@@ -496,6 +498,7 @@
                 return true;
             }
         }
+        
         return false;
     }
 
@@ -534,6 +537,7 @@
         }
         
         log.info( "Alerting users: " + users.size() + ", subject: " + subject );
+        
         messageService.sendMessage( subject, builder.toString(), null, users );
     }
 

=== 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	2014-05-27 02:41:16 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidationRunContext.java	2014-07-16 11:19:08 +0000
@@ -114,7 +114,7 @@
     public String toString()
     {
         return new ToStringBuilder( this, ToStringStyle.SHORT_PREFIX_STYLE )
-            .append( "\n PeriodTypeExtendedMap", (Arrays.toString( periodTypeExtendedMap.entrySet().toArray() )) )
+            .append( "\n PeriodTypeExtendedMap", ( Arrays.toString( periodTypeExtendedMap.entrySet().toArray() ) ) )
             .append( "\n runType", runType )
             .append( "\n lastScheduledRun", lastScheduledRun )
             .append( "\n constantMap", "[" + constantMap.size() + "]" )
@@ -141,7 +141,7 @@
      *
      * @return context object for this run
      */
-    public static ValidationRunContext getNewValidationRunContext( Collection<OrganisationUnit> sources,
+    public static ValidationRunContext getNewContext( Collection<OrganisationUnit> sources,
         Collection<Period> periods, DataElementCategoryOptionCombo attributeCombo, Collection<ValidationRule> rules,
         Map<String, Double> constantMap, ValidationRunType runType, Date lastScheduledRun,
         ExpressionService expressionService, PeriodService periodService,
@@ -166,6 +166,7 @@
         context.cogDimensionConstraints = userService.getCogDimensionConstraints( currentUserCredentials );
         context.coDimensionConstraints = userService.getCoDimensionConstraints( currentUserCredentials );
         context.initialize( sources, periods, rules );
+        
         return context;
     }
 
@@ -243,6 +244,7 @@
                 // Add this rule's data elements to the period extended.
                 periodTypeX.getDataElements().addAll( rule.getCurrentDataElements() );
             }
+            
             // Add the allowed period types for rule's current data elements:
             periodTypeX.getAllowedPeriodTypes().addAll(
                 getAllowedPeriodTypesForDataElements( rule.getCurrentDataElements(), rule.getPeriodType() ) );
@@ -253,6 +255,7 @@
             ValidationRuleExtended ruleX = new ValidationRuleExtended( rule, allowedPastPeriodTypes );
             ruleXMap.put( rule, ruleX );
         }
+        
         return surveillanceRulesPresent;
     }
 
@@ -262,6 +265,7 @@
     private void removeAnyUnneededPeriodTypes()
     {
         Set<PeriodTypeExtended> periodTypeXs = new HashSet<PeriodTypeExtended>( periodTypeExtendedMap.values() );
+        
         for ( PeriodTypeExtended periodTypeX : periodTypeXs )
         {
             if ( periodTypeX.getRules().isEmpty() )
@@ -292,10 +296,12 @@
     private Set<OrganisationUnit> getAllOtherDescendants( Collection<OrganisationUnit> sources )
     {
     	Set<OrganisationUnit> allOtherDescendants = new HashSet<OrganisationUnit>();
+    	
         for ( OrganisationUnit source : sources )
         {
             getOtherDescendantsRecursive( source, sources, allOtherDescendants );
         }
+        
         return allOtherDescendants;
     }
 
@@ -339,12 +345,15 @@
             sourceXs.add( sourceX );
 
             Map<PeriodType, Set<DataElement>> sourceElementsMap = source.getDataElementsInDataSetsByPeriodType();
+            
             for ( PeriodTypeExtended periodTypeX : periodTypeExtendedMap.values() )
             {
                 periodTypeX.getSourceDataElements().put( source, new HashSet<DataElement>() );
+                
                 for ( PeriodType allowedType : periodTypeX.getAllowedPeriodTypes() )
                 {
                     Collection<DataElement> sourceDataElements = sourceElementsMap.get( allowedType );
+                    
                     if ( sourceDataElements != null )
                     {
                         periodTypeX.getSourceDataElements().get( source ).addAll( sourceDataElements );
@@ -365,11 +374,13 @@
     private PeriodTypeExtended getOrCreatePeriodTypeExtended( PeriodType periodType )
     {
         PeriodTypeExtended periodTypeX = periodTypeExtendedMap.get( periodType );
+        
         if ( periodTypeX == null )
         {
             periodTypeX = new PeriodTypeExtended( periodType );
             periodTypeExtendedMap.put( periodType, periodTypeX );
         }
+        
         return periodTypeX;
     }
 
@@ -385,6 +396,7 @@
         PeriodType periodType )
     {
         Collection<PeriodType> allowedPeriodTypes = new HashSet<PeriodType>();
+        
         if ( dataElements != null )
         {
             for ( DataElement dataElement : dataElements )
@@ -398,6 +410,7 @@
                 }
             }
         }
+        
         return allowedPeriodTypes;
     }
 

=== 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	2014-06-02 13:44:57 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/Validator.java	2014-07-16 11:19:08 +0000
@@ -80,7 +80,7 @@
         DataValueService dataValueService, DataElementCategoryService dataElementCategoryService,
         UserService userService, CurrentUserService currentUserService )
     {
-        ValidationRunContext context = ValidationRunContext.getNewValidationRunContext( sources, periods,
+        ValidationRunContext context = ValidationRunContext.getNewContext( sources, periods,
             attributeCombo, rules, constantService.getConstantMap(), ValidationRunType.SCHEDULED, lastScheduledRun,
             expressionService, periodService, dataValueService, dataElementCategoryService, userService, currentUserService );
 

=== 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	2014-05-27 02:41:16 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/ValidatorThread.java	2014-07-16 11:19:08 +0000
@@ -124,6 +124,7 @@
                                     if ( !rightSideValues.isEmpty() || Operator.compulsory_pair.equals( rule.getOperator() ) )
                                     {
                                         Set<Integer> combos = leftSideValues.keySet();
+                                        
                                         if ( Operator.compulsory_pair.equals( rule.getOperator() ) )
                                         {
                                             combos = new HashSet<Integer>( combos );
@@ -155,7 +156,7 @@
                                                     roundSignificant( zeroIfNull( rightSide ) ) ) );
                                             }
 
-                                            log.trace( "-->Evaluated " + rule.getName()
+                                            log.trace( "Evaluated " + rule.getName()
                                                 + ", combo id " + combo + ": "
                                                 + (violation ? "violation" : "OK") + " " + ( leftSide == null ? "(null)" : leftSide.toString() )
                                                 + " " + rule.getOperator() + " " + ( rightSide == null ? "(null)" : rightSide.toString() )
@@ -188,7 +189,7 @@
 
         for ( ValidationRule rule : periodTypeX.getRules() )
         {
-            if ( (ValidationRule.RULE_TYPE_VALIDATION.equals( rule.getRuleType() )) )
+            if ( ( ValidationRule.RULE_TYPE_VALIDATION.equals( rule.getRuleType() ) ) )
             {
                 // For validation-type rules, include only rules where the
                 // organisation collects all the data elements in the rule.
@@ -232,8 +233,7 @@
      * @return true if the rule should be evaluated with this data, false if not
      */
     private boolean evaluateCheck( MapMap<Integer, DataElementOperand, Double> currentValueMapMap,
-                                   MapMap<Integer, DataElementOperand, Date> lastUpdatedMapMap,
-                                   ValidationRule rule )
+        MapMap<Integer, DataElementOperand, Date> lastUpdatedMapMap, ValidationRule rule )
     {
         boolean evaluate = true; // Assume true for now.
 
@@ -316,13 +316,13 @@
      * @param periodTypeX period type being evaluated
      * @param period period being evaluated
      * @param rule ValidationRule being evaluated
-     * @param currentValueMap2 current values already fetched
+     * @param currentValueMap current values already fetched
      * @param sourceDataElements the data elements collected by the organisation
      *        unit
      * @return the right-side values, map by attribute category combo
      */
     private Map<Integer, Double> getRightSideValue( OrganisationUnit source, PeriodTypeExtended periodTypeX, Period period,
-        ValidationRule rule, MapMap<Integer, DataElementOperand, Double> currentValueMap2,
+        ValidationRule rule, MapMap<Integer, DataElementOperand, Double> currentValueMap,
         Collection<DataElement> sourceDataElements )
     {
         Map<Integer, Double> rightSideValues;
@@ -336,7 +336,7 @@
         if ( ValidationRule.RULE_TYPE_VALIDATION.equals( rule.getRuleType() )
             || rule.getRightSide().getDataElementsInExpression().isEmpty() )
         {
-            rightSideValues = getExpressionValueMap( rule.getRightSide(), currentValueMap2, new SetMap<Integer, DataElementOperand>() );
+            rightSideValues = getExpressionValueMap( rule.getRightSide(), currentValueMap, new SetMap<Integer, DataElementOperand>() );
         }
         else
         // ruleType equals SURVEILLANCE, and there are some data elements in the
@@ -373,6 +373,7 @@
                     // Fetch the sequential periods after this prior-year
                     // period.
                     Period sequentialPeriod = new Period( yearlyPeriod );
+                    
                     for ( int sequentialCount = 0; sequentialCount < sequentialSampleCount; sequentialCount++ )
                     {
                         sequentialPeriod = calendarPeriodType.getNextPeriod( sequentialPeriod );
@@ -381,9 +382,10 @@
                     }
                 }
 
-                // Fetch the seqential periods before this period (both this
-                // year and past years):
+                // Fetch the sequential periods before this period (both this
+                // year and past years).
                 Period sequentialPeriod = new Period( yearlyPeriod );
+                
                 for ( int sequentialCount = 0; sequentialCount < sequentialSampleCount; sequentialCount++ )
                 {
                     sequentialPeriod = calendarPeriodType.getPreviousPeriod( sequentialPeriod );
@@ -391,11 +393,12 @@
                         sequentialPeriod, rule, sourceDataElements );
                 }
 
-                // Move to the previous year:
+                // Move to the previous year.
                 yearlyCalendar.set( Calendar.YEAR, yearlyCalendar.get( Calendar.YEAR ) - 1 );
             }
 
             rightSideValues = new HashMap<Integer, Double>();
+            
             for ( Map.Entry<Integer, List<Double>> e : sampleValuesMap.entrySet() )
             {
                 rightSideValues.put( e.getKey(), rightSideAverage( rule, e.getValue(), annualSampleCount, sequentialSampleCount) );
@@ -435,13 +438,13 @@
             Set<DataElement> dataElements = rule.getRightSide().getDataElementsInExpression();
             SetMap<Integer, DataElementOperand> incompleteValuesMap = new SetMap<Integer, DataElementOperand>();
             MapMap<Integer, DataElementOperand, Double> dataValueMapByAttributeCombo = getValueMap2( periodTypeX, dataElements,
-                    sourceDataElements, dataElements, allowedPeriodTypes, period, source, null, incompleteValuesMap );
+                sourceDataElements, dataElements, allowedPeriodTypes, period, source, null, incompleteValuesMap );
             sampleValuesMap.putValueMap( getExpressionValueMap( rule.getRightSide(), dataValueMapByAttributeCombo, incompleteValuesMap ) );
         }
     }
 
     /**
-     * Evaluates an expresssion, returning a map of values by attribute option
+     * Evaluates an expression, returning a map of values by attribute option
      * combo.
      *
      * @param expression expression to evaluate.
@@ -450,21 +453,17 @@
      * @return map of values.
      */
     private Map<Integer, Double> getExpressionValueMap( Expression expression,
-                                                       MapMap<Integer, DataElementOperand, Double> valueMap2,
+                                                       MapMap<Integer, DataElementOperand, Double> valueMap,
                                                        SetMap<Integer, DataElementOperand> incompleteValuesMap )
     {
         Map<Integer, Double> expressionValueMap = new HashMap<Integer, Double>();
 
-        for ( Map.Entry<Integer, Map<DataElementOperand, Double>> e : valueMap2.entrySet() )
+        for ( Map.Entry<Integer, Map<DataElementOperand, Double>> e : valueMap.entrySet() )
         {
-            expressionValueMap.put(
-                    e.getKey(),
-                    context.getExpressionService()
-                            .getExpressionValue(                                    expression,
-                                    e.getValue(),
-                                    context.getConstantMap(),
-                                    null, null, incompleteValuesMap.getSet(
-                                    e.getKey() ) ) );
+            expressionValueMap.put( e.getKey(),
+                context.getExpressionService().getExpressionValue( expression,
+                e.getValue(), context.getConstantMap(), null, null, 
+                incompleteValuesMap.getSet( e.getKey() ) ) );
         }
 
         return expressionValueMap;
@@ -512,11 +511,14 @@
                 sampleValues = sampleValues.subList( lowOutliers, sampleValues.size() - highOutliers );
                 log.trace( "Result: " + Arrays.toString( sampleValues.toArray() ) );
             }
+            
             Double sum = 0.0;
+            
             for ( Double sample : sampleValues )
             {
                 sum += sample;
             }
+            
             average = sum / sampleValues.size();
         }
         
@@ -550,6 +552,7 @@
     {
         Set<DataElement> dataElementsToGet = new HashSet<DataElement>( ruleDataElements );
         dataElementsToGet.retainAll( sourceDataElements );
+        
         log.trace( "getDataValueMapRecursive: source:" + source.getName()
             + " ruleDataElements[" + ruleDataElements.size()
             + "] sourceDataElements[" + sourceDataElements.size()
@@ -557,16 +560,16 @@
             + "] recursiveDataElements[" + recursiveDataElements.size()
             + "] allowedPeriodTypes[" + allowedPeriodTypes.size() + "]" );
 
-        MapMap<Integer, DataElementOperand, Double> dataValueMap2;
+        MapMap<Integer, DataElementOperand, Double> dataValueMap;
         
         if ( dataElementsToGet.isEmpty() )
         {
             // We still might get something recursively
-            dataValueMap2 = new MapMap<Integer, DataElementOperand, Double>();
+            dataValueMap = new MapMap<Integer, DataElementOperand, Double>();
         }
         else
         {
-            dataValueMap2 = context.getDataValueService().getDataValueMapByAttributeCombo( dataElementsToGet,
+            dataValueMap = context.getDataValueService().getDataValueMapByAttributeCombo( dataElementsToGet,
                 period.getStartDate(), source, allowedPeriodTypes, context.getAttributeCombo(),
                 context.getCogDimensionConstraints(), context.getCoDimensionConstraints(), lastUpdatedMap );
         }
@@ -574,6 +577,7 @@
         // See if there are any data elements we need to get recursively:
         Set<DataElement> recursiveDataElementsNeeded = new HashSet<DataElement>( recursiveDataElements );
         recursiveDataElementsNeeded.removeAll( dataElementsToGet );
+        
         if ( !recursiveDataElementsNeeded.isEmpty() )
         {
             int childCount = 0;
@@ -583,8 +587,8 @@
             {
                 Collection<DataElement> childDataElements = periodTypeX.getSourceDataElements().get( child );
                 MapMap<Integer, DataElementOperand, Double> childMap = getValueMap2( periodTypeX,
-                        recursiveDataElementsNeeded, childDataElements, recursiveDataElementsNeeded, allowedPeriodTypes,
-                        period, child, lastUpdatedMap, incompleteValuesMap );
+                    recursiveDataElementsNeeded, childDataElements, recursiveDataElementsNeeded, allowedPeriodTypes,
+                    period, child, lastUpdatedMap, incompleteValuesMap );
 
                 for ( Map.Entry<Integer, Map<DataElementOperand, Double>> entry : childMap.entrySet() )
                 {
@@ -595,8 +599,8 @@
                         DataElementOperand deo = e.getKey();
                         Double childValue = e.getValue();
 
-                        Double baseValue = dataValueMap2.getValue( combo, deo );
-                        dataValueMap2.putEntry( combo, deo, baseValue == null ? childValue : baseValue + childValue );
+                        Double baseValue = dataValueMap.getValue( combo, deo );
+                        dataValueMap.putEntry( combo, deo, baseValue == null ? childValue : baseValue + childValue );
 
                         Integer childValueCount = childValueCounts.getValue( combo, deo );
                         childValueCounts.putEntry( combo, deo, childValueCount == null ? 1 : childValueCount + 1 );
@@ -625,6 +629,6 @@
             }
         }
 
-        return dataValueMap2;
+        return dataValueMap;
     }
 }