Package business

Examples of business.BookListing


        doPost( request, response );
    }

    private ArrayList<BookListing> getUserListings( HttpServletRequest request ) {
        ArrayList<BookListing> listings = new ArrayList<BookListing>();
        BookListing listing;
        String[] fields = { "l.*", "b.*, u.*" };
        String where = "l.userId = " + bzb.getAuthenticatedUser( request ).getUserId();
        String[] join = { "INNER JOIN bzb.book b ON l.isbn=b.isbn",
                    "INNER JOIN bzb.user u ON l.userId=u.userId" };
        ResultSet result = bzb.getDriver().select( "booklisting l", fields, where, join, null, null, null, 0, 0 );

        try {
            while( result.next() ) {
                listing = new BookListing();
                listing.init( bzb.getDriver() );
                listing.populate( result );
                listings.add( listing );
            }
        } catch( SQLException e ) {

        }
View Full Code Here


        String forwardUrl;
        String pageTitle;
        int step = RequestHelper.getInt( "step", request );
        RequestDispatcher dispatcher;
        HashMap<String, String> formErrors = new HashMap<String, String>();
        BookListing listing = ( BookListing ) request.getSession().getAttribute( "userListing" );
        Book book;

        /* Load necessary lexicons */
        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "subject" );
        bzb.getLexicon().load( "book" );
        bzb.getLexicon().load( "listing" );

        pageTitle = bzb.getLexicon().get( "addListing" );

        /* Make sure user is logged in */
        if( bzb.getAuthenticatedUser( request ) == null ) {
            bzb.getLexicon().load( "error" );

            forwardUrl = jspPath + "401.jsp";
            pageTitle = bzb.getLexicon().get( "unauthorized" );
        }
        /* User has submitted the initial ISBN form */
        else if( step == 2 ) {
            /* Invalid ISBN */
            if( !isValidISBN( RequestHelper.getString( "isbn", request ) ) ) {
                forwardUrl = jspPath + "newListingStep1.jsp";

                formErrors.put( "isbn", bzb.getLexicon().get( "invalidField", new String[][]{ { "field", bzb.getLexicon().get( "isbn" ) } } ) );
            }
            else {
                forwardUrl = jspPath + "newListingStep2.jsp";

                request.setAttribute( "languages", getLanguages() );
                /* Add book data to request, if it exists in the DB */
                request.setAttribute( "book", getBook( RequestHelper.getString( "isbn", request ) ) );
            }
        }
        /* User has submitted the book form */
        else if( step == 3 ) {
            /* Existing book? */
            if( RequestHelper.getString( "newBook", request ).equals( "false" ) ) {
                /* Invalid ISBN */
                if( !isValidISBN( RequestHelper.getString( "isbn", request ) ) ) {
                    forwardUrl = jspPath + "newListingStep1.jsp";

                    formErrors.put( "isbn", bzb.getLexicon().get( "invalidField", new String[][]{ { "field", bzb.getLexicon().get( "isbn" ) } } ) );
                }
                else {
                    /* Check to see if book exists in the DB */
                    if( ( book = getBook( RequestHelper.getString( "isbn", request ) ) ) != null ) {
                        forwardUrl = jspPath + "newListingStep3.jsp";

                        /* Create empty listing object for later */
                        if( listing == null ) {
                            listing = new BookListing();
                        }

                        listing.setBook( book );

                        /* Put listing object in SESSION object */
                        request.getSession().setAttribute( "userListing", listing );
                        request.setAttribute( "conditions", getConditions() );
                    }
                    else {
                        forwardUrl = jspPath + "newListingStep1.jsp";

                        formErrors.put( "isbn", bzb.getLexicon().get( "invalidField", new String[][]{ { "field", bzb.getLexicon().get( "isbn" ) } } ) );
                    }
                }
            }
            /* New book being submitted */
            else {
                formErrors = checkBookForm( request);

                /* Has errors - display book form again */
                if( !formErrors.isEmpty() ) {
                    forwardUrl = jspPath + "newListingStep2.jsp";

                    request.setAttribute( "languages", getLanguages() );
                }
                /* No errors - display listing form */
                else {
                    forwardUrl = jspPath + "newListingStep3.jsp";

                    if( listing == null ) {
                        listing = new BookListing();
                    }

                    /* Add listing to SESSION */
                    listing.setBook( getBookFromInput( request ) );
                    request.getSession().setAttribute( "userListing", listing );
                    request.setAttribute( "conditions", getConditions() );
                }
            }
        }
View Full Code Here

        return listings;
    }

    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 );

        try {
            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;
View Full Code Here

        return where.toString();
    }

    private ArrayList<BookListing> getSearchResults( ArrayList<String> parameters ) {
        ResultSet result;
        BookListing listing;
        ArrayList<BookListing> listings = new ArrayList<BookListing>();
        String where = getWhereString( parameters );
        String[] fields = { "l.*", "b.*,u.*" };
        String[] join = { "INNER JOIN bzb.book b ON l.isbn=b.isbn",
                    "INNER JOIN bzb.user u ON l.userId=u.userId" };

        result = bzb.getDriver().select( "booklisting l", fields, where, join, null, null, null, 0, 0 );

        try {
            while( result.next() ) {
                listing = new BookListing();
                listing.init( bzb.getDriver() );
                listing.populate( result );
                listings.add( listing );
            }
        } catch( SQLException e ) {

        }
View Full Code Here

        String forwardUrl;
        String pageTitle;
        String action = RequestHelper.getString( "action", request );
        RequestDispatcher dispatcher;
        HashMap<String, String> formErrors;
        BookListing listing = getListing( RequestHelper.getInt( "listId", request ) );
        User authUser = bzb.getAuthenticatedUser( request );

        /* Load necessary lexicons */
        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "subject" );
        bzb.getLexicon().load( "book" );
        bzb.getLexicon().load( "listing" );

        if( listing == null ) {
            bzb.getLexicon().load( "error" );

            forwardUrl = jspPath + "404.jsp";
            pageTitle = bzb.getLexicon().get( "listingNotFound" );

            request.setAttribute( "customError", bzb.getLexicon().get( "listingNotFoundDesc" ) );
        }
        else if( authUser == null || authUser.getUserId() != listing.getUserId() ) {
            bzb.getLexicon().load( "error" );
            bzb.getLexicon().load( "register" );

            forwardUrl = jspPath + "401.jsp";
            pageTitle = bzb.getLexicon().get( "unauthorized" );

            request.setAttribute( "customError", bzb.getLexicon().get( "notUserListing" ) );
        }
        else if( action.equals( "save" ) ) {
            formErrors = checkListingForm( request );

            listing.setCondition( RequestHelper.getString( "condition", request ) );
            listing.setPrice( RequestHelper.getDouble( "price", request ) );
            listing.setComment( RequestHelper.getString( "comment", request ) );
            listing.setActive( RequestHelper.getBoolean( "active", request ) );

            if( !formErrors.isEmpty() ) {
                forwardUrl = jspPath + "editListingForm.jsp";
                pageTitle = bzb.getLexicon().get( "editListing" );
               
View Full Code Here

        return errors;
    }

    private BookListing getListing( int listId ) {
        BookListing listing = null;
        String[] fields = { "l.*", "b.*" };
        String where = "l.listId = " + listId;
        String[] join = { "INNER JOIN bzb.book b ON l.isbn = b.isbn" };
        ResultSet result;

        if( listId < 1 ) {
            return listing;
        }

        result = bzb.getDriver().select( "booklisting l", fields, where, join, null, null, null, 0, 1 );

        try {
            if( result.next() ) {
                listing = new BookListing();
                listing.init( bzb.getDriver() );
                listing.populate( result );
            }
        } catch( SQLException e ) {
           
        }

View Full Code Here

        return stats;
    }

    private ArrayList<BookListing> getUserListings( int userId ) {
        ArrayList<BookListing> listings = new ArrayList<BookListing>();
        BookListing listing;
        String where = "userId = " + userId;
        String[] fields = { "l.*", "b.*" };
        String[] join = { "INNER JOIN bzb.book b ON l.isbn=b.isbn" };
        String[] orderBy = { "l.listDate DESC" };
        ResultSet result = bzb.getDriver().select( "booklisting l", fields, where, join, null, null, orderBy, 0, 5 );

        try {
            while( result.next() ) {
                listing = new BookListing();
                listing.init( bzb.getDriver() );
                listing.populate( result );
                listings.add( listing );
            }
        } catch( SQLException e ) {

        }
View Full Code Here

    protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
        bzb = new BooksZenBooks( "en", dbConfigResource ); // @TODO language should be a request param
        String forwardUrl;
        RequestDispatcher dispatcher;
        int listId = RequestHelper.getInt( "listId", request );
        BookListing listing = getBookListing( listId );

        /* Load necessary lexicons */
        bzb.getLexicon().load( "global" );
        bzb.getLexicon().load( "book" );
        bzb.getLexicon().load( "listing" );
        bzb.getLexicon().load( "subject" );

        if( listing == null ) {
            request.setAttribute( "pageTitle", bzb.getLexicon().get( "listingNotFound" ) );
        }
        else {
            request.setAttribute( "pageTitle", bzb.getLexicon().get( "showingListing" ) + ": " + listing.getBook().getTitle() );
        }

        forwardUrl = jspPath + "bookListing.jsp";

        /* Make lexicons and config settings available to JSP */
 
View Full Code Here

    protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
        doPost( request, response );
    }

    private BookListing getBookListing( int listId ) {
        BookListing listing = null;
        String where = "listId = " + listId;
        String[] fields = { "b.*, l.listId, l.price, l.comment, l.listDate, l.active, l.condition, l.currency, u.*" };
        String[] join = { "INNER JOIN bzb.book b ON l.isbn=b.isbn",
                    "INNER JOIN bzb.user u ON l.userId=u.userId" };
        ResultSet result = bzb.getDriver().select( "booklisting l", fields, where, join, null, null, null, 0, 1 );

        try {
            if( result.next() ) {
                listing = new BookListing();
                listing.init( bzb.getDriver() );
                listing.populate( result );
            }
        } catch( SQLException e ) {

        }

View Full Code Here

TOP

Related Classes of business.BookListing

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.