magoffin.matt.ma2.biz.impl
Class MediaBizImpl

java.lang.Object
  extended by magoffin.matt.ma2.biz.impl.MediaBizImpl
All Implemented Interfaces:
MediaBiz

public class MediaBizImpl
extends java.lang.Object
implements MediaBiz

Default implementation of MediaBiz.

The configurable properties of this class are:

mediaHandlerFileExtensionMap
A Map of file name extensions (without the period) to implementations of MediaHandler that should be used for files with matching extensions.
mediaHandlerMimeMap
A Map of MIME types to implementations of MediaHandler that should be used for media items with matching MIME types.
geometryMap
A mapping of MediaSize constants to Geometry sizes.
qualityMap
A mapping of MediaQuality constants to Float values, where the float ranges from 0.0 to 1.0 and 1.0 represents the best quality possible.
sortModeMap
A mapping of integer sort keys to Comparators for sorting MediaItem instances with. This is used for sorting album items. If not configured, then the MediaItemSorter class will be used by default. For each sort key defined (either via this map or via the MediaItemSorter.SortMode keys) two message properties will be looked up during a call to the getAlbumSortTypes(BizContext) method. The first will be like album.sortmode.<KEY>.name, where <KEY> is the sort key. This will be used for the display name of this sort mode. The second message will be like album.sortmode.<KEY>.caption and will be used as the optional caption for the sort mode.

Version:
$Revision: 176 $ $Date: 2008-12-28 14:33:18 +1300 (Sun, 28 Dec 2008) $
Author:
matt.magoffin

Constructor Summary
MediaBizImpl()
           
 
Method Summary
 int addMediaItemsToAlbum(Album album, java.lang.Long[] mediaItemIds, BizContext context)
          Add a set of media items to an album.
 Album deleteAlbum(java.lang.Long albumId, BizContext context)
          Delete an album, and any nested albums.
 java.util.List<MediaItem> deleteCollectionAndItems(java.lang.Long collectionId, BizContext context)
          Delete a Collection and physically delete the media items in the collection.
 int deleteMediaItems(java.lang.Long[] itemIds, BizContext context)
          Physically delete media items.
 void finish()
          Call to clean up resources as necessary.
 Album getAlbum(java.lang.Long albumId, BizContext context)
          Get an Album.
 AlbumDao getAlbumDao()
           
 Album getAlbumParent(java.lang.Long childAlbumId, BizContext context)
          Get the parent of an album, if one exists.
 java.util.List<KeyNameType> getAlbumSortTypes(BizContext context)
          Get the list of support album sort types.
 Album getAlbumWithItems(java.lang.Long albumId, BizContext context)
          Get an Album along with the MediaItems of that album.
 CollectionDao getCollectionDao()
           
 Collection getCollectionWithItems(java.lang.Long collectionId, BizContext context)
          Get a Collection along with the MediaItems of that collection.
 DomainObjectFactory getDomainObjectFactory()
           
 Geometry getGeometry(MediaSize size)
          Get a geometry for a given size.
 java.util.EnumMap<MediaSize,Geometry> getGeometryMap()
           
 IOBiz getIoBiz()
           
 MediaHandler getMediaHandler(java.io.File file)
          Get a MediaHandler instance for a given file.
 MediaHandler getMediaHandler(java.lang.String mime)
          Get a MediaHandler instance for a given MIME type.
 java.util.Map<java.lang.String,MediaHandler> getMediaHandlerFileExtensionMap()
           
 java.util.Map<java.lang.String,MediaHandler> getMediaHandlerMimeMap()
           
 Collection getMediaItemCollection(MediaItem item)
          Get the Collection for a given MediaItem.
 MediaItemDao getMediaItemDao()
           
 org.springframework.core.io.Resource getMediaItemResource(MediaItem item)
          Get a Resource for a given MediaItem.
 java.util.List<MediaItem> getMediaItemsForAlbum(Album album, BizContext context)
          Get all MediaItems that belong to a given Album.
 java.util.List<MediaItem> getMediaItemsForCollection(Collection collection, BizContext context)
          Get all MediaItems that belong to a given Collection.
 MediaItem getMediaItemWithInfo(java.lang.Long itemId, BizContext context)
          Get a MediaItem along with the meta data and other info populated.
 org.springframework.context.MessageSource getMessages()
           
 java.util.EnumMap<MediaQuality,java.lang.Float> getQualityMap()
           
 float getQualityValue(MediaQuality quality)
          Get a quality value, where the value ranges from 0.0 to 1.0 and 1.0 represents the hightest quality possible.
 byte[] getSalt()
           
 Geometry getScaledGeometry(MediaItem item, MediaRequest request)
          Creates a Geometry scaled to the desired MediaSize set on the request.
 Album getSharedAlbum(java.lang.String key, BizContext context)
          Get a shared album.
 SystemBiz getSystemBiz()
           
 UserBiz getUserBiz()
           
 int incrementMediaItemHits(java.lang.Long itemId)
          Increment the hits value for a particular MediaItem object and return the incremented value.
 void init()
          Call to initialize after peroprties have been set.
 boolean isFileSupported(java.io.File file)
          Return true if a file is supported by some configured MediaHandler.
 void moveMediaItems(MoveItemsCommand command, BizContext context)
          Move a set of media items from the collection they currently are in to a different collection.
 int removeMediaItemsFromAlbum(java.lang.Long albumId, java.lang.Long[] itemIds, BizContext context)
          Remove a list of item IDs from an Album.
 void setAlbumDao(AlbumDao albumDao)
           
 void setCollectionDao(CollectionDao collectionDao)
           
 void setDomainObjectFactory(DomainObjectFactory domainObjectFactory)
           
 void setGeometryMap(java.util.EnumMap<MediaSize,Geometry> geometryMap)
           
 void setIoBiz(IOBiz ioBiz)
           
 void setMediaHandlerFileExtensionMap(java.util.Map<java.lang.String,MediaHandler> fileExtensionMap)
           
 void setMediaHandlerMimeMap(java.util.Map<java.lang.String,MediaHandler> mediaHandlerMimeMap)
           
 void setMediaItemDao(MediaItemDao mediaItemDao)
           
 void setMessages(org.springframework.context.MessageSource messages)
           
 void setQualityMap(java.util.EnumMap<MediaQuality,java.lang.Float> qualityMap)
           
 void setSalt(byte[] salt)
           
 void setSystemBiz(SystemBiz systemBiz)
           
 void setUserBiz(UserBiz userBiz)
           
 java.lang.String shareAlbum(ShareAlbumCommand command, BizContext context)
          Share an album.
 void sortAlbumItems(Album album)
          Sort the media items within an album based on the Albums' sort mode.
 java.lang.Long storeAlbum(Album album, BizContext context)
          Store an Album.
 void storeAlbumOrdering(SortAlbumsCommand command, BizContext context)
          Set the ording for the child albums of an album.
 void storeAlbumParent(java.lang.Long childAlbumId, java.lang.Long parentAlbumId, BizContext context)
          Make an album a child of another album.
 void storeMediaItemInfo(MediaInfoCommand command, BizContext context)
          Store info for media items.
 void storeMediaItemOrdering(SortMediaItemsCommand command, BizContext context)
          Set the ording for the media items of an album.
 void storeMediaItemPoster(java.lang.Long itemId, java.lang.Long albumId, BizContext context)
          Store the poster item for an album.
 void storeMediaItemRating(java.lang.Long[] itemIds, short rating, BizContext context)
          Set the rating for a media item.
 void storeMediaItemUserComment(UserCommentCommand command, BizContext context)
          Add a new UserComment to a MediaItem.
 void unShareAlbum(java.lang.Long albumId, BizContext context)
          Unshare an album.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MediaBizImpl

public MediaBizImpl()
Method Detail

init

public void init()
Call to initialize after peroprties have been set.


finish

public void finish()
Call to clean up resources as necessary.


isFileSupported

public boolean isFileSupported(java.io.File file)
Description copied from interface: MediaBiz
Return true if a file is supported by some configured MediaHandler.

Specified by:
isFileSupported in interface MediaBiz
Parameters:
file - the file
Returns:
boolean

getMediaHandler

public MediaHandler getMediaHandler(java.io.File file)
Description copied from interface: MediaBiz
Get a MediaHandler instance for a given file.

Specified by:
getMediaHandler in interface MediaBiz
Parameters:
file - the file
Returns:
MediaHandler instance

getMediaHandler

public MediaHandler getMediaHandler(java.lang.String mime)
Description copied from interface: MediaBiz
Get a MediaHandler instance for a given MIME type.

Specified by:
getMediaHandler in interface MediaBiz
Parameters:
mime - the MIME type
Returns:
MediaHandler instance

getGeometry

public Geometry getGeometry(MediaSize size)
Description copied from interface: MediaBiz
Get a geometry for a given size.

Specified by:
getGeometry in interface MediaBiz
Parameters:
size - the size
Returns:
the geometry

getQualityValue

public float getQualityValue(MediaQuality quality)
Description copied from interface: MediaBiz
Get a quality value, where the value ranges from 0.0 to 1.0 and 1.0 represents the hightest quality possible.

Specified by:
getQualityValue in interface MediaBiz
Parameters:
quality - the quality
Returns:
the quality value

storeMediaItemRating

public void storeMediaItemRating(java.lang.Long[] itemIds,
                                 short rating,
                                 BizContext context)
Description copied from interface: MediaBiz
Set the rating for a media item.

Specified by:
storeMediaItemRating in interface MediaBiz
Parameters:
itemIds - the IDs of the items to set the rating for
rating - the rating to set
context - the current context

storeMediaItemPoster

public void storeMediaItemPoster(java.lang.Long itemId,
                                 java.lang.Long albumId,
                                 BizContext context)
Description copied from interface: MediaBiz
Store the poster item for an album.

Specified by:
storeMediaItemPoster in interface MediaBiz
Parameters:
itemId - the ID of the item to use as the poster
albumId - the ID of the album to set the poster for
context - the current context

getMediaItemResource

public org.springframework.core.io.Resource getMediaItemResource(MediaItem item)
Description copied from interface: MediaBiz
Get a Resource for a given MediaItem.

Specified by:
getMediaItemResource in interface MediaBiz
Parameters:
item - the item
Returns:
the Resource

getMediaItemCollection

public Collection getMediaItemCollection(MediaItem item)
Description copied from interface: MediaBiz
Get the Collection for a given MediaItem.

Specified by:
getMediaItemCollection in interface MediaBiz
Parameters:
item - the item
Returns:
the Collection

getMediaItemsForCollection

public java.util.List<MediaItem> getMediaItemsForCollection(Collection collection,
                                                            BizContext context)
Description copied from interface: MediaBiz
Get all MediaItems that belong to a given Collection.

Specified by:
getMediaItemsForCollection in interface MediaBiz
Parameters:
collection - the Collection
context - the current context
Returns:
the list of items

getMediaItemsForAlbum

public java.util.List<MediaItem> getMediaItemsForAlbum(Album album,
                                                       BizContext context)
Description copied from interface: MediaBiz
Get all MediaItems that belong to a given Album.

Specified by:
getMediaItemsForAlbum in interface MediaBiz
Parameters:
album - the Album
context - the current context
Returns:
the list of items

sortAlbumItems

public void sortAlbumItems(Album album)
Description copied from interface: MediaBiz
Sort the media items within an album based on the Albums' sort mode.

Specified by:
sortAlbumItems in interface MediaBiz
Parameters:
album - the album to sort

storeMediaItemOrdering

public void storeMediaItemOrdering(SortMediaItemsCommand command,
                                   BizContext context)
Description copied from interface: MediaBiz
Set the ording for the media items of an album.

Specified by:
storeMediaItemOrdering in interface MediaBiz
Parameters:
command - the sort command
context - the context

addMediaItemsToAlbum

public int addMediaItemsToAlbum(Album album,
                                java.lang.Long[] mediaItemIds,
                                BizContext context)
Description copied from interface: MediaBiz
Add a set of media items to an album.

Specified by:
addMediaItemsToAlbum in interface MediaBiz
Parameters:
album - the album
mediaItemIds - the IDs of the media items to add
context - the context
Returns:
the number of items added to the album

deleteCollectionAndItems

public java.util.List<MediaItem> deleteCollectionAndItems(java.lang.Long collectionId,
                                                          BizContext context)
Description copied from interface: MediaBiz
Delete a Collection and physically delete the media items in the collection.

Specified by:
deleteCollectionAndItems in interface MediaBiz
Parameters:
collectionId - the ID of the collection to delete
context - the current context
Returns:
the media items deleted

getScaledGeometry

public Geometry getScaledGeometry(MediaItem item,
                                  MediaRequest request)
Description copied from interface: MediaBiz
Creates a Geometry scaled to the desired MediaSize set on the request.

Specified by:
getScaledGeometry in interface MediaBiz
Parameters:
item - the media item for the current request
request - the current request
Returns:
the scaled Geometry

getAlbumWithItems

public Album getAlbumWithItems(java.lang.Long albumId,
                               BizContext context)
Description copied from interface: MediaBiz
Get an Album along with the MediaItems of that album.

Specified by:
getAlbumWithItems in interface MediaBiz
Parameters:
albumId - the ID of the Album to get
context - the current context
Returns:
the Album

getAlbum

public Album getAlbum(java.lang.Long albumId,
                      BizContext context)
Description copied from interface: MediaBiz
Get an Album.

The Album may not have any MediaItem instances populated in it. Use the MediaBiz.getAlbumWithItems(Long, BizContext) method to get an Album with its items at the same time.

Specified by:
getAlbum in interface MediaBiz
Parameters:
albumId - the ID of the Album to get
context - the context
Returns:
the Album

getMediaItemWithInfo

public MediaItem getMediaItemWithInfo(java.lang.Long itemId,
                                      BizContext context)
Description copied from interface: MediaBiz
Get a MediaItem along with the meta data and other info populated.

Specified by:
getMediaItemWithInfo in interface MediaBiz
Parameters:
itemId - the ID of the item to get
context - the current context
Returns:
the MediaItem

getCollectionWithItems

public Collection getCollectionWithItems(java.lang.Long collectionId,
                                         BizContext context)
Description copied from interface: MediaBiz
Get a Collection along with the MediaItems of that collection.

Specified by:
getCollectionWithItems in interface MediaBiz
Parameters:
collectionId - the ID of the Collection to get
context - the current context
Returns:
the Collection

removeMediaItemsFromAlbum

public int removeMediaItemsFromAlbum(java.lang.Long albumId,
                                     java.lang.Long[] itemIds,
                                     BizContext context)
Description copied from interface: MediaBiz
Remove a list of item IDs from an Album.

Specified by:
removeMediaItemsFromAlbum in interface MediaBiz
Parameters:
albumId - the ID of the album to remove the items from
itemIds - the IDs of the items to remove
context - the current context
Returns:
the number of items removed

deleteMediaItems

public int deleteMediaItems(java.lang.Long[] itemIds,
                            BizContext context)
Description copied from interface: MediaBiz
Physically delete media items.

Specified by:
deleteMediaItems in interface MediaBiz
Parameters:
itemIds - the media item IDs to delete
context - the current context
Returns:
the number of items deleted

shareAlbum

public java.lang.String shareAlbum(ShareAlbumCommand command,
                                   BizContext context)
Description copied from interface: MediaBiz
Share an album.

Specified by:
shareAlbum in interface MediaBiz
Parameters:
command - the share album command
context - the context
Returns:
the anonymous key used to view the shared album

getSharedAlbum

public Album getSharedAlbum(java.lang.String key,
                            BizContext context)
Description copied from interface: MediaBiz
Get a shared album.

Specified by:
getSharedAlbum in interface MediaBiz
Parameters:
key - the anonymous key of the album
context - the context
Returns:
the album

unShareAlbum

public void unShareAlbum(java.lang.Long albumId,
                         BizContext context)
Description copied from interface: MediaBiz
Unshare an album.

Specified by:
unShareAlbum in interface MediaBiz
Parameters:
albumId - the ID of the album to unshare
context - the context

incrementMediaItemHits

public int incrementMediaItemHits(java.lang.Long itemId)
Description copied from interface: MediaBiz
Increment the hits value for a particular MediaItem object and return the incremented value.

Specified by:
incrementMediaItemHits in interface MediaBiz
Parameters:
itemId - the ID of the item to increment
Returns:
the incremented value

getAlbumParent

public Album getAlbumParent(java.lang.Long childAlbumId,
                            BizContext context)
Description copied from interface: MediaBiz
Get the parent of an album, if one exists.

Specified by:
getAlbumParent in interface MediaBiz
Parameters:
childAlbumId - the ID of the child album to get the parent of
context - the context
Returns:
the parent album, or null if album has no parent

storeAlbumParent

public void storeAlbumParent(java.lang.Long childAlbumId,
                             java.lang.Long parentAlbumId,
                             BizContext context)
Description copied from interface: MediaBiz
Make an album a child of another album.

If parentAlbumId is null then the album for childAlbumId should be made a top-level album.

Specified by:
storeAlbumParent in interface MediaBiz
Parameters:
childAlbumId - the ID of the child album
parentAlbumId - the ID of the parent album
context - the context

deleteAlbum

public Album deleteAlbum(java.lang.Long albumId,
                         BizContext context)
Description copied from interface: MediaBiz
Delete an album, and any nested albums.

Specified by:
deleteAlbum in interface MediaBiz
Parameters:
albumId - the ID of the album to delete
context - the current context
Returns:
the deleted album, or null if the album was not found

storeMediaItemInfo

public void storeMediaItemInfo(MediaInfoCommand command,
                               BizContext context)
Description copied from interface: MediaBiz
Store info for media items.

Specified by:
storeMediaItemInfo in interface MediaBiz
Parameters:
command - the command data
context - the current context

storeAlbum

public java.lang.Long storeAlbum(Album album,
                                 BizContext context)
Description copied from interface: MediaBiz
Store an Album.

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

Specified by:
storeAlbum in interface MediaBiz
Parameters:
album - the Album to store
context - the context
Returns:
the ID of the saved album

getAlbumSortTypes

public java.util.List<KeyNameType> getAlbumSortTypes(BizContext context)
Description copied from interface: MediaBiz
Get the list of support album sort types.

This is to allow the available sort types to be displayed on the front-end.

Specified by:
getAlbumSortTypes in interface MediaBiz
Parameters:
context - the context
Returns:
list of sort types (never null)

storeAlbumOrdering

public void storeAlbumOrdering(SortAlbumsCommand command,
                               BizContext context)
Description copied from interface: MediaBiz
Set the ording for the child albums of an album.

Specified by:
storeAlbumOrdering in interface MediaBiz
Parameters:
command - the sort command
context - the context

moveMediaItems

public void moveMediaItems(MoveItemsCommand command,
                           BizContext context)
Description copied from interface: MediaBiz
Move a set of media items from the collection they currently are in to a different collection.

Specified by:
moveMediaItems in interface MediaBiz
Parameters:
command - the command object
context - the current context

storeMediaItemUserComment

public void storeMediaItemUserComment(UserCommentCommand command,
                                      BizContext context)
Description copied from interface: MediaBiz
Add a new UserComment to a MediaItem.

Specified by:
storeMediaItemUserComment in interface MediaBiz
Parameters:
command - user comment command
context - the context

getMediaHandlerFileExtensionMap

public java.util.Map<java.lang.String,MediaHandler> getMediaHandlerFileExtensionMap()
Returns:
Returns the fileExtensionMap.

setMediaHandlerFileExtensionMap

public void setMediaHandlerFileExtensionMap(java.util.Map<java.lang.String,MediaHandler> fileExtensionMap)
Parameters:
fileExtensionMap - The fileExtensionMap to set.

getMediaHandlerMimeMap

public java.util.Map<java.lang.String,MediaHandler> getMediaHandlerMimeMap()
Returns:
Returns the mediaHandlerMimeMap.

setMediaHandlerMimeMap

public void setMediaHandlerMimeMap(java.util.Map<java.lang.String,MediaHandler> mediaHandlerMimeMap)
Parameters:
mediaHandlerMimeMap - The mediaHandlerMimeMap to set.

getGeometryMap

public java.util.EnumMap<MediaSize,Geometry> getGeometryMap()
Returns:
Returns the geometryMap.

setGeometryMap

public void setGeometryMap(java.util.EnumMap<MediaSize,Geometry> geometryMap)
Parameters:
geometryMap - The geometryMap to set.

getQualityMap

public java.util.EnumMap<MediaQuality,java.lang.Float> getQualityMap()
Returns:
Returns the qualityMap.

setQualityMap

public void setQualityMap(java.util.EnumMap<MediaQuality,java.lang.Float> qualityMap)
Parameters:
qualityMap - The qualityMap to set.

getCollectionDao

public CollectionDao getCollectionDao()
Returns:
Returns the collectionDao.

setCollectionDao

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

getUserBiz

public UserBiz getUserBiz()
Returns:
Returns the userBiz.

setUserBiz

public void setUserBiz(UserBiz userBiz)
Parameters:
userBiz - The userBiz to set.

getMediaItemDao

public MediaItemDao getMediaItemDao()
Returns:
Returns the mediaItemDao.

setMediaItemDao

public void setMediaItemDao(MediaItemDao mediaItemDao)
Parameters:
mediaItemDao - The mediaItemDao to set.

getAlbumDao

public AlbumDao getAlbumDao()
Returns:
Returns the albumDao.

setAlbumDao

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

getIoBiz

public IOBiz getIoBiz()
Returns:
the ioBiz

setIoBiz

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

getDomainObjectFactory

public DomainObjectFactory getDomainObjectFactory()
Returns:
the domainObjectFactory

setDomainObjectFactory

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

getSalt

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

setSalt

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

getSystemBiz

public SystemBiz getSystemBiz()
Returns:
the systemBiz

setSystemBiz

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

getMessages

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

setMessages

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