magoffin.matt.ma2.dao.support
Class RatingAverageBrowseModePlugin

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.RatingAverageBrowseModePlugin
All Implemented Interfaces:
BrowseModePlugin, Plugin

public class RatingAverageBrowseModePlugin
extends AbstractJdbcBrowseModePlugin

Browse mode based on average media item ratings.

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 by average user ratings each item has, e.g. "0.5", "1", etc. These "buckets" will be turned into index keys. The SQL must return two columns: a float avg_rating for the average rating bucket, and an integer item_count for the count of items that fall within this bucket.

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. average rating) 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. average rating section (float) - the average rating section to display
  5. average rating section (float) - the average rating section to display

The average rating section is set twice to allow the SQL to set lower and upper bounds for that section.

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_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_RATING_AVERAGE
          Browse mode key for average rating.
 
Fields inherited from class magoffin.matt.ma2.support.AbstractPlugin
log
 
Constructor Summary
RatingAverageBrowseModePlugin()
           
 
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 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 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_RATING_AVERAGE

public static final java.lang.String MODE_RATING_AVERAGE
Browse mode key for average rating.

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

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

RatingAverageBrowseModePlugin

public RatingAverageBrowseModePlugin()
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