Department of Computing Science Umeå University

Assignment 2 - Data Validation and Storage

Due: 2007-08-14, 10:00

The assignment shall be solved individually.

The purpose of this assignment is to introduce the concept of data validation in JSP, and demonstrate XML Schema-based data validation.

In this assignment, you will create a web application for a small online shop. Data used in your shopping application will be stored in a database and accessed via JDBC. All data stored in the database shall be thoroughly validated (via custom routines in Java or via a XML Schema, the latter approach is recommended). Your solution shall also contain a session-based shopping cart, where users can store and remove products. The database schema and all SQL for the assignment will be provided, however the JDBC accessor class provided will have to be modified to be operational. A fully functional simulated database accessor will also be provided for development purposes.

You are free to choose the appearance and theme (what type of products and how they are presented) of your application, but a minimal functionality set required includes

  • a page which lists the products available, by category and by product (use of paging is recommended -- displaying hundreds or even thousands of items on a single page is not allowed)
  • a page which shows detailed information about products
  • an administration interface where you can add, update and delete products from the database (typically not available to customers)
  • a shopping cart page which shows the current content of your shopping cart (complete with an interface for adding and removing products)
  • a search page, where customer can search for products (based on product name and description)
If you are looking for ideas on how to structure your shopping site, take a look at Amazon.com or a similar shopping site.

Laboration environment

Download assignment2.jar and place it in your web applications library directory (5dv076/username/web/WEB-INF/lib).

This JAR-file contains a data access layer for a two-layer web application architecture. The system is provided in a Java package called assignment2 which contains the following classes:

assignment2.Id                                 <- a UUID wrapper class
assignment2.Product                            <- a product representation
assignment2.ProductAccessor                    <- an accessor interface for the products database
assignment2.ProductAccessorSimulator           <- a simulated implementation of the accessor
assignment2.ProductAccessorSimulator.Factory   <- a factory class for the simulator
assignment2.ProductAccessorTester                 <- a test class for accessor interfaces

The products in this system contains six data fields: id, name, description, arrivalDate, nrInStock and category. The Product class contains get methods for each of them.

The accessor interface contains methods for querying the system for number of products, retrieving a range of products (by product and by category), retrieving a specified product, inserting and updating products and searching for products (based on product name and description). The tester class is a utility which can be used to detect erroneous behavior in an implementation of the accessor interface automatically. It tests all of the accessor interface methods (except the getProducts() methods) by performing a series of operations and comparing the results to the expected results. Use of this class for testing is highly recommended when developing the JDBC accessor.

Not included in the JAR, the JDBC data accessor class you are to implement is named DerbyProductAccessor:

assignment2.DerbyProductAccessor               <- JDBC accessor class
assignment2.DerbyProductAccessor.Factory       <- factory class for the JDBC accessor
Note that this accessor is placed in the same package as the JAR-file classes.
A partial implementation of this accessor is provided in the file DerbyProductAccessor.java which is to be downloaded and placed in the web application source directory (5dv076/username/src/assignment2). The methods you need to implement yourself is getProduct(), insertProduct(), updateProduct() and deleteProduct(). Each of these methods have been marked with a // TODO: comment in the partial implementation.
Hint: When implementing these methods it may be beneficial to look at the implementation of other methods (such as getProducts()) also found in the same file.

You are allowed to start from scratch and develop your own accessor class if you prefer to do so, but all implementations must implement the ProductAccessor interface in order to get a passing grade on the assignment.
If you feel like experimenting with the Derby database, the DerbyProductAccessor class provides some useful test methods towards the end of the file...

Installing the database: The DerbyProductAccessor class contains a static block (located in the Factory class) which attempts to automatically install the database the first time you use the class. This block also populates the database with 1000 test products for you. The data contained in the Derby database is located in a directory called 5dv076/username/db_5dv076.
If you wish to purge the database from test data you can uncomment the call to fillWithTestProducts() in the static block and remove this directory. The next time you restart Tomcat (run the update script) a fresh copy of the database will be reinstalled without the test data. If you are having trouble removing the database, try restarting Tomcat before removing the database directory as well (as Tomcat sometimes locks the database files).
Note that this automatic installation of test data makes use of your insertProduct() method, so you need to implement that before being the database can be populated. The database will still be created, but no data will be inserted into it.
Also due to the automatic installation of the database, your first call to a method in the DerbyProductAccessor class may be quite lengthy (up to 30 seconds on a modern computer).

Using the system: To use the system you simply instantiate an accessor:

  ProductAccessor accessor = ProductAccessorSimulator.Factory.getInstance();
or
  ProductAccessor accessor = DerbyProductAccessor.Factory.getInstance();
and retrieve, store or search for the data you are interested in:
  int nrProducts = accessor.getNrProducts();
  Product[] products = accessor.getProducts(offset,limit);
  int nrProductsByCategory = accessor.getNrProducts();
  Product[] productsByCategory =
    accessor.getProductsByCategory(category,offset,limit);
  Product product = accessor.getProduct(id);
  accessor.insertProduct(product);
  accessor.updateProduct(product);
  Product[] productsByName =
    accessor.searchProductsByName(name,offset,limit);
  Product[] productsByDescription =
    accessor.searchProductsByDescription(description,offset,limit);
  ProductAccessorTester.testAccessor(accessor);
Note that the search methods accept partial string matches, while the getProductsByCategory() method requires an exact category string match. E.g., you can find all products with names that contain the string "product" by performing a search on the substring "prod".

See the environment page for details on installing and using the laboration environment.

Examination

Place a WAR-file containing your solution in

~/edu/5dv076/assignment2/

and email the teachers when you have completed the assignment. Do not send the file directly via email to the teachers.

Due date

2007-08-14, 10:00

http://www.cs.umu.se/kurser/5DV076/SOM-07/assignments/2/index.html
Ansvarig för sidan: P-O Östberg
Senast ändrad 2007-08-07