org.starhope.appius.mb
Class UserEnrolment

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

public class UserEnrolment
extends SQLPeerDatum
implements Invoiceable

Author:
brpocock

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  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
          subscribed user
 
Constructor Summary
UserEnrolment(ResultSet rs)
           
UserEnrolment(String order_source, int product_id, int user_id, Date beginsOn)
          WRITEME: document
UserEnrolment(String order_source, String order_code)
           
 
Method Summary
 void cancelNow()
           
 void flush()
           
private  void generateOrderCode()
          WRITEME: document this method (brpocock, Aug 5, 2009)
static 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.
protected  String getCacheUniqueID()
           
 Currency getCurrency()
           
 Enrolment getEnrolment()
           
 Date getExpires()
           
private  int getID()
           
 String getInvoiceID()
           
 char getInvoiceIDPrefix()
           
 Payment getLastPayment()
           
 String getOrderCode()
           
 String getOrderSource()
           
 int getProductID()
           
 String getTitle()
           
 User getUser()
           
 int getUserID()
           
 void insert()
           
 boolean isActive()
           
 void set(ResultSet rs)
           
 void setAuthSubID(BigDecimal authSubID)
           
 void setBegins(Date newBegins)
           
 void setEnrolment(Enrolment newEnrolment)
           
 void setExpires(Date newExpires)
           
 void setOrderCode(String orderCode)
           
 void setOrderSource(String orderSource)
           
 void setProductID(int productID)
           
 void setUser(User newUser)
           
 void setUserID(int userID)
           
 org.json.JSONObject toJSON()
           
 
Methods inherited from class org.starhope.appius.sql.SQLPeerDatum
changed, findInCache, get, prepare, prepare, saveInCache, set
 
Methods inherited from class org.starhope.appius.util.ManagedReferenceHolder
deref, setRef
 
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


orderCode

private String orderCode
order code


orderSource

private String orderSource
order source


productID

private int productID
Enrolment product ID


userID

private int userID
subscribed user

Constructor Detail

UserEnrolment

public UserEnrolment(ResultSet rs)
              throws NotFoundException
Parameters:
rs - SQL result set
Throws:
NotFoundException

UserEnrolment

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

Parameters:
order_source - order source
product_id -
user_id -
beginsOn -
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 - roder code
Throws:
NotFoundException - if the order doesn't already exist
Method Detail

getAllForUserID

public static UserEnrolment[] getAllForUserID(int userID)
Parameters:
userID - user enrolled
Returns:
array of all current enrolments

cancelNow

public void cancelNow()

flush

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

generateOrderCode

private void generateOrderCode()
WRITEME: document this method (brpocock, Aug 5, 2009)


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()

getEnrolment

public Enrolment getEnrolment()
Returns:
enrolment
Throws:
NotFoundException

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()

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

getTitle

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

getUser

public User 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

isActive

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

set

public void set(ResultSet rs)
         throws SQLException
Specified by:
set in class SQLPeerDatum
Throws:
SQLException
See Also:
SQLPeerDatum.set(java.sql.ResultSet)

setAuthSubID

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

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 orderCode)
Parameters:
orderCode - order code

setOrderSource

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

setProductID

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

setUser

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

setUserID

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

toJSON

public org.json.JSONObject toJSON()
Overrides:
toJSON in class SQLPeerDatum
Returns:
See Also:
SQLPeerDatum.toJSON()