Presentation is loading. Please wait.

Presentation is loading. Please wait.

By: Rick Varella, Cuong Nguyen, & Henry Giathi. What is Books Zen Books? Books Zen Books is an e-commerce web application designed to allow students to.

Similar presentations


Presentation on theme: "By: Rick Varella, Cuong Nguyen, & Henry Giathi. What is Books Zen Books? Books Zen Books is an e-commerce web application designed to allow students to."— Presentation transcript:

1 By: Rick Varella, Cuong Nguyen, & Henry Giathi

2 What is Books Zen Books? Books Zen Books is an e-commerce web application designed to allow students to buy and sell their textbooks to other local students.

3 Purpose Why sell your books to the campus bookstore and get much less money for them? Why buy them for a premium price at the bookstore? Why pay for shipping at an online store? Have books that the bookstore won’t buy? Books Zen Books solves all of that.

4 Features Login system giving access to certain member- only features to registered users. Advanced search options for finding books by title, author, ISBN, subject and others. Users have full control over their listing info. Shopping cart for saving listings of interest. Checkout through Google Checkout or PayPal.

5 Features Caching system for frequently accessed data. Admin interface for managing all aspects of the system, including users, books, and settings.

6 Class Diagram

7 Usage Scenario #1: Login Present use case while logging in to the system.

8 Usage Scenario #1: Login

9 public User checkCredentials( HttpServletRequest request ) { ResultSet result; User user = null; String email = RequestHelper.getString( "email", request ); String password = RequestHelper.getString( "password", request ); String where = "email = '" + email + "' AND password = '" + DigestHelper.md5( password ) + "'"; /* Query for matching user */ result = bzb.getDriver().select( "user", null, where ); try { /* Make sure there's a result */ if( result.next() ) { user = new User(); user.init( bzb.getDriver() ); user.populate( result ); } } catch( SQLException e ) { } return user; }

10 Usage Scenario 2: Add New Listing Present use case while logging in to the system.

11 Usage Scenario 2: Add New Listing

12

13 private void saveListing( BookListing listing, HttpServletRequest request ) { listing.init( bzb.getDriver() ); listing.setActive( true ); listing.setComment( RequestHelper.getString( "comment", request ) ); listing.setCondition( RequestHelper.getString( "condition", request ) ); listing.setCurrency( "usd" ); //@TODO currency should be a system setting listing.setIsbn( listing.getBook().getIsbn() ); listing.setListDate( new java.util.Date() ); listing.setPrice( RequestHelper.getDouble( "price", request ) ); listing.setUserId( ( ( User ) request.getSession().getAttribute( "authUser" ) ).getUserId() ); listing.getBook().setAuthor( listing.getBook().getAuthor().replaceAll( "\n", "|" ).trim() ); listing.save(); if( listing.getBook().isNewObject() ) { listing.getBook().save(); }

14 Usage Scenario 3: Add Listing to Cart Present use case while logging in to the system.

15 Usage Scenario 3: Add Listing to Cart

16 result.close(); fields = new String[] { "COUNT(*) as count" }; result = bzb.getDriver().select( "shoppingcartentry", fields, where ); result.next(); if( result.getInt( "count" ) > 0 ) { isValid = false; } return isValid; } private boolean isValidListing( HttpServletRequest request ) { BookListing listing; boolean isValid = true; String[] fields = { "*" }; String where = "listId = " + RequestHelper.getInt( "listId", request ); ResultSet result = bzb.getDriver().select( "booklisting", fields, where ); if( result.next() ) { listing = new BookListing(); listing.init( bzb.getDriver() ); listing.populate( result ); if( !listing.isActive() ) { isValid = false; } else if( listing.getUserId() == bzb.getAuthenticatedUser( request ).getUserId() ) { isValid = false; } else { isValid = false; }

17 Third Party Tools dom4j - http://dom4j.sourceforge.net/http://dom4j.sourceforge.net/ Dom4j is an open source library for working with XML and XSLT files. We used it for reading our database configuration settings file. This makes it easier to update database details without editing source code. Also used it for generating and reading our XML schema files for our database mapping class. This made it possible to pass a single ResultSet from the DB to an object, and the object would be populated with the result data.

18 A Sample XML Schema File

19 How dom4j Reads XML Data private SchemaColumn readSchemaColumn( Element container ) { int columnId = 0; int dbType = 0; String javaType = null; String columnName = null; String index = null; Iterator attrIterator = container.attributeIterator(); Attribute attribute; while( attrIterator.hasNext() ) { attribute = ( Attribute )attrIterator.next(); if( attribute.getName().equals( "dbType" ) ) { dbType = Integer.parseInt( attribute.getText() ); } else if( attribute.getName().equals( "name" ) ) { columnName = attribute.getText(); } else if( attribute.getName().equals( "javaType" ) ) { javaType = attribute.getText(); } else if( attribute.getName().equals( "index" ) ) { index = attribute.getText(); } return new SchemaColumn( columnId, columnName, dbType, javaType, index ); } public SchemaData getSchema( String className, Field[] fields ) { … SAXReader reader = new SAXReader(); Document document = reader.read( file ); xmlRoot = xmlDocument.getRootElement(); columnIterator = xmlRoot.elementIterator(); while( columnIterator.hasNext() ) { columnRoot = columnIterator.next(); column = readSchemaColumn( columnRoot ); columns.put( column.getName(), column ); } … }

20 Using the Table/Class Mapping ResultSet result = bzb.getDriver().select( "shoppingcartentry e", fields, where, join, null, null, null, 0, 0 ); entry = new ShoppingCartEntry(); entry.init( bzb.getDriver() ); entry.populate( result ); public boolean populate( ResultSet row ) throws SQLException { … for( int i = 1; i <= columnCount; i++ ) { columnName = rsMetaData.getColumnName( i ); if( schema.getColumns().containsKey( columnName ) ) { setField( columnName, row ); } private boolean setField( String key, ResultSet row ) { SchemaColumn column = schema.getColumns().get( key ); … if( javaType.equals( "class java.lang.String" ) ) { methodTypes[0] = java.lang.String.class; methodArgs[0] = row.getString( key ); } … methodName = "set" + Util.toUpperCaseFirst( key ); method = this.getClass().getMethod( methodName, methodTypes ); method.invoke( this, methodArgs ); }

21 Problems Encountered The NetBeans UML plugin ended up crashing NetBeans, resulting in our UML diagrams getting corrupted and unusable. Tried out other UML programs like StarUML, Umlet, and ArgoUML, settled on the trial version of Visual Paradigm.

22 Problems Encountered Mapping database columns to class members was troublesome. Getting existing data out of the database and filling the objects worked without an XML schema for the most part, since we could use the column datatype from the ResultSet. Creating new objects (ie. From user input) to insert into the DB was more difficult, since we didn’t have a ResultSet to refer to when building our queries. So for class datatypes that don’t map to the same column type (eg. Boolean  tinyint), we had issues.

23 Features That Were Not Implemented We didn’t implement checkout. We were planning to integrate with PayPal and Google Checkout. Administration interface. Ideally it would allow the manager to modify settings, update users and books, and change the content of strings that make up the system text. Email validation for new accounts. Because we need an SMTP server to test it out, we did not get it working.


Download ppt "By: Rick Varella, Cuong Nguyen, & Henry Giathi. What is Books Zen Books? Books Zen Books is an e-commerce web application designed to allow students to."

Similar presentations


Ads by Google