org.starhope.appius.mb
Class UserEnrolment

java.lang.Object
  extended by org.starhope.appius.sql.SQLPeerDatum
      extended by org.starhope.appius.mb.UserEnrolment
All Implemented Interfaces:
Serializable, Invoiceable

public class UserEnrolment
extends SQLPeerDatum
implements Invoiceable

This class represents an instance of a purchased enrolment (subscription) to a game, as bound to a particular user and period of time.

Author:
brpocock, Tim Heys
See Also:
Serialized Form

Field Summary
private  BigDecimal authSubID
          Authorize.net subscription ID
private  Date begins
          start date
private  Date expires
          expiry date
private  int id
          database ID
private  boolean isActivated
          Has this enrolment been activated already?
private  String orderCode
          order code
private static char[] orderCodeChars
          An internally-used array of characters used to create order codes.
private  String orderSource
          order source
private  int productID
          Enrolment product ID
private static long serialVersionUID
          serialVersionUID
private  int userID
          The user who owns this enrolment
 
Constructor Summary
UserEnrolment(ResultSet rs)
           
UserEnrolment(String order_source, int product_id, int user_id)
          WRITEME: document
UserEnrolment(String order_source, String order_code)
           
 
Method Summary
 void activate()
          Deprecated. 
 void activate(boolean newEnrolment)
           
 void addPayment()
          Deprecated. 
 void cancelNow()
          WRITEME theys
 void continueEnrolment()
          TODO: document this method (theys, Sep 24, 2009)
 void flush()
           
private  void generateOrderCode()
          Create a pseudorandom, unique order code consisting of the approved letters and numbers.
static Collection<UserEnrolment> getAllForUserID(int userID)
           
 BigDecimal getAmount()
           
 BigDecimal getAuthSubID()
           
 Date getBegins()
           
 Person getBuyer()
          TODO: refactor payment gateways to use the buyer information: promote this up to Invoiceable interface.
static UserEnrolment getBySourceAndCode(String orderSource, String orderCode)
          Retrieve a User Enrolment based off the invoice number split into orderSource and orderCode.
protected  String getCacheUniqueID()
           
 Currency getCurrency()
           
 String getDescription()
          TODO: document this method (brpocock, Nov 19, 2009)
 Enrolment getEnrolment()
           
 Date getExpires()
           
private  int getID()
           
 String getInvoiceID()
           
 char getInvoiceIDPrefix()
           
private  Date getLastExpiration()
          Checks all enrolments for current user to determine when their last expiration ends and if it ends before today.
 Payment getLastPayment()
           
static UserEnrolment[] getLastTwoYearsForUserID(int userID)
          Get all enrolments for a given user in the past two years from today's date.
 String getOrderCode()
           
 String getOrderSource()
           
 int getProductID()
           
 Date getRecurs()
           
 String getTitle()
           
 AbstractUser getUser()
           
 int getUserID()
           
 void insert()
           
 boolean isActive()
           
 boolean isRecurring()
          TODO: document this method (twheys, Oct 2, 2009)
 void killEnrolment()
          TODO: document this method (theys, Sep 24, 2009)
 void set(ResultSet rs)
           
 void setAuthSubID(BigDecimal authSubID1)
           
 void setAuthSubID(String authSubID2)
          TODO: document (twheys)
 void setBegins(Date newBegins)
           
 void setEnrolment(Enrolment newEnrolment)
           
 void setExpires(Date newExpires)
           
 void setOrderCode(String orderCode1)
           
 void setOrderSource(String orderSource1)
           
 void setProductID(int productID1)
           
 void setUser(User newUser)
           
 void setUserID(int userID1)
           
 void startEnrolment()
          TODO: document this method (theys, Sep 24, 2009)
 org.json.JSONObject toJSON()
          This is the default SQLPeerDatum implementation of toJSON.
 
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

orderCodeChars

private static final char[] orderCodeChars
An internally-used array of characters used to create order codes. A-Z, notably excluding I and O, and 0-9.


serialVersionUID

private static final long serialVersionUID
serialVersionUID

See Also:
Constant Field Values

authSubID

private BigDecimal authSubID
Authorize.net subscription ID


begins

private Date begins
start date


expires

private Date expires
expiry date


id

private int id
database ID


isActivated

private volatile boolean isActivated
Has this enrolment been activated already?


orderCode

private String orderCode
order code


orderSource

private String orderSource
order source


productID

private int productID
Enrolment product ID


userID

private int userID
The user who owns this enrolment

Constructor Detail

UserEnrolment

public UserEnrolment(ResultSet rs)
              throws NotFoundException
Parameters:
rs - SQL result set representing an enrolment
Throws:
NotFoundException - WRITEME

UserEnrolment

public UserEnrolment(String order_source,
                     int product_id,
                     int user_id)
              throws NotFoundException
WRITEME: document

Parameters:
order_source - order source
product_id - WRITEME
user_id - WRITEME
Throws:
NotFoundException - if the enrolment type is not found.

UserEnrolment

public UserEnrolment(String order_source,
                     String order_code)
              throws NotFoundException
Parameters:
order_source - order source
order_code - order code
Throws:
NotFoundException - if the order doesn't already exist
Method Detail

getAllForUserID

public static Collection<UserEnrolment> getAllForUserID(int userID)
Parameters:
userID - user enrolled
Returns:
array of all current enrolments

getBySourceAndCode

public static UserEnrolment getBySourceAndCode(String orderSource,
                                               String orderCode)
                                        throws NotFoundException
Retrieve a User Enrolment based off the invoice number split into orderSource and orderCode.

Parameters:
orderSource - The source of the order (ex. 'auth')
orderCode - The code of the order
Returns:
A UserEnrolment with the invoice number of {orderSource}-{orderCode}
Throws:
NotFoundException - if an enrolment cannot be found with the given orderSource and orderCode.

getLastTwoYearsForUserID

public static UserEnrolment[] getLastTwoYearsForUserID(int userID)
Get all enrolments for a given user in the past two years from today's date.

Parameters:
userID - user enrolled
Returns:
array of all current enrolments

activate

@Deprecated
public void activate()
Deprecated. 

Deprecated, see activate()


activate

public void activate(boolean newEnrolment)
Parameters:
newEnrolment - true if this is a new account FIXME: activatedUser.isPaidMember () instead of accepting a boolean?

addPayment

@Deprecated
public void addPayment()
Deprecated. 

Don't use. Use something else instead. WRITEME theys


cancelNow

public void cancelNow()
WRITEME theys


continueEnrolment

public void continueEnrolment()
TODO: document this method (theys, Sep 24, 2009)


flush

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

generateOrderCode

private void generateOrderCode()
Create a pseudorandom, unique order code consisting of the approved letters and numbers. (Excludes the letters O, I, Z, and S for potential confusion with 0, 1, 2, and 5)


getAmount

public BigDecimal getAmount()
Specified by:
getAmount in interface Invoiceable
Returns:
the price of a purchase
See Also:
Invoiceable.getAmount()

getAuthSubID

public BigDecimal getAuthSubID()
Returns:
authorize.net subscriber ID

getBegins

public Date getBegins()
Returns:
begin date

getBuyer

public Person getBuyer()
Description copied from interface: Invoiceable
TODO: refactor payment gateways to use the buyer information: promote this up to Invoiceable interface.

Specified by:
getBuyer in interface Invoiceable
Returns:
the buyer, paying-for this order
See Also:
Invoiceable.getBuyer()

getCacheUniqueID

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

getCurrency

public Currency getCurrency()
Specified by:
getCurrency in interface Invoiceable
Returns:
the currency used to describe the price in Invoiceable.getAmount()
See Also:
Invoiceable.getCurrency()

getDescription

public String getDescription()
TODO: document this method (brpocock, Nov 19, 2009)

Returns:
WRITEME

getEnrolment

public Enrolment getEnrolment()
Returns:
enrolment

getExpires

public Date getExpires()
Returns:
expiry

getID

private int getID()
Returns:
unique ID

getInvoiceID

public String getInvoiceID()
Specified by:
getInvoiceID in interface Invoiceable
Returns:
the invoice ID ("order number") for payment
See Also:
Invoiceable.getInvoiceID()

getInvoiceIDPrefix

public char getInvoiceIDPrefix()
Specified by:
getInvoiceIDPrefix in interface Invoiceable
Returns:
A single-character code representing this class of invoiceable items. This permits easy identification of the type of object being paid for, regardless of how we come across the invoice number.
See Also:
Invoiceable.getInvoiceIDPrefix()

getLastExpiration

private Date getLastExpiration()
Checks all enrolments for current user to determine when their last expiration ends and if it ends before today. Returns the date furthest into the future.

Returns:
WRITEME

getLastPayment

public Payment getLastPayment()
                       throws NotFoundException
Returns:
last payment
Throws:
NotFoundException - if nobody's paid anything yet

getOrderCode

public String getOrderCode()
Returns:
order code

getOrderSource

public String getOrderSource()
Returns:
order source

getProductID

public int getProductID()
Returns:
product ID of enrolment

getRecurs

public Date getRecurs()
Returns:
the next date where billing will reoccur

getTitle

public String getTitle()
Specified by:
getTitle in interface Invoiceable
Returns:
the description of a purchase
See Also:
Invoiceable.getTitle()

getUser

public AbstractUser getUser()
Returns:
user who is enrolled

getUserID

public int getUserID()
Returns:
the user ID of the user who �owns� this enrolment

insert

public void insert()
            throws SQLException
Throws:
SQLException - WRITEME

isActive

public boolean isActive()
Returns:
true if the enrolment hasn't expired yet

isRecurring

public boolean isRecurring()
TODO: document this method (twheys, Oct 2, 2009)

Returns:
FIXME

killEnrolment

public void killEnrolment()
TODO: document this method (theys, Sep 24, 2009)


set

public 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 - WRITEME
See Also:
SQLPeerDatum.set(java.sql.ResultSet)

setAuthSubID

public void setAuthSubID(BigDecimal authSubID1)
Parameters:
authSubID1 - authorize.net subscription ID

setAuthSubID

public void setAuthSubID(String authSubID2)
                  throws NumberFormatException
TODO: document (twheys)

Parameters:
authSubID2 - authorize.net subscription ID
Throws:
NumberFormatException - FIXME

setBegins

public void setBegins(Date newBegins)
Parameters:
newBegins - begin date

setEnrolment

public void setEnrolment(Enrolment newEnrolment)
Parameters:
newEnrolment - enrolment product

setExpires

public void setExpires(Date newExpires)
Parameters:
newExpires - expiry date

setOrderCode

public void setOrderCode(String orderCode1)
Parameters:
orderCode1 - order code

setOrderSource

public void setOrderSource(String orderSource1)
Parameters:
orderSource1 - order source

setProductID

public void setProductID(int productID1)
Parameters:
productID1 - enrolment product

setUser

public void setUser(User newUser)
Parameters:
newUser - user enrolled

setUserID

public void setUserID(int userID1)
Parameters:
userID1 - user enrolled

startEnrolment

public void startEnrolment()
TODO: document this method (theys, Sep 24, 2009)


toJSON

public org.json.JSONObject toJSON()
Description copied from class: SQLPeerDatum
This is the default SQLPeerDatum implementation of toJSON. This uses Java reflection and “bean-type” methods to extract the contents of an object and create a JSON field.

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