/
20. Web App

20. Web App

Web App

The web application is written using Spring Boot. The web app module consists of:

  1. 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).
  2. Controllers:
    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/
  3. 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.
  4. 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 connection

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

Swagger Documentation

The 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:

Dependencies

The 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.


Related content

11. REST endpoints
11. REST endpoints
More like this
99. Testing
99. Testing
More like this
01. System overview
01. System overview
More like this
99. Testing
99. Testing
More like this
Developer corner
Developer corner
More like this
02. Integration of Acquisition GUI
02. Integration of Acquisition GUI
More like this