← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2054: Implemented blueprint aggregated validation statistics

 

------------------------------------------------------------
revno: 2054
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Sat 2010-09-04 08:30:08 +0200
message:
  Implemented blueprint aggregated validation statistics
added:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/CompositeCounter.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.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/hibernate/HibernateValidationRuleStore.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleServiceTest.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientStoreTest.java
  dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/Counter.java
  dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/RunValidationAction.java
  dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/general.js
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/runValidation.js
  dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/viewValidationResultForm.vm


--
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/common/Grid.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java	2010-09-03 13:45:17 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java	2010-09-04 06:30:08 +0000
@@ -74,6 +74,16 @@
      * @param columnIndex the index of the column.
      */
     List<String> getColumn( int columnIndex );
+    
+    /**
+     * Return the value at the given row index and the given column index.
+     * 
+     * @param rowIndex the row index.
+     * @param columnIndex the column index.
+     * @return the column value.
+     * @throws IllegalArgumentException if the grid does not contain the requested row / column.
+     */
+    String getValue( int rowIndex, int columnIndex );
 
     /**
      * Adds a new column at the end of the grid.

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodService.java	2010-07-25 09:58:51 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodService.java	2010-09-04 06:30:08 +0000
@@ -32,6 +32,7 @@
 import java.util.List;
 
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.source.Source;
 
 /**
@@ -241,6 +242,16 @@
      */
     List<Period> getPeriods( Period lastPeriod, int historyLength );
     
+    /**
+     * Populates the name property of Period with the formatted name for the
+     * Periods in the given collection.
+     * 
+     * @param periods the collection of Periods.
+     * @param format the I18nFormat.
+     * @return a collection of Periods.
+     */
+    Collection<Period> namePeriods( Collection<Period> periods, I18nFormat format );
+    
     // -------------------------------------------------------------------------
     // PeriodType
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java	2010-09-01 10:30:03 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleService.java	2010-09-04 06:30:08 +0000
@@ -29,7 +29,9 @@
 
 import java.util.Collection;
 import java.util.Date;
+import java.util.List;
 
+import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.period.Period;
@@ -48,6 +50,12 @@
     // -------------------------------------------------------------------------
 
     /**
+     * Returns a Grid containing the percentage of aggregated violations. Periods
+     * are listed as columns and Sources are listed as rows.
+     */
+    Grid getAggregateValidationResult( Collection<ValidationResult> results, List<Period> periods, List<? extends Source> sources );
+    
+    /**
      * Validates AggregatedDataValues.
      * 
      * @param startDate the start date.

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleStore.java	2010-08-30 13:04:39 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/validation/ValidationRuleStore.java	2010-09-04 06:30:08 +0000
@@ -61,5 +61,19 @@
      */
     void updateValidationRule( ValidationRule validationRule );
     
+    /**
+     * Returns all ValidationRules which are associated through their left or
+     * right side Expression with the given collection of DataElements.
+     * 
+     * @param dataElements the collection of DataElements.
+     * @return a collection of ValidationRules.
+     */
     Collection<ValidationRule> getValidationRulesByDataElements( Collection<DataElement> dataElements );
+    
+    /**
+     * Returns the number of ValidationRules.
+     * 
+     * @return the number of ValidationRules.
+     */
+    Integer getNumberOfValidationRules();
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java	2010-07-25 09:58:51 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java	2010-09-04 06:30:08 +0000
@@ -35,6 +35,7 @@
 import java.util.List;
 
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.source.Source;
 import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.system.util.Filter;
@@ -231,6 +232,16 @@
         return periods;
     }
     
+    public Collection<Period> namePeriods( Collection<Period> periods, I18nFormat format )
+    {
+        for ( Period period : periods )
+        {
+            period.setName( format.formatPeriod( period ) );
+        }
+        
+        return periods;
+    }
+    
     // -------------------------------------------------------------------------
     // PeriodType
     // -------------------------------------------------------------------------

=== 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	2010-09-01 10:30:03 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/DefaultValidationRuleService.java	2010-09-04 06:30:08 +0000
@@ -32,9 +32,13 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.dataset.DataSet;
@@ -43,8 +47,11 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.source.Source;
+import org.hisp.dhis.system.grid.ListGrid;
+import org.hisp.dhis.system.util.CompositeCounter;
 import org.hisp.dhis.system.util.Filter;
 import org.hisp.dhis.system.util.FilterUtils;
+import org.hisp.dhis.system.util.MathUtils;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -56,6 +63,8 @@
 public class DefaultValidationRuleService
     implements ValidationRuleService
 {
+    private static final Log log = LogFactory.getLog( DefaultValidationRuleService.class );
+    
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -105,6 +114,43 @@
     // -------------------------------------------------------------------------
     // ValidationRule business logic
     // -------------------------------------------------------------------------
+
+    public Grid getAggregateValidationResult( Collection<ValidationResult> results, List<Period> periods, List<? extends Source> sources )
+    {
+        int number = validationRuleStore.getNumberOfValidationRules();
+        
+        Grid grid = new ListGrid();
+        
+        CompositeCounter counter = new CompositeCounter();
+        
+        for ( ValidationResult result : results )
+        {
+            counter.count( result.getPeriod(), result.getSource() );
+        }
+
+        grid.nextRow();
+        grid.addValue( "" );
+        
+        for ( Period period : periods )
+        {
+            grid.addValue( period.getName() );
+        }
+        
+        for ( Source source : sources )
+        {
+            grid.nextRow();
+            grid.addValue( source.getName() );
+            
+            for ( Period period : periods )
+            {
+                double percentage = (double) ( 100 * counter.getCount( period, source ) ) / number;
+                
+                grid.addValue( String.valueOf( MathUtils.getRounded( percentage, 1 ) ) );
+            }
+        }
+        
+        return grid;
+    }
     
     public Collection<ValidationResult> validateAggregate( Date startDate, Date endDate, Collection<? extends Source> sources )
     {
@@ -120,6 +166,8 @@
             {
                 validationViolations.addAll( validateInternal( period, source, validationRules, true ) );
             }
+            
+            log.info( "Validated " + source );
         }
         
         return validationViolations;
@@ -145,6 +193,8 @@
             {
                 validationViolations.addAll( validateInternal( period, source, validationRules, true ) );
             }
+            
+            log.info( "Validated " + source );
         }
         
         return validationViolations;
@@ -167,6 +217,8 @@
                     validationViolations.addAll( validateInternal( period, source, relevantRules, false ) );
                 }
             }
+            
+            log.info( "Validated " + source );
         }
 
         return validationViolations;
@@ -191,6 +243,8 @@
                     validationViolations.addAll( validateInternal( period, source, relevantRules, false ) );
                 }
             }
+            
+            log.info( "Validated " + source );
         }
 
         return validationViolations;

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/hibernate/HibernateValidationRuleStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/hibernate/HibernateValidationRuleStore.java	2010-08-30 13:04:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/validation/hibernate/HibernateValidationRuleStore.java	2010-09-04 06:30:08 +0000
@@ -31,6 +31,7 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import org.hibernate.Hibernate;
 import org.hibernate.Session;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.hibernate.HibernateGenericStore;
@@ -102,8 +103,13 @@
         
         hql = "select distinct v from ValidationRule v join v.rightSide rs join rs.dataElementsInExpression rsd where rsd.id in (:ids)";
 
-        validationRules.addAll( sessionFactory.getCurrentSession().createQuery( hql ).setParameterList( "ids", ids ).list() );
+        validationRules.addAll( getQuery( hql ).setParameterList( "ids", ids ).list() );
         
         return validationRules;
     }
+    
+    public Integer getNumberOfValidationRules()
+    {
+        return (Integer) getSqlQuery( "select count(*) as no from validationrule" ).addScalar( "no", Hibernate.INTEGER ).uniqueResult();
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleServiceTest.java	2010-09-01 07:28:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/validation/ValidationRuleServiceTest.java	2010-09-04 06:30:08 +0000
@@ -34,14 +34,17 @@
 import static junit.framework.Assert.assertTrue;
 import static org.hisp.dhis.expression.Expression.SEPARATOR;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.amplecode.quick.BatchHandler;
 import org.amplecode.quick.BatchHandlerFactory;
 import org.hisp.dhis.DhisTest;
 import org.hisp.dhis.aggregation.AggregatedDataValue;
+import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
@@ -243,7 +246,41 @@
     // ----------------------------------------------------------------------
     // Business logic tests
     // ----------------------------------------------------------------------
+    
+    @Test
+    public void testGetAggregatedValidationResult()
+    {
+        validationRuleService.saveValidationRule( validationRuleA );
+        validationRuleService.saveValidationRule( validationRuleB );
+        validationRuleService.saveValidationRule( validationRuleC );
+        validationRuleService.saveValidationRule( validationRuleD );
 
+        List<Period> periods = new ArrayList<Period>();
+        periods.add( periodA );
+        periods.add( periodB );
+        
+        List<Source> sources = new ArrayList<Source>();
+        sources.add( sourceA );
+        sources.add( sourceB );
+        
+        Collection<ValidationResult> results = new HashSet<ValidationResult>();
+        
+        results.add( new ValidationResult( periodA, sourceA, validationRuleA, 1, 1 ) );
+        results.add( new ValidationResult( periodA, sourceA, validationRuleB, 1, 1 ) );
+        results.add( new ValidationResult( periodA, sourceA, validationRuleC, 1, 1 ) );
+        results.add( new ValidationResult( periodB, sourceB, validationRuleA, 1, 1 ) );
+        results.add( new ValidationResult( periodB, sourceB, validationRuleB, 1, 1 ) );
+        
+        Grid grid = validationRuleService.getAggregateValidationResult( results, periods, sources );
+        
+        // First row is Periods, first column in each row is Source
+        
+        assertEquals( "75.0", grid.getValue( 1, 1 ) );
+        assertEquals( "0.0", grid.getValue( 1, 2 ) );
+        assertEquals( "0.0", grid.getValue( 2, 1 ) );
+        assertEquals( "50.0", grid.getValue( 2, 2 ) );
+    }
+    
     @Test
     public void testValidateAggregatedDateDateSources()
     {

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml	2010-08-31 05:47:11 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml	2010-09-04 06:30:08 +0000
@@ -231,6 +231,10 @@
     <aop:aspect ref="deletionInterceptor">      
       <aop:before pointcut="execution( * org.hisp.dhis.datamart.DataMartService.deleteDataMartExport(..) )" method="intercept"/>
     </aop:aspect>
+
+    <aop:aspect ref="statementInterceptor">
+      <aop:around pointcut="execution( * org.hisp.dhis.datamart.DataMartService.export(..) )" method="intercept" />
+	</aop:aspect>
       
   </aop:config>
     

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientStoreTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientStoreTest.java	2010-09-01 08:32:05 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientStoreTest.java	2010-09-04 06:30:08 +0000
@@ -28,14 +28,13 @@
 package org.hisp.dhis.patient;
 
 import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertTrue;
 import static junit.framework.Assert.assertNotNull;
 import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.assertTrue;
 
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.organisationunit.OrganisationUnitStore;
 import org.junit.Test;
 
 /**

=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2010-05-18 17:59:04 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2010-09-04 06:30:08 +0000
@@ -32,6 +32,7 @@
 
 import org.hibernate.Criteria;
 import org.hibernate.Query;
+import org.hibernate.SQLQuery;
 import org.hibernate.SessionFactory;
 import org.hibernate.criterion.Criterion;
 import org.hibernate.criterion.Restrictions;
@@ -85,6 +86,17 @@
     }
     
     /**
+     * Creates a SqlQuery.
+     * 
+     * @param sql the sql query.
+     * @return a SqlQuery instance.
+     */
+    protected final SQLQuery getSqlQuery( String sql )
+    {
+        return sessionFactory.getCurrentSession().createSQLQuery( sql );
+    }
+    
+    /**
      * Creates a Critera for the implementation Class type.
      * 
      * @return a Criteria instance.

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java	2010-09-03 12:44:40 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java	2010-09-04 06:30:08 +0000
@@ -111,6 +111,16 @@
         return column;
     }
     
+    public String getValue( int rowIndex, int columnIndex )
+    {
+        if ( grid.size() < rowIndex || grid.get( rowIndex ) == null || grid.get( rowIndex ).size() < columnIndex )
+        {
+            throw new IllegalArgumentException( "Grid does not contain the requested row / column" );
+        }
+        
+        return grid.get( rowIndex ).get( columnIndex );
+    }
+    
     public void addColumn( List<String> columnValues )
     {
         verifyGridState();

=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/CompositeCounter.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/CompositeCounter.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/CompositeCounter.java	2010-09-04 06:30:08 +0000
@@ -0,0 +1,66 @@
+package org.hisp.dhis.system.util;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author Lars Helge Overland
+ */
+public class CompositeCounter
+    extends Counter<String>
+{
+    private static final char SEPARATOR = '-';
+    
+    public CompositeCounter()
+    {
+        super();
+    }
+    
+    public int count( Object... objects )
+    {
+        String key = getKey( objects );
+        
+        return super.count( key );
+    }
+    
+    public Integer getCount( Object... objects )
+    {
+        return super.getCount( getKey( objects ) );
+    }
+    
+    private String getKey( Object... objects )
+    {
+        String key = "";
+        
+        for ( Object o : objects )
+        {
+            key += o.hashCode() + SEPARATOR;
+        }
+        
+        return key;
+    }
+}

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/Counter.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/Counter.java	2010-09-01 06:14:47 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/Counter.java	2010-09-04 06:30:08 +0000
@@ -63,6 +63,12 @@
     
     public Integer getCount( T key )
     {
-        return map != null ? map.get( key ) : null;
+        return map != null && map.containsKey( key ) ? map.get( key ) : 0;
+    }
+ 
+    @Override
+    public String toString()
+    {
+        return "[" + map.toString() + "]";
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/RunValidationAction.java'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/RunValidationAction.java	2010-09-01 10:30:03 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/RunValidationAction.java	2010-09-04 06:30:08 +0000
@@ -35,6 +35,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.datamart.DataMartService;
 import org.hisp.dhis.i18n.I18nFormat;
@@ -110,7 +111,7 @@
     {
         this.periodService = periodService;
     }
-
+    
     // -------------------------------------------------------------------------
     // Input/output
     // -------------------------------------------------------------------------
@@ -153,6 +154,13 @@
         return validationResults;
     }
     
+    private Grid aggregateResults;
+
+    public Grid getAggregateResults()
+    {
+        return aggregateResults;
+    }
+
     private boolean aggregate;
 
     public boolean isAggregate()
@@ -182,14 +190,17 @@
 
         if ( aggregate ) // Aggregate data source
         {
-            Collection<OrganisationUnit> organisationUnits = unit.getChildren();
+            List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>( unit.getChildren() );
 
+            List<Period> periods = new ArrayList<Period>( periodService.namePeriods( 
+                periodService.getPeriodsBetweenDates( format.parseDate( startDate ), format.parseDate( endDate ) ), format ) );
+            
+            log.info( "Number of periods: " + periods.size() + ", number of organisation units: " + organisationUnits.size() );
+            
             if ( doDataMart )
             {
                 log.info( "Generating datamart" );
                 
-                Collection<Period> periods = periodService.getPeriodsBetweenDates( format.parseDate( startDate ), format.parseDate( endDate ) );
-                
                 Collection<DataElement> dataElements = validationRuleService.getDataElementsInValidationRules();
                 
                 dataMartService.export( getIdentifiers( DataElement.class, dataElements ), new HashSet<Integer>(), 
@@ -212,6 +223,8 @@
                 validationResults = new ArrayList<ValidationResult>( validationRuleService.validateAggregate( format
                     .parseDate( startDate ), format.parseDate( endDate ), organisationUnits, group ) );
             }
+            
+            aggregateResults = validationRuleService.getAggregateValidationResult( validationResults, periods, organisationUnits );
         }
         else // Captured data source
         {

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties	2010-09-01 10:30:03 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties	2010-09-04 06:30:08 +0000
@@ -175,4 +175,5 @@
 captured_data_info = All children of the selected organisation unit will be included.
 get_updated_data = Get updated aggregated data
 use_existing_data = Use existing aggregated data
-method = Method
\ No newline at end of file
+method = Method
+see_statistics = See statistics
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/general.js'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/general.js	2010-09-01 16:55:23 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/general.js	2010-09-04 06:30:08 +0000
@@ -55,6 +55,7 @@
     
     return null;
 }
+
 function getElementValue( parentElement, childElementName )
 {
     var textNode = parentElement.getElementsByTagName( childElementName )[0].firstChild;

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/runValidation.js'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/runValidation.js	2010-09-01 10:30:03 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/javascript/runValidation.js	2010-09-04 06:30:08 +0000
@@ -39,8 +39,7 @@
     }
     else if ( type == 'input' )
     {
-        document.getElementById( 'message' ).innerHTML = message;
-        document.getElementById( 'message' ).style.display = 'block';
+        setMessage( message );
     }
 }
 
@@ -69,3 +68,22 @@
 		$( '#doDataMart' ).attr( 'disabled', 'disabled' );
 	}
 }
+
+function showAggregateResults()
+{
+	$( 'div#validationResults' ).hide();
+	$( 'div#aggregateResults' ).show();	
+	var button = document.getElementById( "resultTypeButton" );
+	button.onclick = function() { showValidationResults(); };
+	button.value = "See validation";
+}
+
+function showValidationResults()
+{
+	$( 'div#aggregateResults' ).hide();
+	$( 'div#validationResults' ).show();
+	
+	var button = document.getElementById( "resultTypeButton" );
+	button.onclick = function() { showAggregateResults(); };
+	button.value = "See statistics";
+}

=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/viewValidationResultForm.vm'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/viewValidationResultForm.vm	2010-08-30 06:24:45 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/viewValidationResultForm.vm	2010-09-04 06:30:08 +0000
@@ -25,16 +25,18 @@
 		<td><input type="button" value="$i18n.getString( 'generate_workbook' )" style="width:100%"
                 onclick="window.location.href='generateValidationResultWorkbook.action'">
 		</td>
-		<td></td>
+		<td>#if( $aggregate )<input id="resultTypeButton" type="button" value="$i18n.getString( 'see_statistics' )" style="width:100%" onclick="showAggregateResults()">#end</td>
 	</tr>
 	<tr>
 		<td colspan="4" height="15"></td>
 	</tr>
 </table>
-#if ( $mapValidationResults.keySet().size() == 0 )
+#if ( $validationResults.size() == 0 )
 	<span id="info">$i18n.getString( "validation_passed_successfully" )</span>
 #else
 
+<div id="validationResults">
+
 <table class="listTable" style="width:100%">
 	<colgroup>
 	    <col>
@@ -78,4 +80,34 @@
 	</tbody>
 </table>
 
+</div>
+
+<div id="aggregateResults" style="display:none">
+
+#if( $aggregate )
+	
+<table class="listTable" style="width:100%">
+	<thead>
+		#foreach( $col in $aggregateResults.getRow( 0 ) )
+		<th>$col</th>
+		#end
+	</thead>
+	<tbody>
+		#set( $lastIndex = $aggregateResults.rows.size() - 1 )
+		#foreach( $row in $aggregateResults.rows )
+		#if ( $velocityCount <= $lastIndex )
+		<tr style="height:32px">
+			#foreach( $col in $aggregateResults.getRow( $velocityCount ) )
+			<td>$col</td>
+			#end
+		</tr>
+		#end
+		#end
+	</tbody>
+</table>
+
+#end
+
+</div>
+
 #end