Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. 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 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. 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 user. Update 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. The following view prototypes illustrate possible variations in the catalog individual item view This is an item the application identifies as an item the user already swapped. This is an item the application identifies as an item the active user has a swap offer for. The user can click See the offer to reply to the offer (mySwaps.jsp). c Bonus: This part is optional and you may earn up to 10 points. In this assignment one you have an opportunity to earn some extra bonus points by doing some research. As weve discussed before there are many approaches and technologies to web-based application development. Assignments 2 and 3 focus on the server side with the implementation done exclusively in Java Servlets and JSPs in the Java track and Node.js and Express in the JavaScript track. Doing some research, youll find other technologies/approaches that can be used to develop the server side end using the MVC design architecture. Choose one that interests you the most and provide a short description, some resources and examples of this technology, advantages/disadvantages specifically comparing it to the technology of the track youre in. Note: You must include a list of references and do not copy and paste from any reference. Tip: When you are implementing the logic for this assigment try to think of functionality encapsulation (aka, methods). If you start programming as you are going the description in this document you will end up with two huge methods (get, post). I recommend that you take an overall look at the description determine the common functionality (actions and validation) and separate that out. This will make the two main methods we are working (get, post) extermely modular and easier to manage (in other words, your debugging nightmares arent as frightening!). What to submit using Canvas (Email submissions will NOT be accepted): 1. HW3.zip - An archive of the entire web application (project) stored in a standard ZIP File, you must ensure that all the files are included as part of the archive. 2. HW3Info.pdf PDF document with the following assignment information: a. Screenshot of the applications home page displayed in your browser. b. Explanation of additional features, if any. c. Explanation of status, stopping point, and issues if incomplete. d. Discuss the easy and challenging parts of the assignment. How did you overcome all or some of the challenges? Note: Do not include the info PDF in the project folder ZIP file. You must submit them separately. 3. (optional) HW3Bonus.pdf PDF document for the bonus part of this assignment

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Progress Monitoring Data Tracking Organizer

Authors: Teacher'S Aid Publications

1st Edition

B0B7QCNRJ1

More Books

Students also viewed these Databases questions

Question

walmart mission and ceo

Answered: 1 week ago

Question

Does it use a maximum of two typefaces or fonts?

Answered: 1 week ago