dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #26369
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13069: in edit orgUnitGroup associations, merge with currentUser OU-tree, don't overwrite other OU-trees
------------------------------------------------------------
revno: 13069
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-11-29 14:31:33 +0100
message:
in edit orgUnitGroup associations, merge with currentUser OU-tree, don't overwrite other OU-trees
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroup/UpdateOrganisationUnitGroupAction.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-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupService.java 2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupService.java 2013-11-29 13:31:33 +0000
@@ -273,4 +273,6 @@
int getOrganisationUnitGroupSetCount();
int getOrganisationUnitGroupSetCountByName( String name );
+
+ void mergeWithCurrentUserOrganisationUnits( OrganisationUnitGroup organisationUnitGroup, Collection<OrganisationUnit> mergeOrganisationUnits );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitGroupService.java 2013-11-29 13:31:33 +0000
@@ -28,21 +28,22 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.i18n.I18nUtils.getCountByName;
-import static org.hisp.dhis.i18n.I18nUtils.getObjectsBetween;
-import static org.hisp.dhis.i18n.I18nUtils.getObjectsBetweenByName;
-import static org.hisp.dhis.i18n.I18nUtils.i18n;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
import org.hisp.dhis.common.GenericIdentifiableObjectStore;
import org.hisp.dhis.i18n.I18nService;
import org.hisp.dhis.system.util.Filter;
import org.hisp.dhis.system.util.FilterUtils;
+import org.hisp.dhis.user.CurrentUserService;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.hisp.dhis.i18n.I18nUtils.*;
+
/**
* @author Torgeir Lorange Ostby
* @version $Id: DefaultOrganisationUnitGroupService.java 5017 2008-04-25
@@ -78,6 +79,22 @@
i18nService = service;
}
+ private CurrentUserService currentUserService;
+
+ @Autowired
+ public void setCurrentUserService( CurrentUserService currentUserService )
+ {
+ this.currentUserService = currentUserService;
+ }
+
+ private OrganisationUnitService organisationUnitService;
+
+ @Autowired
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
// -------------------------------------------------------------------------
// OrganisationUnitGroup
// -------------------------------------------------------------------------
@@ -324,4 +341,24 @@
{
return getObjectsBetweenByName( i18nService, organisationUnitGroupSetStore, name, first, max );
}
+
+ @Override
+ public void mergeWithCurrentUserOrganisationUnits( OrganisationUnitGroup organisationUnitGroup, Collection<OrganisationUnit> mergeOrganisationUnits )
+ {
+ Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>( organisationUnitGroup.getMembers() );
+
+ Set<OrganisationUnit> userOrganisationUnits = new HashSet<OrganisationUnit>();
+
+ for ( OrganisationUnit organisationUnit : currentUserService.getCurrentUser().getOrganisationUnits() )
+ {
+ userOrganisationUnits.addAll( organisationUnitService.getOrganisationUnitsWithChildren( organisationUnit.getUid() ) );
+ }
+
+ organisationUnits.removeAll( userOrganisationUnits );
+ organisationUnits.addAll( mergeOrganisationUnits );
+
+ organisationUnitGroup.updateOrganisationUnits( organisationUnits );
+
+ updateOrganisationUnitGroup( organisationUnitGroup );
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroup/UpdateOrganisationUnitGroupAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroup/UpdateOrganisationUnitGroupAction.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitgroup/UpdateOrganisationUnitGroupAction.java 2013-11-29 13:31:33 +0000
@@ -46,7 +46,7 @@
/**
* @author Torgeir Lorange Ostby
*/
-@SuppressWarnings( "serial" )
+@SuppressWarnings("serial")
public class UpdateOrganisationUnitGroupAction
extends ActionSupport
{
@@ -154,7 +154,7 @@
Collection<OrganisationUnit> selectedOrganisationUnits = selectionTreeManager
.getReloadedSelectedOrganisationUnits();
- organisationUnitGroup.updateOrganisationUnits( new HashSet<OrganisationUnit>( selectedOrganisationUnits ) );
+ organisationUnitGroupService.mergeWithCurrentUserOrganisationUnits( organisationUnitGroup, selectedOrganisationUnits );
if ( jsonAttributeValues != null )
{