com.tootsville
Class WebUtil

java.lang.Object
  extended by com.tootsville.WebUtil
All Implemented Interfaces:
BeforePageHook, MBParamTranslator, PostParentRegistrationHook, PostPaymentHook, PostUserRegistrationHook

public class WebUtil
extends Object
implements MBParamTranslator, PostUserRegistrationHook, PostParentRegistrationHook, PostPaymentHook, BeforePageHook

WebUtil contains business logic methods called by the Membership And Billing front-end JSP pages. This isolates the more complex logic from the presentation-level code in the JSP files.

This, however, turned into a mess of spaghetti code that was mostly split up into more appropriate places, including funnelling most of it into MBSession.

Author:
twheys@gmail.com, brpocock@star-hope.org

Field Summary
private static WebUtil singleton
          singleton for hook impl
(package private)  UserEnrolment subscription
           This is the really critical stage of the billing process, and one in which we've historically had a lot of trouble.
 
Constructor Summary
private WebUtil()
          noop ctor is private for singleton impl
 
Method Summary
static void applyPeanutCodeToNewUser(MBSession session, Toot newToot)
          Apply a Peanut code to a new user account
 void beforePage(MBSession mbSession, javax.servlet.jsp.PageContext context)
          WRITEME: Document this method brpocock@star-hope.org
private static String checkIBC(Object ibcCode, User sessionUser)
           twheys@gmail.com Feb 2, 2010
 void configureMembershipAndBilling()
          This performs some start-up configuration of the generic, Romance M&B system for working with Tootsville, particularly.
static void cookieMonster(javax.servlet.http.HttpServletRequest request)
          Process cookies and set session values.
static Promotion createNewEventPromotion(String prefix, int numberOfCodes, int minValue, int maxValue)
           twheys@gmail.com Jan 7, 2010
 void doAfterEnrolmentAfterLapse(MBSession session, User user, Enrolment enrolment, UserEnrolment userEnrolment, Payment payment)
           
 void doAfterEnrolmentRenewal(MBSession session, User user, Enrolment enrolment, UserEnrolment userEnrolment, Payment payment)
           
 void doAfterFirstTimeEnrolment(MBSession session, User user, Enrolment enrolment, UserEnrolment userEnrolment, Payment payment)
           
static WebUtil get()
           
static Vector<GameWorldMessage> getRecentTootbookPosts(int offset, int limit)
           Get a collection of recent TootsBook postings.
private  void giveCouponForEnrolment(MBSession session, User user, Payment payment)
          WRITEME: Document this method brpocock@star-hope.org
static void go()
          Syntactic sugar function for embedding the set-up step in JSP pages
static void log(String blah)
          Deprecated. use AppiusClaudiusCaecus.blather(String)
 void postParentRegistration(MBSession session, Parent newUser)
           
 void postUserRegistration(MBSession session, User newUser)
           
static void renewSubscription(javax.servlet.ServletRequest request)
           Verifies POST data to ensure ...
static Vector<AbstractPerson> searchUsers(String searchParams)
          find users who ...
 void translateParameters(MBSession session, javax.servlet.ServletRequest request)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

singleton

private static WebUtil singleton
singleton for hook impl


subscription

UserEnrolment subscription

This is the really critical stage of the billing process, and one in which we've historically had a lot of trouble.

This method takes the user-provided credit-card/billing information from the web payment form, and attempts to process the credit-card transaction through the PaymentGateway and add a UserEnrolment to the user's record.

There are a lot of things going on in here, and a lot of values being passed around. As a result, this is a very long, very linear patch of code, of the type I (BRP) dislike seeing immensely; however, I don't see any legitimately effective way to break this down into subroutines, since most of the values are being passed around in a huge bulk of separate things.

XXX Eventually, this should be using some more high-level objects that will check their own values in a more reasonable way; e.g. an Address object smart enough to parse and validate its own component values and return detailed exceptions that can be propagated to the end-user.

Due to lack of time, I'm afraid I need to just refer the interested user to the source code comments.

WRITEME: There should be more detail in this JavaDoc!

above vapidly poor documentation by brpocock@star-hope.org

Constructor Detail

WebUtil

private WebUtil()
noop ctor is private for singleton impl

Method Detail

applyPeanutCodeToNewUser

public static void applyPeanutCodeToNewUser(MBSession session,
                                            Toot newToot)
Apply a Peanut code to a new user account

Parameters:
session - user's session object
newToot - the user account just registered

checkIBC

private static String checkIBC(Object ibcCode,
                               User sessionUser)
                        throws GameLogicException
 twheys@gmail.com Feb 2, 2010
 

Check an IBC code / Chase-It / prepaid card token …

Parameters:
ibcCode - prepaid membership card token
sessionUser - the user claiming the card's benefits
Returns:
next URL in chain
Throws:
GameLogicException - WRITEME

cookieMonster

public static void cookieMonster(javax.servlet.http.HttpServletRequest request)
Process cookies and set session values. Currently only handles “remember my name” buttons.

Parameters:
request - the HTTP request passed through the servlet.

createNewEventPromotion

public static Promotion createNewEventPromotion(String prefix,
                                                int numberOfCodes,
                                                int minValue,
                                                int maxValue)
 twheys@gmail.com Jan 7, 2010
 

Create a new promotional programme code series. These are the “peanut codes” that can be printed on promotional materials such as post-cards or hang-tags and distributed to kids, and then later redeemed for in-game peanuts. The promotional codes will consist of a given prefix (which can be used for tracking the users redeeming them later) and a series of random codes following it.

Prefix codes should all be 4-character alphabetic and avoid the use of the letters “O” and “I” if their usage might be ambiguous in-situ.

Parameters:
prefix - The unique 4-character code representing the promotional programme; this will be prefaced onto each generated code.
numberOfCodes - The number of promotional codes to be generated
minValue - The minimum number of peanuts to be awarded for each code
maxValue - The maximum number of peanuts to be awarded for each code
Returns:
The newly-created Promotion (which can be safely ignored, but); or, null on failure (which maybe should be checked?)

get

public static WebUtil get()
Returns:
the WebUtil singleton

getRecentTootbookPosts

public static Vector<GameWorldMessage> getRecentTootbookPosts(int offset,
                                                              int limit)

Get a collection of recent TootsBook postings.

This returns a set of TootsBook messages (wall posts). It will return only “wall postings,” where the user set their own status; it will not return comments upon this, nor another user's postings.

XXX: contains SQL

Parameters:
offset - The first message to be returned, in negative timewise order (newest-first)
limit - The number of messages to be returned, starting at offset, in negative timewise order (newest-first)
Returns:
a set of GameWorldMessage objects ordered in negative timewise order

go

public static void go()
Syntactic sugar function for embedding the set-up step in JSP pages


log

@Deprecated
public static void log(String blah)
Deprecated. use AppiusClaudiusCaecus.blather(String)

Deprecated, use AppiusClaudiusCaecus.blather(String)

Parameters:
blah - string to log
See Also:
AppiusClaudiusCaecus.blather(String), AppiusClaudiusCaecus.blather(String, String, String, String, boolean)

renewSubscription

public static void renewSubscription(javax.servlet.ServletRequest request)
                              throws DataException,
                                     UnsupportedEncodingException

Verifies POST data to ensure ... something? ... WRITEME ... and then it renews the subscription

WRITEME: this must be the Authorize.net Silent-POST handler?

FIXME: This stuff belongs in AuthorizeNetGateway

Parameters:
request - servlet request from the user... or from Authorize.Net ... ?
Throws:
DataException - if the validation keys aren't present
UnsupportedEncodingException - WRITEME

searchUsers

public static Vector<AbstractPerson> searchUsers(String searchParams)
find users who ... um ... something. WRITEME twheys@gmail.com

XXX: It looks like this is going to fetch up users and parents based upon ID's that could potentially be the same ??

Note, Nomenclator.getUserByLogin(String) understands # + user ID. So user names of the form "#123" are acceptable... I don't think Nomenclator.getParentByMail(String) has an analogous method, though.

Parameters:
searchParams - WRITEME
Returns:
WRITEME

beforePage

public void beforePage(MBSession mbSession,
                       javax.servlet.jsp.PageContext context)
Description copied from interface: BeforePageHook
WRITEME: Document this method brpocock@star-hope.org

Specified by:
beforePage in interface BeforePageHook
See Also:
BeforePageHook.beforePage(org.starhope.appius.mb.MBSession, javax.servlet.jsp.PageContext)

configureMembershipAndBilling

public void configureMembershipAndBilling()
This performs some start-up configuration of the generic, Romance M&B system for working with Tootsville, particularly.


doAfterEnrolmentAfterLapse

public void doAfterEnrolmentAfterLapse(MBSession session,
                                       User user,
                                       Enrolment enrolment,
                                       UserEnrolment userEnrolment,
                                       Payment payment)
Specified by:
doAfterEnrolmentAfterLapse in interface PostPaymentHook
See Also:
PostPaymentHook.doAfterEnrolmentAfterLapse(org.starhope.appius.mb.MBSession, org.starhope.appius.user.User, org.starhope.appius.mb.Enrolment, org.starhope.appius.mb.UserEnrolment, org.starhope.appius.mb.Payment)

doAfterEnrolmentRenewal

public void doAfterEnrolmentRenewal(MBSession session,
                                    User user,
                                    Enrolment enrolment,
                                    UserEnrolment userEnrolment,
                                    Payment payment)
Specified by:
doAfterEnrolmentRenewal in interface PostPaymentHook
See Also:
PostPaymentHook.doAfterEnrolmentRenewal(org.starhope.appius.mb.MBSession, org.starhope.appius.user.User, org.starhope.appius.mb.Enrolment, org.starhope.appius.mb.UserEnrolment, org.starhope.appius.mb.Payment)

doAfterFirstTimeEnrolment

public void doAfterFirstTimeEnrolment(MBSession session,
                                      User user,
                                      Enrolment enrolment,
                                      UserEnrolment userEnrolment,
                                      Payment payment)
Specified by:
doAfterFirstTimeEnrolment in interface PostPaymentHook
See Also:
PostPaymentHook.doAfterFirstTimeEnrolment(org.starhope.appius.mb.MBSession, org.starhope.appius.user.User, org.starhope.appius.mb.Enrolment, org.starhope.appius.mb.UserEnrolment, org.starhope.appius.mb.Payment)

giveCouponForEnrolment

private void giveCouponForEnrolment(MBSession session,
                                    User user,
                                    Payment payment)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
session - WRITEME
user - WRITEME
payment - WRITEME

postParentRegistration

public void postParentRegistration(MBSession session,
                                   Parent newUser)
Specified by:
postParentRegistration in interface PostParentRegistrationHook
See Also:
PostParentRegistrationHook.postParentRegistration(org.starhope.appius.mb.MBSession, org.starhope.appius.user.Parent)

postUserRegistration

public void postUserRegistration(MBSession session,
                                 User newUser)
Specified by:
postUserRegistration in interface PostUserRegistrationHook
See Also:
PostUserRegistrationHook.postUserRegistration(org.starhope.appius.mb.MBSession, org.starhope.appius.user.User)

translateParameters

public void translateParameters(MBSession session,
                                javax.servlet.ServletRequest request)
Specified by:
translateParameters in interface MBParamTranslator
See Also:
MBParamTranslator.translateParameters(MBSession, ServletRequest)