{"id":18809495,"url":"https://github.com/resourcepool/training-java","last_synced_at":"2025-10-24T21:37:35.363Z","repository":{"id":25575067,"uuid":"29008840","full_name":"resourcepool/training-java","owner":"resourcepool","description":"A 2-month fulltime java training around an incremental project. Java / JSP / Servlet / Maven / JUnit / Mockito / Selenium / Spring / Hibernate / JPA / Hikari CP / Jackson / Spring MVC / Spring Security / Gatling","archived":false,"fork":false,"pushed_at":"2017-11-28T09:38:19.000Z","size":5326,"stargazers_count":37,"open_issues_count":0,"forks_count":75,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-05-28T15:23:00.724Z","etag":null,"topics":["docker-container","java","spring-mvc","spring-security","training"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/resourcepool.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-09T08:59:14.000Z","updated_at":"2022-12-10T03:39:32.000Z","dependencies_parsed_at":"2022-08-02T10:42:05.348Z","dependency_job_id":null,"html_url":"https://github.com/resourcepool/training-java","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resourcepool%2Ftraining-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resourcepool%2Ftraining-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resourcepool%2Ftraining-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resourcepool%2Ftraining-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/resourcepool","download_url":"https://codeload.github.com/resourcepool/training-java/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223602609,"owners_count":17171952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker-container","java","spring-mvc","spring-security","training"],"created_at":"2024-11-07T23:16:33.890Z","updated_at":"2025-10-24T21:37:30.310Z","avatar_url":"https://github.com/resourcepool.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"Training: computer-database    \n===========================  \n\n# Content\nThis training material holds a sequence of steps and features to implement in a Computer Database webapp.  \nHere is the macro-planning and timeline of all milestones:  \n * t0    - Start of the project\n * t0+2  - Base Architecture, CLI (Add / Edit features), Logging\n * t0+8  - Web UI, Maven, Unit Tests, jQuery Validation, Backend Validation\n * t0+11 - Search, OrderBy, Transactions, Connection-Pool\n * t0+14 - Threadlocal, Java Performance contest\n * t0+19 - Continuous delivery (Jenkins, Docker, Dockerhub, Glazer)\n * t0+21 - Spring integration\n * t0+24 - Spring MVC integration, JDBC Template, i18n\n * t0+30 - Maven Multi-modules, Spring Security, Hibernate ORM (JPA, Criteria, QueryDSL, Spring Data JPA)\n * t0+32 - Web Services, end of java project\n * t0+37 - End of angular.js project\n * t0+38 - Project presentation to sales \u0026 tech audience\n\n# Installation\n\n##1. Database\nCreate a local **MySQL** server.  \nExecute scripts **1-SCHEMA.sql**, **2-PRIVILEGES.sql** and **3-ENTRIES.sql** in config/db.  \nSchema created: **computer-database-db**\nTables created: **company, computer**  \nUser created: `admincdb`\nwith password: `qwerty1234`\n\n### Bonus\nIf you already know about [Docker](https://docker.io):  \nCreate a **Dockerfile** and wrap your mysql server instance inside a docker image.\nCreate a container, and create a run script to load the database each time it runs (or use tmpfs).  \nUse the container instead of the local MySQL server instance.\n\n`\nNOTE: Docker containers are very useful when it comes to bootstrapping your development environment.\nWe entered the era of micro-services,\nwhich means it is not uncommon to have multiple containers running at the same time\nnecessary to run your module.\n`\n\n\n## 2. IDE  \n### 2.1. Eclipse  \n- Add your project to the current workspace: **File** -\u003e **Import** -\u003e **Existing projects into workspace**    \n- Create a new Tomcat 8.0 Server: Follow steps **[HERE](http://www.eclipse.org/webtools/jst/components/ws/M4/tutorials/InstallTomcat.html)**\n- In your project properties, select **Project facets**, convert your project to faceted form, and tick **Dynamic Web Module** (3.0) and **Java** (1.8)\n- Select **Runtime** tab (in the previous **project facets** menu)  and check the Tomcat 8.0 Server created above as your project runtime  \n\n### 2.2. IntelliJ IDEA   \n- Add your project to the current workspace: **Import Project**, select **Create project from existing sources**\n- Create a new Tomcat 8.0 Server: **Run** -\u003e **Edit Configurations** and point it to your local Tomcat directory (button **Configure...**)\n- Set project structure: In **File** -\u003e **Project Structure**, add an Artifact with default options (Artifact tab)  \n\n## 3. Git repository\n- Create your own github account, and initialize a new git repository called \"training-java\".  \n- After the initial commit, add and commit a meaningful .gitignore file.\n\nYou are ready to start coding.\n\n## 4. Start coding\n#### 4.1. Layout\nYour customer requested to build a computer database application. He owns about 500+ computers made by different manufacturers (companies such as Apple, Acer, Asus...).  \nIdeally, each computer would contain the following: a name, the date when it was introduced, eventually the date when it was discontinued, and the manufacturer.\nObviously, 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.\nFurthermore, the date it was discontinued must be greater than the one he was introduced.\nThe 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.  \nThe list of companies should be exhaustive, and therefore will not require any update, deletion etc...  \n\n### 4.2. Command line interface client\nThe first iteration will be dedicated to implement a first working version of your computer database, with a Command-Line Interface.  \nThe CLI will have the following features:\n\n- List computers  \n- List companies  \n- Show computer details (the detailed information of only one computer)  \n- Create a computer  \n- Update a computer  \n- Delete a computer  \n\n#### 4.2.1. Start\nYou will organize your project among several packages, such as model, persistence, service, ui, mapper...  \nPlease use Singleton patterns where it makes sense, and implement your own Persistence management layer (for connections).\n\n#### 4.2.2. Pages\nNow 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.  \n\n#### 4.2.3. Code review, logging (t0 + 2 days)\nImportant Points: Architecture (daos, mappers, services, models, exceptions etc...)? Singleton, IOC patterns? Validation (dirty checking?)? Date API? Secure inputs?  \nJavadoc? Comments? Use Slf4j-api logging library, with the most common implementation: logback.  \n\n### 4.3. CLI + Web interface client\nNow that your backend skeleton is working, we want to add a second more user-friendly UI, such as a Web-UI.  \nAs it will require more and more libraries (more JARs to include in the build path etc...), we should consider using a build manager.\nMoreover, testing is a very important aspect of QA, and testing libraries should be implemented before going any further, the same for logging.  \nThen, you can work on implementing all features on the provided static pages, using JSTL, Tags, Servlets, JSPs...  \n\n#### 4.3.1. Maven, Logging \u0026 Unit testing\nRefactor your project tree to match maven standards. (Tip: you should exit eclipse, move folders around, and reimport your project using File -\u003e Import -\u003e Existing maven projects).  \nInclude necessary libraries such as mysql-connector, JUnit, Mockito, Slf4j, and create the test classes for the backend you have already developed\n(N.B.: This is against TDD best practices. You should always code your tests simulteanously while developing your features).  \nCreating test classes implies to take into account ALL possibilities: Illegal calls, legal calls with invalid data, and legal calls with valid data.  \nAdd and configure the Maven checktyle plugin with the checkstyle.xml and suppressions.xml provided in config/checkstyle/\n\n`\nNOTE: You don't need to test your Persistence layer. However, you will have to think about your SQL Database and how your database gets reset for each test.\nYou may want to mock some of it using Mockito, and have sql-scripts populated before each test.\n`\n\n#### 4.3.2. Implement listing and computer add features in the web-ui\nUsing the provided template https://github.com/resourcepool/training-java/tree/master/static, integrate the previous features using Servlets, JSPs, JSTL, and Tags.  \nUse DTOs (Data Transfer Object) to transport only relevant data to the JSPs.  \nImplement Computer listing (paginated), and add features.  \nCreate two tags (In your own Taglib): one for the pagination module, one for links.  \nExample:\n```\n\u003cmylib:link target=\"dashboard\" page=\"${requestScope.page.current + 1}\" limit=\"${requestScope.page.limit}\" ... /\u003e   \n\u003cmylib:pagination page=\"${requestScope.page.current}\" page-count=\"${requestScope.page.count}\" ... /\u003e  \n```\nWarning: All features will be implemented and tested using Selenium automated with maven.  \n\n#### Bonus\nIf you already know about Docker:\nUse Docker to launch two selenium environments (firefox \u0026 chrome) and integrate it within your maven test\n\n#### 4.3.3. Secure through validation\nImplement both frontend (jQuery) and backend validation in the web-ui.\n\n#### 4.3.4. Code review (t0 + 8 days)\nImportant Points: Maven structure? Library scopes? Architecture (daos, mappers, services, models, dtos, controllers, exceptions, validators)? Validation? Unit test coverage? What about selenium integration into maven?  JSTL Tags and HTML documents structure.  \nPrepare a point about Threading (Connections, concurrency), and Transactions.\n\n#### 4.3.5. Connection pool, Transactions\nAdd a connection pool (HikariCP), put your credentials in an external properties file.  \nImplement a solid transaction handling model.  \n\n#### 4.3.6. Implement all other features in the web-ui\nImplement Computer edit, delete, total count features.  \nWarning: All features will be implemented and tested using Selenium automated with maven  \n\n#### 4.3.7. Implement search and order by features\nSearch box can look for either computer or company objects.\n\n#### 4.3.8. Add Company deletion feature in cli\nIn the command line interface, add a feature which deletes a company, and all computers related to this company. Warning: Using SQL CASCADE is forbidden. This implies the use of a transaction.  \n\n#### 4.3.9. Code review (t0 + 11 days)\nImportant Points: Maven structure? Library scopes? Architecture (daos, mappers, services, models, dtos, controllers, exceptions, validators)? Validation? Unit test coverage? Search and order by design choices? JSTL Tags and HTML documents structure.  \nPoint about Threading (Connections, concurrency), and Transactions.\n\n#### 4.3.10. Threadlocal\nReplace existing connection logic with a ThreadLocal object.\n\n#### 4.3.11. Performance Tuning Challenge\nNow is the time to start evaluating your global application performance with a stress-test campain.  \nHow does my application behave under load?  \nWhat is the memory footprint of my app?  \nUsing Gatling, you have two days to perform **ANY** kind of improvement of your web application (gatling test and directions present in the folder gatling-test).\nThe goal is to reach the highest score, see the relevant gatling-test/README file for more explanations.  \nFor now, choose the simulation **without** Spring Security.\n\n#### 4.3.12. Code review (t0 + 14 days)\nImportant Points: What were the bottlenecks, what optimizations were done, for how much performance gain, which scores were reached.\n\n### 4.4 Continuous Integration / Continuous Delivery\nWe want to setup a continuous integration system for our webapp with [Jenkins](https://jenkins-ci.org/) and [Docker](https://www.docker.com).  \nEach time we push on master we want Jenkins to retrieve the changes, compile, test on a specific environment, build and push the new image to a registry, then automatically deploy the new image on a Cloud.\n\nFor now the use of [docker-compose](https://docs.docker.com/compose/) is discouraged.\n\n#### 4.4.1 Jenkins \u0026 Docker\nHere we are going to create a **build** environment for your application. To do that we need to create two Docker images:\n- A builder for your webapp containing a jdk8 + maven. The goal of this container is just to compile test and package your application.\n- A database containing a MySQL feeded with your test entries.\n\nDuring the test phase, the webapp builder needs to communicate with the MySQL database in order to perform its integration tests. Find a way to enable communication between containers.\n\nInstall and configure a Jenkins on your host. Create a job that starts the build process each time a push on master is performed, then display the JUnits results. Don't use Docker-in-Docker.\n\n#### 4.4.2 Continuous Delivery\nNow it's time to dockerize your application.\n- Create a Docker image with a **run** environment for your webapp containing a Tomcat and your webapp war. Find a way to retrieve the war previously built by the webapp builder container.\n- Create an image for your MySQL database with your **production** data (schema/user/entries).\n\nPush them to [Docker Hub](https://hub.docker.com).\n\nAdapt your Jenkins job to build and push to Docker Hub those two images.\n\n#### 4.4.3 Continuous Deployment\n- Connect with your login to [Docker Cloud](https://cloud.docker.com/)\n\n- Create a [free account](https://aws.amazon.com/fr/free/) on Amazon Web Services.\n\n- [Link](https://docs.docker.com/docker-cloud/getting-started/link-aws/) your Amazon Web Services account to deploy node clusters and nodes using Docker Cloud’s dashboard. Be careful when choosing the type of node on Docker Cloud, select 't2.micro' under the conditions of free AWS account.\n\n- Observe the diagram below to properly configure the architecture of Docker containers to set up the continuous delivery:\n![image](https://s7.postimg.org/qoqib8ktn/Continuous_delivery.png)\n\n- Below the activity diagram to figure out all the process:\n![image](http://s32.postimg.org/ijyeykoyd/CDProcess_Diagram.png)\n\n#### Bonus: Pipeline\nSince Jenkins 1.6, a new configuration for your delivery pipeline appeared. The \"plugin-workflow\", later renamed \"pipeline\" in Jenkins 2.0, allows anyone to script your deployment pipeline from build to test, archive, and deploy.  \n\u003cimg src=\"https://wiki.jenkins-ci.org/download/attachments/102662163/who-broke-it.png?version=1\u0026modificationDate=1478695629000\" width=\"320\" height=\"240\"/\u003e  \nYou can use a JenkinsFile with your groovy pipeline script at the root of your repository.  \nWant to go further? Try Blue Ocean, the new UI for Jenkins.\n\n#### Bonus 2: Travis-CI / Gitlab-CI\nTry something else than Jenkins. Contrarily to Jenkins, Travis and Gitlab-CI were built with the concept of 'containers' in mind. In particular, Gitlab-CI has a dedicated Docker registry tied with your repositories.\nIntegrate them in your own Continuous delivery pipeline.\n\n#### 4.4.4. Point overview: Continuous Integration (t0 + 19 days)\nWhat is a container ? What is it used for ?  \nWhat is a Docker image ?  \nWhat about communication between Containers ?   \nDockerHub: automated build limitations ?  \n\n### 4.5. Embracing Spring Framework\n\n#### 4.5.1. Spring\nEnable the use of Spring to manage your objects's lifecycle, and transactions. You will use the XML declaration (applicationContext.xml) instead of programmative Java Configuration.  \nImportant: Be careful to use slf4j bridges to display spring logs. Do not forget to setup your logback configuration.  \nReplace your connection pool by a real datasource configured in the spring context.  \nWhich problems did you encounter? Study and note all the possible ways of solving the dependency injection issue in servlets.  \nWarning: Do not replace your Servlets by another class. Your controllers should still extend HttpServlet.\n\n#### 4.5.2. Point overview: Spring integration (t0 + 21 days)\nHow a webapp is started, how spring initializes itself.  \nExplanation of the common problems encountered with the different contexts.  \nRoundtable of the solutions found, best practices.\n\n#### 4.5.3. JDBCTemplate\nChange your DAO Implementation and use the JDBCTemplate from spring-jdbc to make your requests\n\n#### 4.5.4. Spring MVC\nYou can now forget about Servlets and use Spring MVC as Controller for your webapp.  \nUse Spring MVC validation annotations to validate your DTOs.  \nAdd custom error pages.  \n\n#### 4.5.5. i18n\nImplement spring multilingual features (French/English).\n\n#### 4.5.6. Code Review (t0 + 24 days)\nImportant Points: How did you split your Spring / Spring MVC contexts? How to switch from a language to another? How about javascript translation? Did you use spring-mvc annotations, forms and models?\n\n### 4.6. Multi module, ORM, and Security\n\n#### 4.6.1. Hibernate\nAdd 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.\n\n#### 4.6.2. Maven multi-module\nNow that your app is getting dense, it makes sense to split it into modules.  \nSplit your maven app into 6 different modules (we recommend exiting your IDE and making those changes by hand).  \nWarning: you need to also split your applicationContext files: indeed, each module should be able to work as a standalone.  \nFollowing modules can be created: core, persistence, service, binding, webapp, console.\n\n#### 4.6.3. Security\nAdd 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.  \nUse Digest HTTP Auth.\n\n#### 4.6.4. Code Review (t0 + 30 days)\nImportant points: Which API was the most efficient for your queries? Limitations of those APIs.\nMaven and Spring contexts evaluation, unit tests evaluation.\n\n### 4.7. Web Services, REST API\n\n#### 4.7.1. Jackson\nNow, we want your webapp to also produce APIs so that clients could access the resources remotely.  \nTo allow the creation of AngularJS, Mobile (Android/iOS) or third party clients, you should expose all features using Jackson and Spring RestController.\n\n#### 4.7.2. Jax WS / Jax RS\nRefactor your CLI client to act as a remote client to your webapp, using either Jax-RS or Jax-WS libraries.\n\n#### BONUS: Performance review with Gatling\nNow that you have enabled Spring Security, you can use the second Gatling Simulation with Spring Security. See the README present in the gatling-test folder for more details.\n\n#### 4.7.4. Final Code Review (t0 + 32 days)\nSteps to fix before final release, code quality overview and possible improvements. Point about UX\n\n### 4.8. Final refactoring of webapp, UX (t0 + 33 days)\nThe final stage is your production release.\n- Refactor and clean your project, make sure your REST API is valid.\n- Refactor your UI looking for a greater User eXperience, challenge the technical choices of the base page template, and customize it to your standards.\n\n### 4.9. Static Website with Angular.js\nMore and more, webapps need to be developed for multiple devices. Smartphones, tablets, browsers, etc...\nThe need for exposing data through an API has increased and allowed for the rebirth of client-server approaches.\nThanks to the most recent javascript engine performance improvements, developing client-side applications is not possible.\n\nDuring this step, you will learn how to develop the computer-database static website with Angular.js\n(training-angularjs)[https://github.com/resourcepool/training-angularjs]\n\n**N.B.: This is when you need to think like a user, and not a developer. Look at what your favorite websites have. Take a look at design best practices, and be careful to facilitate the use of your product.**\n\n### End of refactoring + UX (t0 + 38 days)\n\n### 4.10. Final Presentation (t0 + 39 days)\nThe presentation will be made with the whole group, on one project of their choice.  \nIt consists of 3 parts:  \nThe product-presentation, from a user-centered perspective (non-technical).\nYou are presenting your \"Computer database\" product, and telling us what it does and how it was made.  \nA live-demonstration. Be careful, the audience may interrupt your demo and ask you to try / show something else.  \nA technical review: you will reassure your client on what he paid for. Give him the necessary technical data and metrics which will allow him to think \"they are competent and they did the job, and I am confident that it is maintainable and well coded\".\n\n**Warning**: this presentation is not a restitution of what you have done. It is a **simulation** of the presentation of a project you would deliver to your customer.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fresourcepool%2Ftraining-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fresourcepool%2Ftraining-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fresourcepool%2Ftraining-java/lists"}