=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/DataIntegrityService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/DataIntegrityService.java 2009-12-02 15:08:11 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/DataIntegrityService.java 2010-03-19 04:15:47 +0000 @@ -85,7 +85,7 @@ /** * Gets all indicators with identical numerator and denominator. */ - Collection getIndicatorsWithIdenticalFormulas(); + Collection> getIndicatorsWithIdenticalFormulas(); /** * Gets all indicators which are not assigned to any groups. === modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java' --- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java 2010-03-18 09:31:22 +0000 +++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java 2010-03-19 04:15:47 +0000 @@ -61,14 +61,15 @@ /** * @author Lars Helge Overland - * @version $Id: DefaultDataIntegrityService.java 2010-03-18 11:52:20Z Chau Thu Tran $ + * @version $Id: DefaultDataIntegrityService.java 2010-03-18 11:52:20Z Chau Thu + * Tran $ */ @Transactional public class DefaultDataIntegrityService implements DataIntegrityService { private static final String FORMULA_SEPARATOR = "#"; - + // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -100,21 +101,21 @@ { this.organisationUnitService = organisationUnitService; } - + private OrganisationUnitGroupService organisationUnitGroupService; public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService ) { this.organisationUnitGroupService = organisationUnitGroupService; } - + private ValidationRuleService validationRuleService; public void setValidationRuleService( ValidationRuleService validationRuleService ) { this.validationRuleService = validationRuleService; } - + private ExpressionService expressionService; public void setExpressionService( ExpressionService expressionService ) @@ -137,22 +138,22 @@ public Collection getDataElementsWithoutGroups() { - return dataElementService.getDataElementsWithoutGroups(); + return dataElementService.getDataElementsWithoutGroups(); } - + public Map> getDataElementsAssignedToDataSetsWithDifferentPeriodTypes() { Collection dataElements = dataElementService.getAllDataElements(); - + Collection dataSets = dataSetService.getAllDataSets(); - + Map> targets = new HashMap>(); - + for ( DataElement element : dataElements ) { final Set targetPeriodTypes = new HashSet(); final Collection targetDataSets = new HashSet(); - + for ( DataSet dataSet : dataSets ) { if ( dataSet.getDataElements().contains( element ) ) @@ -161,13 +162,13 @@ targetDataSets.add( dataSet ); } } - + if ( targetPeriodTypes.size() > 1 ) { targets.put( element, targetDataSets ); - } + } } - + return targets; } @@ -178,25 +179,25 @@ public Collection getDataSetsNotAssignedToOrganisationUnits() { Collection dataSets = dataSetService.getAllDataSets(); - + return FilterUtils.filter( dataSets, new Filter() + { + public boolean retain( DataSet object ) { - public boolean retain( DataSet object ) - { - return object.getSources() == null || object.getSources().size() == 0; - } - } ); + return object.getSources() == null || object.getSources().size() == 0; + } + } ); } - + // ------------------------------------------------------------------------- // Indicator // ------------------------------------------------------------------------- - public Collection getIndicatorsWithIdenticalFormulas() + public Collection> getIndicatorsWithIdenticalFormulas() { Hashtable formulas = new Hashtable(); - Set targets = new HashSet(); + Hashtable> targets = new Hashtable>(); Collection indicators = indicatorService.getAllIndicators(); @@ -205,9 +206,19 @@ final String formula = indicator.getNumerator() + FORMULA_SEPARATOR + indicator.getDenominator(); if(formulas.containsKey( formula )) - { - targets.add (formulas.get( formula )); - targets.add( indicator ); + { + if(targets.containsKey( formula )){ + targets.get( formula ).add( indicator ); + } + else{ + Set elements = new HashSet(); + + elements.add( indicator ); + elements.add (formulas.get( formula )); + + targets.put( formula, elements); + targets.get( formula ).add( indicator ); + } } else { @@ -215,48 +226,48 @@ } } - return targets; + return targets.values(); } public Collection getIndicatorsWithoutGroups() { return indicatorService.getIndicatorsWithoutGroups(); } - + public Map getInvalidIndicatorNumerators() { Map invalids = new HashMap(); - + for ( Indicator indicator : indicatorService.getAllIndicators() ) { String result = expressionService.expressionIsValid( indicator.getNumerator() ); - + if ( !result.equals( ExpressionService.VALID ) ) { invalids.put( indicator, result ); } } - + return invalids; } public Map getInvalidIndicatorDenominators() { Map invalids = new HashMap(); - + for ( Indicator indicator : indicatorService.getAllIndicators() ) { String result = expressionService.expressionIsValid( indicator.getDenominator() ); - + if ( !result.equals( ExpressionService.VALID ) ) { invalids.put( indicator, result ); } } - + return invalids; } - + // ------------------------------------------------------------------------- // OrganisationUnit // ------------------------------------------------------------------------- @@ -264,52 +275,55 @@ public Collection getOrganisationUnitsWithCyclicReferences() { Collection organisationUnits = organisationUnitService.getAllOrganisationUnits(); - + Set cyclic = new HashSet(); - + Set visited = new HashSet(); - + OrganisationUnit parent = null; - + for ( OrganisationUnit unit : organisationUnits ) { parent = unit; - - while ( ( parent = parent.getParent() ) != null ) + + while ( (parent = parent.getParent()) != null ) { if ( parent.equals( unit ) ) // Cyclic reference { cyclic.add( unit ); - break; + break; } - else if ( visited.contains( parent ) ) // Ends in cyclic reference but not part of it + else if ( visited.contains( parent ) ) // Ends in cyclic + // reference but not part + // of it { break; } - else // Remember visited + else + // Remember visited { visited.add( parent ); } } - + visited.clear(); } - + return cyclic; } public Collection getOrphanedOrganisationUnits() { Collection organisationUnits = organisationUnitService.getAllOrganisationUnits(); - + return FilterUtils.filter( organisationUnits, new Filter() + { + public boolean retain( OrganisationUnit object ) { - public boolean retain( OrganisationUnit object ) - { - return object.getParent() == null && ( object.getChildren() == null || object.getChildren().size() == 0 ); - } - } ); + return object.getParent() == null && (object.getChildren() == null || object.getChildren().size() == 0); + } + } ); } public Collection getOrganisationUnitsWithoutGroups() @@ -319,12 +333,13 @@ public Collection getOrganisationUnitsViolatingCompulsoryGroupSets() { - Collection groupSets = organisationUnitGroupService.getCompulsoryOrganisationUnitGroupSets(); - + Collection groupSets = organisationUnitGroupService + .getCompulsoryOrganisationUnitGroupSets(); + Collection organisationUnits = organisationUnitService.getAllOrganisationUnits(); - + Set targets = new HashSet(); - + for ( OrganisationUnit unit : organisationUnits ) { for ( OrganisationUnitGroupSet groupSet : groupSets ) @@ -335,28 +350,29 @@ } } } - + return targets; } public Collection getOrganisationUnitsViolatingExclusiveGroupSets() - { + { Collection groupSets = organisationUnitGroupService.getAllOrganisationUnitGroupSets(); Set targets = new HashSet(); for ( OrganisationUnitGroupSet groupSet : groupSets ) { - targets.addAll( getDuplicates( new ArrayList( groupSet.getOrganisationUnits() ), new OrganisationUnitNameComparator() ) ); + targets.addAll( getDuplicates( new ArrayList( groupSet.getOrganisationUnits() ), + new OrganisationUnitNameComparator() ) ); } - + return targets; } public Collection getOrganisationUnitGroupsWithoutGroupSets() { Collection groups = organisationUnitGroupService.getAllOrganisationUnitGroups(); - + return FilterUtils.filter( groups, new OrganisationUnitGroupWithoutGroupSetFilter() ); } @@ -367,47 +383,49 @@ public Collection getValidationRulesWithoutGroups() { Collection validationRules = validationRuleService.getAllValidationRules(); - + return FilterUtils.filter( validationRules, new Filter() + { + public boolean retain( ValidationRule object ) { - public boolean retain( ValidationRule object ) - { - return object.getGroups() == null || object.getGroups().size() == 0; - } - } ); + return object.getGroups() == null || object.getGroups().size() == 0; + } + } ); } - + public Map getInvalidValidationRuleLeftSideExpressions() { Map invalids = new HashMap(); - + for ( ValidationRule rule : validationRuleService.getAllValidationRules() ) { String result = expressionService.expressionIsValid( rule.getLeftSide().getExpression() ); - + if ( !result.equals( ExpressionService.VALID ) ) { invalids.put( rule, result ); } } - + return invalids; } - + public Map getInvalidValidationRuleRightSideExpressions() { Map invalids = new HashMap(); - + for ( ValidationRule rule : validationRuleService.getAllValidationRules() ) { String result = expressionService.expressionIsValid( rule.getRightSide().getExpression() ); - + if ( !result.equals( ExpressionService.VALID ) ) { invalids.put( rule, result ); } } - + return invalids; } } + + === modified file 'dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/dataintegrity/DataIntegrityServiceTest.java' --- dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/dataintegrity/DataIntegrityServiceTest.java 2010-01-20 10:06:43 +0000 +++ dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/dataintegrity/DataIntegrityServiceTest.java 2010-03-19 04:15:47 +0000 @@ -280,7 +280,7 @@ @Test public void testGetIndicatorsWithIdenticalFormulas() { - Collection expected = dataIntegrityService.getIndicatorsWithIdenticalFormulas(); + Collection> expected = dataIntegrityService.getIndicatorsWithIdenticalFormulas(); assertTrue( message( expected ), equals( expected, indicatorC ) ); } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/dataintegrity/GetDataIntegrityAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/dataintegrity/GetDataIntegrityAction.java 2009-12-02 15:08:11 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/dataintegrity/GetDataIntegrityAction.java 2010-03-19 04:15:47 +0000 @@ -90,9 +90,9 @@ return dataElementsAssignedToDataSetsWithDifferentPeriodTypes; } - private Collection indicatorsWithIdenticalFormulas; + private Collection> indicatorsWithIdenticalFormulas; - public Collection getIndicatorsWithIdenticalFormulas() + public Collection> getIndicatorsWithIdenticalFormulas() { return indicatorsWithIdenticalFormulas; } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/dataIntegrity.js' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/dataIntegrity.js 2010-01-26 21:17:32 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/dataIntegrity.js 2010-03-19 04:15:47 +0000 @@ -59,4 +59,4 @@ } $( "#" + id + "Div" ).hide(); -} +} \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/responseDataIntegrity.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/responseDataIntegrity.vm 2010-01-26 14:30:54 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/responseDataIntegrity.vm 2010-03-19 04:15:47 +0000 @@ -7,6 +7,17 @@ ] #end +#macro( violationWithCollection $name $list ) +#set( $listSize = $list.size() ) +"${name}": [ +#foreach( $o in $list ) +#set( $oSize = $o.size() ) +"#foreach( $p in $o ) ${p.name} #if( $velocityCount < $oSize ), #end +#end "#if( $velocityCount < $listSize ),#end +#end +] +#end + #macro( violationWithMap $name $map ) #set( $size = $map.keySet().size() ) "${name}": [ @@ -31,7 +42,7 @@ #violation( "dataElementsWithoutGroups" $dataElementsWithoutGroups ), #violationWithMapList( "dataElementsAssignedToDataSetsWithDifferentPeriodTypes" $dataElementsAssignedToDataSetsWithDifferentPeriodTypes ), #violation( "dataSetsNotAssignedToOrganisationUnits" $dataSetsNotAssignedToOrganisationUnits ), - #violation( "indicatorsWithIdenticalFormulas" $indicatorsWithIdenticalFormulas ), + #violationWithCollection( "indicatorsWithIdenticalFormulas" $indicatorsWithIdenticalFormulas ), #violation( "indicatorsWithoutGroups" $indicatorsWithoutGroups ), #violationWithMap( "invalidIndicatorNumerators" $invalidIndicatorNumerators ), #violationWithMap( "invalidIndicatorDenominators" $invalidIndicatorDenominators ),