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.
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.
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.
There are three views accessible directly through the web app menu, which it is located at the top right hand side. The views are:
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.
The 'Home' view gives an introduction to the web app.
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.
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.
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/).
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
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.
-
In the command line
copy project into your local storage
-
Inside Eclipse
File -> Import -> Maven -> Existing Maven project
Java Config | Comments |
---|---|
Java Config branch | Customerproducts uses XML configuration by default. In case you'd like to use Java Config instead. |
Inside the 'Web' layer | Files |
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' layers | Files |
---|---|
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 |
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.
- 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..