=== 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-01-19 21:48:28 +0000 +++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java 2010-01-19 23:07:17 +0000 @@ -154,6 +154,8 @@ return dataElements; } + // TODO re-implement using new model + public Collection getDataElementsWithoutGroups() { Collection groups = dataElementService.getAllDataElementGroups(); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java 2010-01-19 21:48:28 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dimension/DefaultDimensionService.java 2010-01-19 23:07:17 +0000 @@ -27,6 +27,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import static org.hisp.dhis.dimension.DimensionType.CATEGORY; +import static org.hisp.dhis.dimension.DimensionType.DATAELEMENTGROUPSET; +import static org.hisp.dhis.dimension.DimensionType.INDICATORGROUPSET; + import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -40,8 +44,6 @@ import org.hisp.dhis.dataelement.DataElementService; import org.hisp.dhis.system.util.ConversionUtils; -import static org.hisp.dhis.dimension.DimensionType.*; - /** * @author Lars Helge Overland * @version $Id: Indicator.java 5540 2008-08-19 10:47:07Z larshelg $ @@ -131,7 +133,7 @@ return dataElements; } - + // ------------------------------------------------------------------------- // Supportive methods // ------------------------------------------------------------------------- === added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ListUtils.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ListUtils.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ListUtils.java 2010-01-19 23:07:17 +0000 @@ -0,0 +1,96 @@ +package org.hisp.dhis.system.util; + +/* + * Copyright (c) 2004-2007, 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. + */ + +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * @author Lars Helge Overland + */ +public class ListUtils +{ + /** + * Checks whether the given list contains duplicates. List entries are compared + * using the given comparator. + * + * @param list the list. + * @param comparator the comparator. + * @return true if the list contains duplicates, false if not. + */ + public static boolean containsDuplicates( List list, Comparator comparator ) + { + Collections.sort( list, comparator ); + + T previous = null; + + for ( T entry : list ) + { + if ( previous != null && previous.equals( entry ) ) + { + return true; + } + + previous = entry; + } + + return false; + } + + /** + * Returns the duplicates in the given list. List entries are compared + * using the given comparator. + * + * @param list the list. + * @param comparator the comparator. + * @return a set of duplicates from the given list. + */ + public static Set getDuplicates( List list, Comparator comparator ) + { + Set duplicates = new HashSet(); + + Collections.sort( list, comparator ); + + T previous = null; + + for ( T entry : list ) + { + if ( previous != null && previous.equals( entry ) ) + { + duplicates.add( entry ); + } + + previous = entry; + } + + return duplicates; + } +} === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroupset/ValidateGroupSetAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroupset/ValidateGroupSetAction.java 2009-08-20 08:17:49 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroupset/ValidateGroupSetAction.java 2010-01-19 23:07:17 +0000 @@ -29,13 +29,14 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; +import java.util.List; import org.hisp.dhis.i18n.I18n; import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitGroup; import org.hisp.dhis.organisationunit.OrganisationUnitGroupService; import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet; +import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator; +import org.hisp.dhis.system.util.ListUtils; import com.opensymphony.xwork2.ActionSupport; @@ -56,7 +57,7 @@ { this.organisationUnitGroupService = organisationUnitGroupService; } - + // ------------------------------------------------------------------------- // Input // ------------------------------------------------------------------------- @@ -89,13 +90,6 @@ this.compulsory = compulsory; } - private boolean exclusive; - - public void setExclusive( boolean exclusive ) - { - this.exclusive = exclusive; - } - private Collection selectedGroups; public void setSelectedGroups( Collection selectedGroups ) @@ -183,40 +177,29 @@ return INPUT; } - // -------------------------------------------------------------------------------- + // --------------------------------------------------------------------- // When adding or updating an exclusive group set any unit in the - // selected groups - // can not be a member of more than one group - // -------------------------------------------------------------------------------- + // selected groups can not be a member of more than one group + // --------------------------------------------------------------------- - if ( exclusive && selectedGroups != null && selectedGroups.size() > 0 ) - { - Collection allUnitsInGroupSet = new ArrayList(); + if ( selectedGroups != null && selectedGroups.size() > 0 ) + { + List units = new ArrayList(); for ( String groupId : selectedGroups ) { - OrganisationUnitGroup group = organisationUnitGroupService.getOrganisationUnitGroup( Integer - .parseInt( groupId ) ); - - allUnitsInGroupSet.addAll( group.getMembers() ); + units.addAll( organisationUnitGroupService.getOrganisationUnitGroup( Integer.parseInt( groupId ) ).getMembers() ); } - Iterator unitIterator = allUnitsInGroupSet.iterator(); - - while ( unitIterator.hasNext() ) + Collection duplicates = ListUtils.getDuplicates( units, new OrganisationUnitNameComparator() ); + + if ( duplicates.size() > 0 ) { - OrganisationUnit unit = unitIterator.next(); - - unitIterator.remove(); - - if ( allUnitsInGroupSet.contains( unit ) ) - { - message = i18n.getString( "the_group_set_can_not_be_creat_bec_it_is_exc_and" ) + " " - + unit.getShortName() + " " + i18n.getString( "is_a_member_of_more_than_one_selected_group" ); - - return INPUT; - } - } + message = i18n.getString( "the_group_set_can_not_be_creat_bec_it_is_exc_and" ) + " " + + duplicates.iterator().next().getShortName() + " " + i18n.getString( "is_a_member_of_more_than_one_selected_group" ); + + return INPUT; + } } message = "Everything's ok";