com.objectplanet.survey.plugin.api
Class UserManager

java.lang.Object
  extended by com.objectplanet.survey.plugin.api.UserManager

public class UserManager
extends java.lang.Object

Manage survey system users.

Author:
Irina Brun

Field Summary
static int PERMISSION_ADMIN
          Permission type: admin.
static int PERMISSION_FOLDER_ADD_FOLDER
          Permission type: add new folder to an existing folder
static int PERMISSION_FOLDER_ADD_SURVEY
          Permission type: add new survey to an existing folder
static int PERMISSION_MODIFY
          Permission type: modify survey/folder
static int PERMISSION_READ
          Permission type: read survey/folder
static int PERMISSION_SURVEY_CREATE_REPORT
          Permission type: create survey reports
static int PERMISSION_SURVEY_DELETE_RESPONDENT
          Permission type: delete survey respondents
static int PERMISSION_SURVEY_INVITATION
          Permission type: create survey invitations
static int PERMISSION_SURVEY_VIEW_RESPONDENT
          Permission type: view survey respondents
 
Constructor Summary
UserManager()
           
 
Method Summary
static void addGroupMember(User user, long userGroupId, long userId)
          Add a new member to the user group.
static User createUser(User user, java.lang.String login, java.lang.String password, java.lang.String email, java.lang.String memo)
          Creates a new user
static UserGroup createUserGroup(User user, java.lang.String name, java.lang.String description)
          Creates a new user group
static void deleteAddQuestionLibraryPermission(User user, long userId)
          Deny permission to create question libraries for a user with id userId.
static void deleteFolderPermission(User user, long userId, long folderId, int permissionType)
          Deny folder permission to a user with id userId.
static void deleteGroupMember(User user, long userGroupId, long userId)
          Deletes a member from the group.
static void deleteSurveyPermission(User user, long userId, long surveyId, int permissionType)
          Deny survey permission to a user with id userId.
static void deleteUser(User user, java.lang.String login)
          Deletes a user by login name
static void deleteUserGroup(User user, long userGroupId)
          Deletes a user group
static User getUser(java.lang.String login)
          Gets the user by login name.
static User getUser(java.lang.String login, java.lang.String password)
          Gets the user by login name.
static User getUser(User user, long userId)
          Gets the user by id.
static java.util.ArrayList getUserList(User user)
          Gets all users current user has access to, sorted alphabetic The ArrayList contains ListItems with the UserId and Login values.
static void grandFolderPermission(User user, long userId, long folderId, int permissionType)
          Grand folder permission to a user.
static void grandSurveyPermission(User user, long userId, long surveyId, int permissionType)
          Grand survey permission to a user.
static void grantAddQuestionLibraryPermission(User user, long userId)
          Grant permission to create question libraries to a user
static void grantUserGroupAdminPermission(User user, long userId, long userGroupId)
          Grant user group admin permission to a user
static boolean hasFolderPermission(User user, long userId, long folderId, int permissionType)
          Return true is user with id userId has the specified folder permission.
static boolean hasSurveyPermission(User user, long userId, long surveyId, int permissionType)
          Return true is user with id userId has the specified survey permission.
static boolean isSuperUser(User userToCheck)
          Check if the user is super user
static boolean isUniqueLogin(java.lang.String login)
          Check if login name is unique
static void logOutUser(long userId)
          Logs out user (if online) with the specified user id
static void updateUser(User userToUpdate)
          Update user information.
static void updateUserGroup(User user, UserGroup userGroupToUpdate)
          Updates the user group.
static boolean userExists(long userId)
          Checks if the user with the specified user id exists.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PERMISSION_ADMIN

public static final int PERMISSION_ADMIN
Permission type: admin. Full access to a survey/folder

See Also:
Constant Field Values

PERMISSION_FOLDER_ADD_FOLDER

public static final int PERMISSION_FOLDER_ADD_FOLDER
Permission type: add new folder to an existing folder

See Also:
Constant Field Values

PERMISSION_FOLDER_ADD_SURVEY

public static final int PERMISSION_FOLDER_ADD_SURVEY
Permission type: add new survey to an existing folder

See Also:
Constant Field Values

PERMISSION_MODIFY

public static final int PERMISSION_MODIFY
Permission type: modify survey/folder

See Also:
Constant Field Values

PERMISSION_READ

public static final int PERMISSION_READ
Permission type: read survey/folder

See Also:
Constant Field Values

PERMISSION_SURVEY_CREATE_REPORT

public static final int PERMISSION_SURVEY_CREATE_REPORT
Permission type: create survey reports

See Also:
Constant Field Values

PERMISSION_SURVEY_VIEW_RESPONDENT

public static final int PERMISSION_SURVEY_VIEW_RESPONDENT
Permission type: view survey respondents

See Also:
Constant Field Values

PERMISSION_SURVEY_DELETE_RESPONDENT

public static final int PERMISSION_SURVEY_DELETE_RESPONDENT
Permission type: delete survey respondents

See Also:
Constant Field Values

PERMISSION_SURVEY_INVITATION

public static final int PERMISSION_SURVEY_INVITATION
Permission type: create survey invitations

See Also:
Constant Field Values
Constructor Detail

UserManager

public UserManager()
Method Detail

createUser

public static User createUser(User user,
                              java.lang.String login,
                              java.lang.String password,
                              java.lang.String email,
                              java.lang.String memo)
                       throws SurveySystemException,
                              SurveySecurityException
Creates a new user

Parameters:
user - User with permission create users
login - Login name
Returns:
Throws:
SurveySystemException - Thrown if the user has no permission to fulfill the operation
SurveySecurityException - If an error occurs in the application

deleteUser

public static void deleteUser(User user,
                              java.lang.String login)
                       throws SurveySecurityException,
                              SurveySystemException
Deletes a user by login name

Parameters:
user - User with permission delete users
login - Login name
Throws:
SurveySecurityException - Thrown if the user has no permission to fulfill the operation
SurveySystemException - If an error occurs in the application

createUserGroup

public static UserGroup createUserGroup(User user,
                                        java.lang.String name,
                                        java.lang.String description)
                                 throws SurveySystemException,
                                        SurveySecurityException
Creates a new user group

Parameters:
user - A user with permission to create user groups
name - The user group name
description - The user group description
Returns:
The new user group
Throws:
SurveySystemException - Thrown if the user has no permission to fulfill the operation
SurveySecurityException - If an error occurs in the application

deleteUserGroup

public static void deleteUserGroup(User user,
                                   long userGroupId)
                            throws SurveySecurityException,
                                   SurveySystemException
Deletes a user group

Parameters:
user - A user with permission to delete user groups
userGroupId - The user group id
Throws:
SurveySystemException - Thrown if the user has no permission to fulfill the operation
SurveySecurityException - If an error occurs in the application

isSuperUser

public static boolean isSuperUser(User userToCheck)
Check if the user is super user

Parameters:
user -
Returns:
true if user is super user

getUser

public static User getUser(User user,
                           long userId)
                    throws SurveySystemException,
                           SurveySecurityException
Gets the user by id.

Parameters:
userId - User id
user - User object
Returns:
The user with id userId
Throws:
SurveySecurityException - Thrown if the user has no permission to fulfill the operation
SurveySystemException - If an error occurs in the application

getUser

public static User getUser(java.lang.String login)
                    throws SurveySystemException,
                           SurveySecurityException
Gets the user by login name. To be used only in login module where a user gets his/hers User object, otherwise SurveySecurityException will be thrown.

Parameters:
login - Login name
Returns:
The user or null if user with this login name not found
Throws:
SurveySecurityException - Thrown if the login doesn't match with the user's login name.
SurveySystemException - If an error occurs in the application

getUser

public static User getUser(java.lang.String login,
                           java.lang.String password)
                    throws SurveySystemException,
                           SurveySecurityException
Gets the user by login name. Password is checked before returning the user. If user with the login name does not exist, or if password does not match, return null.

Parameters:
login - Login name
password - User password
Returns:
The user or null if user with this login name not found or invalid password is entered
Throws:
SurveySecurityException - Thrown if the login doesn't match with the user's login name.
SurveySystemException - If an error occurs in the application

getUserList

public static java.util.ArrayList getUserList(User user)
                                       throws SurveySystemException
Gets all users current user has access to, sorted alphabetic The ArrayList contains ListItems with the UserId and Login values.

Parameters:
user - User object
Returns:
The ArrayList of ListItems
Throws:
SurveySystemException - If an error occurs in the application

deleteFolderPermission

public static void deleteFolderPermission(User user,
                                          long userId,
                                          long folderId,
                                          int permissionType)
                                   throws SurveySecurityException,
                                          SurveySystemException
Deny folder permission to a user with id userId.

Parameters:
user - User with permission to administer other users
userId - User who will be denied the folder permission.
folderId - Folder id
permissionType - Permission type, one of the following types:
  • PERMISSION_ADMIN
  • PERMISSION_READ
  • PERMISSION_MODIFY
  • PERMISSION_FOLDER_ADD_FOLDER
  • PERMISSION_FOLDER_ADD_SURVEY
Throws:
SurveySystemException - If an error occurs in the system
SurveySecurityException - Thrown if the user is not authorized to administer the user.

deleteSurveyPermission

public static void deleteSurveyPermission(User user,
                                          long userId,
                                          long surveyId,
                                          int permissionType)
                                   throws SurveySecurityException,
                                          SurveySystemException
Deny survey permission to a user with id userId.

Parameters:
user - User with permission to administer other users
userId - User who will be denied the survey permission.
surveyId - Survey id
permissionType - Permission type, one of the following types:
  • PERMISSION_ADMIN
  • PERMISSION_READ
  • PERMISSION_MODIFY
  • PERMISSION_SURVEY_CREATE_REPORT
  • PERMISSION_SURVEY_DELETE_RESPONDENT
  • PERMISSION_SURVEY_INVITATION
Throws:
SurveySecurityException - Thrown if the user is not authorized to administer the user.
SurveySystemException - If an error occurs in the system

deleteAddQuestionLibraryPermission

public static void deleteAddQuestionLibraryPermission(User user,
                                                      long userId)
                                               throws SurveySecurityException,
                                                      SurveySystemException
Deny permission to create question libraries for a user with id userId.

Parameters:
user - User with permission to administer other users
userId - User who will be denied the permission to create question libraries
Throws:
SurveySystemException - If an error occurs in the system
SurveySecurityException - Thrown if the user is not authorized to administer the user.

grandFolderPermission

public static void grandFolderPermission(User user,
                                         long userId,
                                         long folderId,
                                         int permissionType)
                                  throws SurveySecurityException,
                                         SurveySystemException
Grand folder permission to a user.

Parameters:
user - User with permission to administer other users
userId - User who will get the permission.
folderId - Folder id
permissionType - Permission type, one of the following types:
  • PERMISSION_ADMIN
  • PERMISSION_READ
  • PERMISSION_MODIFY
  • PERMISSION_FOLDER_ADD_FOLDER
  • PERMISSION_FOLDER_ADD_SURVEY
Throws:
SurveySecurityException - Thrown if the user is not authorized to administer the user.
SurveySystemException - If an error occurs in the system

grandSurveyPermission

public static void grandSurveyPermission(User user,
                                         long userId,
                                         long surveyId,
                                         int permissionType)
                                  throws SurveySecurityException,
                                         SurveySystemException
Grand survey permission to a user.

Parameters:
user - User with permission to administer other users
userId - User who will get the permission.
surveyId - Survey id
permissionType - Permission type, one of the following types:
  • PERMISSION_ADMIN
  • PERMISSION_READ
  • PERMISSION_MODIFY
  • PERMISSION_SURVEY_CREATE_REPORT
  • PERMISSION_SURVEY_DELETE_RESPONDENT
  • PERMISSION_SURVEY_INVITATION
Throws:
SurveySecurityException - Thrown if the user is not authorized to administer the user.
SurveySystemException - If an error occurs in the system

grantUserGroupAdminPermission

public static void grantUserGroupAdminPermission(User user,
                                                 long userId,
                                                 long userGroupId)
                                          throws SurveySecurityException,
                                                 SurveySystemException
Grant user group admin permission to a user

Parameters:
user - User with permission to administer other users
userId - User who will get the permission.
userGroupId - The user group the user will get permission to manage
Throws:
SurveySecurityException - Thrown if the user is not authorized to administer the user.
SurveySystemException - If an error occurs in the system

grantAddQuestionLibraryPermission

public static void grantAddQuestionLibraryPermission(User user,
                                                     long userId)
                                              throws SurveySecurityException,
                                                     SurveySystemException
Grant permission to create question libraries to a user

Parameters:
user - User with permission to administer other users
userId - User who will get the permission.
Throws:
SurveySecurityException - Thrown if the user is not authorized to administer the user.
SurveySystemException - If an error occurs in the system

hasFolderPermission

public static boolean hasFolderPermission(User user,
                                          long userId,
                                          long folderId,
                                          int permissionType)
                                   throws SurveySecurityException,
                                          SurveySystemException
Return true is user with id userId has the specified folder permission.

Parameters:
user - User with permission to administer other users
userId - User to check permission.
folderId - Folder id
permissionType - Permission type, one of the following types:
  • PERMISSION_ADMIN
  • PERMISSION_READ
  • PERMISSION_MODIFY
  • PERMISSION_FOLDER_ADD_FOLDER
  • PERMISSION_FOLDER_ADD_SURVEY
Returns:
True if permission is granted, false otherwise
Throws:
SurveySecurityException - Thrown if the user is not authorized to administer the user.
SurveySystemException - If an error occurs in the system

hasSurveyPermission

public static boolean hasSurveyPermission(User user,
                                          long userId,
                                          long surveyId,
                                          int permissionType)
                                   throws SurveySecurityException,
                                          SurveySystemException
Return true is user with id userId has the specified survey permission.

Parameters:
user - User with permission to administer other users
userId - User to check permission.
surveyId - Survey id
permissionType - Permission type, one of the following types:
  • PERMISSION_ADMIN
  • PERMISSION_READ
  • PERMISSION_MODIFY
  • PERMISSION_SURVEY_CREATE_REPORT
  • PERMISSION_SURVEY_DELETE_RESPONDENT
  • PERMISSION_SURVEY_INVITATION
Returns:
True if permission is granted, false otherwise
Throws:
SurveySecurityException - Thrown if the user is not authorized to administer the user.
SurveySystemException - If an error occurs in the system

isUniqueLogin

public static boolean isUniqueLogin(java.lang.String login)
                             throws SurveySystemException
Check if login name is unique

Parameters:
login - Login name to check
Returns:
True/false
Throws:
SurveySystemException - If an error occurs in the system

logOutUser

public static void logOutUser(long userId)
                       throws SurveySystemException
Logs out user (if online) with the specified user id

Parameters:
uerId -
Throws:
SurveySystemException

updateUser

public static void updateUser(User userToUpdate)
                       throws SurveySystemException
Update user information.

Parameters:
userToUpdate - Description of the Parameter
Throws:
SurveySystemException - If an error occurs in the application

updateUserGroup

public static void updateUserGroup(User user,
                                   UserGroup userGroupToUpdate)
                            throws SurveySystemException,
                                   SurveySecurityException
Updates the user group. Doesn't update members in the group.

Parameters:
user - A user with permission to create user groups
userGroupToUpdate - The user group to update
Throws:
SurveySystemException - Thrown if the user has no permission to fulfill the operation
SurveySecurityException - If an error occurs in the application

addGroupMember

public static void addGroupMember(User user,
                                  long userGroupId,
                                  long userId)
                           throws SurveySystemException,
                                  SurveySecurityException
Add a new member to the user group.

Parameters:
user - A user with permission manage the user group.
userGroupId - User group id
userId - User id to add
Throws:
SurveySystemException - Thrown if the user has no permission to fulfill the operation
SurveySecurityException - If an error occurs in the application

deleteGroupMember

public static void deleteGroupMember(User user,
                                     long userGroupId,
                                     long userId)
                              throws SurveySystemException,
                                     SurveySecurityException
Deletes a member from the group.

Parameters:
user - A user with permission manage the user group.
userGroupId - User group id
userId - User id to add
Throws:
SurveySystemException - Thrown if the user has no permission to fulfill the operation
SurveySecurityException - If an error occurs in the application

userExists

public static boolean userExists(long userId)
                          throws SurveySystemException
Checks if the user with the specified user id exists.

Parameters:
userId - The user id
Returns:
True if the user exists, false otherwise.
Throws:
SurveySystemException - if any exception occurs.

Copyright ? ObjectPlanet Inc. All Rights Reserved.

Built on December 20 2016