Web AppUse case description: "transferring XML Event Tree representation with the Internet"This page is also available in Polish - go to 7. AimTransfer the tree with a web application and then store tree values in a database. Initial conditionsHave an Event Tree in XML format to use with the application. Final conditionsSuccessful tree transfer to a database. Process- Client application communicates with a REST server using POST method.
- Correct function is called which enables to switch to business logic layer. In this layer XML validation is conducted.
- New Data Model class object is being created.
- Proper Java Bean object is being used from business objects repository.
- Data Model object is being saved.
- In the next step, object saving status is being returned to REST server.
- Server returns appropriate status code to inform about operation success (200).
Alternative course- XML validation failed, business logic layer generates exception.
- REST service returns appropriate status code to inform about operation failure (400).
Diagrams Image Removed
Figure 1. Class diagram. Image Removed
Figure 2. Class diagram. Image Removed
Figure 3. Sequence diagram. Image Removed
Figure 4. Sequence diagram. Additional resourcesPolish prototype PDF for this pageThe 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:
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/ - 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. - 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: Image Added
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:
Image Added 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: Image Added
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.
|