org.starhope.appius.user
Class Parent

java.lang.Object
  extended by org.starhope.appius.sql.SQLPeerDatum
      extended by org.starhope.appius.user.Person
          extended by org.starhope.appius.user.Parent
All Implemented Interfaces:
Serializable

public class Parent
extends Person

This class represents the parent of a kid or teen account

Author:
brpocock,theys
See Also:
User.getParent(), Serialized Form

Field Summary
private  int parentID
          Database ID value
private static long serialVersionUID
          Java serialization unique ID
 
Fields inherited from class org.starhope.appius.user.Person
canContact, dialect, forgotPasswordAnswer, forgotPasswordQuestion, givenName, language, mail, mailConfirmed, mailConfirmSent, password
 
Constructor Summary
Parent(ResultSet rs)
           
Parent(String parentMail)
          Create a new Parent record
Parent(String newMail, String newPassword)
          Create a new parent record and set an initial password at the same time
 
Method Summary
 void flush()
           
 String getApprovalCookie()
          Get a cookie object for sending mail.
static Parent getByApprovalCookie(String cookie)
           
static Parent getByID(int id)
           
static Parent getByMail(String mail)
           
protected  String getCacheUniqueID()
          This is an overriding method.
 User[] getChildren()
          This will load up to 2×maxChildren children for an account.
 String getConfirmationTemplate()
          Get the name of the template file to be used to confirm accounts of this type.
 String getDisplayName()
          This method's only use is for more closely aligning User and Parent classes.
 HashMap<Timestamp,HashMap<String,String>> getHistory(Date after, int limit)
          This is an overriding method.
 int getID()
          Return the parent record's database ID
 String getName()
          WRITEME: document this method (twheys, Aug 05, 2009)
static Parent getOrCreateByMail(String parentMail)
           
 String getPotentialUserName()
          This is an overriding method.
 String getResponsibleMail()
          This is an overriding method.
 boolean hasBannedKids()
           
private  void insert()
          Insert a new parent record into the database, saving the parent eMail address and password.
 boolean isRegistered()
           
 void mailIsConfirmed()
          assert that the mail
protected  void remindPassword()
          This is an overriding method.
 void rename(String newName)
          This is an overriding method.
 void requestApproval(User user)
           
 void sendNotificationForChild(User kid)
           Send a notification to the parent that their child has registered an account, giving instructions on how to approve the account.
protected  void set(ResultSet rs)
           
 org.json.JSONObject toJSON()
          This is an overriding method.
 
Methods inherited from class org.starhope.appius.user.Person
checkPassword, forgotPassword, generateNewPassword, getCouponCode, getDialect, getForgotPasswordAnswer, getForgotPasswordQuestion, getGivenName, getLanguage, getMail, getMailConfirmed, getPassword, getResponsiblePerson, isCanContact, sendConfirmationMail, sendStaffPasswordReset, sentConfirmationMail, setCanContact, setCouponCode, setForgotPasswordAnswer, setForgotPasswordQuestion, setGivenName, setMail, setMailConfirmed, setPassword, setPasswordAndPasswordRecovery, setPasswordRecovery, setRandomPassword
 
Methods inherited from class org.starhope.appius.sql.SQLPeerDatum
changed, findInCache, get, saveInCache, set
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Java serialization unique ID

See Also:
Constant Field Values

parentID

private int parentID
Database ID value

Constructor Detail

Parent

public Parent(ResultSet rs)
Parameters:
rs - resultset describing a parent

Parent

public Parent(String parentMail)
       throws AlreadyExistsException
Create a new Parent record

Parameters:
parentMail - the address of the parent
Throws:
AlreadyExistsException - if a parent record already exists with the given eMail address

Parent

public Parent(String newMail,
              String newPassword)
       throws PrivilegeRequiredException,
              AlreadyExistsException
Create a new parent record and set an initial password at the same time

Parameters:
newMail - mail address
newPassword - password
Throws:
AlreadyExistsException - if the user has an existing account, and they know the password
PrivilegeRequiredException - if the mail exists, but the password is wrong
Method Detail

getByApprovalCookie

public static Parent getByApprovalCookie(String cookie)
                                  throws NotFoundException,
                                         IOException
Parameters:
cookie - the approval cookie uniquely identifying the desired Parent
Returns:
the Parent uniquely identified by the given approval cookie
Throws:
NotFoundException - if the cookie does not uniquely identify any Parent
IOException - if the contents of the approval cookie can't be decoded

getByID

public static Parent getByID(int id)
Parameters:
id - database ID number
Returns:
the relevant Parent record (if it exists), or null if not.

getByMail

public static Parent getByMail(String mail)
Parameters:
mail - The parent's eMail address
Returns:
the relevant Parent record, or null if there is none

getOrCreateByMail

public static Parent getOrCreateByMail(String parentMail)
Parameters:
parentMail - the mail address for the parent
Returns:
a new parent record or existing one; never null.

flush

public void flush()
Specified by:
flush in class Person
See Also:
SQLPeerDatum.flush()

getApprovalCookie

public String getApprovalCookie()
Description copied from class: Person
Get a cookie object for sending mail. Cookies are generated differently between User and Parent.

Specified by:
getApprovalCookie in class Person
Returns:
get an approval cookie which can be used to uniquely identify this Parent
See Also:
Parent, User

getCacheUniqueID

protected String getCacheUniqueID()
This is an overriding method.

Specified by:
getCacheUniqueID in class SQLPeerDatum
Returns:
The local (Stringified) version of an unique ID; usually the database ID column
See Also:
SQLPeerDatum.getCacheUniqueID()

getChildren

public User[] getChildren()
This will load up to 2×maxChildren children for an account. If the user account has more children, it will silently ignore additional children.

Returns:
all children associated with this parent

getConfirmationTemplate

public String getConfirmationTemplate()
Get the name of the template file to be used to confirm accounts of this type.

Specified by:
getConfirmationTemplate in class Person
Returns:
the template filename to be used for confirming this account
See Also:
Person.getConfirmationTemplate()

getDisplayName

public String getDisplayName()
Description copied from class: Person
This method's only use is for more closely aligning User and Parent classes. Since Parent class does not have a user name, it returns null.

Specified by:
getDisplayName in class Person
Returns:
null
See Also:
Person.getDisplayName()

getHistory

public HashMap<Timestamp,HashMap<String,String>> getHistory(Date after,
                                                            int limit)
This is an overriding method.

Specified by:
getHistory in class Person
Parameters:
after - If non-null, specifies the date after which we want to view records. To see all records, back to the creation of the user record, supply a null.
limit - If this is a positive number, it limits the results to this number of records.
Returns:
A map of timestamps to key/value pairs. All values are expressed as strings (even though they may have numeric, enumerative, or date / date-time types in the database), since this is primarily (only?) for human-viewable auditing.
See Also:
Person.getHistory(java.sql.Date,int)

getID

public int getID()
Return the parent record's database ID

Returns:
the parent ID

getName

public String getName()
WRITEME: document this method (twheys, Aug 05, 2009)

Returns:
WRITEME

getPotentialUserName

public String getPotentialUserName()
This is an overriding method.

Specified by:
getPotentialUserName in class Person
Returns:
a user name that could be used
See Also:
Person.getPotentialUserName()

getResponsibleMail

public String getResponsibleMail()
This is an overriding method.

Specified by:
getResponsibleMail in class Person
Returns:
the eMail address
See Also:
Person.getResponsibleMail()

hasBannedKids

public boolean hasBannedKids()
Returns:
true, if this parent has any child account that is banned

insert

private void insert()
             throws AlreadyExistsException
Insert a new parent record into the database, saving the parent eMail address and password.

Throws:
AlreadyExistsException - if the record already exists

isRegistered

public boolean isRegistered()
Returns:
true, if the account has been registered (has a real password)

mailIsConfirmed

public void mailIsConfirmed()
assert that the mail


remindPassword

protected void remindPassword()
This is an overriding method. If any of this parent's children are staff members, resets their passwords as well as the parent account password and sends a flurry of reminder mails.

Overrides:
remindPassword in class Person
See Also:
Person.remindPassword()

rename

public void rename(String newName)
This is an overriding method.

Specified by:
rename in class Person
Parameters:
newName - The new user name
See Also:
Person.rename(java.lang.String)

requestApproval

public void requestApproval(User user)
Parameters:
user - send a notification for the given child user, to request parental approval

sendNotificationForChild

public void sendNotificationForChild(User kid)

Send a notification to the parent that their child has registered an account, giving instructions on how to approve the account.

Parameters:
kid - the user who is a child of this parent

set

protected void set(ResultSet rs)
            throws SQLException
Specified by:
set in class SQLPeerDatum
Parameters:
rs - The result of an SQL query, with the cursor already pointed at the row describing this specific instance of the object.
Throws:
SQLException - if the database fails somehow
See Also:
SQLPeerDatum.set(java.sql.ResultSet)

toJSON

public org.json.JSONObject toJSON()
This is an overriding method.

Overrides:
toJSON in class SQLPeerDatum
Returns:
This object's data, serialized into JSON form.
See Also:
SQLPeerDatum.toJSON()