Giter Site home page Giter Site logo

amadeoas / spring-customerproducts Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 2.16 MB

Implementation of a web app that allows customers to select products which are available to them, based on their home location.

License: Other

Shell 5.75% Batchfile 4.20% Java 80.58% JavaScript 2.29% CSS 7.18%

spring-customerproducts's Introduction

Spring Customer Products Application

By Amadeo Ascó, April 2016.

This is an implementation of a simple web app using Java and Spring that allows customers to select products which are available to them, based on their home location.

Licensed under the Apache License, Version 2.0, see more in the license file.

Running customerproducts locally

cd spring-customerproducts

./mvnw tomcat7:run

You can then access customerproducts here: http://localhost:9966/customerproducts/

If the web app is started from within eclipse then access customerproducts here: http://localhost:8080/customerproducts/

Note: The unit-tests for the JPA are implemented. Other implementations like JDBC and Sprint Data need to be completed for the full unit-tests to fully pass.

Running unit tests

To run all the unit-tests use:

./mvnw test

To run an specific unit-test used the format /mvnw -Dtest=TestClassName test, example:

./mvnw -Dtest=CustomerServiceJpaTests test

Note: the JPA and JDBC implementations have unit-tests implemented and tested.

How to use customerproducts

There are three views accessible directly through the web app menu, which it is located at the top right hand side. The views are:

  1. Home

  2. Customers

  3. Products

If an exception is thrown when processing a request by one of the controller then an internal error page is displayed on the browser.

All the pages have at the footer, left hand side, a list of the languages supported represented by the flags of the countries the language originate from. The first of this flags corresponds to the language displayed in the shown page and subsequent pages. The next flags to this one are the other language supported, any of which can be clicked to change the language.

Home view

The 'Home' view gives an introduction to the web app.

Customers view

The 'Customers' view lists all the customer details in the data base. The customer can be sorted by any of the shown columns by clicking on the corresponding header.

  • Subscriptions Selection View: Each customer's full name can be clicked, which will bring up the product selection view for the customer with the products the customer can be subscribed to, based on his/her location. This view allows selecting the desired products and submit them by clicking on the 'Checkout' button. When the 'Checkout' button is pressed the selections are sent to the web server where they are printed out on the system out, and if this operation is successful the success page is displayed.

  • Subscriptions View: The last columns (View) contains a link to each for each of the customers to see his/her subscriptions.

Products view

The 'Products' view lists all the products in the database. The products can be sorted by any of the shown columns by clicking on the corresponding header.

Overview

View: JSP with custom tags + bootstrap (CSS), Webjars and Dandelion.

Controller: Sprint and MVC annotations with bean validation.

Service: @Cacheable and @Transactional.

Repository: 3 profiles - Sprint Data JPA, default (JPA) and jdbc.


The Web Layer: Sprint MVC and third-party web libraries (Dandelion and Webjars).

Dandelion: datatables (based on JQuery datatables and Bootstrap) with functionality to sort and filter

Webjars: Allows CSS and JS libraries to be imported as Maven libraries (http://www.webjar.org/).

Flow Diagram

FD

Database

ERD

Database configuration

In its default configuration, Customerproducts uses an in-memory database (HSQLDB) which gets populated at startup with data. A similar setup is provided for MySql in case a persistent database configuration is needed. Note that whenever the database type is changed, the data-access.properties file needs to be updated and the mysql-connector-java artifact from the pom.xml needs to be uncommented.

You may start a MySql database with docker:

docker run -e MYSQL_ROOT_PASSWORD=customerproducts -e MYSQL_DATABASE=customerproducts -p 3306:3306 mysql:5.7.8

Working with Customerproducts in Eclipse/STS

Prerequisites

The following items should be installed in your system:

  • Maven 3

Note: when m2e is available, there is an m2 icon in Help -> About dialog. If m2e is not there, just follow the install process here.

Steps:

  1. In the command line copy project into your local storage

  2. Inside Eclipse File -> Import -> Maven -> Existing Maven project

Looking for something in particular?

Java ConfigComments
Java Config branch Customerproducts uses XML configuration by default. In case you'd like to use Java Config instead.
Inside the 'Web' layerFiles
Spring MVC - XML integration mvc-view-config.xml
Spring MVC - ContentNegotiatingViewResolver mvc-view-config.xml
JSP custom tags WEB-INF/tags
Bower Bower-install maven profile declaration inside pom.xml
JavaScript libraries are defined by the manifest file bower.json
Bower configuration using JSON
Resource mapping in Spring configuration
Dandelion-datatables customersList.jsp, productList.jsp, subscriptionsList.jsp, web.xml and datatables.properties

'Service' and 'Repository' layersFiles
Transactions business-config.xml, CatalogueServiceImpl.java, CustomerLocationServiceImpl.java and CustomerServiceImpl.java
Cache tools-config.xml, CatalogueServiceImpl.java, CustomerLocationServiceImpl.java and CustomerServiceImpl.java
Bean Profiles business-config.xml, CustomerServiceJdbcTests.java and web.xml
JdbcTemplate business-config.xml and jdbc folder
JPA business-config.xml and jpa folder
Spring Data JPA business-config.xml and springdatajpa folder

Others

The graphics were created using draw.io. They can be modified by uploading the XML files located under the docs directory from within draw.io.

TODO

  • Complete the unit-tests for the Sprint Data JPA implementation
  • The "Checkout" button should be at the bottom of the basket area, fixed. Also areas for each product should be possible to scroll if not all products or selections fit in the area..

spring-customerproducts's People

Contributors

amadeoas avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.