public class UserFavoritesHandler extends DBUHandler
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
FAVORITE_ID_PREFIX
The prefix used for generated favorite cart ids.
|
private static long |
serialVersionUID
The class' serialization version id.
|
protected static java.lang.String |
SN_FAVORITE_CART
The session's key for the shopping users current favorites cart.
|
protected static java.lang.String |
SN_FAVORITE_DESC
The session's key for the shopping users current favorites descriptors.
|
ivContext
Constructor and Description |
---|
UserFavoritesHandler()
Constructs a new instance of the user favorites handler with a
null servlet or thread context. |
Modifier and Type | Method and Description |
---|---|
boolean |
addList(FavoritesDescriptor fd)
Addes a new favorites list for the shopping user and then makes the new
list the shopping user's current favorites list.
|
boolean |
copyList(FavoritesDescriptor fd,
User user)
Copies an existing favorites list from one user to another.
|
Cart |
createNewCart()
Creates a new favorites cart and persists it to the database.
|
Cart |
createNewList(User user,
java.lang.String description)
Creates a new favorites list for a user.
|
boolean |
deleteList()
Deletes the current favorites list for the shopping user and then makes the
first available existing list the shopping user's current favorites list.
|
Cart |
getCart()
Returns the shopping user's current favorites cart.
|
java.util.TreeSet<FavoritesDescriptor> |
getDescriptors()
Returns the shopping user's current set of favorites descriptors.
|
java.lang.String |
getListId()
Returns the shopping user's current favorites list id.
|
Select |
getListUISelect(java.lang.String id)
Returns an HTML
Select object of the shopping user's favorites
lists with the given id preselected in the set of options. |
boolean |
setListId(java.lang.String id)
Sets the shopping user's favorites list id to the given id.
|
void |
setSessionValues(User user)
Sets the session object in the current servlet context with the favorites
information for a user.
|
boolean |
updateList(FavoritesDescriptor fd)
Updates the current favorites list for the shopping user.
|
getContext, setContext
private static final long serialVersionUID
public static final java.lang.String FAVORITE_ID_PREFIX
protected static final java.lang.String SN_FAVORITE_CART
protected static final java.lang.String SN_FAVORITE_DESC
public UserFavoritesHandler()
null
servlet or thread context.
A CONTEXT MUST BE SET BEFORE INVOKING ANY OTHER METHODS.
.public boolean addList(FavoritesDescriptor fd)
fd
- (FavoritesDescriptor) A descriptor that contains the
list data to add.true
if the add is successful,
otherwise false
.public boolean deleteList()
true
if the delete is successful,
otherwise false
.public boolean updateList(FavoritesDescriptor fd)
fd
- (FavoritesDescriptor) A descriptor that contains the
list data to update.true
if the update is successful,
otherwise false
.public Cart getCart()
null
if there currently
is no favorites cart.public java.util.TreeSet<FavoritesDescriptor> getDescriptors()
public java.lang.String getListId()
public boolean setListId(java.lang.String id)
id
- (String) The id of the favorites list to set.true
if the id is successfully set,
otherwise false
.public Select getListUISelect(java.lang.String id)
Select
object of the shopping user's favorites
lists with the given id preselected in the set of options. Invokers must
assign a form field name to the returned object via the setName
method before adding the object to the velocity template data.id
- (String) The descriptor id to preselect in the select's set
of options. Pass an empty string for this parameter if a blank
option is to be created as the first option and then preselected.
Pass a null
for this parameter if no blank option and no
preselecting is desired.Select
object.public void setSessionValues(User user)
NOTE: The user supplied here must either be the current shopping user or a user who is about to become the current shopping user. All methods in this class that do not have a user parameter are based on the current shopping user.
user
- (User) The user whose favorite information should be set
or null
to nullify the session's favorites information.public Cart createNewCart()
null
if the new
cart could not be created.public Cart createNewList(User user, java.lang.String description)
user
- (User) The user who owns the new favorite.description
- (String) The description for the favorite.null
if the new
cart could not be created.public boolean copyList(FavoritesDescriptor fd, User user)
NOTE: If copying to an existing favorite (the copy-to description is the same as the copy-from description), no new cart or descriptor objects are created; the existing copy-to objects are used. In this case, the copy-to favorite's cart lines are deleted before the copying occurs (i.e. there is no merging of cart lines; the copy-to favorite cart lines are replaced.
fd
- (FavoritesDescriptor) The favorites list to copy from.user
- (User) The user who owns the new favorites being copied to.true
if the copying is successful,
otherwise false
.