dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #13788
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4514: - Implemented filter in user list displaying users who have been active for x number of months. U...
------------------------------------------------------------
revno: 4514
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2011-09-04 12:21:24 +0200
message:
- Implemented filter in user list displaying users who have been active for x number of months. Useful for identifying inactive user accounts. - Added counts of users who have logged in today, yesterday, last 7 days and last 30 days in data statistics view. Useful for measuring user utilization of the system.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/statistics/GetStatisticsAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/viewStatistics.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/user.vm
--
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/user/UserService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2011-06-11 19:51:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2011-09-04 10:21:24 +0000
@@ -189,7 +189,13 @@
Collection<UserCredentials> getUsersByOrganisationUnitBetweenByName( OrganisationUnit orgUnit, String name,
int first, int max );
+
+ Collection<UserCredentials> getInactiveUsers( int months, int first, int max );
+
+ int getInactiveUsersCount( int months );
+ int getActiveUsersCount( int days );
+
// -------------------------------------------------------------------------
// UserAuthorityGroup
// -------------------------------------------------------------------------
@@ -209,7 +215,7 @@
*/
void updateUserAuthorityGroup( UserAuthorityGroup userAuthorityGroup );
- /**
+ /**2
* Retrieves the UserAuthorityGroup with the given identifier.
*
* @param id the identifier of the UserAuthorityGroup to retrieve.
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java 2011-04-24 13:44:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserStore.java 2011-09-04 10:21:24 +0000
@@ -28,6 +28,7 @@
*/
import java.util.Collection;
+import java.util.Date;
import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -172,6 +173,12 @@
Collection<UserCredentials> getUsersByOrganisationUnitBetweenByName( OrganisationUnit orgUnit, String name,
int first, int max );
+
+ Collection<UserCredentials> getInactiveUsers( Date date, int first, int max );
+
+ int getInactiveUsersCount( Date date );
+
+ int getActiveUsersCount( Date date );
// -------------------------------------------------------------------------
// UserAuthorityGroup
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2011-06-11 19:51:41 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2011-09-04 10:21:24 +0000
@@ -1,5 +1,6 @@
package org.hisp.dhis.user;
+import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
@@ -7,6 +8,7 @@
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.system.util.AuditLogUtil;
import org.springframework.transaction.annotation.Transactional;
@@ -358,6 +360,30 @@
credentials.setLastLogin( new Date() );
updateUserCredentials( credentials );
}
+
+ public Collection<UserCredentials> getInactiveUsers( int months, int first, int max )
+ {
+ Calendar cal = PeriodType.createCalendarInstance();
+ cal.add( Calendar.MONTH, ( months * -1 ) );
+
+ return userStore.getInactiveUsers( cal.getTime(), first, max );
+ }
+
+ public int getInactiveUsersCount( int months )
+ {
+ Calendar cal = PeriodType.createCalendarInstance();
+ cal.add( Calendar.MONTH, ( months * -1 ) );
+
+ return userStore.getInactiveUsersCount( cal.getTime() );
+ }
+
+ public int getActiveUsersCount( int days )
+ {
+ Calendar cal = PeriodType.createCalendarInstance();
+ cal.add( Calendar.DAY_OF_YEAR, ( days * -1 ) );
+
+ return userStore.getActiveUsersCount( cal.getTime() );
+ }
// -------------------------------------------------------------------------
// UserSettings
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2011-09-03 21:34:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/hibernate/HibernateUserStore.java 2011-09-04 10:21:24 +0000
@@ -29,6 +29,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Date;
import java.util.Iterator;
import java.util.List;
@@ -64,7 +65,7 @@
{
this.sessionFactory = sessionFactory;
}
-
+
private GenericIdentifiableObjectStore<UserAuthorityGroup> userRoleStore;
public void setUserRoleStore( GenericIdentifiableObjectStore<UserAuthorityGroup> userRoleStore )
@@ -327,7 +328,7 @@
criteria.add( Restrictions.ilike( "username", "%" + name + "%" ) );
- criteria.setProjection( Projections.rowCount() ).uniqueResult();
+ criteria.setProjection( Projections.rowCount() );
Number rs = (Number) criteria.uniqueResult();
@@ -418,6 +419,39 @@
return findByName( toUserCredentials( getUsersWithoutOrganisationUnit() ), name ).size();
}
+ @SuppressWarnings("unchecked")
+ public Collection<UserCredentials> getInactiveUsers( Date date, int first, int max )
+ {
+ Criteria criteria = sessionFactory.getCurrentSession().createCriteria( UserCredentials.class );
+ criteria.add( Restrictions.lt( "lastLogin", date ) );
+ criteria.setFirstResult( first );
+ criteria.setMaxResults( max );
+
+ return criteria.list();
+ }
+
+ public int getInactiveUsersCount( Date date )
+ {
+ Criteria criteria = sessionFactory.getCurrentSession().createCriteria( UserCredentials.class );
+ criteria.add( Restrictions.lt( "lastLogin", date ) );
+ criteria.setProjection( Projections.rowCount() );
+
+ Number rs = (Number) criteria.uniqueResult();
+
+ return rs != null ? rs.intValue() : 0;
+ }
+
+ public int getActiveUsersCount( Date date )
+ {
+ Criteria criteria = sessionFactory.getCurrentSession().createCriteria( UserCredentials.class );
+ criteria.add( Restrictions.ge( "lastLogin", date ) );
+ criteria.setProjection( Projections.rowCount() );
+
+ Number rs = (Number) criteria.uniqueResult();
+
+ return rs != null ? rs.intValue() : 0;
+ }
+
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
@@ -444,19 +478,11 @@
private List<UserCredentials> getBlockUser( Collection<UserCredentials> usersList, int startPos, int pageSize )
{
- List<UserCredentials> returnList;
List<UserCredentials> elementList = new ArrayList<UserCredentials>( usersList );
-
- try
- {
- returnList = elementList.subList( startPos, startPos + pageSize );
- }
- catch ( IndexOutOfBoundsException ex )
- {
- returnList = elementList.subList( startPos, elementList.size() );
- }
-
- return returnList;
+
+ int toIndex = Math.min( startPos + pageSize, elementList.size() );
+
+ return elementList.subList( startPos, toIndex );
}
private List<UserCredentials> toUserCredentials( Collection<User> users )
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/statistics/GetStatisticsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/statistics/GetStatisticsAction.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/statistics/GetStatisticsAction.java 2011-09-04 10:21:24 +0000
@@ -27,11 +27,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.HashMap;
import java.util.Map;
import org.hisp.dhis.statistics.StatisticsProvider;
import org.hisp.dhis.common.Objects;
import org.hisp.dhis.system.util.EnumMapWrapper;
+import org.hisp.dhis.user.UserService;
import com.opensymphony.xwork2.Action;
@@ -52,6 +54,13 @@
{
this.statisticsProvider = statisticsProvider;
}
+
+ private UserService userService;
+
+ public void setUserService( UserService userService )
+ {
+ this.userService = userService;
+ }
// -------------------------------------------------------------------------
// Output
@@ -63,6 +72,13 @@
{
return objects;
}
+
+ private Map<Integer, Integer> activeUsers = new HashMap<Integer, Integer>();
+
+ public Map<Integer, Integer> getActiveUsers()
+ {
+ return activeUsers;
+ }
// -------------------------------------------------------------------------
// Action implementation
@@ -75,6 +91,11 @@
objects = new EnumMapWrapper<Objects, Integer>( Objects.class, counts );
+ activeUsers.put( 0, userService.getActiveUsersCount( 0 ) );
+ activeUsers.put( 1, userService.getActiveUsersCount( 1 ) );
+ activeUsers.put( 7, userService.getActiveUsersCount( 7 ) );
+ activeUsers.put( 30, userService.getActiveUsersCount( 30 ) );
+
return SUCCESS;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml 2011-06-30 07:55:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml 2011-09-04 10:21:24 +0000
@@ -78,6 +78,7 @@
<bean id="org.hisp.dhis.dataadmin.action.statistics.GetStatisticsAction" class="org.hisp.dhis.dataadmin.action.statistics.GetStatisticsAction"
scope="prototype">
<property name="statisticsProvider" ref="org.hisp.dhis.statistics.StatisticsProvider" />
+ <property name="userService" ref="org.hisp.dhis.user.UserService" />
</bean>
<bean id="org.hisp.dhis.dataadmin.action.statistics.GetStatisticsChartAction" class="org.hisp.dhis.dataadmin.action.statistics.GetStatisticsChartAction"
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties 2011-07-01 04:50:26 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties 2011-09-04 10:21:24 +0000
@@ -326,4 +326,10 @@
create_new_constant = Add Constant
edit_constant = Edit Constant
value_must_be_double = Value must be an number
-confirm_delete_constant = Do you want to delete this constant object ?
\ No newline at end of file
+confirm_delete_constant = Do you want to delete this constant?
+object_type = Object type
+users_logged_in = Users logged in
+today = Today
+yesterday = Yesterday
+last_7_days = Last 7 days
+last_30_days = Last 30 days
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/viewStatistics.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/viewStatistics.vm 2010-09-21 06:16:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/viewStatistics.vm 2011-09-04 10:21:24 +0000
@@ -3,7 +3,7 @@
<table>
<tr>
- <th style="width:200px">$i18n.getString( "type" )</th>
+ <th style="width:200px">$i18n.getString( "object_type" )</th>
<th style="width:200px">$i18n.getString( "number" )</th>
</tr>
<tr>
@@ -67,4 +67,30 @@
</tr>
</table>
+<table>
+ <tr>
+ <th style="width:200px">$i18n.getString( "users_logged_in" )</th>
+ <th style="width:200px">$i18n.getString( "number" )</th>
+ </tr>
+ <tr>
+ <td>$i18n.getString( "today" )</td>
+ <td>$activeUsers.get( 0 )</td>
+ </tr>
+ <tr>
+ <td>$i18n.getString( "yesterday" )</td>
+ <td>$activeUsers.get( 1 )</td>
+ </tr>
+ <tr>
+ <td>$i18n.getString( "last_7_days" )</td>
+ <td>$activeUsers.get( 7 )</td>
+ </tr>
+ <tr>
+ <td>$i18n.getString( "last_30_days" )</td>
+ <td>$activeUsers.get( 30 )</td>
+ </tr>
+ <tr>
+ <td colspan="2" style="height:15px"></td>
+ </tr>
+</table>
+
<p><img src="viewStatisticsChart.action" alt="$i18n.getString( 'number_of_objects' )" style="border: 1px solid #d0d0d0; margin-left: 2px"/></p>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java 2011-06-19 10:57:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java 2011-09-04 10:21:24 +0000
@@ -101,6 +101,18 @@
{
return key;
}
+
+ private Integer months;
+
+ public Integer getMonths()
+ {
+ return months;
+ }
+
+ public void setMonths( Integer months )
+ {
+ this.months = months;
+ }
// -------------------------------------------------------------------------
// Action implemantation
@@ -114,18 +126,26 @@
this.paging = createPaging( userService.getUserCountByName( key ) );
userCredentialsList = new ArrayList<UserCredentials>( userService.getUsersBetweenByName( key, paging.getStartPos(), paging.getPageSize() ) );
+
+ Collections.sort( userCredentialsList, new UsernameComparator() );
+ }
+ else if ( months != null && months != 0 )
+ {
+ this.paging = createPaging( userService.getInactiveUsersCount( months ) );
+
+ userCredentialsList = new ArrayList<UserCredentials>( userService.getInactiveUsers( months, paging.getStartPos(), paging.getPageSize() ) );
}
else
{
this.paging = createPaging( userService.getUserCount() );
userCredentialsList = new ArrayList<UserCredentials>( userService.getUsersBetween( paging.getStartPos(), paging.getPageSize() ) );
+
+ Collections.sort( userCredentialsList, new UsernameComparator() );
}
FilterUtils.filter( userCredentialsList, new UserCredentialsCanUpdateFilter( currentUserService.getCurrentUser() ) );
- Collections.sort( userCredentialsList, new UsernameComparator() );
-
currentUserName = currentUserService.getCurrentUsername();
return SUCCESS;
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties 2011-08-21 10:26:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties 2011-09-04 10:21:24 +0000
@@ -248,6 +248,10 @@
confirm_delete = Confirm delete
add_user_group = Add user group
available_users = Available users
-group_members = Group members
-no_of_Users = Number of users
-last_login = Last login
\ No newline at end of file
+group_members = Group members
+no_of_Users = Number of users
+last_login = Last login
+inactive_for = Inactive for
+month = month
+months = months
+select = Select
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm 2011-06-11 19:51:41 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm 2011-09-04 10:21:24 +0000
@@ -16,9 +16,21 @@
<table style="width:100%">
<tr>
<td style="vertical-align:top">
- <table width='100%'>
+ <table width="100%">
<tr>
- <td>#filterDiv( "alluser" )</td>
+ <td>
+ #filterDiv( "alluser" )
+ </td>
+ <td>
+ <label>$i18n.getString( "inactive_for" ):</label><br>
+ <select id="months" style="width:85px" onchange="getInactiveUsers()">
+ <option value="0">[ $i18n.getString( "select" ) ]</option>
+ <option value="1"#if( $months && $months == 1 ) selected="selected"#end>1 $i18n.getString( "month" )</option>
+ #foreach( $m in [2..12] )
+ <option value="${m}"#if( $months && $months == $m ) selected="selected"#end>${m} $i18n.getString( "months" )</option>
+ #end
+ </select>
+ </td>
<td colspan="3" style="text-align:right"><input type="button" value="$i18n.getString( 'add_new' )" onclick="window.location.href='showAddUserForm.action'"/></td>
</tr>
</table>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js 2011-06-11 19:51:41 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/user.js 2011-09-04 10:21:24 +0000
@@ -7,17 +7,24 @@
{
var key = getFieldValue( 'key' );
- if( key != '' )
+ if ( key != '' )
{
- jQuery( '#userForm' ).load( "searchUser.action", {key:key}, unLockScreen );
+ jQuery( '#userForm' ).load( 'searchUser.action', {key:key}, unLockScreen );
lockScreen();
}
else
{
- jQuery("#userForm").submit();
+ jQuery( '#userForm' ).submit();
}
}
+function getInactiveUsers()
+{
+ var months = $( '#months' ).val();
+
+ window.location.href = 'alluser.action?months=' + months;
+}
+
// -----------------------------------------------------------------------------
// View details
// -----------------------------------------------------------------------------
@@ -82,5 +89,5 @@
function removeUserGroup( userGroupId, userGroupName )
{
- removeItem( userGroupId, userGroupName, i18n_confirm_delete, "removeUserGroup.action" );
+ removeItem( userGroupId, userGroupName, i18n_confirm_delete, 'removeUserGroup.action' );
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/user.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/user.vm 2011-06-11 19:51:41 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/user.vm 2011-09-04 10:21:24 +0000
@@ -6,7 +6,6 @@
<h3>$i18n.getString( "user_management" ) #openHelp( "users" )</h3>
-<form id="userForm" method="POST">
<table style="width:100%">
<tr>
<td style="vertical-align:top">
@@ -80,4 +79,3 @@
</td>
</tr>
</table>
-</form>