Question: 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
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.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 swapping If 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.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
