com.cutunes.server
Class RequestHandler

java.lang.Object
  extended bycom.cutunes.server.RequestHandler

public class RequestHandler
extends java.lang.Object

RequestHandler specifies the format of the incoming XML-RPC messages. All messages requires some sort of access to the database, but all database logic has been separated into the DatabaseController class. The four methods below define the API used to communicate between the client and server, making for a very simple and easy to understand API.

Author:
blake, hal2001

Constructor Summary
RequestHandler()
          Constructor gets an instance of the DatabaseController.
 
Method Summary
 boolean bulkLoadSongs(int userID, boolean sendAllSongs, java.util.Date lastSync, java.lang.String version, java.util.Vector songGroup)
          This method received the user's song information over XML-RPC and adds it to the database.
 int countForArtist(java.lang.String query, java.lang.String version)
          Get the total playcounts for an artist query
 java.util.Vector getArtistsLike(java.lang.String artist, java.lang.String version)
          Gets artists similar to a specified artist
 java.util.Vector getArtistsOfUser(int userID, int myUserID, int limit, java.lang.String version)
          Get the top artists of a user that another user also has
 java.sql.Timestamp getLastSync(int userID, java.lang.String version)
          Queries database to get the time of the user's last sync.
 java.util.Vector getSongsForArtist(java.lang.String artist, int userID, int numItems, java.lang.String version)
          Get songs of an artist that a user has
 java.lang.Integer getUserID(java.lang.String username, java.lang.String password, java.lang.String version)
          getUserID() performs basic login checks and returns the given user's unique ID number.
 java.util.Vector getUserIDFor(java.lang.String query, java.lang.String version)
          Get a userID, and name for a given query.
 boolean loadPlaylists(int userID, boolean sendAllSongs, java.util.Date lastSync, java.lang.String version, java.util.Vector playlistGroup)
          Load playlist data -- currently not used, because we dont have a way to store playlists in the database yet
 void logPlaylist(java.lang.String query, int userID, java.lang.String version)
          Log a user creating a playlist from a query
 boolean setLastSync(int userID, java.lang.String version)
          Sets the user's last sync time to the current time.
 boolean updateForFirstSync(int userID, java.lang.String version)
          The first time the user syncs we should update their this week play counts in a specific way
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestHandler

public RequestHandler()
Constructor gets an instance of the DatabaseController.

Method Detail

getUserID

public java.lang.Integer getUserID(java.lang.String username,
                                   java.lang.String password,
                                   java.lang.String version)
getUserID() performs basic login checks and returns the given user's unique ID number. Checks to see if user is running an acceptable version of the client program, and queries the database to get the user ID.

Parameters:
username - String username
password - String password
version - String identifying version of client software
Returns:
Returns userID if user/password match database, returns -1 if user/password pair not in DB, and returns -10 if wrong version of client software is being used.

getLastSync

public java.sql.Timestamp getLastSync(int userID,
                                      java.lang.String version)
Queries database to get the time of the user's last sync.

Parameters:
userID - Unique ID of user
version - String identifying version of client software
Returns:
Timestamp of user's last sync

setLastSync

public boolean setLastSync(int userID,
                           java.lang.String version)
Sets the user's last sync time to the current time.

Parameters:
userID - Unique ID of user
version - String identifying version of client software
Returns:
True if successfully updated

updateForFirstSync

public boolean updateForFirstSync(int userID,
                                  java.lang.String version)
The first time the user syncs we should update their this week play counts in a specific way

Parameters:
userID - Unique ID of user
version - String identifying version of client software
Returns:
True if successfully updated

bulkLoadSongs

public boolean bulkLoadSongs(int userID,
                             boolean sendAllSongs,
                             java.util.Date lastSync,
                             java.lang.String version,
                             java.util.Vector songGroup)
This method received the user's song information over XML-RPC and adds it to the database. Many things have been done to improve performance, specifically the user's track information is written to two files in the server's /tmp space so that MySQL load data function can be used.

The songsFile contains all the track information to put in the songs table of the database (this includes track name, album, artist, etc). This information is always loaded into the database using MySQLs bulk load function, even if it already exists in the table (in which case it is ignored).

The hasSongsFile contains all the information about the playcount and last play date of a specified song for a given user. It is written and bulk loaded only if the sendAllSongs boolean is true (which indicates this is a user's first sync). Otherwise this information is loaded using the DatabaseController's updateHasSong function (which updates weekly playcounts according to a specified algorithm).

Parameters:
userID - Unique ID identifying user
sendAllSongs - Boolean variable is true if this is a user's first sync, in which case the has_song table data is bulk loaded
lastSync - The time of the user's last sync
version - String identifying version of client software
songGroup - Vector of SongData objects
Returns:
True if successfully loads data

loadPlaylists

public boolean loadPlaylists(int userID,
                             boolean sendAllSongs,
                             java.util.Date lastSync,
                             java.lang.String version,
                             java.util.Vector playlistGroup)
Load playlist data -- currently not used, because we dont have a way to store playlists in the database yet

Parameters:
userID -
sendAllSongs -
lastSync -
version -
playlistGroup -
Returns:

getArtistsLike

public java.util.Vector getArtistsLike(java.lang.String artist,
                                       java.lang.String version)
Gets artists similar to a specified artist

Parameters:
artist -
version -
Returns:

getSongsForArtist

public java.util.Vector getSongsForArtist(java.lang.String artist,
                                          int userID,
                                          int numItems,
                                          java.lang.String version)
Get songs of an artist that a user has

Parameters:
artist -
userID -
numItems -
version -
Returns:

getArtistsOfUser

public java.util.Vector getArtistsOfUser(int userID,
                                         int myUserID,
                                         int limit,
                                         java.lang.String version)
Get the top artists of a user that another user also has

Parameters:
userID -
myUserID -
limit -
version -
Returns:

getUserIDFor

public java.util.Vector getUserIDFor(java.lang.String query,
                                     java.lang.String version)
Get a userID, and name for a given query. The query can be a firstname, lastname, username, or fullname.

Parameters:
query -
version -
Returns:

countForArtist

public int countForArtist(java.lang.String query,
                          java.lang.String version)
Get the total playcounts for an artist query

Parameters:
query -
version -
Returns:

logPlaylist

public void logPlaylist(java.lang.String query,
                        int userID,
                        java.lang.String version)
Log a user creating a playlist from a query

Parameters:
query -
userID -
version -