com.tootsville.promo
Class Promotion

java.lang.Object
  extended by org.starhope.appius.sql.SQLPeerDatum
      extended by com.tootsville.promo.Promotion
All Implemented Interfaces:
Serializable, Comparable<Object>

public class Promotion
extends SQLPeerDatum

Promotions used for Marketing. These can either be used for tracking links from advertising sites or for peanut codes for marketing events.

Author:
Tim Heys
See Also:
Serialized Form

Nested Class Summary
private static class Promotion.TrackingType
          Types of marketing tracking available.
 
Field Summary
private  char[] code
          4 letter tracking code for storing a referer for User.
private  String description
          Description of this promotion.
private  String link
          The link used for advertisement links.
private  int promotionID
          The ID of this promotion
private  String redirect
          URL to where the tracking link redirects to.
private static long serialVersionUID
          Java serialisation unique ID
(package private)  Promotion.TrackingType type
          The Tracking type for this promotion.
 
Constructor Summary
protected Promotion(ResultSet rs)
          Create a Promotion object from a result set.
  Promotion(String newCode, String newLink, String newDescription, Promotion.TrackingType newType)
          Creates a promotion with a redirect link set as the default "http://www.tootsville.com"
  Promotion(String newCode, String newLink, String newRedirect, String newDescription, Promotion.TrackingType newType)
          Create a new promotion.
 
Method Summary
private  void assertPromotionLinkAvailable(String newLink)
          Check if the link already exists.
 void changed()
          Indicate that some of the contents of this datum have changed, and that the database and/or object caches may need to be updated.
static Promotion createEventPromotion(String prefixCode)
          Create a new promotional code series for a specific event
 void createPeanutCodesForPromotion(int numberOfCodes, int minValue, int maxValue)
           twheys@gmail.com Jan 7, 2010
 void flush()
           
private  String generatePeanutCode(String prefix)
          Create a pseudorandom, unique order code consisting of the approved letters and numbers.
static Promotion getAdByLink(String maybe)
          Get an Advertisement Promotion object from a tracking link.
static Promotion getByLink(String maybe)
          Get a Promotion object from a tracking link.
protected  String getCacheUniqueID()
           
 String getCode()
           
 String getDescription()
           
 String getLink()
           
 String getRedirect()
           
 Promotion.TrackingType getType()
           
private  void insert()
           twheys@gmail.com Jan 7, 2010
protected  void set(ResultSet rs)
           
 void setCode(String newCodeString)
          Set the code for this promotion.
 void setDescription(String newDescription)
           
 void setLink(String newLink)
           
 void setRedirect(String newRedirectLink)
           
 void setType(Promotion.TrackingType newType)
           
 
Methods inherited from class org.starhope.appius.sql.SQLPeerDatum
compareTo, findInCache, saveInCache, set, toJSON
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Java serialisation unique ID

See Also:
Constant Field Values

code

private char[] code
4 letter tracking code for storing a referer for User.


description

private String description
Description of this promotion.


link

private String link
The link used for advertisement links. link is a relative link with the format: https://members.tootsville.com/l/{#link} Only provide the last part of the link.


promotionID

private int promotionID
The ID of this promotion


redirect

private String redirect
URL to where the tracking link redirects to.


type

Promotion.TrackingType type
The Tracking type for this promotion.

See Also:
Promotion.TrackingType
Constructor Detail

Promotion

protected Promotion(ResultSet rs)
             throws SQLException
Create a Promotion object from a result set. Calls set(ResultSet).

Parameters:
rs - The result set of a Promotion.
Throws:
SQLException - if the result set can't be interpreted

Promotion

public Promotion(String newCode,
                 String newLink,
                 String newRedirect,
                 String newDescription,
                 Promotion.TrackingType newType)
          throws IndexOutOfBoundsException,
                 DataException,
                 AlreadyExistsException
Create a new promotion. Code must follow be 4 letters exactly. Link must exist as a unique value.

Parameters:
newCode - The code 4 letter tracking code for storing a referrer for User.
newLink - The link to this promotion. Follows the format of https://members.tootsville.com/l/{link}
newRedirect - The redirect link for this link if it is other than default.
newDescription - The description for this promotion.
newType - The type of this promotion.
Throws:
IndexOutOfBoundsException - if the code is not 4 characters long.
DataException - if the code contains characters other than letters.
AlreadyExistsException - if a Promotion with this link already exists.
See Also:
Promotion.TrackingType

Promotion

public Promotion(String newCode,
                 String newLink,
                 String newDescription,
                 Promotion.TrackingType newType)
          throws IndexOutOfBoundsException,
                 DataException,
                 AlreadyExistsException
Creates a promotion with a redirect link set as the default "http://www.tootsville.com"

Parameters:
newCode - The code 4 letter tracking code for storing a referer for User.
newLink - The link to this promotion. Follows the format of https://members.tootsville.com/l/{link}
newDescription - The description for this promotion.
newType - The type of this promotion.
Throws:
IndexOutOfBoundsException - if the code is not 4 characters long.
DataException - if the code contains characters other than letters.
AlreadyExistsException - if a Promotion with this link already exists.
See Also:
Promotion(String, String, String, String, TrackingType), Promotion.TrackingType
Method Detail

createEventPromotion

public static Promotion createEventPromotion(String prefixCode)
                                      throws IndexOutOfBoundsException,
                                             DataException,
                                             AlreadyExistsException
Create a new promotional code series for a specific event

Parameters:
prefixCode - WRITEME
Returns:
WRITEME
Throws:
AlreadyExistsException - WRITEME
DataException - WRITEME
IndexOutOfBoundsException - WRITEME

getAdByLink

public static Promotion getAdByLink(String maybe)
                             throws NotFoundException
Get an Advertisement Promotion object from a tracking link. Use this instead of getByLink(String) to only retrieve promotions labeled as an advertisement type.

Parameters:
maybe - The link in question.
Returns:
a Promotion if there is one matching the link.
Throws:
NotFoundException - if there is no such ad link matching param maybe.

getByLink

public static Promotion getByLink(String maybe)
                           throws NotFoundException
Get a Promotion object from a tracking link.

Parameters:
maybe - The link in question.
Returns:
a Promotion if there is one matching the link.
Throws:
NotFoundException - if there is no such link matching param maybe.

assertPromotionLinkAvailable

private void assertPromotionLinkAvailable(String newLink)
                                   throws AlreadyExistsException
Check if the link already exists.

Parameters:
newLink - The link in question.
Throws:
AlreadyExistsException - if the link already exists.

changed

public void changed()
Description copied from class: SQLPeerDatum
Indicate that some of the contents of this datum have changed, and that the database and/or object caches may need to be updated.

Overrides:
changed in class SQLPeerDatum
See Also:
SQLPeerDatum.changed()

createPeanutCodesForPromotion

public void createPeanutCodesForPromotion(int numberOfCodes,
                                          int minValue,
                                          int maxValue)
 twheys@gmail.com Jan 7, 2010
 
TO createPeanutCodesForPromotion WRITEME...

Parameters:
numberOfCodes - WRITEME
minValue - WRITEME
maxValue - WRITEME

flush

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

generatePeanutCode

private String generatePeanutCode(String prefix)
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)

Parameters:
prefix - prefix code for this event/product
Returns:
an unique peanut code

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

getCode

public String getCode()
Returns:
the code for this promotion
See Also:
code

getDescription

public String getDescription()
Returns:
the description for this promotion
See Also:
description

getLink

public String getLink()
Returns:
the link for this promotion
See Also:
link

getRedirect

public String getRedirect()
Returns:
the redirect link for this promotion
See Also:
redirect

getType

public Promotion.TrackingType getType()
Returns:
the type for this promotion
See Also:
type

insert

private void insert()
 twheys@gmail.com Jan 7, 2010
 
TO insert WRITEME...


set

protected 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 - if the database fails somehow
See Also:
SQLPeerDatum.set(java.sql.ResultSet)

setCode

public void setCode(String newCodeString)
             throws IndexOutOfBoundsException,
                    DataException
Set the code for this promotion. The code MUST be 4 characters exactly and contain ONLY letters. The letter characters will automatically be converted to lower case.

Parameters:
newCodeString - a 4 character string of only letters.
Throws:
IndexOutOfBoundsException - if the code is not 4 characters long.
DataException - if the code contains characters other than letters.

setDescription

public void setDescription(String newDescription)
Parameters:
newDescription - the description of this promotion.
See Also:
description

setLink

public void setLink(String newLink)
Parameters:
newLink - the tracking link for this promotion.
See Also:
link

setRedirect

public void setRedirect(String newRedirectLink)
Parameters:
newRedirectLink - the redirect to set
See Also:
redirect

setType

public void setType(Promotion.TrackingType newType)
Parameters:
newType - the type to set
See Also:
type