Package org.onebusaway.users.impl
Class CurrentUserServiceImpl
- java.lang.Object
-
- org.onebusaway.users.impl.CurrentUserServiceImpl
-
- All Implemented Interfaces:
CurrentUserService
@Component public class CurrentUserServiceImpl extends Object implements CurrentUserService
-
-
Field Summary
-
Fields inherited from interface org.onebusaway.users.services.CurrentUserService
MODE_ADD_ACCOUNT, MODE_LOGIN, MODE_REGISTRATION
-
-
Constructor Summary
Constructors Constructor Description CurrentUserServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intaddStopBookmark(String name, List<String> stopIds, RouteFilter filter)Add a stop bookmark with the specified name, stop ids, and route filter.voidclearDefaultLocation()Clear the default search location for the current uservoidclearPhoneNumberRegistration()Clear any pending phone number registration for the current user.booleancompletePhoneNumberRegistration(String registrationCode)Registers the specified phone number with the user by attaching a new UserIndex to the user with the phone number, or merging an existing user account with an existing UserIndex.voiddeleteCurrentUser()Delete the current user.voiddeleteStopBookmarks(int index)Delete the stop bookmark with the specified id.voidenableAdminRole()Enable admin role for the current user if there are no other admins in the system already.UserBeangetAnonymousUser()UserBeangetCurrentUser()UserBeangetCurrentUser(boolean createUserIfAppropriate)UserIndexgetCurrentUserAsUserIndex()IndexedUserDetailsgetCurrentUserDetails()IndexedUserDetailshandleAddAccount(String type, String id, String credentials, boolean isAnonymous)Handle the addition of a user index with the specified index type+id+credentials to the currently logged in user.IndexedUserDetailshandleLogin(String type, String id, String credentials, boolean isAnonymous, boolean registerIfNewUser)Handle login action for a user with the specified user index type+id+credentials.IndexedUserDetailshandleRegistration(String type, String id, String credentials, boolean isAnonymous)Handle registration/user-creation action for a user with the specified user index type+id+credentials.IndexedUserDetailshandleUserAction(String type, String id, String credentials, boolean isAnonymous, String mode)A generic method that dispatches based on the "mode" parameter.booleanhasPhoneNumberRegistration()booleanisCurrentUserAdmin()SeeStandardAuthoritiesServicefor definition of adminbooleanisCurrentUserAnonymous()CurrentUserServiceInterfacebooleanisCurrentUserReporting()SeeStandardAuthoritiesServicefor definition of reportingvoidmarkServiceAlertAsRead(String situationId, long time, boolean isRead)Mark the specified service alert as read or unread at the specified time for the current user.StringregisterPhoneNumber(String phoneNumber)voidremoveUserIndex(UserIndexKey key)Remove theUserIndexwith the specified key from the user.voidresetCurrentUser()Reset the properties to default values for the current user.voidsetAuthoritiesService(StandardAuthoritiesService authoritiesService)voidsetCurrentUserStrategy(CurrentUserStrategy currentUserStrategy)voidsetDefaultLocation(String locationName, double lat, double lon)Set the default search location for the current uservoidsetLastSelectedStopIds(List<String> stopIds)Set the last selected stop ids for the specified uservoidsetRememberUserPreferencesEnabled(boolean rememberPreferencesEnabled)voidsetUserPropertiesService(UserPropertiesService userPropertiesService)voidsetUserService(UserService service)voidupdateStopBookmark(int id, String name, List<String> stopIds, RouteFilter routeFilter)Updated a stop bookmark with the specified id with the specified name, stop ids, and route filter.
-
-
-
Method Detail
-
setUserService
@Autowired public void setUserService(UserService service)
-
setUserPropertiesService
@Autowired public void setUserPropertiesService(UserPropertiesService userPropertiesService)
-
setAuthoritiesService
@Autowired public void setAuthoritiesService(StandardAuthoritiesService authoritiesService)
-
setCurrentUserStrategy
@Autowired public void setCurrentUserStrategy(CurrentUserStrategy currentUserStrategy)
-
isCurrentUserAnonymous
public boolean isCurrentUserAnonymous()
CurrentUserServiceInterface- Specified by:
isCurrentUserAnonymousin interfaceCurrentUserService- Returns:
- true if the current user is anonymous or if there is no current user
-
isCurrentUserAdmin
public boolean isCurrentUserAdmin()
Description copied from interface:CurrentUserServiceSeeStandardAuthoritiesServicefor definition of admin- Specified by:
isCurrentUserAdminin interfaceCurrentUserService- Returns:
- true if the current user is an admin
-
isCurrentUserReporting
public boolean isCurrentUserReporting()
Description copied from interface:CurrentUserServiceSeeStandardAuthoritiesServicefor definition of reporting- Specified by:
isCurrentUserReportingin interfaceCurrentUserService- Returns:
- true if the current user is a reporting
-
getCurrentUserDetails
public IndexedUserDetails getCurrentUserDetails()
- Specified by:
getCurrentUserDetailsin interfaceCurrentUserService- Returns:
- the current user's details, or null if no user is currently logged in
-
getCurrentUser
public UserBean getCurrentUser()
- Specified by:
getCurrentUserin interfaceCurrentUserService- Returns:
- the current user, or null if no user is currently logged in
-
getCurrentUser
public UserBean getCurrentUser(boolean createUserIfAppropriate)
- Specified by:
getCurrentUserin interfaceCurrentUserService- Returns:
- the current user, creating the user as appropriate or returning null if no user is logged in or could not be created
-
getCurrentUserAsUserIndex
public UserIndex getCurrentUserAsUserIndex()
- Specified by:
getCurrentUserAsUserIndexin interfaceCurrentUserService- Returns:
- the current user, or null if no user is logged in
-
getAnonymousUser
public UserBean getAnonymousUser()
- Specified by:
getAnonymousUserin interfaceCurrentUserService- Returns:
- an anonymous, temporary user account that can be used as a placholder if no user is logged in. Never returns null.
-
handleUserAction
public IndexedUserDetails handleUserAction(String type, String id, String credentials, boolean isAnonymous, String mode)
Description copied from interface:CurrentUserServiceA generic method that dispatches based on the "mode" parameter. If mode isCurrentUserService.MODE_LOGIN, then we pass off toCurrentUserService.handleLogin(String, String, String, boolean, boolean)with registerIfNewUser set to true. If mode isCurrentUserService.MODE_REGISTRATION, then we pass off toCurrentUserService.handleRegistration(String, String, String, boolean). Finally, if mode isCurrentUserService.MODE_ADD_ACCOUNT, we pass off toCurrentUserService.handleAddAccount(String, String, String, boolean).- Specified by:
handleUserActionin interfaceCurrentUserService- Parameters:
type- theUserIndexKeytypeid- theUserIndexKeyidcredentials-UserIndexcredentialsisAnonymous- seeStandardAuthoritiesServicefor definition of anonymousmode- one ofCurrentUserService.MODE_LOGIN,CurrentUserService.MODE_REGISTRATION, orCurrentUserService.MODE_ADD_ACCOUNT- Returns:
- the details of the logged in user on success, otherwise null
-
handleLogin
public IndexedUserDetails handleLogin(String type, String id, String credentials, boolean isAnonymous, boolean registerIfNewUser)
Description copied from interface:CurrentUserServiceHandle login action for a user with the specified user index type+id+credentials. Supports creating a new user with the specified user index if the registerIfNewUser flag is true. If an existing anonymous user account is already logged in and a new user is created, the existing user account will be migrated to the new user account.- Specified by:
handleLoginin interfaceCurrentUserService- Parameters:
type- theUserIndexKeytypeid- theUserIndexKeyidcredentials-UserIndexcredentialsisAnonymous- seeStandardAuthoritiesServicefor definition of anonymousregisterIfNewUser- if true, automatically register a new user if one does not exist already- Returns:
- the details of the logged in user on success, otherwise null
-
handleRegistration
public IndexedUserDetails handleRegistration(String type, String id, String credentials, boolean isAnonymous)
Description copied from interface:CurrentUserServiceHandle registration/user-creation action for a user with the specified user index type+id+credentials. If a user already existed with the specified user index already exists, it will be used. If an existing anonymous user account is already logged in, the existing user account will be migrated to the new user account.- Specified by:
handleRegistrationin interfaceCurrentUserService- Parameters:
type- theUserIndexKeytypeid- theUserIndexKeyidcredentials-UserIndexcredentialsisAnonymous- seeStandardAuthoritiesServicefor definition of anonymous- Returns:
- the details of the logged in user on success, otherwise null
-
handleAddAccount
public IndexedUserDetails handleAddAccount(String type, String id, String credentials, boolean isAnonymous)
Description copied from interface:CurrentUserServiceHandle the addition of a user index with the specified index type+id+credentials to the currently logged in user. If there is no currently logged in user, a new user will be created with the specified user index.- Specified by:
handleAddAccountin interfaceCurrentUserService- Parameters:
type- theUserIndexKeytypeid- theUserIndexKeyidcredentials-UserIndexcredentialsisAnonymous- seeStandardAuthoritiesServicefor definition of anonymous- Returns:
- the details of the logged in user on success, otherwise null
-
setDefaultLocation
public void setDefaultLocation(String locationName, double lat, double lon)
Description copied from interface:CurrentUserServiceSet the default search location for the current user- Specified by:
setDefaultLocationin interfaceCurrentUserService
-
clearDefaultLocation
public void clearDefaultLocation()
Description copied from interface:CurrentUserServiceClear the default search location for the current user- Specified by:
clearDefaultLocationin interfaceCurrentUserService
-
addStopBookmark
public int addStopBookmark(String name, List<String> stopIds, RouteFilter filter)
Description copied from interface:CurrentUserServiceAdd a stop bookmark with the specified name, stop ids, and route filter. SeeUserBean.getBookmarks().- Specified by:
addStopBookmarkin interfaceCurrentUserService- Returns:
- the newly created bookmark id
-
updateStopBookmark
public void updateStopBookmark(int id, String name, List<String> stopIds, RouteFilter routeFilter)Description copied from interface:CurrentUserServiceUpdated a stop bookmark with the specified id with the specified name, stop ids, and route filter. SeeUserBean.getBookmarks().- Specified by:
updateStopBookmarkin interfaceCurrentUserService
-
deleteStopBookmarks
public void deleteStopBookmarks(int index)
Description copied from interface:CurrentUserServiceDelete the stop bookmark with the specified id. SeeUserBean.getBookmarks().- Specified by:
deleteStopBookmarksin interfaceCurrentUserService
-
setLastSelectedStopIds
public void setLastSelectedStopIds(List<String> stopIds)
Description copied from interface:CurrentUserServiceSet the last selected stop ids for the specified user- Specified by:
setLastSelectedStopIdsin interfaceCurrentUserService
-
setRememberUserPreferencesEnabled
public void setRememberUserPreferencesEnabled(boolean rememberPreferencesEnabled)
- Specified by:
setRememberUserPreferencesEnabledin interfaceCurrentUserService- Parameters:
rememberPreferencesEnabled- true if preferences should be remembered for the current user
-
registerPhoneNumber
public String registerPhoneNumber(String phoneNumber)
Description copied from interface:CurrentUserService- Specified by:
registerPhoneNumberin interfaceCurrentUserService- Parameters:
phoneNumber- the phone number to register to the current user- Returns:
- the registration code that must be used validate the phoneNumber in
a subsequent call to
CurrentUserService.completePhoneNumberRegistration(String).
-
hasPhoneNumberRegistration
public boolean hasPhoneNumberRegistration()
Description copied from interface:CurrentUserService- Specified by:
hasPhoneNumberRegistrationin interfaceCurrentUserService- Returns:
- if the current user has a pending phone number registration outstanding
-
completePhoneNumberRegistration
public boolean completePhoneNumberRegistration(String registrationCode)
Description copied from interface:CurrentUserServiceRegisters the specified phone number with the user by attaching a new UserIndex to the user with the phone number, or merging an existing user account with an existing UserIndex. SeeUserService.completePhoneNumberRegistration(UserIndex, String)- Specified by:
completePhoneNumberRegistrationin interfaceCurrentUserService- Returns:
- true if the registration was successful, otherwise false
-
clearPhoneNumberRegistration
public void clearPhoneNumberRegistration()
Description copied from interface:CurrentUserServiceClear any pending phone number registration for the current user. SeeUserService.clearPhoneNumberRegistration(UserIndexKey)- Specified by:
clearPhoneNumberRegistrationin interfaceCurrentUserService
-
markServiceAlertAsRead
public void markServiceAlertAsRead(String situationId, long time, boolean isRead)
Description copied from interface:CurrentUserServiceMark the specified service alert as read or unread at the specified time for the current user.- Specified by:
markServiceAlertAsReadin interfaceCurrentUserService- Parameters:
situationId- the service alert situation idtime- the time the service alert was read or marked unreadisRead- whether the service alert should be marked read or unread
-
enableAdminRole
public void enableAdminRole()
Description copied from interface:CurrentUserServiceEnable admin role for the current user if there are no other admins in the system already. SeeUserService.enableAdminRoleForUser(User, boolean).- Specified by:
enableAdminRolein interfaceCurrentUserService
-
removeUserIndex
public void removeUserIndex(UserIndexKey key)
Description copied from interface:CurrentUserServiceRemove theUserIndexwith the specified key from the user. SeeUserService.removeUserIndexForUser(User, UserIndexKey)- Specified by:
removeUserIndexin interfaceCurrentUserService
-
deleteCurrentUser
public void deleteCurrentUser()
Description copied from interface:CurrentUserServiceDelete the current user. SeeUserService.deleteUser(User)- Specified by:
deleteCurrentUserin interfaceCurrentUserService
-
resetCurrentUser
public void resetCurrentUser()
Description copied from interface:CurrentUserServiceReset the properties to default values for the current user. SeeUserService.resetUser(User).- Specified by:
resetCurrentUserin interfaceCurrentUserService
-
-