Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 3 JSP, Servlet, and MVC - Managing Profile using Sessions This assignment is to be completed individually. No group work is allowed. This assignment

Assignment 3 JSP, Servlet, and MVC - Managing Profile using Sessions This assignment is to be completed individually. No group work is allowed.

This assignment is intended to familiarize you with using sessions to maintain state in your web application. For this assignment, you will continue working on your servlet/jsp-based application from assignment 2. The assignment builds upon and completes the previous assignments MVC architecture. Assignment Description: In this assignment, you will add new features to your previous JSP/Servlet MVC web application, according to the following specifications:

1. Correct any errors identified or partial/missing functionality from the previous assignment. If your application developed in assignment 2 has error and not complete it is your responsibility to communicate and coordinate with course staff to help fix those bugs. Keep in mind that you are building in this application in stages. It is important that you have a working application for each stage.

2. All structure, design, and content requirements from previous assignments are mandatory, unless explicitly updated in this assignment description.

3. Use JavaBeans to implement the business layer of the application (model).

4. Use JSP pages to present the view to the browser.

5. Use Servlet pages to control the flow of the application

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 UserSwap 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 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 identificationUser 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.

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 thestatus 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.

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!).

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

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago