magoffin.matt.ma2.biz.impl
Class UserBizImpl

java.lang.Object
  extended by magoffin.matt.ma2.biz.impl.UserBizImpl
All Implemented Interfaces:
UserBiz

public class UserBizImpl
extends java.lang.Object
implements UserBiz

Standard implementation of UserBiz.

Note: the init() method should be called after configuring this class but before calling any other methods; the finish() should be called when finished using.

The configurable properties of this class are:

encryptor
An optional DataEncryption instance to use for encrypting the registration confirmation with.
salt
An optional salt to add to encrypted passwords.
ioBiz
The IOBiz implementation to ues.
systemBiz
The SystemBiz implementation to use.
userDao
A UserDao to use for managing persistent User objects.
collectionDao
A CollectionDao to use for managing persistent Collection objects.
mediaItemDao
A MediaItemDao to use for managing persistent MediaItem objects.
userValidator
An optional Validator instance to use for validating User data with.
messages
A MessageSource.
domainObjectFactory
The DomainObjectFactory for creating new domain objects.
defaultCollectionNameMessageKey
The MessageSource key that resolves to the default name to apply to a new user's first Collection. Defaults to default.collection.name.
defaultCollectionCommentMessageKey
The MessageSource key that resolves to the default name to apply to a new user's first Collection. Defaults to default.collection.comment.
adminUserTemplate
A map of properties to apply to the default initial admin user.

Version:
$Revision: 43 $ $Date: 2007-10-21 11:10:01 +1300 (Sun, 21 Oct 2007) $
Author:
Matt Magoffin (spamsqr@msqr.us)

Field Summary
static int DEFAULT_ALBUM_FEED_MAX_LENGHT
          The default value for the albumFeedMaxLength property.
 
Fields inherited from interface magoffin.matt.ma2.biz.UserBiz
ACCESS_ADMIN, DO_NOT_CHANGE_VALUE, WATERMARK_META_KEY
 
Constructor Summary
UserBizImpl()
           
 
Method Summary
 User confirmForgotPassword(java.lang.String login, java.lang.String confirmationCode, java.lang.String newPassword, BizContext context)
          Confirm a forgotten password.
 User confirmRegisteredUser(java.lang.String login, java.lang.String confirmationCode, BizContext context)
          Confirm a registered user.
 void finish()
          Call to release any class resources when finished using.
 java.lang.String forgotPassword(java.lang.String login, BizContext context)
          Call to email a user a link with a one-time password.
 java.util.Map<java.lang.String,java.lang.Object> getAdminUserTemplate()
           
 AlbumDao getAlbumDao()
           
 java.util.List<Album> getAlbumFeedForUser(AlbumFeedCommand command)
          Get a List of Albums for a user's album feed.
 int getAlbumFeedMaxLength()
           
 java.util.List<Album> getAlbumsForUser(User user, BizContext context)
          Get all albums for a given user.
 User getAnonymousUser()
          Get an anonymous user object.
 java.util.Map<java.lang.String,java.lang.Object> getAnonymousUserTemplate()
           
 Collection getCollection(java.lang.Long collectionId, BizContext context)
          Get a single collection.
 CollectionDao getCollectionDao()
           
 java.io.File getCollectionDirectory(Collection collection, BizContext context)
          Get the directory for a given collection.
 java.util.List<Collection> getCollectionsForUser(User user, BizContext context)
          Get all collections for a given user.
 java.lang.String getDefaultCollectionCommentMessageKey()
           
 java.lang.String getDefaultCollectionNameMessageKey()
           
 MediaQuality getDefaultThumbQuality()
           
 MediaSize getDefaultThumbSize()
           
 MediaQuality getDefaultViewQuality()
           
 MediaSize getDefaultViewSize()
           
 DomainObjectFactory getDomainObjectFactory()
           
 magoffin.matt.util.DataEncryption getEncryptor()
           
 IOBiz getIoBiz()
           
 org.springframework.context.MessageSource getMessages()
           
 byte[] getSalt()
           
 java.util.List<Album> getSharedAlbumsForUser(BrowseAlbumsCommand command)
          Get a List of Albums for a browse command.
 SystemBiz getSystemBiz()
           
 User getUserByAnonymousKey(java.lang.String key)
          Get a User by its anonymous key.
 User getUserById(java.lang.Long userId, BizContext context)
          Get a User by its ID.
 UserDao getUserDao()
           
 java.util.Locale getUserLocale(User user, BizContext context)
          Get the Locale for a User.
 java.util.List<User> getUsersWithAccess(int level)
          Get a list of User objects that have a specific access level.
 org.springframework.validation.Validator getUserValidator()
           
 org.springframework.core.io.Resource getUserWatermark(java.lang.Long userId)
          Get a Resource for a user's watermark.
 java.util.Set<MediaSize> getWatermarkSizes()
           
 boolean hasAccessLevel(User user, int level)
          Return true if the supplied user has the specified access level.
 void init()
          Call to initialize the class after configuring properties.
 boolean isAnonymousUser(User user)
          Test if a User is an anonoymous user.
 User logonUser(java.lang.String login, java.lang.String password)
          Authenticate a user by their username and password.
 Collection newCollectionForUser(Collection collection, User user, BizContext context)
          Create a new Collection for a given user.
 java.lang.String registerUser(User user, BizContext context)
          Register a new user.
 void removeUser(java.lang.Long userId, BizContext context)
          Remove a User from the back end.
 void setAdminUserTemplate(java.util.Map<java.lang.String,java.lang.Object> adminUserTemplate)
           
 void setAlbumDao(AlbumDao albumDao)
           
 void setAlbumFeedMaxLength(int albumFeedMaxLength)
           
 void setAnonymousUserTemplate(java.util.Map<java.lang.String,java.lang.Object> anonymousUserTemplate)
           
 void setCollectionDao(CollectionDao collectionDao)
           
 void setDefaultCollectionCommentMessageKey(java.lang.String defaultCollectionCommentMessageKey)
           
 void setDefaultCollectionNameMessageKey(java.lang.String defaultCollectionNameMessageKey)
           
 void setDefaultThumbQuality(MediaQuality defaultThumbQuality)
           
 void setDefaultThumbSize(MediaSize defaultThumbMediaSize)
           
 void setDefaultViewQuality(MediaQuality defaultViewQuality)
           
 void setDefaultViewSize(MediaSize defaultViewMediaSize)
           
 void setDomainObjectFactory(DomainObjectFactory domainObjectFactory)
           
 void setEncryptor(magoffin.matt.util.DataEncryption encryptor)
           
 void setIoBiz(IOBiz ioBiz)
           
 void setMessages(org.springframework.context.MessageSource messages)
           
 void setSalt(byte[] salt)
           
 void setSystemBiz(SystemBiz systemBiz)
           
 void setUserDao(UserDao userDao)
           
 void setUserValidator(org.springframework.validation.Validator userValidator)
           
 void setWatermarkSizes(java.util.Set<MediaSize> watermarkSizes)
           
 java.lang.Long storeCollection(Collection collection, BizContext context)
          Store a collection in the back end.
 java.lang.Long storeUser(User user, BizContext context)
          Store a User in the back end.
 void storeUserPreferences(PreferencesCommand command, BizContext context)
          Store user preferences in the back end.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ALBUM_FEED_MAX_LENGHT

public static final int DEFAULT_ALBUM_FEED_MAX_LENGHT
The default value for the albumFeedMaxLength property.

See Also:
Constant Field Values
Constructor Detail

UserBizImpl

public UserBizImpl()
Method Detail

init

public void init()
Call to initialize the class after configuring properties.


finish

public void finish()
Call to release any class resources when finished using.


getCollection

public Collection getCollection(java.lang.Long collectionId,
                                BizContext context)
Description copied from interface: UserBiz
Get a single collection.

The collection items need not be populated here. See the MediaBiz.getCollectionWithItems(Long, BizContext) method for that.

Specified by:
getCollection in interface UserBiz
Parameters:
collectionId - the ID of the collection to get
context - the current context
Returns:
the collection, or null if not available

storeCollection

public java.lang.Long storeCollection(Collection collection,
                                      BizContext context)
                               throws AuthorizationException
Description copied from interface: UserBiz
Store a collection in the back end.

This method will accept new collections as well as updates to existing collections.

Specified by:
storeCollection in interface UserBiz
Parameters:
collection - the collection to store
context - the current context
Returns:
the stored collection's primary key
Throws:
AuthorizationException - if the current user is not authorized to update this collection

registerUser

public java.lang.String registerUser(User user,
                                     BizContext context)
                              throws AuthorizationException
Description copied from interface: UserBiz
Register a new user.

Use this method to register a new user. After registration the user will be stored in the back end, but the user will require confirmation before they can officially log into the application (see UserBiz.confirmRegisteredUser(String, String, BizContext)).

Specified by:
registerUser in interface UserBiz
Parameters:
user - the new user to register
context - the BizContext
Returns:
a confirmation string suitable to pass to UserBiz.confirmRegisteredUser(String, String, BizContext)
Throws:
AuthorizationException - if the desired login is taken already, this exception will be thrown with the reason code AuthorizationException.Reason#DUPLICATE_LOGIN

confirmRegisteredUser

public User confirmRegisteredUser(java.lang.String login,
                                  java.lang.String confirmationCode,
                                  BizContext context)
                           throws AuthorizationException
Description copied from interface: UserBiz
Confirm a registered user.

After a user has registered (see UserBiz.registerUser(User, BizContext)) they must confirm the registration via this method. After confirmation the user can login via UserBiz.logonUser(String, String) as a normal user.

Specified by:
confirmRegisteredUser in interface UserBiz
Parameters:
login - the login to confirm
confirmationCode - the confirmation code
context - the BizContext
Returns:
the confirmed user
Throws:
AuthorizationException - if the confirmationCode does not match then the reason code will be set to AuthorizationException.Reason#REGISTRATION_NOT_CONFIRMED, if the login is not found then AuthorizationException.Reason#UNKNOWN_LOGIN, if the account has already been confirmed then AuthorizationException.Reason#REGISTRATION_ALREADY_CONFIRMED

getCollectionsForUser

public java.util.List<Collection> getCollectionsForUser(User user,
                                                        BizContext context)
Description copied from interface: UserBiz
Get all collections for a given user.

Note this method is not presumed to return Collection instances populated with the MediaItem instances associated with each Collection. That is assumed to be a very expensive operation, so the implementation need not bother returning "complete" Collection instanes.

Specified by:
getCollectionsForUser in interface UserBiz
Parameters:
user - the user to get collections for
context - the current context
Returns:
non-null List of users's collections

newCollectionForUser

public Collection newCollectionForUser(Collection collection,
                                       User user,
                                       BizContext context)
Description copied from interface: UserBiz
Create a new Collection for a given user.

Specified by:
newCollectionForUser in interface UserBiz
Parameters:
collection - the collection object to associate with the user
user - the user
context - the current context
Returns:
the saved Collection

getAlbumsForUser

public java.util.List<Album> getAlbumsForUser(User user,
                                              BizContext context)
Description copied from interface: UserBiz
Get all albums for a given user.

Note this method is not presumed to return Album instances populated with the MediaItem instances associated with each Album. That is assumed to be a very expensive operation, so the implementation need not bother returning "complete" Album instanes.

Specified by:
getAlbumsForUser in interface UserBiz
Parameters:
user - the user to get albums for
context - the current context
Returns:
non-null List of users's albums

getCollectionDirectory

public java.io.File getCollectionDirectory(Collection collection,
                                           BizContext context)
Description copied from interface: UserBiz
Get the directory for a given collection.

Specified by:
getCollectionDirectory in interface UserBiz
Parameters:
collection - the collection to get the root directory for
context - the current context
Returns:
the directory

getUserLocale

public java.util.Locale getUserLocale(User user,
                                      BizContext context)
Description copied from interface: UserBiz
Get the Locale for a User.

Specified by:
getUserLocale in interface UserBiz
Parameters:
user - the user to get the Locale for
context - the current context
Returns:
Locale

storeUser

public java.lang.Long storeUser(User user,
                                BizContext context)
                         throws AuthorizationException
Description copied from interface: UserBiz
Store a User in the back end.

This method will accept new users as well as updates to existing users.

When updating an existing user, if the User's password field is set to UserBiz.DO_NOT_CHANGE_VALUE then the User's password will not be updated in the back end.

Specified by:
storeUser in interface UserBiz
Parameters:
user - the user to store
context - the current context
Returns:
the stored user's primary key
Throws:
AuthorizationException - if the current user is not authorized to update this user

storeUserPreferences

public void storeUserPreferences(PreferencesCommand command,
                                 BizContext context)
                          throws AuthorizationException
Description copied from interface: UserBiz
Store user preferences in the back end.

Specified by:
storeUserPreferences in interface UserBiz
Parameters:
command - the preferences to store
context - the current context
Throws:
AuthorizationException - if the current user is not authorized to update this user

getUserWatermark

public org.springframework.core.io.Resource getUserWatermark(java.lang.Long userId)
Description copied from interface: UserBiz
Get a Resource for a user's watermark.

Specified by:
getUserWatermark in interface UserBiz
Parameters:
userId - the ID of the user to get the watermark resource for
Returns:
a Resource, or null if none available

removeUser

public void removeUser(java.lang.Long userId,
                       BizContext context)
Description copied from interface: UserBiz
Remove a User from the back end.

Specified by:
removeUser in interface UserBiz
Parameters:
userId - the ID of the User to remove
context - the current context

logonUser

public User logonUser(java.lang.String login,
                      java.lang.String password)
               throws AuthorizationException
Description copied from interface: UserBiz
Authenticate a user by their username and password.

Specified by:
logonUser in interface UserBiz
Parameters:
login - the login name of the user to logon
password - the attempted password
Returns:
the User if found and password matches
Throws:
AuthorizationException - if user not found or password does not match

getAlbumFeedForUser

public java.util.List<Album> getAlbumFeedForUser(AlbumFeedCommand command)
Description copied from interface: UserBiz
Get a List of Albums for a user's album feed.

Specified by:
getAlbumFeedForUser in interface UserBiz
Parameters:
command - the command
Returns:
the albums

getSharedAlbumsForUser

public java.util.List<Album> getSharedAlbumsForUser(BrowseAlbumsCommand command)
Description copied from interface: UserBiz
Get a List of Albums for a browse command.

Specified by:
getSharedAlbumsForUser in interface UserBiz
Parameters:
command - the browse command
Returns:
the albums

getUserById

public User getUserById(java.lang.Long userId,
                        BizContext context)
Description copied from interface: UserBiz
Get a User by its ID.

Specified by:
getUserById in interface UserBiz
Parameters:
userId - the ID of the user to get
context - the current context
Returns:
User

hasAccessLevel

public boolean hasAccessLevel(User user,
                              int level)
Description copied from interface: UserBiz
Return true if the supplied user has the specified access level.

Specified by:
hasAccessLevel in interface UserBiz
Parameters:
user - the user to test
level - the level (use the ACCESS_* constants)
Returns:
true if the supplied user has the specified access level

forgotPassword

public java.lang.String forgotPassword(java.lang.String login,
                                       BizContext context)
                                throws AuthorizationException
Description copied from interface: UserBiz
Call to email a user a link with a one-time password.

Calling this method will do the following:

  1. Generate a random password for the user
  2. Update the user with the new password
  3. Generate a confirmation code for the user to pass later to UserBiz.confirmForgotPassword(String, String, String, BizContext)

Specified by:
forgotPassword in interface UserBiz
Parameters:
login - the login of the user that forgot their password
context - the current context
Returns:
a confirmation string suitable to pass to UserBiz.confirmForgotPassword(String, String, String, BizContext)
Throws:
AuthorizationException - if the login is not found the reason code will be set to AuthorizationException.Reason#UNKNOWN_LOGIN

confirmForgotPassword

public User confirmForgotPassword(java.lang.String login,
                                  java.lang.String confirmationCode,
                                  java.lang.String newPassword,
                                  BizContext context)
                           throws AuthorizationException
Description copied from interface: UserBiz
Confirm a forgotten password.

Specified by:
confirmForgotPassword in interface UserBiz
Parameters:
login - the login of the user being confirmed
confirmationCode - the confirmation code issued by a previous call to UserBiz.forgotPassword(String, BizContext)
newPassword - the new password to set
context - the current context
Returns:
the confirmed user
Throws:
AuthorizationException - if the login is not found the reason code will be set to AuthorizationException.Reason#UNKNOWN_LOGIN, if the confirmationCode does not match then the reason code will be set to AuthorizationException.Reason#FORGOTTEN_PASSWORD_NOT_CONFIRMED

getUserByAnonymousKey

public User getUserByAnonymousKey(java.lang.String key)
Description copied from interface: UserBiz
Get a User by its anonymous key.

Specified by:
getUserByAnonymousKey in interface UserBiz
Parameters:
key - the key of the user to get
Returns:
the user, or null if not found

getUsersWithAccess

public java.util.List<User> getUsersWithAccess(int level)
Description copied from interface: UserBiz
Get a list of User objects that have a specific access level.

Specified by:
getUsersWithAccess in interface UserBiz
Parameters:
level - the access level
Returns:
list of users

getAnonymousUser

public User getAnonymousUser()
Description copied from interface: UserBiz
Get an anonymous user object.

Specified by:
getAnonymousUser in interface UserBiz
Returns:
user instance

isAnonymousUser

public boolean isAnonymousUser(User user)
Description copied from interface: UserBiz
Test if a User is an anonoymous user.

Specified by:
isAnonymousUser in interface UserBiz
Parameters:
user - the user to test
Returns:
true if the user is an anonymous user

getEncryptor

public magoffin.matt.util.DataEncryption getEncryptor()
Returns:
Returns the encryptor.

setEncryptor

public void setEncryptor(magoffin.matt.util.DataEncryption encryptor)
Parameters:
encryptor - The encryptor to set.

getSalt

public byte[] getSalt()
Returns:
Returns the salt.

setSalt

public void setSalt(byte[] salt)
Parameters:
salt - The salt to set.

getUserDao

public UserDao getUserDao()
Returns:
Returns the userDao.

setUserDao

public void setUserDao(UserDao userDao)
Parameters:
userDao - The userDao to set.

getUserValidator

public org.springframework.validation.Validator getUserValidator()
Returns:
Returns the userValidator.

setUserValidator

public void setUserValidator(org.springframework.validation.Validator userValidator)
Parameters:
userValidator - The userValidator to set.

getSystemBiz

public SystemBiz getSystemBiz()
Returns:
Returns the systemBiz.

setSystemBiz

public void setSystemBiz(SystemBiz systemBiz)
Parameters:
systemBiz - The systemBiz to set.

getCollectionDao

public CollectionDao getCollectionDao()
Returns:
Returns the collectionDao.

setCollectionDao

public void setCollectionDao(CollectionDao collectionDao)
Parameters:
collectionDao - The collectionDao to set.

getDomainObjectFactory

public DomainObjectFactory getDomainObjectFactory()
Returns:
Returns the domainObjectFactory.

setDomainObjectFactory

public void setDomainObjectFactory(DomainObjectFactory domainObjectFactory)
Parameters:
domainObjectFactory - The domainObjectFactory to set.

getMessages

public org.springframework.context.MessageSource getMessages()
Returns:
Returns the messages.

setMessages

public void setMessages(org.springframework.context.MessageSource messages)
Parameters:
messages - The messages to set.

getDefaultCollectionNameMessageKey

public java.lang.String getDefaultCollectionNameMessageKey()
Returns:
Returns the defaultCollectionNameMessageKey.

setDefaultCollectionNameMessageKey

public void setDefaultCollectionNameMessageKey(java.lang.String defaultCollectionNameMessageKey)
Parameters:
defaultCollectionNameMessageKey - The defaultCollectionNameMessageKey to set.

getDefaultCollectionCommentMessageKey

public java.lang.String getDefaultCollectionCommentMessageKey()
Returns:
Returns the defaultCollectionCommentMessageKey.

setDefaultCollectionCommentMessageKey

public void setDefaultCollectionCommentMessageKey(java.lang.String defaultCollectionCommentMessageKey)
Parameters:
defaultCollectionCommentMessageKey - The defaultCollectionCommentMessageKey to set.

getAlbumDao

public AlbumDao getAlbumDao()
Returns:
Returns the albumDao.

setAlbumDao

public void setAlbumDao(AlbumDao albumDao)
Parameters:
albumDao - The albumDao to set.

getAdminUserTemplate

public java.util.Map<java.lang.String,java.lang.Object> getAdminUserTemplate()
Returns:
Returns the adminUserTemplate.

setAdminUserTemplate

public void setAdminUserTemplate(java.util.Map<java.lang.String,java.lang.Object> adminUserTemplate)
Parameters:
adminUserTemplate - The adminUserTemplate to set.

getDefaultThumbSize

public MediaSize getDefaultThumbSize()
Returns:
the defaultThumbMediaSize

setDefaultThumbSize

public void setDefaultThumbSize(MediaSize defaultThumbMediaSize)
Parameters:
defaultThumbMediaSize - the defaultThumbMediaSize to set

getDefaultThumbQuality

public MediaQuality getDefaultThumbQuality()
Returns:
the defaultThumbQuality

setDefaultThumbQuality

public void setDefaultThumbQuality(MediaQuality defaultThumbQuality)
Parameters:
defaultThumbQuality - the defaultThumbQuality to set

getDefaultViewSize

public MediaSize getDefaultViewSize()
Returns:
the defaultViewMediaSize

setDefaultViewSize

public void setDefaultViewSize(MediaSize defaultViewMediaSize)
Parameters:
defaultViewMediaSize - the defaultViewMediaSize to set

getDefaultViewQuality

public MediaQuality getDefaultViewQuality()
Returns:
the defaultViewQuality

setDefaultViewQuality

public void setDefaultViewQuality(MediaQuality defaultViewQuality)
Parameters:
defaultViewQuality - the defaultViewQuality to set

getAlbumFeedMaxLength

public int getAlbumFeedMaxLength()
Returns:
the albumFeedMaxLength

setAlbumFeedMaxLength

public void setAlbumFeedMaxLength(int albumFeedMaxLength)
Parameters:
albumFeedMaxLength - the albumFeedMaxLength to set

getAnonymousUserTemplate

public java.util.Map<java.lang.String,java.lang.Object> getAnonymousUserTemplate()
Returns:
the anonymousUserTemplate

setAnonymousUserTemplate

public void setAnonymousUserTemplate(java.util.Map<java.lang.String,java.lang.Object> anonymousUserTemplate)
Parameters:
anonymousUserTemplate - the anonymousUserTemplate to set

getWatermarkSizes

public java.util.Set<MediaSize> getWatermarkSizes()
Returns:
the watermarkSizes

setWatermarkSizes

public void setWatermarkSizes(java.util.Set<MediaSize> watermarkSizes)
Parameters:
watermarkSizes - the watermarkSizes to set

getIoBiz

public IOBiz getIoBiz()
Returns:
the ioBiz

setIoBiz

public void setIoBiz(IOBiz ioBiz)
Parameters:
ioBiz - the ioBiz to set