20. Web App
The web application is written using Spring Boot. The web app module consists of: To connect to database you need to run the application and go to this link: localhost:8080/h2-console. There you have to put properties from application.properties there: It has to look like that: Full JDBC URL: jdbc:h2:./test;DB_CLOSE_DELAY=- 1;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE User name: user Password: pass The REST API documentation is available here: localhost:8080/swagger-ui.html If you want to see, what request parameters you have to send or what is response for some request, just click on the path that is point of your interest and read everything. Here is an example: The web app module uses following dependencies: For versions of this dependencies, go to pom.xml in safety-web module.Web App
This application is basically the class that contains main method. It is used to run the application. The class is annotated with @SpringBootApplication annotation, which tells Spring that it is spring boot application. Spring does the basic configuration for our app, so we don't have to write web.xml, persistenceContext.xml or any other configuration files. The class also configures Swagger, which generates the Rest Api Documentation (after program starts it is available here: localhost:8080/swagger-ui.html).
2.1 Rest Controllers (annotated with @RestController). They are used to perform some actions (for example adding a false tree).
2.2 MVC Controllers (annotated with @Controller). They are used to return some view, that is more user-friendly than plain text.
Here you can read more about the differences between rest controllers and mvc controllers: https://www.genuitec.com/spring-frameworkrestcontroller-vs-controller/
Methods from services are called from controllers. For example if controller wants to add new fault tree to the database, it only calls the appropriate method form service and the core logic is placed in services. We don't put any logic in controllers. Services are the layer between controller and repository.
Here are HTML files for our views (in folder templates) and application.properties file. We use thymeleaf as a view template. Here is the documentation:
http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html
http://www.thymeleaf.org/doc/tutorials/3.0/thymeleafspring.htmlDatabase connection
Swagger Documentation
It looks like that:Dependencies
spring-boot-starter-data-jpa - includes Hibernate,
spring-boot-starter-thymeleaf - thymeleaf is a template engine for creating views on the server site,
spring-boot-starter-web - includes Spring MVC, the core dependency of this module,
spring-boot-devtools - nice developer tools, that helps to work more efficiently. Here you can read more:
https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.htmlh2 - includes h2 database,
spring-boot-starter-test - includes most popular testing frameworks (for example JUnit, Mockito, AssertJ),
springfox-swagger2 - includes swagger, that generates documentation,
springfox-swagger-ui - generates swagger gui,
safety-model
safety-eventstree
safety-faulttree
safety-api
safety-report