=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2011-05-05 21:14:56 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2011-05-30 18:34:15 +0000 @@ -224,6 +224,34 @@ // Logic // ------------------------------------------------------------------------- + public void addDataElementGroup( DataElementGroup group ) + { + groups.add( group ); + group.getMembers().add( this ); + } + + public void removeDataElementGroup( DataElementGroup group ) + { + groups.remove( group ); + group.getMembers().remove( this ); + } + + public void updateDataElementGroups( Set updates ) + { + for ( DataElementGroup group : new HashSet( groups ) ) + { + if ( !updates.contains( group ) ) + { + removeDataElementGroup( group ); + } + } + + for ( DataElementGroup group : updates ) + { + addDataElementGroup( group ); + } + } + /** * Returns the value type. If value type is int and the number type exists, * the number type is returned, if the type is int and the number type does === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java 2011-05-05 21:14:56 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java 2011-05-30 18:34:15 +0000 @@ -77,6 +77,34 @@ // Logic // ------------------------------------------------------------------------- + public void addIndicatorGroup( IndicatorGroup group ) + { + groups.add( group ); + group.getMembers().add( this ); + } + + public void removeIndicatorGroup( IndicatorGroup group ) + { + groups.remove( group ); + group.getMembers().remove( this ); + } + + public void updateIndicatorGroups( Set updates ) + { + for ( IndicatorGroup group : new HashSet( groups ) ) + { + if ( !updates.contains( group ) ) + { + removeIndicatorGroup( group ); + } + } + + for ( IndicatorGroup group : updates ) + { + addIndicatorGroup( group ); + } + } + public boolean isAnnualized() { return annualized != null && annualized; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2011-05-05 21:14:56 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2011-05-30 18:34:15 +0000 @@ -120,6 +120,34 @@ // Logic // ------------------------------------------------------------------------- + public void addOrganisationUnit( OrganisationUnit unit ) + { + organisationUnits.add( unit ); + unit.getUsers().add( this ); + } + + public void removeOrganisationUnit( OrganisationUnit unit ) + { + organisationUnits.remove( unit ); + unit.getUsers().remove( this ); + } + + public void updateOrganisationUnits( Set updates ) + { + for ( OrganisationUnit unit : new HashSet( organisationUnits ) ) + { + if ( !updates.contains( unit ) ) + { + removeOrganisationUnit( unit ); + } + } + + for ( OrganisationUnit unit : updates ) + { + addOrganisationUnit( unit ); + } + } + /** * Returns the concatenated first name and surname. */ === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/AssignGroupsForDataElementAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/AssignGroupsForDataElementAction.java 2010-12-13 06:40:41 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelementgroup/AssignGroupsForDataElementAction.java 2011-05-30 18:34:15 +0000 @@ -38,13 +38,10 @@ /** * @author Tran Thanh Tri - * @version $Id: AssignGroupsForDataElementAction.java 2869 2010-03-27 14:26:09Z Chau Thu Tran $ */ - public class AssignGroupsForDataElementAction implements Action { - // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -78,32 +75,19 @@ public String execute() throws Exception { - DataElement dataElement = dataElementService.getDataElement( dataElementId ); - Set selectedGroups = new HashSet(); for ( Integer id : dataElementGroups ) { - DataElementGroup dataElementGroup = dataElementService.getDataElementGroup( id ); - - selectedGroups.add( dataElementGroup ); - - dataElementGroup.getMembers().add( dataElement ); - - dataElementService.updateDataElementGroup( dataElementGroup ); - - } - - SetremoveGroups = new HashSet( dataElementService - .getGroupsContainingDataElement( dataElement ) ); - removeGroups.removeAll( selectedGroups ); - - for ( DataElementGroup removeGroup : removeGroups ) - { - removeGroup.getMembers().remove( dataElement ); - dataElementService.updateDataElementGroup( removeGroup ); - } - + selectedGroups.add( dataElementService.getDataElementGroup( id ) ); + } + + DataElement dataElement = dataElementService.getDataElement( dataElementId ); + + dataElement.updateDataElementGroups( selectedGroups ); + + dataElementService.updateDataElement( dataElement ); + return SUCCESS; } } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicatorgroup/AssignGroupsForIndicatorAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicatorgroup/AssignGroupsForIndicatorAction.java 2010-12-13 06:40:41 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicatorgroup/AssignGroupsForIndicatorAction.java 2011-05-30 18:34:15 +0000 @@ -38,13 +38,10 @@ /** * @author Tran Thanh Tri - * @version $Id: AssignGroupsForIndicatorAction.java 2869 2010-03-27 15:01:079Z - * Chau Thu Tran $ */ public class AssignGroupsForIndicatorAction implements Action { - // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -78,34 +75,19 @@ public String execute() throws Exception { - - Indicator indicator = indicatorService.getIndicator( indicatorId ); - Set selectedGroups = new HashSet(); for ( Integer id : indicatorGroups ) { - IndicatorGroup group = indicatorService.getIndicatorGroup( id ); - - selectedGroups.add( group ); - - group.getMembers().add( indicator ); - - indicatorService.updateIndicatorGroup( group ); - - } - - Set removeGroups = new HashSet( indicatorService - .getGroupsContainingIndicator( indicator ) ); - removeGroups.removeAll( selectedGroups ); - - for ( IndicatorGroup removeGroup : removeGroups ) - { - removeGroup.getMembers().remove( indicator ); - indicatorService.updateIndicatorGroup( removeGroup ); - } - + selectedGroups.add( indicatorService.getIndicatorGroup( id ) ); + } + + Indicator indicator = indicatorService.getIndicator( indicatorId ); + + indicator.updateIndicatorGroups( selectedGroups ); + + indicatorService.updateIndicator( indicator ); + return SUCCESS; } - } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java 2011-04-01 03:10:08 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserAction.java 2011-05-30 18:34:15 +0000 @@ -175,7 +175,7 @@ user.setFirstName( firstName ); user.setEmail( email ); user.setPhoneNumber( phoneNumber ); - user.setOrganisationUnits( new HashSet( orgUnits ) ); + user.updateOrganisationUnits( new HashSet( orgUnits ) ); UserCredentials userCredentials = new UserCredentials(); userCredentials.setUser( user ); === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java 2011-04-01 03:10:08 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserAction.java 2011-05-30 18:34:15 +0000 @@ -167,7 +167,7 @@ user.setFirstName( firstName ); user.setEmail( email ); user.setPhoneNumber( phoneNumber ); - user.setOrganisationUnits( new HashSet( units ) ); + user.updateOrganisationUnits( new HashSet( units ) ); UserCredentials userCredentials = userService.getUserCredentials( user );