Institute of Computer Science
  1. Courses
  2. 2021/22 spring
  3. Enterprise System Integration (MTAT.03.229)
ET
Log in

Enterprise System Integration 2021/22 spring

  • Home
  • Lectures
  • Practicals
  • Assignements
  • Project and exam
  • Message Board

Part 2: Building API

  1. Download the source code Attach:advera.zip
  2. Import it to IntelliJ IDEA
  3. Add your Postgres Database credentials in application.properties file
spring.datasource.url= jdbc:postgresql://localhost:5432/Your_Database
spring.datasource.username= Your_Postgres_Username
spring.datasource.password= Your_Password
  1. Run

Project Structure

src
└── main
    ├── java
    │   └── com
    │        └── advera.advera
    │           ├── AdveraApplication.java
    │           ├── controller
    │           │   └── AdvertisementController.java
    |           |   └── PublisherController.java
    │           ├── exception
    │           │   └── ResourceNotFoundException.java
    │           └── model
    │               ├── Advertisement.java
    │               └── Publisher.java
    │           └── repository
    │               ├── AdvertisementRepository.java
    │               └── PublisherRepository.java
    └── resources
        ├── application.properties
        ├── data-postgres.sql
        ├── static
        └── templates
            ├── showPublishers.ftl

Load Initial Data

  • You can create data-postgres.sql files in your src/main/resources folder to automatically load initial data when the application starts. In this file you can add some INSERT statements. In order to avoid inserting duplicate data, we should TRUNCATE command in the beginning of INSERT statements. TRUNCATE quickly removes all rows from a table or a set of tables. As we have a Many-To-Many relationship, then make sure you add all tables.
TRUNCATE publishers,advertisements,ads RESTART IDENTITY;
INSERT INTO publishers(name, publisher_address, publisher_contact) VALUES('Adsense','Mountain View, California, United States','info@adsense.com');
INSERT INTO publishers(name, publisher_address, publisher_contact) VALUES('Elanaat','Tartu mnt 4590','info@elanaat.com');

Using Freemaker template engine

The below diagram demonstrates the relationships between model, controller, and the Freemaker template. Follow this digram to make some small changes in your source code to generate text output (HTML web pages).

  • Add Freemaker dependency to build.gradle
    • implementation 'org.springframework.boot:spring-boot-starter-freemarker'
  • Add these two lines to application.properties file:
spring.freemarker.template-loader-path=classpath:/templates
spring.freemarker.suffix=.ftl
  1. Part 1: Initial Scenario
  2. Part 3: Testing API
  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment