Question
Create New JavaBeans for Business Objects (Model) Create JavaBeans for the following Model elements, with the specified instance variables and additional methods. User represents user
Create New JavaBeans for Business Objects (Model) Create JavaBeans for the following Model elements, with the specified instance variables and additional methods. User represents user User ID First Name Last Name Email Address Address 1 Field Address 2 Field City State / Region Post Code Country UserItem associates an item with a user and a swap User Item Rating Status this attribute should indicate swap item status available, pending (offer made), swapped (offer accepted) Swap Item this is the item swapped with this user item (an item that was offered for swapping by another user and was swapped with this user item). Swap Item Rating this is the users rating for the item swapped with this user item Swapper Rating this is the users rating for the other user that owns the item swapped with this user item Note: if the user item status is available then theres no values for Swap Item, Swap Item Rating, or Swapper Rating. When the status is pending then Swap Item has a value but but not the ratings for the swap item and the swapper. When the status is swapped then the user will be able to rate the swap item and the swapper (the other user) UserProfile A class to manage a List / Collection (your choice) of UserItem(s) User ID attribute used for user identification User Items attribute used for UserItem(s) removeUserItem(Item) removes any UserItem associated with the given Item. getUserItems() returns a List / Collection of UserItem from this user profile emptyProfile() clears the entire profile contents any other helper methods you might need to manage this list/collection Create New Utility Class for Persistent Data Use a hard-coded database to represent your sets of users similar to what you did with the items in assignment 2. You should hard-code a fixed set of users within the following class. You must have at least one user with at least two items (UserItem) in their profile. UserDB Hard-Coded set of user details (your choice on how to represent) List/Collection getUsers() returns a set of all the users in the hardcoded database UserProfile getUserProfile(User Id) returns a UserProfile object for a specific user Create Servlets for Business Logic (Controller) For this assignment, you will implement dynamic user profile functionality. You must use sessions to pass data. This means that the user profile will be able to hold multiple kinds of items at a time, and will maintain its content even if you navigate away from the user items page (My Swaps web page). We will be referring to the page with a users swap items (myItems) as the profile JSP view. Implement the following Controller servlet to operationalize the business logic. You will need to send parameters as part of the GET or POST http requests from button / form submissions as the context information that tells the controllers how to proceed. ProfileController.java Load the database of items. Check the session for a current user, using the attribute theUser o If there is no user attribute create a User bean, by selecting the first (or random) user from the UserDB. This is currently a placeholder for having the user go through all the steps of entering their details or logging in to their account. add the User bean to the current session as theUser get the user profile items - this is currently a placeholder for a users saved information and items. Create a hard coded UserProfile object that contains at least two valid and current items. add the user profile to the session object as currentProfile and dispatch to the profile JSP view o if there is a user attribute and it is valid check the http request for a parameter called action if there is an action parameter, validate that its value is either update, accept, reject, withdraw, offer, delete or signout if there is no action parameter, or if it has an unknown value, dispatch to the profile JSP view. If this is a new user and no items are added to their profile this page should be empty (you can display a message indicating that there no items to display). if the action is update checks the http request for a parameter called theItem o validate that its value matches your item code format and is a valid current item code. This tells you which item is to be added to or updated in the profile. o validate that this request was an intentional user action check that it originated from a view that displayed this item as a candidate for an update and all items displayed are valid current items and that they belong to this user. Hint: use a hidden field named itemList in the view with the item code as the value for that field. The controller will receive that as a parameter with that name and having an array of values (all the items on the view. For e.g., request.getParameterValues(itemList) will give you a list of all the items on the view) o if the item validates and exists in the user profile, get the UserItem bean saved in the user profile for this item check the status value. if the status value indicates that this item is pending, add the UserItem bean to the request as swapItem redirect to mySwaps view. (to allow the user to accept/reject/withdraw) if the status value indicates that this item is available for swap or was already swapped add the UserItem bean to the request as userItem dispatch to the individual item view. Note: As a place holder for this stage of implementation choose either the user item or the swap item to display on the individual item view. o if the item does not validate or does not exist in the user profile dispatch to the profile JSP view. If the action is accept, reject or withdraw check the http request for a parameter called theItem o validate that its value matches your item code format and is a valid current item code. This tells you which item is to be updated in the profile. validate that this request was an intentional user action check that it originated from a view that displayed this item as a candidate for an accept, reject or withdraw and all items displayed are valid current items and that they belong to this user. if the item validates and exists in the user profile and its status is pending (the status value indicates that this item has a swap offer), get the UserItem bean saved in the user profile o If action was reject or withdraw reset the status value to indicate that this item is available for swap and clear the value for the swap status property. o If action was accept set the status value to indicate that this item was swapped. having an updated profile, add the updated profile to the session object as sessionProfile and dispatch to the user profile JSP view. Note: you dont need to update the hard-coded user profile. You should just update the instance created in the session. If the action is delete check the http request for a parameter called theItem o validate that its value matches your item code format and is a valid current item code. This tells you which item is to be updated in the profile. validate that this request was an intentional user action and that it originated from a view that displayed this item as a candidate for a delete and all items displayed are valid current items and that they belong to this user. if the item validates and exists in the user, remove this item from the user profile having an updated profile, add the updated profile to the session object as sessionProfile and dispatch to the profile JSP view. Remember that we are not updating the original hard-coded data. if the item doesnt validate dispatch to the profile JSP view. If the action is offer check the http request for a parameter called theItem validate that its value matches your item code format and is a valid current item code. This tells you which item the active user wants to make a swap offer for one of their own items. validate that this request was an intentional user action and that it originated from a view that displayed this item as a candidate for a swap. Check the user profile for any items they have available for swappingIf there are no available items in the user profile o add a message to the request indicating that to the user. (Sorry, you do not have any available items for swapping. Please add more items to start swapping again!) o dispatch back to the individual item JSP view displaying the message and the item. If there are available items in the user profile o add the available items to the request and dispatch to the swap item view (swap.jsp) If the action is signout Clear the session and dispatch to the categories/catalog JSP view. Update the Catalog controller Update the catalog controller to display items that do not belong to the active user. Check the session for a current user, using the attribute theUser o if there is no user attribute use the requirements from the previous assignment starting with loading the complete catalog and ending with either displaying the complete catalog or an individual item view. o if there is a user attribute and it is valid load a catalog that doesnt include any of the active users items. Hint: add a function/method to the database utility classes that can filter the catalog based on a userUpdate JSP Views to Include Dynamic Content from Bean Data Each of the principal views for swapping an item (swap, myItems, mySwaps) will now receive some kind of dynamic data. Update the JSP views to replace any of the placeholder information with the dynamic data. Also, if the user has been added to the session as part of a sign in, we consider them to have logged into their account, and so all the page headers should now display the user name dynamically and the user navigation bar should display Sign Out rather that Sign In. Update Form / Button Actions and Links in the Site to Dispatch Correctly Each of the places in the site where a user can take an action that uses the dynamic data from this assignment should be updated to make the appropriate link or GET or POST request with the necessary parameters or form data. The following requirement is for 5166 students only Additional user specific functionality: Update the catalog controller to check if the session contains valid user identification data If a user data exists and the individual item view was requested from the catalog/categories view it should display user specific swap status information. o check the http request for a parameter called theItem o validate that its value matches your item code format and is a valid current item code. This tells you which item is to be displayed. o if the item validates and exists in the user profile add an attribute to the request under the name itemStatus and its value is the item swap status. dispatch to the item view. update the item to check whether a request attribute exists with the name itemStatus o if this attribute exists use the value as the condition for displaying item data.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started