magoffin.matt.ma2.dao.support
Class PopularityBrowseModePlugin

java.lang.Object
  extended by magoffin.matt.ma2.support.AbstractPlugin
      extended by magoffin.matt.ma2.dao.support.AbstractJdbcBrowseModePlugin
          extended by magoffin.matt.ma2.dao.support.PopularityBrowseModePlugin
All Implemented Interfaces:
BrowseModePlugin, Plugin

public class PopularityBrowseModePlugin
extends AbstractJdbcBrowseModePlugin

Browse mode based on media item popularity (hits).

The configurable properties of this class are:

sqlBrowse

The SQL to generate the browse results. This must return the aggregate count of all browsable items, grouped in "buckets" by number of hits each item has, e.g. "0 - 19", "20 - 39", etc. These "buckets" will be turned into index keys. The SQL must return two columns: an integer bucket for the lower bound of the bucket range, and an integer item_count for the count of items that fall within this bucket.

The SQL query takes a template parameter 0 as the bucket size, configured by the setPopularityBucketSize(int) property. Then the following positional SQL parameters will be set:

  1. User ID (long) - the user to display the browsable items for
  2. allow anonymous flag (boolean) - will be set to true
  3. allow browse flag (boolean) - will be set to true

The boolean flags are set as positional parameters for cross-database support for boolean values.

sqlBrowseSection

The SQL to generate the results for a single index section (i.e. popularity bucket range) and also to populate the items in a single album for viewing a single album. The following positional SQL parameters will be set:

  1. User ID (long) - the user to display the browsable items for
  2. allow anonymous flag (boolean) - will be set to true
  3. allow browse flag (boolean) - will be set to true
  4. bucket lower range (integer) - the lower hits range, inclusive, to display
  5. bucket upper range (integer) - the upper hits range, exclusive, to display

The SQL must return the following columns:

item_id
The Long item ID.
item_name
The String item name.
item_mime
The String item MIME value.
sectionAlbumMaxSize
The maximum album size for items within a single section. This is to break up large sections into smaller albums. This plugin will generate albums with at most this many items in them.
messages
The plugin message resources.

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

Field Summary
static int DEFAULT_POPULARITY_BUCKET_SIZE
          The default value for the popularityBucketSize property.
static int DEFAULT_SECTION_ALBUM_MAX_SIZE
          The default value for the sectionAlbumMaxSize property.
static java.lang.String MESSAGE_KEY_ALBUM_TITLE_MULTI
          The message key for an album title with more than one item in it.
static java.lang.String MESSAGE_KEY_ALBUM_TITLE_SINGLE
          The message key for an album title with just one item in it.
static java.lang.String MODE_POPULARITY
          Browse mode key for popularity.
 
Fields inherited from class magoffin.matt.ma2.support.AbstractPlugin
log
 
Constructor Summary
PopularityBrowseModePlugin()
           
 
Method Summary
 SearchResults find(BrowseAlbumsCommand command, PaginationCriteria pagination)
          Perform the search, returning SearchResults populated with AlbumSearchResult objects.
 java.lang.String[] getMessageResourceNames()
          Get a list of message resource names to register.
 org.springframework.context.MessageSource getMessages()
           
 int getPopularityBucketSize()
           
 int getSectionAlbumMaxSize()
           
 java.lang.String getSqlBrowse()
           
 java.lang.String getSqlBrowseSection()
           
 java.lang.String[] getSupportedModes()
          Get the supported modes of this plugin.
 void init()
          Manual initialization method.
protected  void init(org.springframework.context.ApplicationContext application)
          Initialization hook for subclasses.
 void setMessages(org.springframework.context.MessageSource messages)
           
 void setPopularityBucketSize(int popularityBucketSize)
           
 void setSectionAlbumMaxSize(int sectionAlbumMaxSize)
           
 void setSqlBrowse(java.lang.String sqlBrowse)
           
 void setSqlBrowseSection(java.lang.String sqlBrowseSection)
           
 boolean supportsMode(java.lang.String mode)
          Test if this plugin supports a given browse mode.
 
Methods inherited from class magoffin.matt.ma2.dao.support.AbstractJdbcBrowseModePlugin
getDomainObjectFactory, getJdbcTemplate, getPluginType, getUserBiz, setDomainObjectFactory, setJdbcTemplate, setUserBiz
 
Methods inherited from class magoffin.matt.ma2.support.AbstractPlugin
getConfigName, initialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface magoffin.matt.ma2.plugin.Plugin
initialize
 

Field Detail

MODE_POPULARITY

public static final java.lang.String MODE_POPULARITY
Browse mode key for popularity.

See Also:
Constant Field Values

DEFAULT_SECTION_ALBUM_MAX_SIZE

public static final int DEFAULT_SECTION_ALBUM_MAX_SIZE
The default value for the sectionAlbumMaxSize property.

See Also:
Constant Field Values

DEFAULT_POPULARITY_BUCKET_SIZE

public static final int DEFAULT_POPULARITY_BUCKET_SIZE
The default value for the popularityBucketSize property.

See Also:
Constant Field Values

MESSAGE_KEY_ALBUM_TITLE_SINGLE

public static final java.lang.String MESSAGE_KEY_ALBUM_TITLE_SINGLE
The message key for an album title with just one item in it.

See Also:
Constant Field Values

MESSAGE_KEY_ALBUM_TITLE_MULTI

public static final java.lang.String MESSAGE_KEY_ALBUM_TITLE_MULTI
The message key for an album title with more than one item in it.

See Also:
Constant Field Values
Constructor Detail

PopularityBrowseModePlugin

public PopularityBrowseModePlugin()
Method Detail

supportsMode

public boolean supportsMode(java.lang.String mode)
Description copied from interface: BrowseModePlugin
Test if this plugin supports a given browse mode.

Parameters:
mode - the mode to test
Returns:
boolean

init

protected void init(org.springframework.context.ApplicationContext application)
Description copied from class: AbstractPlugin
Initialization hook for subclasses.

This method will be called at the end of the AbstractPlugin.initialize(org.springframework.context.ApplicationContext) method.

Overrides:
init in class AbstractPlugin
Parameters:
application - the ApplicationContext

getMessageResourceNames

public java.lang.String[] getMessageResourceNames()
Description copied from interface: Plugin
Get a list of message resource names to register.

Returns:
the message resource names

getSupportedModes

public java.lang.String[] getSupportedModes()
Description copied from interface: BrowseModePlugin
Get the supported modes of this plugin.

Returns:
the supported modes

init

public void init()
Manual initialization method.

This is used by unit tests.


find

public SearchResults find(BrowseAlbumsCommand command,
                          PaginationCriteria pagination)
Description copied from interface: BrowseModePlugin
Perform the search, returning SearchResults populated with AlbumSearchResult objects.

Parameters:
command - the browse command
pagination - the pagination criteria
Returns:
the search results

getSqlBrowse

public java.lang.String getSqlBrowse()
Returns:
the sqlBrowse

setSqlBrowse

public void setSqlBrowse(java.lang.String sqlBrowse)
Parameters:
sqlBrowse - the sqlBrowse to set

getSqlBrowseSection

public java.lang.String getSqlBrowseSection()
Returns:
the sqlBrowseSection

setSqlBrowseSection

public void setSqlBrowseSection(java.lang.String sqlBrowseSection)
Parameters:
sqlBrowseSection - the sqlBrowseSection to set

getSectionAlbumMaxSize

public int getSectionAlbumMaxSize()
Returns:
the sectionAlbumMaxSize

setSectionAlbumMaxSize

public void setSectionAlbumMaxSize(int sectionAlbumMaxSize)
Parameters:
sectionAlbumMaxSize - the sectionAlbumMaxSize 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

getPopularityBucketSize

public int getPopularityBucketSize()
Returns:
the popularityBucketSize

setPopularityBucketSize

public void setPopularityBucketSize(int popularityBucketSize)
Parameters:
popularityBucketSize - the popularityBucketSize to set