org.onebusaway.users.impl
Class CurrentUserServiceImpl

java.lang.Object
  extended by 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
CurrentUserServiceImpl()
           
 
Method Summary
 int addStopBookmark(String name, List<String> stopIds, RouteFilter filter)
          Add a stop bookmark with the specified name, stop ids, and route filter.
 void clearDefaultLocation()
          Clear the default search location for the current user
 void clearPhoneNumberRegistration()
          Clear any pending phone number registration for the current user.
 boolean completePhoneNumberRegistration(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.
 void deleteCurrentUser()
          Delete the current user.
 void deleteStopBookmarks(int index)
          Delete the stop bookmark with the specified id.
 void enableAdminRole()
          Enable admin role for the current user if there are no other admins in the system already.
 UserBean getAnonymousUser()
           
 UserBean getCurrentUser()
           
 UserBean getCurrentUser(boolean createUserIfAppropriate)
           
 UserIndex getCurrentUserAsUserIndex()
           
 IndexedUserDetails getCurrentUserDetails()
           
 IndexedUserDetails handleAddAccount(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.
 IndexedUserDetails handleLogin(String type, String id, String credentials, boolean isAnonymous, boolean registerIfNewUser)
          Handle login action for a user with the specified user index type+id+credentials.
 IndexedUserDetails handleRegistration(String type, String id, String credentials, boolean isAnonymous)
          Handle registration/user-creation action for a user with the specified user index type+id+credentials.
 IndexedUserDetails handleUserAction(String type, String id, String credentials, boolean isAnonymous, String mode)
          A generic method that dispatches based on the "mode" parameter.
 boolean hasPhoneNumberRegistration()
          See UserService.hasPhoneNumberRegistration(UserIndexKey)
 boolean isCurrentUserAdmin()
          See StandardAuthoritiesService for definition of admin
 boolean isCurrentUserAnonymous()
          CurrentUserService Interface
 void markServiceAlertAsRead(String situationId, long time, boolean isRead)
          Mark the specified service alert as read or unread at the specified time for the current user.
 String registerPhoneNumber(String phoneNumber)
          See UserService.registerPhoneNumber(User, String)
 void removeUserIndex(UserIndexKey key)
          Remove the UserIndex with the specified key from the user.
 void resetCurrentUser()
          Reset the properties to default values for the current user.
 void setAuthoritiesService(StandardAuthoritiesService authoritiesService)
           
 void setCurrentUserStrategy(CurrentUserStrategy currentUserStrategy)
           
 void setDefaultLocation(String locationName, double lat, double lon)
          Set the default search location for the current user
 void setLastSelectedStopIds(List<String> stopIds)
          Set the last selected stop ids for the specified user
 void setRememberUserPreferencesEnabled(boolean rememberPreferencesEnabled)
           
 void setUserPropertiesService(UserPropertiesService userPropertiesService)
           
 void setUserService(UserService service)
           
 void updateStopBookmark(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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CurrentUserServiceImpl

public CurrentUserServiceImpl()
Method Detail

setUserService

public void setUserService(UserService service)

setUserPropertiesService

public void setUserPropertiesService(UserPropertiesService userPropertiesService)

setAuthoritiesService

public void setAuthoritiesService(StandardAuthoritiesService authoritiesService)

setCurrentUserStrategy

public void setCurrentUserStrategy(CurrentUserStrategy currentUserStrategy)

isCurrentUserAnonymous

public boolean isCurrentUserAnonymous()
CurrentUserService Interface

Specified by:
isCurrentUserAnonymous in interface CurrentUserService
Returns:
true if the current user is anonymous or if there is no current user

isCurrentUserAdmin

public boolean isCurrentUserAdmin()
Description copied from interface: CurrentUserService
See StandardAuthoritiesService for definition of admin

Specified by:
isCurrentUserAdmin in interface CurrentUserService
Returns:
true if the current user is an admin

getCurrentUserDetails

public IndexedUserDetails getCurrentUserDetails()
Specified by:
getCurrentUserDetails in interface CurrentUserService
Returns:
the current user's details, or null if no user is currently logged in

getCurrentUser

public UserBean getCurrentUser()
Specified by:
getCurrentUser in interface CurrentUserService
Returns:
the current user, or null if no user is currently logged in

getCurrentUser

public UserBean getCurrentUser(boolean createUserIfAppropriate)
Specified by:
getCurrentUser in interface CurrentUserService
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:
getCurrentUserAsUserIndex in interface CurrentUserService
Returns:
the current user, or null if no user is logged in

getAnonymousUser

public UserBean getAnonymousUser()
Specified by:
getAnonymousUser in interface CurrentUserService
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: CurrentUserService
A generic method that dispatches based on the "mode" parameter. If mode is CurrentUserService.MODE_LOGIN, then we pass off to CurrentUserService.handleLogin(String, String, String, boolean, boolean) with registerIfNewUser set to true. If mode is CurrentUserService.MODE_REGISTRATION, then we pass off to CurrentUserService.handleRegistration(String, String, String, boolean) . Finally, if mode is CurrentUserService.MODE_ADD_ACCOUNT, we pass off to CurrentUserService.handleAddAccount(String, String, String, boolean).

Specified by:
handleUserAction in interface CurrentUserService
Parameters:
type - the UserIndexKey type
id - the UserIndexKey id
credentials - UserIndex credentials
isAnonymous - see StandardAuthoritiesService for definition of anonymous
mode - one of CurrentUserService.MODE_LOGIN, CurrentUserService.MODE_REGISTRATION, or CurrentUserService.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: CurrentUserService
Handle 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:
handleLogin in interface CurrentUserService
Parameters:
type - the UserIndexKey type
id - the UserIndexKey id
credentials - UserIndex credentials
isAnonymous - see StandardAuthoritiesService for definition of anonymous
registerIfNewUser - 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: CurrentUserService
Handle 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:
handleRegistration in interface CurrentUserService
Parameters:
type - the UserIndexKey type
id - the UserIndexKey id
credentials - UserIndex credentials
isAnonymous - see StandardAuthoritiesService for 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: CurrentUserService
Handle 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:
handleAddAccount in interface CurrentUserService
Parameters:
type - the UserIndexKey type
id - the UserIndexKey id
credentials - UserIndex credentials
isAnonymous - see StandardAuthoritiesService for 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: CurrentUserService
Set the default search location for the current user

Specified by:
setDefaultLocation in interface CurrentUserService

clearDefaultLocation

public void clearDefaultLocation()
Description copied from interface: CurrentUserService
Clear the default search location for the current user

Specified by:
clearDefaultLocation in interface CurrentUserService

addStopBookmark

public int addStopBookmark(String name,
                           List<String> stopIds,
                           RouteFilter filter)
Description copied from interface: CurrentUserService
Add a stop bookmark with the specified name, stop ids, and route filter. See UserBean.getBookmarks().

Specified by:
addStopBookmark in interface CurrentUserService
Returns:
the newly created bookmark id

updateStopBookmark

public void updateStopBookmark(int id,
                               String name,
                               List<String> stopIds,
                               RouteFilter routeFilter)
Description copied from interface: CurrentUserService
Updated a stop bookmark with the specified id with the specified name, stop ids, and route filter. See UserBean.getBookmarks().

Specified by:
updateStopBookmark in interface CurrentUserService

deleteStopBookmarks

public void deleteStopBookmarks(int index)
Description copied from interface: CurrentUserService
Delete the stop bookmark with the specified id. See UserBean.getBookmarks().

Specified by:
deleteStopBookmarks in interface CurrentUserService

setLastSelectedStopIds

public void setLastSelectedStopIds(List<String> stopIds)
Description copied from interface: CurrentUserService
Set the last selected stop ids for the specified user

Specified by:
setLastSelectedStopIds in interface CurrentUserService

setRememberUserPreferencesEnabled

public void setRememberUserPreferencesEnabled(boolean rememberPreferencesEnabled)
Specified by:
setRememberUserPreferencesEnabled in interface CurrentUserService
Parameters:
rememberPreferencesEnabled - true if preferences should be remembered for the current user

registerPhoneNumber

public String registerPhoneNumber(String phoneNumber)
Description copied from interface: CurrentUserService
See UserService.registerPhoneNumber(User, String)

Specified by:
registerPhoneNumber in interface CurrentUserService
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
See UserService.hasPhoneNumberRegistration(UserIndexKey)

Specified by:
hasPhoneNumberRegistration in interface CurrentUserService
Returns:
if the current user has a pending phone number registration outstanding

completePhoneNumberRegistration

public boolean completePhoneNumberRegistration(String registrationCode)
Description copied from interface: CurrentUserService
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. See UserService.completePhoneNumberRegistration(UserIndex, String)

Specified by:
completePhoneNumberRegistration in interface CurrentUserService
Returns:
true if the registration was successful, otherwise false

clearPhoneNumberRegistration

public void clearPhoneNumberRegistration()
Description copied from interface: CurrentUserService
Clear any pending phone number registration for the current user. See UserService.clearPhoneNumberRegistration(UserIndexKey)

Specified by:
clearPhoneNumberRegistration in interface CurrentUserService

markServiceAlertAsRead

public void markServiceAlertAsRead(String situationId,
                                   long time,
                                   boolean isRead)
Description copied from interface: CurrentUserService
Mark the specified service alert as read or unread at the specified time for the current user.

Specified by:
markServiceAlertAsRead in interface CurrentUserService
Parameters:
situationId - the service alert situation id
time - the time the service alert was read or marked unread
isRead - whether the service alert should be marked read or unread

enableAdminRole

public void enableAdminRole()
Description copied from interface: CurrentUserService
Enable admin role for the current user if there are no other admins in the system already. See UserService.enableAdminRoleForUser(User, boolean).

Specified by:
enableAdminRole in interface CurrentUserService

removeUserIndex

public void removeUserIndex(UserIndexKey key)
Description copied from interface: CurrentUserService
Remove the UserIndex with the specified key from the user. See UserService.removeUserIndexForUser(User, UserIndexKey)

Specified by:
removeUserIndex in interface CurrentUserService

deleteCurrentUser

public void deleteCurrentUser()
Description copied from interface: CurrentUserService
Delete the current user. See UserService.deleteUser(User)

Specified by:
deleteCurrentUser in interface CurrentUserService

resetCurrentUser

public void resetCurrentUser()
Description copied from interface: CurrentUserService
Reset the properties to default values for the current user. See UserService.resetUser(User).

Specified by:
resetCurrentUser in interface CurrentUserService


Copyright © 2011 OneBusAway. All Rights Reserved.