Web AppThe web application is written using Spring Boot. The web app module consists of: - Main app class (SafetyWebApplication)
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). - Controllers:
The application has two types of controllers: rest controllers 2.1 Rest Controllers (annotated with @RestController) and normal controllers (annotated with @Controller). Rest controllers They are used to perform some actions (for example adding a false tree) and normal controllers . 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/ - Services:
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.Utils: For now there is only one class in utils pacage: TreeAnalyser. It analyse fault trees and event trees (it calls methods from MainApi class). It is not working yet. - Resources
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.html
Database connectionTo 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 Swagger DocumentationThe REST API documentation is available here: localhost:8080/swagger-ui.html It looks like that:
 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: 
DependenciesThe web app module uses following 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.html h2 - 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
For versions of this dependencies, go to pom.xml in safety-web module.
|