← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10020: DataEntry - Reorganised code in Validation

 

------------------------------------------------------------
revno: 10020
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-03-07 12:40:43 +0700
message:
  DataEntry - Reorganised code in Validation
modified:
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.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-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.java	2013-03-06 03:56:21 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/ValidationAction.java	2013-03-07 05:40:43 +0000
@@ -189,24 +189,58 @@
     {
         OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( organisationUnitId );
 
+        DataSet dataSet = dataSetService.getDataSet( dataSetId );
+
         Period selectedPeriod = PeriodType.createPeriodExternalId( periodId );
 
-        if ( orgUnit != null && selectedPeriod != null )
+        Period period = null;
+
+        if ( selectedPeriod != null )
         {
-            Period period = periodService.getPeriod( selectedPeriod.getStartDate(), selectedPeriod.getEndDate(),
+            period = periodService.getPeriod( selectedPeriod.getStartDate(), selectedPeriod.getEndDate(),
                 selectedPeriod.getPeriodType() );
 
-            DataSet dataSet = dataSetService.getDataSet( dataSetId );
-
+            if ( validationCheck( orgUnit, dataSet, period ).equals( INPUT ) )
+            {
+                return INPUT;
+            }
+        }
+
+        if ( multiOrganisationUnit && selectedPeriod != null )
+        {
+            List<OrganisationUnit> children = new ArrayList<OrganisationUnit>( orgUnit.getChildren() );
+
+            Collections.sort( children, IdentifiableObjectNameComparator.INSTANCE );
+
+            for ( OrganisationUnit child : children )
+            {
+                if ( validationCheck( child, dataSet, period ).equals( INPUT ) )
+                {
+                    return INPUT;
+                }
+            }
+        }
+
+        return dataValues.size() == 0 && results.size() == 0 ? SUCCESS : INPUT;
+    }
+
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+
+    private String validationCheck( OrganisationUnit unit, DataSet dataSet, Period period )
+    {
+        if ( unit != null )
+        {
             // ---------------------------------------------------------------------
             // Min-max and outlier analysis
             // ---------------------------------------------------------------------
 
-            dataValues = minMaxOutlierAnalysisService.analyse( getCollection( orgUnit ), dataSet.getDataElements(),
+            dataValues = minMaxOutlierAnalysisService.analyse( getCollection( unit ), dataSet.getDataElements(),
                 getCollection( period ), null );
 
             log.debug( "Number of outlier values: " + dataValues.size() );
-            
+
             if ( dataValues.size() > 0 )
             {
                 return INPUT;
@@ -216,7 +250,7 @@
             // Validation rule analysis
             // ---------------------------------------------------------------------
 
-            results = new ArrayList<ValidationResult>( validationRuleService.validate( dataSet, period, orgUnit ) );
+            results = new ArrayList<ValidationResult>( validationRuleService.validate( dataSet, period, unit ) );
 
             log.debug( "Number of validation violations: " + results.size() );
 
@@ -235,71 +269,12 @@
                     rightsideFormulaMap.put( rule.getId(), expressionService.getExpressionDescription( rule
                         .getRightSide().getExpression() ) );
                 }
-                
+
                 return INPUT;
             }
         }
 
-        if ( multiOrganisationUnit && selectedPeriod != null )
-        {
-            List<OrganisationUnit> children = new ArrayList<OrganisationUnit>( orgUnit.getChildren() );
-            
-            Collections.sort( children, IdentifiableObjectNameComparator.INSTANCE );
-            
-            for ( OrganisationUnit child : children )
-            {
-                if ( child != null )
-                {
-                    Period period = periodService.getPeriod( selectedPeriod.getStartDate(),
-                        selectedPeriod.getEndDate(), selectedPeriod.getPeriodType() );
-
-                    DataSet dataSet = dataSetService.getDataSet( dataSetId );
-
-                    // ---------------------------------------------------------------------
-                    // Min-max and outlier analysis
-                    // ---------------------------------------------------------------------
-
-                    dataValues = minMaxOutlierAnalysisService.analyse( getCollection( orgUnit ), dataSet
-                        .getDataElements(), getCollection( period ), null );
-
-                    log.debug( "Number of outlier values: " + dataValues.size() );
-
-                    if ( dataValues.size() > 0 )
-                    {
-                        return INPUT;
-                    }
-                    
-                    // ---------------------------------------------------------------------
-                    // Validation rule analysis
-                    // ---------------------------------------------------------------------
-
-                    results = new ArrayList<ValidationResult>( validationRuleService
-                        .validate( dataSet, period, orgUnit ) );
-
-                    log.debug( "Number of validation violations: " + results.size() );
-
-                    if ( results.size() > 0 )
-                    {
-                        leftsideFormulaMap = new HashMap<Integer, String>( results.size() );
-                        rightsideFormulaMap = new HashMap<Integer, String>( results.size() );
-
-                        for ( ValidationResult result : results )
-                        {
-                            ValidationRule rule = result.getValidationRule();
-
-                            leftsideFormulaMap.put( rule.getId(), expressionService.getExpressionDescription( rule
-                                .getLeftSide().getExpression() ) );
-
-                            rightsideFormulaMap.put( rule.getId(), expressionService.getExpressionDescription( rule
-                                .getRightSide().getExpression() ) );
-                        }
-                        
-                        return INPUT;
-                    }
-                }
-            }
-        }
-
-        return dataValues.size() == 0 && results.size() == 0 ? SUCCESS : INPUT;
+        return NONE;
     }
+
 }