ensemble
Class DatabaseBean

java.lang.Object
  extended by ensemble.DatabaseBean
All Implemented Interfaces:
java.io.Serializable

@Named(value="databaseBean")
@ApplicationScoped
public class DatabaseBean
extends java.lang.Object
implements java.io.Serializable

This bean handles communication with the database.

See Also:
Serialized Form

Nested Class Summary
static class DatabaseBean.Status
           
 
Constructor Summary
DatabaseBean()
          Initializes data in the bean and prepares it for use.
 
Method Summary
 DatabaseBean.Status checkLogin(java.lang.String userName, java.lang.String password)
          Checks to see if a given username exists and if it matches the given password.
 void excludePredictions(int predID, boolean exclude)
          Sets the flag indicating whether a set of predictions should be excluded from ensembles.
 void excludePredictions(Prediction_set pSet, boolean exclude)
          Sets the flag indicating whether a set of predictions should be excluded from ensembles.
 void excludeUser(java.lang.String userName, boolean exclude)
          Sets the flag indicating whether predictions from a particular user should be excluded from ensembles.
 void excludeUser(User u, java.lang.Boolean exclude)
          Sets the flag indicating whether predictions from a particular user should be excluded from ensembles.
 java.lang.String generateDataSetName(java.lang.String dataName)
          Generates a unique name for a data set.
 java.lang.String generatePredSetName(java.lang.String predName)
          Generates a unique name for a prediction set.
 java.util.List<javax.faces.model.SelectItem> getDataItems()
          Retrieves data sets from the database in the form of SelectItems, with each set's name as the label and its id number as the value.
 java.util.List<Data_set> getDataList()
          Retrieves a list of all the data sets in the database.
 java.util.List<DataSet> getDataSets()
          Returns a list of datasets built from the available XML files.
 java.util.List<Ensemble> getEnsembles()
          Retrieves a list of all ensembles in the database.
 java.lang.String getIndexMessage()
          Retrieves the message to be displayed on the index page.
 java.util.List<Prediction_set> getPredListFor(Data_set data)
          Retrieves a list of all predictions for the given data set.
 java.util.List<PredictionSet> getPredSetsFor(DataSet data)
          Retrieves prediction sets for a set of data.
 java.sql.SQLException getSqlEx()
          Retrieves the most recently thrown SQLException for debugging purposes.
 java.util.List<User> getUserList()
          Generates a list of all users registered in the data base.
 java.lang.Boolean hasNoData()
          Determines if there are no data sets available.
 boolean isAdminRegistered()
          Checks that if user "admin" has been registered, which would indicate that initial setup has taken place.
 java.lang.Boolean isUpdated()
          Determines whether any data or predictions have been added since the last time the method was called.
 boolean isUserExcluded(java.lang.String userName)
          Determines if a particular user's contributions have been excluded by the admin.
 void registerDataset(java.lang.String setName, java.lang.String userName, java.lang.String desc)
          Attempts to register a new data set in the database using the given information.
 void registerEnsemble(Ensemble e)
          Adds an ensemble to the database.
 void registerPredictions(java.lang.String predName, int dataID, java.lang.String userName, java.lang.String desc)
          Attempts to register a set of predictions in the database using the given information.
 DatabaseBean.Status registerUser(java.lang.String userName, java.lang.String password)
          Attempts to register a new user in the database using the given information.
 void removeData(Data_set data)
          Deletes a data set and all predictions for it from the database, and deletes their XML files.
 void removeEnsemble(Ensemble e)
          Deletes an ensemble from the database, and deletes its XML file.
 void removePred(Prediction_set ps)
          Deletes a set of predictions from the database, and deletes its XML file.
 void setIndexMessage(java.lang.String indexMessage)
          Set the message to be displayed on the index page.
 void setSqlEx(java.sql.SQLException ex)
          Sets the SQLExceptoion whose message should be displayed on the dbError page.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseBean

public DatabaseBean()
             throws java.sql.SQLException,
                    java.io.IOException
Initializes data in the bean and prepares it for use.

Throws:
java.sql.SQLException
java.io.IOException
Method Detail

isAdminRegistered

public boolean isAdminRegistered()
                          throws java.sql.SQLException,
                                 java.io.IOException
Checks that if user "admin" has been registered, which would indicate that initial setup has taken place.

Returns:
True if a user with name "admin" exists in database, else false.
Throws:
java.sql.SQLException
java.io.IOException

checkLogin

public DatabaseBean.Status checkLogin(java.lang.String userName,
                                      java.lang.String password)
                               throws java.sql.SQLException,
                                      java.io.IOException
Checks to see if a given username exists and if it matches the given password.

Parameters:
userName - The name given by the user
password - The password given by the user
Returns:
Status.OK if name was found and matched the password, Status.BAD_PSWRD if the name was found but didn't match, or Status.BAD_NAME if the name wasn't found.
Throws:
java.sql.SQLException
java.io.IOException

registerUser

public DatabaseBean.Status registerUser(java.lang.String userName,
                                        java.lang.String password)
                                 throws java.sql.SQLException,
                                        java.io.IOException
Attempts to register a new user in the database using the given information.

Parameters:
userName - The new user's name
password - The new user's password
Returns:
Status.OK if registration was successful, or Status.BAD_NAME if the given name is already registered
Throws:
java.sql.SQLException
java.io.IOException

registerDataset

public void registerDataset(java.lang.String setName,
                            java.lang.String userName,
                            java.lang.String desc)
                     throws java.sql.SQLException,
                            java.io.IOException
Attempts to register a new data set in the database using the given information. Also sets the DatabaseBean's "updated" flag to true if successful.

Parameters:
setName - The name of the new data set
userName - The name of the user who submitted the data set
desc - A description of the data set
Throws:
java.sql.SQLException
java.io.IOException

registerPredictions

public void registerPredictions(java.lang.String predName,
                                int dataID,
                                java.lang.String userName,
                                java.lang.String desc)
                         throws java.sql.SQLException,
                                java.io.IOException
Attempts to register a set of predictions in the database using the given information. Also sets the DatabaseBean's "updated" flag to true if successful.

Parameters:
setName - The name of the new data set
dataID - An ID number identifying the data set the predictions are for
userName - The name of the user who submitted the data set
desc - A description of the data set
Throws:
java.sql.SQLException
java.io.IOException

registerEnsemble

public void registerEnsemble(Ensemble e)
                      throws java.sql.SQLException,
                             java.io.IOException
Adds an ensemble to the database.

Parameters:
e - The ensemble to add
Throws:
java.sql.SQLException
java.io.IOException

getDataItems

public java.util.List<javax.faces.model.SelectItem> getDataItems()
                                                          throws java.sql.SQLException,
                                                                 java.io.IOException
Retrieves data sets from the database in the form of SelectItems, with each set's name as the label and its id number as the value.

Returns:
A list of SelectItems representing the "datasets" database.
Throws:
java.sql.SQLException
java.io.IOException

getDataList

public java.util.List<Data_set> getDataList()
                                     throws java.sql.SQLException,
                                            java.io.IOException
Retrieves a list of all the data sets in the database.

Returns:
A list representing all data sets currently in the database.
Throws:
java.sql.SQLException
java.io.IOException

getPredListFor

public java.util.List<Prediction_set> getPredListFor(Data_set data)
                                              throws java.sql.SQLException,
                                                     java.io.IOException
Retrieves a list of all predictions for the given data set.

Returns:
A list representing all sets of predictions for the data set.
Throws:
java.sql.SQLException
java.io.IOException

getPredSetsFor

public java.util.List<PredictionSet> getPredSetsFor(DataSet data)
                                             throws java.sql.SQLException,
                                                    java.io.IOException
Retrieves prediction sets for a set of data.

Parameters:
data - The DataSet to retrieve predictions for
Returns:
A list containing all PredictionSets for the indicated data, excepting those sets that have been excluded by the admin.
Throws:
java.sql.SQLException
java.io.IOException

getDataSets

public java.util.List<DataSet> getDataSets()
                                    throws java.sql.SQLException,
                                           java.io.IOException
Returns a list of datasets built from the available XML files. Any sets with a file that cannot be parsed are excluded from the list.

Returns:
A list containing all available datasets.
Throws:
java.sql.SQLException
java.io.IOException

getEnsembles

public java.util.List<Ensemble> getEnsembles()
                                      throws java.sql.SQLException,
                                             java.io.IOException
Retrieves a list of all ensembles in the database.

Returns:
A list of all ensembles
Throws:
java.sql.SQLException
java.io.IOException

removePred

public void removePred(Prediction_set ps)
                throws java.sql.SQLException,
                       java.io.IOException
Deletes a set of predictions from the database, and deletes its XML file.

Parameters:
ps - The predictions set to delete
Throws:
java.sql.SQLException
java.io.IOException

removeData

public void removeData(Data_set data)
                throws java.sql.SQLException,
                       java.io.IOException
Deletes a data set and all predictions for it from the database, and deletes their XML files.

Parameters:
data - The data set to delete
Throws:
java.sql.SQLException
java.io.IOException

removeEnsemble

public void removeEnsemble(Ensemble e)
                    throws java.sql.SQLException,
                           java.io.IOException
Deletes an ensemble from the database, and deletes its XML file.

Parameters:
e - The ensemble to delete
Throws:
java.sql.SQLException
java.io.IOException

isUserExcluded

public boolean isUserExcluded(java.lang.String userName)
                       throws java.sql.SQLException,
                              java.io.IOException
Determines if a particular user's contributions have been excluded by the admin.

Parameters:
userName - The name of the user to check
Returns:
True if the user is excluded, else false
Throws:
java.sql.SQLException
java.io.IOException

excludeUser

public void excludeUser(java.lang.String userName,
                        boolean exclude)
                 throws java.sql.SQLException,
                        java.io.IOException
Sets the flag indicating whether predictions from a particular user should be excluded from ensembles. Also sets the DatabaseBean's "updated" flag to true.

Parameters:
userName - the name of a user
exclude - True to exclude the user, false to include them
Throws:
java.sql.SQLException
java.io.IOException

excludeUser

public void excludeUser(User u,
                        java.lang.Boolean exclude)
                 throws java.sql.SQLException,
                        java.io.IOException
Sets the flag indicating whether predictions from a particular user should be excluded from ensembles. Also sets the DatabaseBean's "updated" flag to true.

Parameters:
u - A user
exclude - True to exclude the user, false to include them
Throws:
java.sql.SQLException
java.io.IOException

excludePredictions

public void excludePredictions(Prediction_set pSet,
                               boolean exclude)
                        throws java.sql.SQLException,
                               java.io.IOException
Sets the flag indicating whether a set of predictions should be excluded from ensembles. Also sets the DatabaseBean's "updated" flag to true.

Parameters:
pSet - A set of predictions
exclude - True to exclude the set, false to include it
Throws:
java.sql.SQLException
java.io.IOException

excludePredictions

public void excludePredictions(int predID,
                               boolean exclude)
                        throws java.sql.SQLException,
                               java.io.IOException
Sets the flag indicating whether a set of predictions should be excluded from ensembles. Also sets the DatabaseBean's "updated" flag to true.

Parameters:
predID - The database id of the prediction set
exclude - True to exclude the set, false to include it
Throws:
java.sql.SQLException
java.io.IOException

getUserList

public java.util.List<User> getUserList()
                                 throws java.sql.SQLException,
                                        java.io.IOException
Generates a list of all users registered in the data base.

Returns:
A list of all users
Throws:
java.sql.SQLException
java.io.IOException

hasNoData

public java.lang.Boolean hasNoData()
                            throws java.sql.SQLException,
                                   java.io.IOException
Determines if there are no data sets available.

Returns:
True if there are no data sets in the database, else false
Throws:
java.sql.SQLException
java.io.IOException

getSqlEx

public java.sql.SQLException getSqlEx()
Retrieves the most recently thrown SQLException for debugging purposes.

Returns:
The SQLException which was most recently thrown

setSqlEx

public void setSqlEx(java.sql.SQLException ex)
Sets the SQLExceptoion whose message should be displayed on the dbError page.

Parameters:
ex - An SQLException

getIndexMessage

public java.lang.String getIndexMessage()
Retrieves the message to be displayed on the index page.

Returns:

setIndexMessage

public void setIndexMessage(java.lang.String indexMessage)
Set the message to be displayed on the index page.

Parameters:
indexMessage -

isUpdated

public java.lang.Boolean isUpdated()
Determines whether any data or predictions have been added since the last time the method was called.

Returns:
True if there are new data or predictions, false otherwise

generateDataSetName

public java.lang.String generateDataSetName(java.lang.String dataName)
                                     throws java.sql.SQLException,
                                            java.io.IOException
Generates a unique name for a data set.

Parameters:
dataName - Name of the data set.
Returns:
"[dataName]" if no previous sets have been submitted with the same name, otherwise ":[int]" will be concatenated to dataName to make it unique
Throws:
java.sql.SQLException
java.io.IOException

generatePredSetName

public java.lang.String generatePredSetName(java.lang.String predName)
                                     throws java.sql.SQLException,
                                            java.io.IOException
Generates a unique name for a prediction set.

Parameters:
dataName - Name of the data set.
Returns:
"[predName]" if no previous sets have been submitted with the same name, otherwise ":[int]" will be concatenated to predName to make it unique
Throws:
java.sql.SQLException
java.io.IOException