-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f764cd0
commit 98c5c5d
Showing
1 changed file
with
142 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,142 @@ | ||
# spec-cdb | ||
Training: computer-database | ||
=========================== | ||
|
||
#Installation | ||
|
||
##1. Database | ||
Create a local **MySQL** server. | ||
Execute scripts **1-SCHEMA.sql**, **2-PRIVILEGES.sql** and **3-ENTRIES.sql** in config/db. | ||
Schema created: **computer-database-db** | ||
Tables created: **company, computer** | ||
User created: `admincdb` | ||
with password: `qwerty1234` | ||
|
||
##2. IDE | ||
###2.1. Eclipse | ||
- Add your project to the current workspace: **File** -> **Import** -> **Existing projects into workspace** | ||
- Create a new Tomcat 8.0 Server: Follow steps **[HERE](http://www.eclipse.org/webtools/jst/components/ws/M4/tutorials/InstallTomcat.html)** | ||
- In your project properties, select **Project facets**, convert your project to faceted form, and tick **Dynamic Web Module** (3.0) and **Java** (1.8) | ||
- Select **Runtime** tab (in the previous **project facets** menu) and check the Tomcat 8.0 Server created above as your project runtime | ||
|
||
###2.2. IntelliJ IDEA | ||
- Add your project to the current workspace: **Import Project**, select **Create project from existing sources** | ||
- Create a new Tomcat 8.0 Server: **Run** -> **Edit Configurations** and point it to your local Tomcat directory (button **Configure...**) | ||
- Set project structure: In **File** -> **Project Structure**, add an Artifact with default options (Artifact tab) | ||
|
||
##3. Git repository | ||
- Create your own github account, and initialize a new git repository called "computer-database". | ||
- After the initial commit, add and commit a meaningful .gitignore file. | ||
|
||
You are ready to start coding. | ||
|
||
##4. Start coding | ||
####4.1. Layout | ||
Your customer requested to build a computer database application. He owns about 500+ computers made by different manufacturers (companies such as Apple, Acer, Asus...). | ||
Ideally, each computer would contain the following: a name, the date when it was introduced, eventually the date when it was discontinued, and the manufacturer. Obviously, for some reasons, the existing data is incomplete, and he requested that only the name should remain mandatory when adding a computer, the other fields being filled when possible. | ||
The list of computers can be modified, meaning your customer should be able to list, add, delete, and update computers. The list of computers should also be pageable. | ||
The list of companies should be exhaustive, and therefore will not require any update, deletion etc... | ||
|
||
###4.2. Command line interface client | ||
The first iteration will be dedicated to implement a first working version of your computer database, with a CLI-UI. | ||
The CLI will have the following features: | ||
|
||
- List computers | ||
- List companies | ||
- Show computer details (the detailed information of only one computer) | ||
- Create a computer | ||
- Update a computer | ||
- Delete a computer | ||
|
||
####4.2.1. Start | ||
You will organize your project among several packages, such as model, persistence, service, ui, mapper... | ||
Please use Singleton patterns where it makes sense, and implement your own Persistence management layer (for connections). | ||
|
||
####4.2.2. Pages | ||
Now that your app's main features work, implement the pageable feature. We recommend the use of a Page class, containing your entities and the page information. | ||
|
||
####4.2.3. Code review, logging | ||
Important Points: Architecture (daos, mappers, services, models, exceptions etc...)? Singleton, IOC patterns? Validation (dirty checking?)? Date API? Secure inputs? | ||
Javadoc? Comments? Use Slf4j-api logging library, with the most common implementation: logback. | ||
|
||
###4.3. CLI + Web interface client | ||
Now that your backend skeleton is working, we want to add a second more user-friendly UI, such as a Web-UI. | ||
As it will require more and more libraries (more JARs to include in the build path etc...), we should consider using a build manager. Moreover, testing is a very important aspect of QA, and testing libraries should be implemented before going any further, the same for logging. | ||
Then, you can work on implementing all features on the provided static pages, using JSTL, Tags, Servlets, JSPs... | ||
|
||
####4.3.1. Maven, Logging & Unit testing | ||
Refactor your project tree to match maven standards. (Tip: you should exit eclipse, move folders around, and reimport your project using File -> Import -> Existing maven projects). | ||
Include necessary libraries such as mysql-connector, JUnit, Mockito, Slf4j, and create the test classes for the backend you have already developed (Note: This is against TDD best practices. You should always code your tests simulteanously while developing your features). | ||
|
||
####4.3.2. Implement your features in the web-ui | ||
Using the provided template https://github.com/loicortola/computer-database/TODO:inserttemplate, integrate the previous features using Servlets, JSPs, JSTL, and Tags. | ||
Implement Computer listing (paginated), add, edit, delete, total count features. | ||
|
||
####4.3.3. Secure through validation | ||
Implement both frontend (jQuery) and backend validation in the web-ui. | ||
|
||
####4.3.4. Implement search and order by features | ||
Search box can look for either computer or company objects. | ||
|
||
####4.3.5. Add Company deletion feature in cli | ||
In the command line interface, add a feature which deletes a company, and all computers related to this company. Warning: Using SQL CASCADE is forbidden. | ||
|
||
####4.3.6. Code review | ||
Important Points: Architecture (daos, mappers, services, models, dtos, controllers, exceptions, validators)? Validation? Unit test coverage? Maven structure? Library scopes? Search and order by design choices? JSTL Tags and HTML documents structure. | ||
Point about Threading (Connections, concurrency), and Transactions. | ||
|
||
####4.3.7. Connection pool, Transactions | ||
Add a connection pool (BoneCP), put your credentials in an external properties file. | ||
Implement a solid transaction handling model. | ||
Replace existing connection logic with a ThreadLocal object. | ||
|
||
###4.4. Embracing Spring Framework | ||
|
||
####4.4.1. Spring | ||
Enable the use of Spring to manage your objects's lifecycle, and transactions. | ||
Replace your connection pool by a real datasource configured in the spring context. | ||
Warning: Do not replace your Servlets by another class. Your controllers should still extend HttpServlet | ||
|
||
####4.4.2. JDBCTemplate | ||
Change your DAO Implementation and use the JDBCTemplate from spring-jdbc to make your requests | ||
|
||
####4.4.3. Spring MVC | ||
You can now forget about Servlets and use Spring MVC as Controller for your webapp. | ||
Use Spring MVC validation annotations to validate your DTOs. | ||
Add custom error pages. | ||
|
||
####4.4.4. i18n | ||
Implement spring multilingual features (French/English). | ||
|
||
####4.4.5. Code Review | ||
Important Points: How to switch from a language to another? How about javascript translation? Did you use spring-mvc annotations, forms and models? | ||
|
||
###4.5. Multi module, ORM, and Security | ||
|
||
####4.5.1. Hibernate | ||
Add the Hibernate ORM to your project (managed by spring). You can choose the following APIs to implement it. HQL, JPA/Criteria, QueryDSL, Spring data JPA. | ||
|
||
####4.5.2. Maven multi-module | ||
Now that your app is getting dense, it makes sense to split it into modules. | ||
Split your maven app into 5 different modules (we recommend exiting your IDE and making those changes by hand). | ||
Warning: you need to also split your applicationContext files: indeed, each module should be able to work as a standalone. | ||
Following modules can be created: core, persistence, service, binding, webapp, console. | ||
|
||
####4.5.3. Security | ||
Add Spring Security to your project. Choose a stateless approach, and use an extra UserDAO and related SQL table to store and retrieve user login info. | ||
Use Digest HTTP Auth. | ||
|
||
####4.5.4. Code Review | ||
Important points: Which API was the most efficient for your queries? Limitations of those APIs. | ||
Maven and Spring contexts evaluation, unit tests evaluation. | ||
|
||
###4.6. Web Services, REST API | ||
|
||
####4.6.1. Jax WS / Jax RS | ||
Now, we want your webapp to also produce APIs so that clients could access the resources remotely. | ||
Refactor your CLI client to act as a remote client to your webapp, using either Jax-RS or Jax-WS libraries. | ||
|
||
####4.6.2. Jackson | ||
Finally, to allow the creation of AngularJS, Mobile (Android/iOS) or third party clients, you should expose the computer listing feature using Jackson and Spring RestController. | ||
|
||
####4.6.3. Final Code Review | ||
|