commit 45d0c4d790ed38e18c14cdd42af1521e99b070cf
Author: Jakub Smid <jaksmid@seznam.cz>
Date:   Thu Mar 10 20:11:55 2022 +0100

    Added entities
      - connected to Postgres database
      - created repositories and services for entities
      - created setup for given csv catalog data
    re #9191
    re #9099

diff --git a/backend/pom.xml b/backend/pom.xml
index 09008fa..0c6b808 100644
--- a/backend/pom.xml
+++ b/backend/pom.xml
@@ -14,7 +14,7 @@
     <name>backend-api</name>
     <description>Backend API for Neo-assyrian web application</description>
     <properties>
-        <java.version>17</java.version>
+        <java.version>11</java.version>
     </properties>
     <dependencies>
         <dependency>
@@ -32,6 +32,40 @@
             <artifactId>spring-boot-starter-test</artifactId>
             <scope>test</scope>
         </dependency>
+
+
+        <dependency>
+            <groupId>org.postgresql</groupId>
+            <artifactId>postgresql</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-validation</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-security</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.security</groupId>
+            <artifactId>spring-security-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-csv</artifactId>
+            <version>1.9.0</version>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/StubController.java b/backend/src/main/java/cz/zcu/kiv/backendapi/StubController.java
index 8c62ea9..eee0df6 100644
--- a/backend/src/main/java/cz/zcu/kiv/backendapi/StubController.java
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/StubController.java
@@ -13,8 +13,8 @@ public class StubController {
         LOGGER.info("StubController initialized!");
     }
 
-    @GetMapping("/stub")
-    public StubDto getStubDto() {
-        return new StubDto("Hello API", true);
-    }
+//    @GetMapping("/stub")
+//    public StubDto getStubDto() {
+//        return new StubDto("Hello API", true);
+//    }
 }
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/StubDto.java b/backend/src/main/java/cz/zcu/kiv/backendapi/StubDto.java
index 330a980..e37a47d 100644
--- a/backend/src/main/java/cz/zcu/kiv/backendapi/StubDto.java
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/StubDto.java
@@ -1,5 +1,5 @@
 package cz.zcu.kiv.backendapi;
 
-
-import lombok.AllArgsConstructor;
-public record StubDto(String message, Boolean success) {}
+//
+//import lombok.AllArgsConstructor;
+//public record StubDto(String message, Boolean success) {}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/config/DataInitiator.java b/backend/src/main/java/cz/zcu/kiv/backendapi/config/DataInitiator.java
new file mode 100644
index 0000000..9429ff0
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/config/DataInitiator.java
@@ -0,0 +1,53 @@
+package cz.zcu.kiv.backendapi.config;
+
+import cz.zcu.kiv.backendapi.model.CatalogEntity;
+import cz.zcu.kiv.backendapi.service.catalog.ICatalogService;
+import lombok.RequiredArgsConstructor;
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVParser;
+import org.apache.commons.csv.CSVRecord;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+//TODO comment or delete
+@Component
+@RequiredArgsConstructor
+public class DataInitiator implements ApplicationListener<ContextRefreshedEvent> {
+
+    private final ICatalogService catalogService;
+
+    @Override
+    @Transactional
+    public void onApplicationEvent(ContextRefreshedEvent event) {
+        List<CatalogEntity> catalog = loadCatalog();
+        catalogService.saveCatalog(catalog);
+
+    }
+
+    private List<CatalogEntity> loadCatalog() {
+        List<CatalogEntity> catalogEntities = new ArrayList<>();
+        File csvData = new File("AssyrianProject-AllNoDupl.csv");
+        CSVParser parser;
+        try {
+            parser = CSVParser.parse(csvData, StandardCharsets.UTF_8, CSVFormat.Builder.create(CSVFormat.DEFAULT)
+                    .setHeader()
+                    .setSkipHeaderRecord(true)
+                    .build());
+            for (CSVRecord csvRecord : parser) {
+                catalogEntities.add(new CatalogEntity(csvRecord.toList()));
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return catalogEntities;
+
+    }
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/model/AlternativeNameEntity.java b/backend/src/main/java/cz/zcu/kiv/backendapi/model/AlternativeNameEntity.java
new file mode 100644
index 0000000..ecca1b0
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/model/AlternativeNameEntity.java
@@ -0,0 +1,34 @@
+package cz.zcu.kiv.backendapi.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.util.UUID;
+
+/**
+ * Alternative name entity representing alternative name of geographic entry
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Entity
+@Table(name = "alternative_names")
+@IdClass(AlternativeNameEntity.class)
+public class AlternativeNameEntity implements Serializable {
+    /**
+     * Name, serves as ID
+     */
+    @Id
+    private String name;
+
+    /**
+     * Catalog entity
+     */
+    @ManyToOne
+    @JoinColumn(name = "catalog_id")
+    @Id
+    private CatalogEntity catalog;
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/model/BibliographyEntity.java b/backend/src/main/java/cz/zcu/kiv/backendapi/model/BibliographyEntity.java
new file mode 100644
index 0000000..bbe9ba6
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/model/BibliographyEntity.java
@@ -0,0 +1,29 @@
+package cz.zcu.kiv.backendapi.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+/**
+ * Bibliography entity representing bibliography
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Entity
+@Table(name = "bibliography")
+@IdClass(BibliographyEntity.class)
+public class BibliographyEntity implements Serializable {
+    /**
+     * Source, serves as ID
+     */
+    @Id
+    private String source;
+
+    @ManyToOne
+    @JoinColumn(name = "catalog_id")
+    private CatalogEntity catalog;
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/model/CatalogEntity.java b/backend/src/main/java/cz/zcu/kiv/backendapi/model/CatalogEntity.java
new file mode 100644
index 0000000..1ced9c0
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/model/CatalogEntity.java
@@ -0,0 +1,156 @@
+package cz.zcu.kiv.backendapi.model;
+
+import lombok.Data;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.hibernate.annotations.LazyCollection;
+import org.hibernate.annotations.LazyCollectionOption;
+
+import javax.persistence.*;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * Catalog entity representing catalog
+ */
+//@Data
+@Getter
+@Setter
+@NoArgsConstructor
+@Entity
+@Table(name = "catalog")
+public class CatalogEntity {
+    private static final String INTEGER_PATTERN = "\\d+";
+    private static final String DOUBLE_PATTERN = "(\\d+[.]\\d+)|(\\d+)";
+    private static final String EMPTY_ENTRY = "–";
+    /**
+     * Catalog entry id
+     */
+    @Id
+    @GeneratedValue
+    private UUID id;
+
+    /**
+     * Name of geographic entry
+     */
+    private String name;
+
+    /**
+     * Certainty
+     */
+    private int certainty;
+
+    /**
+     * Longitude
+     */
+    private double longitude;
+
+    /**
+     * Latitude
+     */
+    private double latitude;
+
+    /**
+     * Bibliography
+     */
+    @OneToMany(mappedBy = "catalog", cascade = CascadeType.ALL)
+    @LazyCollection(LazyCollectionOption.FALSE)
+    private Set<BibliographyEntity> bibliography;
+
+    /**
+     * Countries
+     */
+    @OneToMany(mappedBy = "catalog", cascade = CascadeType.ALL)
+    @LazyCollection(LazyCollectionOption.FALSE)
+    private Set<CountryEntity> countries;
+
+    /**
+     * Written forms
+     */
+    @OneToMany(mappedBy = "catalog", cascade = CascadeType.ALL)
+    @LazyCollection(LazyCollectionOption.FALSE)
+    private Set<WrittenFormEntity> writtenForms;
+
+    /**
+     * Alternative name
+     */
+    @OneToMany(mappedBy = "catalog", cascade = CascadeType.ALL)
+    @LazyCollection(LazyCollectionOption.FALSE)
+    private Set<AlternativeNameEntity> alternativeNames;
+
+    /**
+     * Set of user roles - many-to-many relationship
+     */
+    @ManyToMany(fetch = FetchType.EAGER)
+    @JoinTable(
+            name = "catalog_type",
+            joinColumns = {
+                    @JoinColumn(name = "catalog_id", referencedColumnName = "id")
+            },
+            inverseJoinColumns = {
+                    @JoinColumn(name = "type", referencedColumnName = "type")
+            }
+    )
+    private Set<TypeEntity> types = Collections.emptySet();
+
+    public CatalogEntity(final List<String> csvFields) {
+
+        this.name = csvFields.get(1);
+        List<String> stringList = processListField(csvFields.get(2));
+        this.alternativeNames = new HashSet<>(stringList.size());
+        for (String s : stringList) {
+            this.alternativeNames.add(new AlternativeNameEntity(s, this));
+        }
+        this.certainty = processIntField(csvFields.get(3));
+        this.latitude = processDoubleField(csvFields.get(4));
+        this.longitude = processDoubleField(csvFields.get(5));
+        stringList = processListField(csvFields.get(6));
+        this.writtenForms = new HashSet<>(stringList.size());
+        for (String s : stringList) {
+            this.writtenForms.add(new WrittenFormEntity(s, this));
+        }
+        stringList = processListField(csvFields.get(7));
+        this.types = new HashSet<>(stringList.size());
+        for (String s : stringList) {
+            this.types.add(new TypeEntity(s));
+        }
+        stringList = processListField(csvFields.get(8));
+        this.countries = new HashSet<>(stringList.size());
+        for (String s : stringList) {
+            this.countries.add(new CountryEntity(s, this));
+        }
+        stringList = processListField(csvFields.get(10));
+        this.bibliography = new HashSet<>(stringList.size());
+        for (String s : stringList) {
+            this.bibliography.add(new BibliographyEntity(s, this));
+        }
+    }
+
+    private int processIntField(String field) {
+        Matcher matcher = Pattern.compile(INTEGER_PATTERN).matcher(field);
+        if (matcher.find()) {
+            return Integer.parseInt(matcher.group());
+        } else {
+            return 0;
+        }
+    }
+
+    private double processDoubleField(String field) {
+        Matcher matcher = Pattern.compile(DOUBLE_PATTERN).matcher(field);
+        if (matcher.find()) {
+            return Double.parseDouble(matcher.group());
+        } else {
+            return 0.0;
+        }
+    }
+
+    private List<String> processListField(String field) {
+        if (field.isEmpty() || field.equals(EMPTY_ENTRY)) {
+            return new ArrayList<>();
+        }
+        return Arrays.stream(field.split(",")).map(String::trim).collect(Collectors.toList());
+    }
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/model/CountryEntity.java b/backend/src/main/java/cz/zcu/kiv/backendapi/model/CountryEntity.java
new file mode 100644
index 0000000..e05ef5b
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/model/CountryEntity.java
@@ -0,0 +1,30 @@
+package cz.zcu.kiv.backendapi.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+/**
+ * Country entity representing country of geographic entry
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Entity
+@Table(name = "countries")
+@IdClass(CountryEntity.class)
+public class CountryEntity implements Serializable {
+    /**
+     * Name of country, serves as ID
+     */
+    @Id
+    private String name;
+
+    @ManyToOne
+    @JoinColumn(name = "catalog_id")
+    @Id
+    private CatalogEntity catalog;
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/model/Role.java b/backend/src/main/java/cz/zcu/kiv/backendapi/model/Role.java
new file mode 100644
index 0000000..ab17876
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/model/Role.java
@@ -0,0 +1,26 @@
+package cz.zcu.kiv.backendapi.model;
+
+import lombok.Getter;
+
+/**
+ * Enum for user roles
+ */
+@Getter
+public enum Role {
+    ADMIN("ROLE_ADMIN"),
+    USER("ROLE_USER");
+
+    /**
+     * Role
+     */
+    private final String role;
+
+    /**
+     * Creates role
+     *
+     * @param role role
+     */
+    Role(final String role) {
+        this.role = role;
+    }
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/model/TypeEntity.java b/backend/src/main/java/cz/zcu/kiv/backendapi/model/TypeEntity.java
new file mode 100644
index 0000000..aaeb07d
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/model/TypeEntity.java
@@ -0,0 +1,25 @@
+package cz.zcu.kiv.backendapi.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * Type entity representing type of geographic entry
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Entity
+@Table(name = "types")
+public class TypeEntity {
+    /**
+     * Type (e.g. river), serves as ID
+     */
+    @Id
+    private String type;
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/model/UserEntity.java b/backend/src/main/java/cz/zcu/kiv/backendapi/model/UserEntity.java
new file mode 100644
index 0000000..4f65a90
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/model/UserEntity.java
@@ -0,0 +1,87 @@
+package cz.zcu.kiv.backendapi.model;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.hibernate.annotations.Type;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
+
+import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * User entity representing application user
+ */
+@Data
+@NoArgsConstructor
+@Entity
+@Table(name = "users")
+public class UserEntity implements UserDetails {
+    /**
+     * Name
+     */
+    private String name;
+
+    /**
+     * Email - serves as username and must be unique - serves as Id
+     */
+    @Id
+    private String email;
+
+    /**
+     * Password
+     */
+    private String password;
+
+    /**
+     * Whether the user is admin or not
+     */
+    @Column(name = "is_admin")
+    @Type(type = "numeric_boolean")
+    private boolean isAdmin;
+
+    @Override
+    public Collection<? extends GrantedAuthority> getAuthorities() {
+        final List<GrantedAuthority> authorities = new ArrayList<>();
+        if (isAdmin) {
+            authorities.add(new SimpleGrantedAuthority(Role.ADMIN.getRole()));
+        } else {
+            authorities.add(new SimpleGrantedAuthority(Role.USER.getRole()));
+        }
+
+        return authorities;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    @Override
+    public String getUsername() {
+        return email;
+    }
+
+    @Override
+    public boolean isAccountNonExpired() {
+        return true;
+    }
+
+    @Override
+    public boolean isAccountNonLocked() {
+        return true;
+    }
+
+    @Override
+    public boolean isCredentialsNonExpired() {
+        return true;
+    }
+
+    @Override
+    public boolean isEnabled() {
+        return true;
+    }
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/model/WrittenFormEntity.java b/backend/src/main/java/cz/zcu/kiv/backendapi/model/WrittenFormEntity.java
new file mode 100644
index 0000000..e12fd97
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/model/WrittenFormEntity.java
@@ -0,0 +1,30 @@
+package cz.zcu.kiv.backendapi.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+/**
+ * Written form entity representing written form of geographic entry
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Entity
+@Table(name = "written_forms")
+@IdClass(WrittenFormEntity.class)
+public class WrittenFormEntity implements Serializable {
+    /**
+     * Written form, serves as ID
+     */
+    @Id
+    private String form;
+
+    @ManyToOne
+    @JoinColumn(name = "catalog_id")
+    @Id
+    private CatalogEntity catalog;
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/repo/AlternativeNameRepository.java b/backend/src/main/java/cz/zcu/kiv/backendapi/repo/AlternativeNameRepository.java
new file mode 100644
index 0000000..52cb305
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/repo/AlternativeNameRepository.java
@@ -0,0 +1,14 @@
+package cz.zcu.kiv.backendapi.repo;
+
+import cz.zcu.kiv.backendapi.model.AlternativeNameEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Alternative name repository
+ */
+@Repository
+@Transactional(readOnly = true)
+public interface AlternativeNameRepository extends JpaRepository<AlternativeNameEntity, AlternativeNameEntity> {
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/repo/BibliographyRepository.java b/backend/src/main/java/cz/zcu/kiv/backendapi/repo/BibliographyRepository.java
new file mode 100644
index 0000000..074f928
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/repo/BibliographyRepository.java
@@ -0,0 +1,14 @@
+package cz.zcu.kiv.backendapi.repo;
+
+import cz.zcu.kiv.backendapi.model.BibliographyEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Bibliography repository
+ */
+@Repository
+@Transactional(readOnly = true)
+public interface BibliographyRepository extends JpaRepository<BibliographyEntity, BibliographyEntity> {
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/repo/CatalogRepository.java b/backend/src/main/java/cz/zcu/kiv/backendapi/repo/CatalogRepository.java
new file mode 100644
index 0000000..95c2ce7
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/repo/CatalogRepository.java
@@ -0,0 +1,16 @@
+package cz.zcu.kiv.backendapi.repo;
+
+import cz.zcu.kiv.backendapi.model.CatalogEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.UUID;
+
+/**
+ * Catalog repository
+ */
+@Repository
+@Transactional(readOnly = true)
+public interface CatalogRepository extends JpaRepository<CatalogEntity, UUID> {
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/repo/CountryRepository.java b/backend/src/main/java/cz/zcu/kiv/backendapi/repo/CountryRepository.java
new file mode 100644
index 0000000..adee9e2
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/repo/CountryRepository.java
@@ -0,0 +1,14 @@
+package cz.zcu.kiv.backendapi.repo;
+
+import cz.zcu.kiv.backendapi.model.CountryEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Country repository
+ */
+@Repository
+@Transactional(readOnly = true)
+public interface CountryRepository extends JpaRepository<CountryEntity, CountryEntity> {
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/repo/TypeRepository.java b/backend/src/main/java/cz/zcu/kiv/backendapi/repo/TypeRepository.java
new file mode 100644
index 0000000..e88d436
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/repo/TypeRepository.java
@@ -0,0 +1,15 @@
+package cz.zcu.kiv.backendapi.repo;
+
+import cz.zcu.kiv.backendapi.model.TypeEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+
+/**
+ * Type repository
+ */
+@Repository
+@Transactional(readOnly = true)
+public interface TypeRepository extends JpaRepository<TypeEntity, String> {
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/repo/UserRepository.java b/backend/src/main/java/cz/zcu/kiv/backendapi/repo/UserRepository.java
new file mode 100644
index 0000000..52496fa
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/repo/UserRepository.java
@@ -0,0 +1,15 @@
+package cz.zcu.kiv.backendapi.repo;
+
+import cz.zcu.kiv.backendapi.model.UserEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+
+/**
+ * User repository
+ */
+@Repository
+@Transactional(readOnly = true)
+public interface UserRepository extends JpaRepository<UserEntity, String> {
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/repo/WrittenFormRepository.java b/backend/src/main/java/cz/zcu/kiv/backendapi/repo/WrittenFormRepository.java
new file mode 100644
index 0000000..f919da9
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/repo/WrittenFormRepository.java
@@ -0,0 +1,14 @@
+package cz.zcu.kiv.backendapi.repo;
+
+import cz.zcu.kiv.backendapi.model.WrittenFormEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Written form repository
+ */
+@Repository
+@Transactional(readOnly = true)
+public interface WrittenFormRepository extends JpaRepository<WrittenFormEntity, WrittenFormEntity> {
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/service/alternativename/AlternativeNameServiceImpl.java b/backend/src/main/java/cz/zcu/kiv/backendapi/service/alternativename/AlternativeNameServiceImpl.java
new file mode 100644
index 0000000..b8ab6f2
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/service/alternativename/AlternativeNameServiceImpl.java
@@ -0,0 +1,20 @@
+package cz.zcu.kiv.backendapi.service.alternativename;
+
+import cz.zcu.kiv.backendapi.repo.AlternativeNameRepository;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Alternative name service implementation
+ */
+@Service
+@Transactional
+@RequiredArgsConstructor
+public class AlternativeNameServiceImpl implements IAlternativeNameService {
+
+    /**
+     * Alternative name repository
+     */
+    private final AlternativeNameRepository alternativeNameRepository;
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/service/alternativename/IAlternativeNameService.java b/backend/src/main/java/cz/zcu/kiv/backendapi/service/alternativename/IAlternativeNameService.java
new file mode 100644
index 0000000..bd34a5a
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/service/alternativename/IAlternativeNameService.java
@@ -0,0 +1,7 @@
+package cz.zcu.kiv.backendapi.service.alternativename;
+
+/**
+ * Alternative name service interface
+ */
+public interface IAlternativeNameService {
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/service/bibliography/BibliographyServiceImpl.java b/backend/src/main/java/cz/zcu/kiv/backendapi/service/bibliography/BibliographyServiceImpl.java
new file mode 100644
index 0000000..dd8e7b0
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/service/bibliography/BibliographyServiceImpl.java
@@ -0,0 +1,19 @@
+package cz.zcu.kiv.backendapi.service.bibliography;
+
+import cz.zcu.kiv.backendapi.repo.BibliographyRepository;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Bibliography service implementation
+ */
+@Service
+@Transactional
+@RequiredArgsConstructor
+public class BibliographyServiceImpl implements IBibliographyService {
+    /**
+     * Bibliography repository
+     */
+    private final BibliographyRepository bibliographyRepository;
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/service/bibliography/IBibliographyService.java b/backend/src/main/java/cz/zcu/kiv/backendapi/service/bibliography/IBibliographyService.java
new file mode 100644
index 0000000..c3059ba
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/service/bibliography/IBibliographyService.java
@@ -0,0 +1,7 @@
+package cz.zcu.kiv.backendapi.service.bibliography;
+
+/**
+ * Bibliography service interface
+ */
+public interface IBibliographyService {
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/service/catalog/CatalogServiceImpl.java b/backend/src/main/java/cz/zcu/kiv/backendapi/service/catalog/CatalogServiceImpl.java
new file mode 100644
index 0000000..65d3f23
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/service/catalog/CatalogServiceImpl.java
@@ -0,0 +1,39 @@
+package cz.zcu.kiv.backendapi.service.catalog;
+
+import cz.zcu.kiv.backendapi.model.CatalogEntity;
+import cz.zcu.kiv.backendapi.model.TypeEntity;
+import cz.zcu.kiv.backendapi.repo.CatalogRepository;
+import cz.zcu.kiv.backendapi.service.type.ITypeService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+/**
+ * Catalog service implementation
+ */
+@Service
+@Transactional
+@RequiredArgsConstructor
+public class CatalogServiceImpl implements ICatalogService {
+    /**
+     * Catalog repository
+     */
+    private final CatalogRepository catalogRepository;
+
+    private final ITypeService typeService;
+
+    @Override
+    public void saveCatalog(List<CatalogEntity> catalogEntities) {
+        for (CatalogEntity catalogEntity : catalogEntities) {
+            for (TypeEntity type: catalogEntity.getTypes()                 ) {
+
+                if (typeService.getTypeByName(type.getType()).isEmpty()){
+                    typeService.saveType(type);
+                }
+            }
+        }
+        catalogRepository.saveAll(catalogEntities);
+    }
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/service/catalog/ICatalogService.java b/backend/src/main/java/cz/zcu/kiv/backendapi/service/catalog/ICatalogService.java
new file mode 100644
index 0000000..862bbe2
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/service/catalog/ICatalogService.java
@@ -0,0 +1,12 @@
+package cz.zcu.kiv.backendapi.service.catalog;
+
+import cz.zcu.kiv.backendapi.model.CatalogEntity;
+
+import java.util.List;
+
+/**
+ * Catalog service interface
+ */
+public interface ICatalogService {
+    void saveCatalog(List<CatalogEntity> catalogEntities);
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/service/country/CountryServiceImpl.java b/backend/src/main/java/cz/zcu/kiv/backendapi/service/country/CountryServiceImpl.java
new file mode 100644
index 0000000..92a0d57
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/service/country/CountryServiceImpl.java
@@ -0,0 +1,20 @@
+package cz.zcu.kiv.backendapi.service.country;
+
+import cz.zcu.kiv.backendapi.repo.CountryRepository;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Country service implementation
+ */
+@Service
+@Transactional
+@RequiredArgsConstructor
+public class CountryServiceImpl implements ICountryService {
+
+    /**
+     * Country repository
+     */
+    private final CountryRepository countryRepository;
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/service/country/ICountryService.java b/backend/src/main/java/cz/zcu/kiv/backendapi/service/country/ICountryService.java
new file mode 100644
index 0000000..96248b5
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/service/country/ICountryService.java
@@ -0,0 +1,7 @@
+package cz.zcu.kiv.backendapi.service.country;
+
+/**
+ * Country service interface
+ */
+public interface ICountryService {
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/service/type/ITypeService.java b/backend/src/main/java/cz/zcu/kiv/backendapi/service/type/ITypeService.java
new file mode 100644
index 0000000..353e9df
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/service/type/ITypeService.java
@@ -0,0 +1,18 @@
+package cz.zcu.kiv.backendapi.service.type;
+
+import cz.zcu.kiv.backendapi.model.TypeEntity;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Type service interface
+ */
+public interface ITypeService {
+
+    void saveType(TypeEntity typeEntity);
+
+    void saveTypes(List<TypeEntity> typesEntities);
+
+    Optional<TypeEntity> getTypeByName(String type);
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/service/type/TypeServiceImpl.java b/backend/src/main/java/cz/zcu/kiv/backendapi/service/type/TypeServiceImpl.java
new file mode 100644
index 0000000..f54918c
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/service/type/TypeServiceImpl.java
@@ -0,0 +1,40 @@
+package cz.zcu.kiv.backendapi.service.type;
+
+import cz.zcu.kiv.backendapi.model.TypeEntity;
+import cz.zcu.kiv.backendapi.repo.TypeRepository;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Type service implementation
+ */
+@Service
+@Transactional
+@RequiredArgsConstructor
+public class TypeServiceImpl implements ITypeService {
+    /**
+     * Type repository
+     */
+    private final TypeRepository typeRepository;
+
+    @Override
+    public void saveType(TypeEntity typeEntity) {
+        typeRepository.save(typeEntity);
+    }
+
+    @Override
+    public void saveTypes(List<TypeEntity> typesEntities) {
+        typeRepository.saveAll(typesEntities);
+    }
+
+    @Override
+    public Optional<TypeEntity> getTypeByName(String type) {
+        return typeRepository.findById(type);
+    }
+
+
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/service/user/IUserService.java b/backend/src/main/java/cz/zcu/kiv/backendapi/service/user/IUserService.java
new file mode 100644
index 0000000..6f040cb
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/service/user/IUserService.java
@@ -0,0 +1,7 @@
+package cz.zcu.kiv.backendapi.service.user;
+
+/**
+ * User service interface
+ */
+public interface IUserService {
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/service/user/UserServiceImpl.java b/backend/src/main/java/cz/zcu/kiv/backendapi/service/user/UserServiceImpl.java
new file mode 100644
index 0000000..5781c59
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/service/user/UserServiceImpl.java
@@ -0,0 +1,26 @@
+package cz.zcu.kiv.backendapi.service.user;
+
+import cz.zcu.kiv.backendapi.repo.UserRepository;
+import lombok.RequiredArgsConstructor;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * User service implementation
+ */
+@Service
+@Transactional
+@RequiredArgsConstructor
+public class UserServiceImpl implements IUserService {
+    /**
+     * User repository
+     */
+    private final UserRepository userRepository;
+
+//    /**
+//     * Password encoder
+//     */
+    // TODO bean
+//    private final BCryptPasswordEncoder passwordEncoder;
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/service/writtenform/IWrittenFormService.java b/backend/src/main/java/cz/zcu/kiv/backendapi/service/writtenform/IWrittenFormService.java
new file mode 100644
index 0000000..aa8e970
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/service/writtenform/IWrittenFormService.java
@@ -0,0 +1,7 @@
+package cz.zcu.kiv.backendapi.service.writtenform;
+
+/**
+ * Written form service interface
+ */
+public interface IWrittenFormService {
+}
diff --git a/backend/src/main/java/cz/zcu/kiv/backendapi/service/writtenform/WrittenFormServiceImpl.java b/backend/src/main/java/cz/zcu/kiv/backendapi/service/writtenform/WrittenFormServiceImpl.java
new file mode 100644
index 0000000..a4f8155
--- /dev/null
+++ b/backend/src/main/java/cz/zcu/kiv/backendapi/service/writtenform/WrittenFormServiceImpl.java
@@ -0,0 +1,20 @@
+package cz.zcu.kiv.backendapi.service.writtenform;
+
+import cz.zcu.kiv.backendapi.repo.WrittenFormRepository;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Written form service implementation
+ */
+@Service
+@Transactional
+@RequiredArgsConstructor
+public class WrittenFormServiceImpl implements IWrittenFormService {
+
+    /**
+     * Written form repository
+     */
+    private final WrittenFormRepository writtenFormRepository;
+}
diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties
index 8b13789..c3a4acd 100644
--- a/backend/src/main/resources/application.properties
+++ b/backend/src/main/resources/application.properties
@@ -1 +1,10 @@
+spring.datasource.url=jdbc:postgresql://localhost:5432/test
+spring.datasource.username=test
+spring.datasource.password=Password.123
 
+spring.jpa.hibernate.ddl-auto=create-drop
+spring.jpa.generate-ddl=true
+spring.jpa.open-in-view=false
+spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL10Dialect
+spring.jpa.properties.hibernate.format_sql=true
+spring.jpa.show-sql=true
\ No newline at end of file
