|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.starhope.appius.util.SimpleDataRecord<UserEnrolment>
org.starhope.appius.mb.UserEnrolment
public class UserEnrolment
This class represents an instance of a purchased enrolment (subscription) to a game, as bound to a particular user and period of time.
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 often-used array of characters used to create order codes. |
private String |
orderSource
order source |
private int |
productID
Enrolment product ID |
private static long |
serialVersionUID
Java serialisation unique ID |
private int |
userID
The user who owns this enrolment |
Fields inherited from class org.starhope.appius.util.SimpleDataRecord |
---|
myLoader, timeLastChanged, timeLastSaved |
Constructor Summary | |
---|---|
UserEnrolment(String order_source,
int product_id,
int user_id)
Create a new enrolment for the given user. |
|
UserEnrolment(String orderSource2,
String orderCode2)
WRITEME: Document this constructor brpocock@star-hope.org |
|
UserEnrolment(UserEnrolmentSQLLoader userEnrolmentSQLLoader)
WRITEME: Document this constructor brpocock@star-hope.org |
Method Summary | |
---|---|
void |
activate(boolean newEnrolment)
XXX: This method should probably be checking activatedUser.isPaidMember () instead of requiring a boolean into it |
private void |
add(int months,
int days)
Extend the expiration date by a given amount. |
void |
cancelNow()
cancel the enrolment, effective immediately. |
void |
checkStale()
Indicates that a data record is stale and needs to be refreshed |
private void |
continueEnrolment()
Based upon the current expiry date, extend the expiry by the number of months and days indicated by the enrolment type. |
private void |
generateOrderCode()
Create a pseudo-random, unique order code consisting of the approved letters and numbers in orderCodeChars |
private String |
genRandomOrderCode()
Create a 10-character sequence using the “non-ambiguous” character set of order code characters. |
static Collection<UserEnrolment> |
getAllForUserID(int userID)
|
BigDecimal |
getAmount()
|
BigDecimal |
getAuthSubID()
|
Date |
getBegins()
|
AbstractPerson |
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. |
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. |
Currency |
getCurrency()
|
String |
getDescription()
Get the description of the subscription: typically, this says a subscription to a given product (“Subscription to Tootsville”), plus “for,” and the display name of the subscriber. |
Enrolment |
getEnrolment()
|
Date |
getExpires()
|
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()
|
static String |
getOrderCode(String orderNumber)
get the order code from an order number |
static char[] |
getOrderCodeChars()
Get a set of characters that are unlikely to be confused for one another. |
String |
getOrderSource()
|
static String |
getOrderSource(String orderNumber)
get the order source from an order number |
int |
getProductID()
|
Date |
getRecurs()
|
String |
getSubversionRevision()
Return the Subversion revision level of this class's source code file, as supplied via the special "$Rev: " sequence. |
String |
getTitle()
|
AbstractUser |
getUser()
|
int |
getUserID()
|
void |
insert()
insert the enrolment into the database |
boolean |
isActive()
|
boolean |
isRecurring()
find whether this is a recurring enrolment type |
void |
killEnrolment()
set both the start and end effective dates to the epoch |
void |
setAuthSubID(BigDecimal authSubID1)
|
void |
setAuthSubID(String authSubID2)
set the authorize.net subscription ID |
void |
setBegins(Date newBegins)
|
void |
setEnrolment(Enrolment newEnrolment)
|
void |
setExpires(Date newExpires)
|
void |
setID(int newID)
|
void |
setOrderCode(String orderCode1)
|
void |
setOrderSource(String orderSource1)
|
void |
setProductID(int productID1)
|
void |
setUser(GeneralUser newUser)
|
void |
setUserID(int userID1)
|
private void |
startEnrolment()
WRITEME: document this method (twheys@gmail.com, Sep 24, 2009) |
org.json.JSONObject |
toJSON()
This returns a copy of the object's data cast into a JSON form. |
String |
toString()
|
Methods inherited from class org.starhope.appius.util.SimpleDataRecord |
---|
changed, 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 |
---|
private static final char[] orderCodeChars
An often-used array of characters used to create order codes.
This excludes letters and digits which reasonably might be confused in some handwriting or stylised fonts: O/Q/0, I/1, 2/Z, 5/S, 7/T, and U/V.
Note that this gives us a base-21 system, thus possible permutations are:
n×1 21 n×2 441 n×3 9,261 n×4 194,481 n×5 4,084,101 n×6 85,766,121 n×7 1,801,088,541 n×8 37,822,859,361 n×9 764,280,046,581 n×10 16,679,880,978,201
∴ we have about 17 trillion available 10-digit order codes even after excluding all of those potential characters
private static final long serialVersionUID
private BigDecimal authSubID
private Date begins
private Date expires
private int id
private volatile boolean isActivated
private String orderCode
private String orderSource
private int productID
private int userID
Constructor Detail |
---|
public UserEnrolment(String order_source, int product_id, int user_id) throws NotFoundException
order_source
- order source codeproduct_id
- the product for which the user is enrollinguser_id
- the user being enrolled
NotFoundException
- if the enrolment type is not found.public UserEnrolment(String orderSource2, String orderCode2)
orderSource2
- WRITEMEorderCode2
- WRITEMEpublic UserEnrolment(UserEnrolmentSQLLoader userEnrolmentSQLLoader)
userEnrolmentSQLLoader
- WRITEMEMethod Detail |
---|
public static Collection<UserEnrolment> getAllForUserID(int userID)
userID
- user enrolled
public static UserEnrolment getBySourceAndCode(String orderSource, String orderCode) throws NotFoundException
orderSource
- The source of the order (ex. 'auth')orderCode
- The code of the order
NotFoundException
- if an enrolment cannot be found with
the given orderSource and orderCode.public static UserEnrolment[] getLastTwoYearsForUserID(int userID)
userID
- user enrolled
public static String getOrderCode(String orderNumber)
orderNumber
- an order number string
public static char[] getOrderCodeChars()
orderCodeChars
public static String getOrderSource(String orderNumber)
orderNumber
- an order number
public void activate(boolean newEnrolment)
XXX: This method should probably be checking activatedUser.isPaidMember () instead of requiring a boolean into it
newEnrolment
- true if this is a new accountprivate void add(int months, int days)
Extend the expiration date by a given amount. Months are added based upon the calendar day; i.e. we take into account the length differences of months and so forth; then, additional days are appended.
Out of paranoia, the base date (to which the new months & days are added) will be set to the later of either the current expiry date, or the current date. This means that if an enrolment expires in the past, and is then extended, it will end at the proper date from now; but if it has not yet expired, the renewal will be tacked onto the end.
months
- months to extenddays
- days to extend.public void cancelNow()
public void checkStale()
DataRecord
checkStale
in interface DataRecord
checkStale
in class SimpleDataRecord<UserEnrolment>
SimpleDataRecord.checkStale()
private void continueEnrolment()
Based upon the current expiry date, extend the expiry by the number of months and days indicated by the enrolment type.
private void generateOrderCode()
orderCodeChars
private String genRandomOrderCode()
generateOrderCode()
,
for which you probably are looking, if you found this.
public BigDecimal getAmount()
getAmount
in interface Invoiceable
Invoiceable.getAmount()
public BigDecimal getAuthSubID()
public Date getBegins()
public AbstractPerson getBuyer()
Invoiceable
getBuyer
in interface Invoiceable
Invoiceable.getBuyer()
public int getCacheableID() throws NotFoundException
DataRecord
DataRecord.getCacheableID()
or a string identifier (
DataRecord.getCacheableIdent()
or both.
getCacheableID
in interface DataRecord
NotFoundException
- if the item doesn't have a distinct
numeric IDDataRecord.getCacheableID()
public String getCacheableIdent() throws NotFoundException
DataRecord
DataRecord.getCacheableID()
or a string identifier (
DataRecord.getCacheableIdent()
or both.
getCacheableIdent
in interface DataRecord
NotFoundException
- if the item doesn't have a distinct
string identifierDataRecord.getCacheableIdent()
public Currency getCurrency()
getCurrency
in interface Invoiceable
Invoiceable.getAmount()
Invoiceable.getCurrency()
public String getDescription()
public Enrolment getEnrolment()
public Date getExpires()
public int getID()
public String getInvoiceID()
getInvoiceID
in interface Invoiceable
Invoiceable.getInvoiceID()
public char getInvoiceIDPrefix()
getInvoiceIDPrefix
in interface Invoiceable
Invoiceable.getInvoiceIDPrefix()
private Date getLastExpiration()
public Payment getLastPayment() throws NotFoundException
NotFoundException
- if nobody's paid anything yetpublic String getOrderCode()
public String getOrderSource()
public int getProductID()
public Date getRecurs()
public String getSubversionRevision()
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: "; }
getSubversionRevision
in interface HasSubversionRevision
HasSubversionRevision.getSubversionRevision()
public String getTitle()
getTitle
in interface Invoiceable
Invoiceable.getTitle()
public AbstractUser getUser()
public int getUserID()
public void insert() throws SQLException
SQLException
- if the record can't be inserted into the
databasepublic boolean isActive()
public boolean isRecurring()
public void killEnrolment()
@Setter(getter="getAuthSubID") @OpEd(advice="The Authorize.Net (or other payment authenticator) Subscription ID number", isAdvanced=true, label="Authenticator Subscription ID") public void setAuthSubID(BigDecimal authSubID1)
authSubID1
- authorize.net subscription IDpublic void setAuthSubID(String authSubID2) throws NumberFormatException
authSubID2
- authorize.net subscription ID
NumberFormatException
- if the id or something can't be
interpreted? but I don't know what circumstances
might cause this, probably a non-numeric subscriber
ID being returned from the provider? WRITEME@Setter(getter="getBegins") public void setBegins(Date newBegins)
newBegins
- begin datepublic void setEnrolment(Enrolment newEnrolment)
newEnrolment
- enrolment productpublic void setExpires(Date newExpires)
newExpires
- expiry datepublic void setID(int newID)
newID
- the id to setpublic void setOrderCode(String orderCode1)
orderCode1
- order codepublic void setOrderSource(String orderSource1)
orderSource1
- order sourcepublic void setProductID(int productID1)
productID1
- enrolment productpublic void setUser(GeneralUser newUser)
newUser
- user enrolledpublic void setUserID(int userID1)
userID1
- user enrolledprivate void startEnrolment()
Set the proper enrolment start date. This might not work right?
public org.json.JSONObject toJSON()
CastsToJSON
toJSON
in interface CastsToJSON
public String toString()
toString
in class SimpleDataRecord<UserEnrolment>
Object.toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |