org.starhope.appius.user
Class Parent

java.lang.Object
  extended by org.starhope.appius.util.SimpleDataRecord<Parent>
      extended by org.starhope.appius.user.Parent
All Implemented Interfaces:
com.whirlycott.cache.Cacheable, Serializable, Comparable<Parent>, AbstractPerson, CTime, DataRecord, HasSubversionRevision

public class Parent
extends SimpleDataRecord<Parent>
implements AbstractPerson

This class represents the parent of a kid or teen account

Author:
brpocock@star-hope.org, twheys@gmail.com
See Also:
User.getParent(), Serialized Form

Field Summary
private  boolean canContact
          consent to receive contact
private  String dialect
          dialect of language
private  String forgotPasswordAnswer
          password recovery question's answer
private  String forgotPasswordQuestion
          password recovery question
private  String givenName
          parent's given name (if known)
private  int id
          Database ID value
private  String language
          language
private  String mail
          email address
private  Date mailConfirmed
          the date that the eMail address was confirmed
private  Date mailConfirmSent
          the date that the confirmation mail was sent
private static int MAX_KIDS_NAMES
          When showing the parent's name, how many children's names should be displayed before we just start counting them?
private  String password
          password
private static long serialVersionUID
          Java serialisation unique ID
 
Fields inherited from class org.starhope.appius.util.SimpleDataRecord
myLoader, timeLastChanged, timeLastSaved
 
Constructor Summary
Parent()
          Create a blank parent record
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
 boolean canContact()
          Can this person be contacted for marketing and other purposes?
 boolean checkPassword(String passwordGuess)
          Returns true if the password is correct.
 boolean forgotPassword(String forgottenPasswordQ, String forgottenPasswordA)
          Send the user their forgotten password if they know the answer to their secret question.
 String getApprovalCookie()
          Get a cookie object for sending mail.
static Parent getByApprovalCookie(String cookie)
          Deprecated. Use Nomenclator.getParentByApprovalCookie(String) instead
static Parent getByID(int id)
          Deprecated. Use Nomenclator.getParentByID(int) instead
static Parent getByMail(String mail)
          Deprecated. Use Nomenclator.getParentByMail(String) instead
 int getCacheableID()
          Note that all records must have either a numeric ID ( DataRecord.getCacheableID() or a string identifier ( DataRecord.getCacheableIdent() or both.
 String getCacheableIdent()
          Note that all records must have either a numeric ID ( DataRecord.getCacheableID() or a string identifier ( DataRecord.getCacheableIdent() or both.
 User[] getChildren()
           
 String getConfirmationTemplate()
          Get the name of the template file to be used to confirm accounts of this type.
 String getDialect()
          Get this person's preferred language-dialect.
 String getDisplayName()
          Get the name to be displayed in user interface for this person.
 String getForgotPasswordAnswer()
          Get the forgotten password question
 String getForgotPasswordQuestion()
          Get the forgotten password question
 GeneralUser[] getFreeChildren()
           
 String getGivenName()
           
 HashMap<Timestamp,HashMap<String,String>> getHistory(Date after, int limit)
          Returns the historical contents of this user's record.
 int getID()
          Return the parent record's database ID
 String getLanguage()
           
 String getMail()
           
 Date getMailConfirmed()
           
 Date getMailConfirmSent()
           
 String getName()
          Get the given name of the parent
static Parent getOrCreateByMail(String parentMail)
           
 String getPassword()
           
 String getPotentialUserName()
          This is an overriding method.
 String getResponsibleMail()
          This is an overriding method.
 String getSubversionRevision()
           Return the Subversion revision level of this class's source code file, as supplied via the special "$Rev: " sequence.
 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
 void remindPassword()
          This is an overriding method.
 void rename(String newName)
           Rename the user account, updating all necessary related records.
 void requestApproval(User user)
           
 void sendConfirmationMail()
          Sends confirmation mail to whomever should receive it
 void sendNotificationForChild(User sessionUser)
           Send a notification to the parent that their child has registered an account, giving instructions on how to approve the account.
 void sendStaffPasswordReset()
          Sends mail to user or parent when a staff member resets their password.
 void sentConfirmationMail()
          WRITEME: document this method (brpocock@star-hope.org, Sep 25, 2009)
 void setCanContact(boolean canContact1)
           
 void setDialect(String newDialect)
           
 void setForgotPasswordAnswer(String answer)
          WRITEME: document this method (brpocock@star-hope.org, Sep 25, 2009)
 void setForgotPasswordQuestion(String question)
          WRITEME: document this method (brpocock@star-hope.org, Sep 25, 2009)
 void setGivenName(String givenName1)
           
 void setID(int int1)
           
 void setLanguage(String newLanguage)
           
 void setMail(String mail1)
           
 void setMailConfirmed(Date mailConfirmed1)
           
 void setMailConfirmSent(Date date)
           
 void setPassword(String password1)
          Changes the person's password
 void setPasswordAndPasswordRecovery(String question, String answer, String newPassword)
           
 void setPasswordRecovery(String newForgottenPasswordQuestion, String newForgottenPasswordAnswer)
          Set the password-recovery question and answer pair
 String setRandomPassword()
          WRITEME: document this method (brpocock@star-hope.org, Sep 25, 2009)
 org.json.JSONObject toJSON()
          This is an overriding method.
 String toString()
           
 
Methods inherited from class org.starhope.appius.util.SimpleDataRecord
changed, checkStale, compareTo, equals, finalize, getRecordLoader, getTimeLastChanged, getTimeLastSaved, hashCode, isBeingLoaded, markAsLoaded, markAsSaved, markForReload, onRemove, onRetrieve, onStore, save, setRecordLoader
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_KIDS_NAMES

private static final int MAX_KIDS_NAMES
When showing the parent's name, how many children's names should be displayed before we just start counting them?

See Also:
Constant Field Values

serialVersionUID

private static final long serialVersionUID
Java serialisation unique ID

See Also:
Constant Field Values

canContact

private boolean canContact
consent to receive contact


dialect

private String dialect
dialect of language


forgotPasswordAnswer

private String forgotPasswordAnswer
password recovery question's answer


forgotPasswordQuestion

private String forgotPasswordQuestion
password recovery question


givenName

private String givenName
parent's given name (if known)


id

private int id
Database ID value


language

private String language
language


mail

private String mail
email address


mailConfirmed

private Date mailConfirmed
the date that the eMail address was confirmed


mailConfirmSent

private Date mailConfirmSent
the date that the confirmation mail was sent


password

private String password
password

Constructor Detail

Parent

public Parent()
Create a blank parent record


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

@Deprecated
public static Parent getByApprovalCookie(String cookie)
                                  throws NotFoundException,
                                         IOException
Deprecated. Use Nomenclator.getParentByApprovalCookie(String) instead

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

@Deprecated
public static Parent getByID(int id)
Deprecated. Use Nomenclator.getParentByID(int) instead

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

getByMail

@Deprecated
public static Parent getByMail(String mail)
Deprecated. Use Nomenclator.getParentByMail(String) instead

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.

canContact

public boolean canContact()
Description copied from interface: AbstractPerson
Can this person be contacted for marketing and other purposes?

Specified by:
canContact in interface AbstractPerson
Returns:
true, if this person permits communications of that sort
See Also:
AbstractPerson.canContact()

checkPassword

public boolean checkPassword(String passwordGuess)
Description copied from interface: AbstractPerson
Returns true if the password is correct. Returns false if password is not set or the guess was blank.

Specified by:
checkPassword in interface AbstractPerson
Parameters:
passwordGuess - The password which is to be checked
Returns:
true, if the password is correct and not null
See Also:
AbstractPerson.checkPassword(java.lang.String)

forgotPassword

public boolean forgotPassword(String forgottenPasswordQ,
                              String forgottenPasswordA)
Description copied from interface: AbstractPerson
Send the user their forgotten password if they know the answer to their secret question. If AbstractPerson.remindPassword() throws a NotFoundException, this will fail and return false as well.

Specified by:
forgotPassword in interface AbstractPerson
Parameters:
forgottenPasswordQ - The question being answered
forgottenPasswordA - The answer provided
Returns:
true if answer is correct (also calls AbstractPerson.remindPassword()); and false if it is not
See Also:
AbstractPerson.forgotPassword(java.lang.String, java.lang.String)

getApprovalCookie

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

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

getCacheableID

public int getCacheableID()
                   throws NotFoundException
Description copied from interface: DataRecord
Note that all records must have either a numeric ID ( DataRecord.getCacheableID() or a string identifier ( DataRecord.getCacheableIdent() or both.

Specified by:
getCacheableID in interface DataRecord
Returns:
an unique ID number
Throws:
NotFoundException - if the item doesn't have a distinct numeric ID
See Also:
DataRecord.getCacheableID()

getCacheableIdent

public String getCacheableIdent()
                         throws NotFoundException
Description copied from interface: DataRecord
Note that all records must have either a numeric ID ( DataRecord.getCacheableID() or a string identifier ( DataRecord.getCacheableIdent() or both.

Specified by:
getCacheableIdent in interface DataRecord
Returns:
an unique identifier string
Throws:
NotFoundException - if the item doesn't have a distinct string identifier
See Also:
DataRecord.getCacheableIdent()

getChildren

public User[] getChildren()
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 interface AbstractPerson
Returns:
the template filename to be used for confirming this account
See Also:
AbstractPerson.getConfirmationTemplate()

getDialect

public String getDialect()
Description copied from interface: AbstractPerson
Get this person's preferred language-dialect.

Specified by:
getDialect in interface AbstractPerson
Returns:
the dialect
See Also:
AbstractPerson.getDialect()

getDisplayName

public String getDisplayName()
Description copied from interface: AbstractPerson
Get the name to be displayed in user interface for this person. This should give the person's given name, but if that information is unavailable, fall back upon other unique identifier such as their avatar label

Specified by:
getDisplayName in interface AbstractPerson
Returns:
the display name
See Also:
AbstractPerson.getDisplayName()

getForgotPasswordAnswer

public String getForgotPasswordAnswer()
Description copied from interface: AbstractPerson
Get the forgotten password question

Specified by:
getForgotPasswordAnswer in interface AbstractPerson
Returns:
the question to ask
See Also:
AbstractPerson.getForgotPasswordAnswer()

getForgotPasswordQuestion

public String getForgotPasswordQuestion()
Description copied from interface: AbstractPerson
Get the forgotten password question

Specified by:
getForgotPasswordQuestion in interface AbstractPerson
Returns:
the question to ask
See Also:
AbstractPerson.getForgotPasswordQuestion()

getFreeChildren

public GeneralUser[] getFreeChildren()
Returns:
all children without a membership associated with this parent

getGivenName

public String getGivenName()
Specified by:
getGivenName in interface AbstractPerson
Returns:
the givenName
See Also:
AbstractPerson.getGivenName()

getHistory

public HashMap<Timestamp,HashMap<String,String>> getHistory(Date after,
                                                            int limit)
Description copied from interface: AbstractPerson
Returns the historical contents of this user's record.

Specified by:
getHistory in interface AbstractPerson
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:
AbstractPerson.getHistory(java.sql.Date, int)

getID

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

Returns:
the parent ID

getLanguage

public String getLanguage()
Specified by:
getLanguage in interface AbstractPerson
Returns:
the language
See Also:
AbstractPerson.getLanguage()

getMail

public String getMail()
Specified by:
getMail in interface AbstractPerson
Returns:
the mail
See Also:
AbstractPerson.getMail()

getMailConfirmed

public Date getMailConfirmed()
Specified by:
getMailConfirmed in interface AbstractPerson
Returns:
the mailConfirmed
See Also:
AbstractPerson.getMailConfirmed()

getMailConfirmSent

public Date getMailConfirmSent()
Returns:
the mailConfirmSent

getName

public String getName()
Get the given name of the parent

Returns:
the parent's given name

getPassword

public String getPassword()
Specified by:
getPassword in interface AbstractPerson
Returns:
the user's cleartext password, if available. If the password storage mechanism does not permit cleartext retrieval, returns a null.
See Also:
AbstractPerson.getPassword()

getPotentialUserName

public String getPotentialUserName()
This is an overriding method.

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

getResponsibleMail

public String getResponsibleMail()
This is an overriding method.

Specified by:
getResponsibleMail in interface AbstractPerson
Returns:
the eMail address
See Also:
AbstractPerson.getResponsibleMail()

getSubversionRevision

public String getSubversionRevision()
Description copied from interface: HasSubversionRevision

Return the Subversion revision level of this class's source code file, as supplied via the special "$Rev: " sequence.

As an example,the Subversion revision string for this file is "$Rev: 1968 $"

 
 @Override
 public String getSubversionRevision () {
        return "$Rev: ";
 }
 

Specified by:
getSubversionRevision in interface HasSubversionRevision
Returns:
The Subversion revision level for this class's source code file.
See Also:
HasSubversionRevision.getSubversionRevision()

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

public void remindPassword()
                    throws NotReadyException
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.

Specified by:
remindPassword in interface AbstractPerson
Throws:
NotReadyException - If the password or eMail address hasn't been set
See Also:
AbstractPerson.remindPassword()

rename

public void rename(String newName)
            throws GameLogicException,
                   AlreadyUsedException,
                   ForbiddenUserException
Description copied from interface: AbstractPerson

Rename the user account, updating all necessary related records. Note, in particular, that Smartfox is wholly dependant upon user names, so all records related to Smartfox must be updated!

If the user is currently online, this will fuck up hilariously, I think.

Specified by:
rename in interface AbstractPerson
Parameters:
newName - The new user name
Throws:
GameLogicException - if the user is online (and therefore can't be renamed)
AlreadyUsedException - WRITEME
ForbiddenUserException - WRITEME
See Also:
AbstractPerson.rename(java.lang.String)

requestApproval

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

sendConfirmationMail

public void sendConfirmationMail()
Description copied from interface: AbstractPerson
Sends confirmation mail to whomever should receive it

Specified by:
sendConfirmationMail in interface AbstractPerson
See Also:
AbstractPerson.sendConfirmationMail()

sendNotificationForChild

public void sendNotificationForChild(User sessionUser)

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

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

sendStaffPasswordReset

public void sendStaffPasswordReset()
Description copied from interface: AbstractPerson
Sends mail to user or parent when a staff member resets their password.

Specified by:
sendStaffPasswordReset in interface AbstractPerson
See Also:
AbstractPerson.sendStaffPasswordReset()

sentConfirmationMail

public void sentConfirmationMail()
Description copied from interface: AbstractPerson
WRITEME: document this method (brpocock@star-hope.org, Sep 25, 2009)

Specified by:
sentConfirmationMail in interface AbstractPerson
See Also:
AbstractPerson.sentConfirmationMail()

setCanContact

public void setCanContact(boolean canContact1)
Specified by:
setCanContact in interface AbstractPerson
Parameters:
canContact1 - if true, the user has explicitly given us their legal consent to be contacted for marketing and other options.
See Also:
AbstractPerson.setCanContact(boolean)

setDialect

@Setter(getter="getDialect")
public void setDialect(String newDialect)
Parameters:
newDialect - the dialect to set

setForgotPasswordAnswer

@Setter(getter="getForgotPasswordAnswer")
public void setForgotPasswordAnswer(String answer)
Description copied from interface: AbstractPerson
WRITEME: document this method (brpocock@star-hope.org, Sep 25, 2009)

Specified by:
setForgotPasswordAnswer in interface AbstractPerson
Parameters:
answer - WRITEME
See Also:
AbstractPerson.setForgotPasswordAnswer(java.lang.String)

setForgotPasswordQuestion

@Setter(getter="getForgotPasswordQuestion")
public void setForgotPasswordQuestion(String question)
Description copied from interface: AbstractPerson
WRITEME: document this method (brpocock@star-hope.org, Sep 25, 2009)

Specified by:
setForgotPasswordQuestion in interface AbstractPerson
Parameters:
question - WRITEME
See Also:
AbstractPerson.setForgotPasswordQuestion(java.lang.String)

setGivenName

@Setter(getter="getGivenName")
public void setGivenName(String givenName1)
Specified by:
setGivenName in interface AbstractPerson
Parameters:
givenName1 - the givenName to set
See Also:
AbstractPerson.setGivenName(java.lang.String)

setID

@Setter(getter="getID")
public void setID(int int1)
Parameters:
int1 - new id

setLanguage

@Setter(getter="getLanguage")
public void setLanguage(String newLanguage)
Parameters:
newLanguage - the language to set

setMail

@Setter(getter="getMail")
public void setMail(String mail1)
             throws GameLogicException
Specified by:
setMail in interface AbstractPerson
Parameters:
mail1 - the mail to set
Throws:
GameLogicException - WRITEME
See Also:
AbstractPerson.setMail(java.lang.String)

setMailConfirmed

@Setter(getter="getMailConfirmed")
public void setMailConfirmed(Date mailConfirmed1)
Specified by:
setMailConfirmed in interface AbstractPerson
Parameters:
mailConfirmed1 - the mailConfirmed to set
See Also:
AbstractPerson.setMailConfirmed(java.sql.Date)

setMailConfirmSent

@Setter(getter="getMailConfirmSent")
public void setMailConfirmSent(Date date)
Specified by:
setMailConfirmSent in interface AbstractPerson
Parameters:
date - the date on which the mail confirmation message was sent
See Also:
AbstractPerson.setMailConfirmSent(java.sql.Date)

setPassword

@Setter(getter="getPassword")
public void setPassword(String password1)
Description copied from interface: AbstractPerson
Changes the person's password

Specified by:
setPassword in interface AbstractPerson
Parameters:
password1 - the password to set
See Also:
AbstractPerson.setPassword(java.lang.String)

setPasswordAndPasswordRecovery

public void setPasswordAndPasswordRecovery(String question,
                                           String answer,
                                           String newPassword)
                                    throws GameLogicException
Specified by:
setPasswordAndPasswordRecovery in interface AbstractPerson
Parameters:
question - WRITEME
answer - WRITEME
newPassword - WRITEME
Throws:
GameLogicException - WRITEME
See Also:
AbstractPerson.setPasswordAndPasswordRecovery(java.lang.String, java.lang.String, java.lang.String)

setPasswordRecovery

public void setPasswordRecovery(String newForgottenPasswordQuestion,
                                String newForgottenPasswordAnswer)
Description copied from interface: AbstractPerson
Set the password-recovery question and answer pair

Specified by:
setPasswordRecovery in interface AbstractPerson
Parameters:
newForgottenPasswordQuestion - the question
newForgottenPasswordAnswer - the correct answer
See Also:
AbstractPerson.setPasswordRecovery(java.lang.String, java.lang.String)

setRandomPassword

public String setRandomPassword()
Description copied from interface: AbstractPerson
WRITEME: document this method (brpocock@star-hope.org, Sep 25, 2009)

Specified by:
setRandomPassword in interface AbstractPerson
Returns:
WRITEME
See Also:
AbstractPerson.setRandomPassword()

toJSON

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

Returns:
JSON form of the parent (basically just the mail address)
See Also:
CastsToJSON.toJSON()

toString

public String toString()
Overrides:
toString in class SimpleDataRecord<Parent>
See Also:
SimpleDataRecord.toString()