dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18079
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7472: Removing charts and map views when user is deleted. Impl user group deletion handler.
------------------------------------------------------------
revno: 7472
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-07-01 13:33:07 +0200
message:
Removing charts and map views when user is deleted. Impl user group deletion handler.
added:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserGroupDeletionHandler.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroup.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserDeletionHandler.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/User.hbm.xml
dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java
dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/MapViewDeletionHandler.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/ChartDeletionHandler.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java
dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/pom.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserGroupAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserGroupAction.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/chart/ChartService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java 2012-05-29 12:04:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java 2012-07-01 11:33:07 +0000
@@ -38,6 +38,7 @@
import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
+import org.hisp.dhis.user.User;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.PlotOrientation;
@@ -93,4 +94,6 @@
int getChartCount();
int getChartCountByName( String name );
+
+ Collection<Chart> getChartsByUser( User user );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java 2012-06-06 13:31:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java 2012-07-01 11:33:07 +0000
@@ -31,6 +31,8 @@
import java.util.Date;
import java.util.List;
+import org.hisp.dhis.user.User;
+
/**
* @author Lars Helge Overland
*/
@@ -131,4 +133,11 @@
* @return the number of objects equal or newer than given date.
*/
long getCountByLastUpdated( Date lastUpdated );
+
+ /**
+ * Retrieves objects associated with the given user.
+ *
+ * @param user the user.
+ */
+ Collection<T> getByUser( User user );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java 2012-04-29 18:04:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java 2012-07-01 11:33:07 +0000
@@ -29,6 +29,7 @@
import org.hisp.dhis.aggregation.AggregatedMapValue;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.user.User;
import java.util.Collection;
import java.util.Set;
@@ -156,6 +157,8 @@
Collection<MapView> getSystemAndUserMapViews();
Collection<MapView> getMapViewsByFeatureType( String featureType );
+
+ Collection<MapView> getMapViewsByUser( User user );
// -------------------------------------------------------------------------
// MapLayer
=== 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 2012-05-29 21:23:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2012-07-01 11:33:07 +0000
@@ -79,6 +79,8 @@
private UserCredentials userCredentials;
+ private Set<UserGroup> groups = new HashSet<UserGroup>();
+
/**
* All OrgUnits where the user could belong
* <p/>
@@ -341,6 +343,16 @@
this.userCredentials = userCredentials;
}
+ public Set<UserGroup> getGroups()
+ {
+ return groups;
+ }
+
+ public void setGroups( Set<UserGroup> groups )
+ {
+ this.groups = groups;
+ }
+
@JsonProperty
@JsonSerialize( contentAs = BaseIdentifiableObject.class )
@JsonView( {DetailedView.class, ExportView.class} )
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroup.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroup.java 2012-06-01 11:35:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroup.java 2012-07-01 11:33:07 +0000
@@ -122,6 +122,34 @@
members.clear();
}
+ public void addUser( User user )
+ {
+ members.add( user );
+ user.getGroups().add( this );
+ }
+
+ public void removeUser( User user )
+ {
+ members.remove( user );
+ user.getGroups().remove( this );
+ }
+
+ public void updateUsers( Set<User> updates )
+ {
+ for ( User user : new HashSet<User>( members ) )
+ {
+ if ( !updates.contains( user ) )
+ {
+ removeUser( user );
+ }
+ }
+
+ for ( User user : updates )
+ {
+ addUser( user );
+ }
+ }
+
// -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserDeletionHandler.java 2012-07-01 07:12:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserDeletionHandler.java 2012-07-01 11:33:07 +0000
@@ -89,4 +89,17 @@
return null;
}
+
+ @Override
+ public void deleteUserGroup( UserGroup group )
+ {
+ Iterator<User> iterator = group.getMembers().iterator();
+
+ while ( iterator.hasNext() )
+ {
+ User user = iterator.next();
+ user.getGroups().remove( user );
+ userService.updateUser( user );
+ }
+ }
}
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserGroupDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserGroupDeletionHandler.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserGroupDeletionHandler.java 2012-07-01 11:33:07 +0000
@@ -0,0 +1,72 @@
+package org.hisp.dhis.user;
+
+/*
+ * Copyright (c) 2004-2012, 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.Iterator;
+
+import org.hisp.dhis.system.deletion.DeletionHandler;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class UserGroupDeletionHandler
+ extends DeletionHandler
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private UserGroupService userGroupService;
+
+ public void setUserGroupService( UserGroupService userGroupService )
+ {
+ this.userGroupService = userGroupService;
+ }
+
+ // -------------------------------------------------------------------------
+ // DeletionHandler implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ protected String getClassName()
+ {
+ return UserGroup.class.getSimpleName();
+ }
+
+ public void deleteUser( User user )
+ {
+ Iterator<UserGroup> iterator = user.getGroups().iterator();
+
+ while ( iterator.hasNext() )
+ {
+ UserGroup group = iterator.next();
+ group.removeUser( user );
+ userGroupService.updateUserGroup( group );
+ }
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2012-07-01 07:12:58 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2012-07-01 11:33:07 +0000
@@ -796,6 +796,10 @@
<property name="userService" ref="org.hisp.dhis.user.UserService" />
</bean>
+ <bean id="org.hisp.dhis.user.UserGroupDeletionHandler" class="org.hisp.dhis.user.UserGroupDeletionHandler">
+ <property name="userGroupService" ref="org.hisp.dhis.user.UserGroupService" />
+ </bean>
+
<bean id="org.hisp.dhis.user.UserAuthorityGroupDeletionHandler" class="org.hisp.dhis.user.UserAuthorityGroupDeletionHandler">
<property name="userService" ref="org.hisp.dhis.user.UserService" />
</bean>
@@ -865,6 +869,7 @@
<ref local="org.hisp.dhis.organisationunit.OrganisationUnitGroupDeletionHandler" />
<ref local="org.hisp.dhis.organisationunit.OrganisationUnitGroupSetDeletionHandler" />
<ref local="org.hisp.dhis.user.UserDeletionHandler" />
+ <ref local="org.hisp.dhis.user.UserGroupDeletionHandler" />
<ref local="org.hisp.dhis.user.UserAuthorityGroupDeletionHandler" />
<ref local="org.hisp.dhis.user.UserCredentialsDeletionHandler" />
<ref local="org.hisp.dhis.user.UserSettingDeletionHandler" />
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/User.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/User.hbm.xml 2012-05-29 21:23:47 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/user/hibernate/User.hbm.xml 2012-07-01 11:33:07 +0000
@@ -30,6 +30,12 @@
<one-to-one name="userCredentials" class="org.hisp.dhis.user.UserCredentials" foreign-key="fk_userinfo_userid" />
+ <set name="groups" table="usergroupmembers" inverse="true">
+ <cache usage="read-write" />
+ <key column="userid" />
+ <many-to-many class="org.hisp.dhis.user.UserGroup" column="usergroupid" />
+ </set>
+
<set name="organisationUnits" table="usermembership">
<cache usage="read-write" />
<key column="userinfoid" foreign-key="fk_usermembership_userinfoid" />
=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2012-04-29 18:04:08 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2012-07-01 11:33:07 +0000
@@ -598,6 +598,11 @@
return mapViews;
}
+
+ public Collection<MapView> getMapViewsByUser( User user )
+ {
+ return mapViewStore.getByUser( user );
+ }
// -------------------------------------------------------------------------
// MapLayer
=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/MapViewDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/MapViewDeletionHandler.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/MapViewDeletionHandler.java 2012-07-01 11:33:07 +0000
@@ -27,6 +27,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.Iterator;
+
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementGroup;
import org.hisp.dhis.indicator.Indicator;
@@ -34,6 +36,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.system.deletion.DeletionHandler;
+import org.hisp.dhis.user.User;
/**
* @author Lars Helge Overland
@@ -149,4 +152,16 @@
}
}
+ @Override
+ public void deleteUser( User user )
+ {
+ Iterator<MapView> iterator = mappingService.getMapViewsByUser( user ).iterator();
+
+ while ( iterator.hasNext() )
+ {
+ MapView mapView = iterator.next();
+ iterator.remove();
+ mappingService.deleteMapView( mapView );
+ }
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/ChartDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/ChartDeletionHandler.java 2012-01-28 17:42:13 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/ChartDeletionHandler.java 2012-07-01 11:33:07 +0000
@@ -27,9 +27,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.Iterator;
+
import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.system.deletion.DeletionHandler;
+import org.hisp.dhis.user.User;
/**
* @author Lars Helge Overland
@@ -82,4 +85,17 @@
}
}
}
+
+ @Override
+ public void deleteUser( User user )
+ {
+ Iterator<Chart> iterator = chartService.getChartsByUser( user ).iterator();
+
+ while ( iterator.hasNext() )
+ {
+ Chart chart = iterator.next();
+ iterator.remove();
+ chartService.deleteChart( chart );
+ }
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java 2012-05-31 16:52:52 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java 2012-07-01 11:33:07 +0000
@@ -769,4 +769,9 @@
{
return chartStore.getBetweenByName( name, first, max );
}
+
+ public Collection<Chart> getChartsByUser( User user )
+ {
+ return chartStore.getByUser( user );
+ }
}
=== 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 2012-07-01 07:12:58 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java 2012-07-01 11:33:07 +0000
@@ -36,6 +36,7 @@
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.common.GenericNameableObjectStore;
+import org.hisp.dhis.user.User;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -375,4 +376,11 @@
return count != null ? (Long) count : -1;
}
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public Collection<T> getByUser( User user )
+ {
+ return getCriteria( Restrictions.eq( "user", user ) ).list();
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/pom.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/pom.xml 2012-05-10 09:57:03 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/pom.xml 2012-07-01 11:33:07 +0000
@@ -46,7 +46,6 @@
<groupId>org.hisp.dhis</groupId>
<artifactId>dhis-web-api</artifactId>
</dependency>
-
</dependencies>
<properties>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserGroupAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserGroupAction.java 2012-06-01 11:35:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/AddUserGroupAction.java 2012-07-01 11:33:07 +0000
@@ -27,9 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import org.hisp.dhis.attribute.AttributeService;
import org.hisp.dhis.system.util.AttributeUtils;
@@ -100,16 +98,14 @@
public String execute()
throws Exception
{
- Set<User> userList = new HashSet<User>();
-
+ UserGroup userGroup = new UserGroup( name );
+
for ( Integer groupMember : groupMembersList )
{
User user = userService.getUser( groupMember );
- userList.add( user );
+ userGroup.addUser( user );
}
- UserGroup userGroup = new UserGroup( name, userList );
-
if ( jsonAttributeValues != null )
{
AttributeUtils.updateAttributeValuesFromJson( userGroup.getAttributeValues(), jsonAttributeValues,
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserGroupAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserGroupAction.java 2012-06-01 11:35:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/UpdateUserGroupAction.java 2012-07-01 11:33:07 +0000
@@ -113,7 +113,7 @@
UserGroup userGroup = userGroupService.getUserGroup( userGroupId );
userGroup.setName( name );
- userGroup.setMembers( userList );
+ userGroup.updateUsers( userList );
if ( jsonAttributeValues != null )
{