Projekt

Obecné

Profil

« Předchozí | Další » 

Revize b2af5445

Přidáno uživatelem Jakub Šmíd před více než 2 roky(ů)

Passwords and permissions update

Zobrazit rozdíly:

backend/src/main/java/cz/zcu/kiv/backendapi/alternativename/AlternativeName.java
1
package cz.zcu.kiv.backendapi.alternativename;
2

  
3
import cz.zcu.kiv.backendapi.catalog.CatalogEntry;
4
import lombok.AllArgsConstructor;
5
import lombok.Data;
6
import lombok.NoArgsConstructor;
7

  
8
import javax.persistence.*;
9
import java.io.Serializable;
10

  
11
/**
12
 * Alternative name entity representing alternative name of geographic entry
13
 */
14
@Data
15
@NoArgsConstructor
16
@AllArgsConstructor
17
@Entity
18
@Table(name = "alternative_names")
19
@IdClass(AlternativeName.class)
20
public class AlternativeName implements Serializable {
21
    /**
22
     * Name, serves as ID
23
     */
24
    @Id
25
    private String name;
26

  
27
    /**
28
     * Catalog entity
29
     */
30
    @ManyToOne
31
    @JoinColumn(name = "catalog_id")
32
    @Id
33
    private CatalogEntry catalog;
34
}
backend/src/main/java/cz/zcu/kiv/backendapi/alternativename/AlternativeNameEntity.java
1
package cz.zcu.kiv.backendapi.alternativename;
2

  
3
import cz.zcu.kiv.backendapi.catalog.CatalogEntity;
4
import lombok.AllArgsConstructor;
5
import lombok.Data;
6
import lombok.NoArgsConstructor;
7

  
8
import javax.persistence.*;
9
import java.io.Serializable;
10

  
11
/**
12
 * Alternative name entity representing alternative name of geographic entry
13
 */
14
@Data
15
@NoArgsConstructor
16
@AllArgsConstructor
17
@Entity
18
@Table(name = "alternative_names")
19
@IdClass(AlternativeNameEntity.class)
20
public class AlternativeNameEntity implements Serializable {
21
    /**
22
     * Name, serves as ID
23
     */
24
    @Id
25
    private String name;
26

  
27
    /**
28
     * Catalog entity
29
     */
30
    @ManyToOne
31
    @JoinColumn(name = "catalog_id")
32
    @Id
33
    private CatalogEntity catalog;
34
}
backend/src/main/java/cz/zcu/kiv/backendapi/alternativename/AlternativeNameRepository.java
9 9
 */
10 10
@Repository
11 11
@Transactional(readOnly = true)
12
public interface AlternativeNameRepository extends JpaRepository<AlternativeNameEntity, AlternativeNameEntity> {
12
public interface AlternativeNameRepository extends JpaRepository<AlternativeName, AlternativeName> {
13 13
}
backend/src/main/java/cz/zcu/kiv/backendapi/bibliography/Bibliography.java
1
package cz.zcu.kiv.backendapi.bibliography;
2

  
3
import cz.zcu.kiv.backendapi.catalog.CatalogEntry;
4
import lombok.AllArgsConstructor;
5
import lombok.Data;
6
import lombok.NoArgsConstructor;
7

  
8
import javax.persistence.*;
9
import java.io.Serializable;
10

  
11
/**
12
 * Bibliography entity representing bibliography
13
 */
14
@Data
15
@NoArgsConstructor
16
@AllArgsConstructor
17
@Entity
18
@Table(name = "bibliography")
19
@IdClass(Bibliography.class)
20
public class Bibliography implements Serializable {
21
    /**
22
     * Source, serves as ID
23
     */
24
    @Id
25
    private String source;
26

  
27
    @ManyToOne
28
    @JoinColumn(name = "catalog_id")
29
    private CatalogEntry catalog;
30
}
backend/src/main/java/cz/zcu/kiv/backendapi/bibliography/BibliographyEntity.java
1
package cz.zcu.kiv.backendapi.bibliography;
2

  
3
import cz.zcu.kiv.backendapi.catalog.CatalogEntity;
4
import lombok.AllArgsConstructor;
5
import lombok.Data;
6
import lombok.NoArgsConstructor;
7

  
8
import javax.persistence.*;
9
import java.io.Serializable;
10

  
11
/**
12
 * Bibliography entity representing bibliography
13
 */
14
@Data
15
@NoArgsConstructor
16
@AllArgsConstructor
17
@Entity
18
@Table(name = "bibliography")
19
@IdClass(BibliographyEntity.class)
20
public class BibliographyEntity implements Serializable {
21
    /**
22
     * Source, serves as ID
23
     */
24
    @Id
25
    private String source;
26

  
27
    @ManyToOne
28
    @JoinColumn(name = "catalog_id")
29
    private CatalogEntity catalog;
30
}
backend/src/main/java/cz/zcu/kiv/backendapi/bibliography/BibliographyRepository.java
9 9
 */
10 10
@Repository
11 11
@Transactional(readOnly = true)
12
public interface BibliographyRepository extends JpaRepository<BibliographyEntity, BibliographyEntity> {
12
public interface BibliographyRepository extends JpaRepository<Bibliography, Bibliography> {
13 13
}
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogController.java
19 19
    /**
20 20
     * Catalog service
21 21
     */
22
    private final ICatalogService catalogService;
22
    private final ICatalogEntryService catalogService;
23 23

  
24
    /**
25
     * Saves new catalog entry
26
     *
27
     * @param catalogEntryDto catalog entry DTO
28
     */
24 29
    @PostMapping("")
25
    public void addCatalogEntry(@RequestBody CatalogDto catalogDto) {
26
        catalogService.saveCatalogEntry(catalogDto);
30
    public void addCatalogEntry(@RequestBody CatalogEntryDto catalogEntryDto) {
31
        catalogService.saveCatalogEntry(catalogEntryDto);
27 32
    }
28 33

  
29 34
    /**
......
35 40
     * @return list of catalog entries satisfying given filter
36 41
     */
37 42
    @GetMapping("")
38
    public ResponseEntity<List<CatalogDto>> getCatalog(@RequestParam(defaultValue = "") String name, @RequestParam(defaultValue = "") String country, @RequestParam(defaultValue = "") String type) {
43
    public ResponseEntity<List<CatalogEntryDto>> getCatalog(@RequestParam(defaultValue = "") String name, @RequestParam(defaultValue = "") String country, @RequestParam(defaultValue = "") String type) {
39 44
        return new ResponseEntity<>(catalogService.getCatalog(name, country, type), HttpStatus.OK);
40 45
    }
41 46

  
42 47
    /**
43 48
     * Updates catalog entry with given ID
44 49
     *
45
     * @param id         ID
46
     * @param catalogDto catalog DTO
50
     * @param id              ID
51
     * @param catalogEntryDto catalog DTO
47 52
     */
48 53
    @PutMapping("/{id}")
49
    public void updateCatalogEntry(@PathVariable UUID id, @RequestBody CatalogDto catalogDto) {
50
        catalogService.updateCatalogEntry(id, catalogDto);
54
    public void updateCatalogEntry(@PathVariable UUID id, @RequestBody CatalogEntryDto catalogEntryDto) {
55
        catalogService.updateCatalogEntry(id, catalogEntryDto);
51 56
    }
52 57

  
53 58
    /**
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogDto.java
1
package cz.zcu.kiv.backendapi.catalog;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4
import lombok.AllArgsConstructor;
5
import lombok.Data;
6
import lombok.NoArgsConstructor;
7

  
8
import java.util.Collections;
9
import java.util.Set;
10
import java.util.UUID;
11

  
12
/**
13
 * Class representing catalog DTO
14
 */
15
@Data
16
@AllArgsConstructor
17
@NoArgsConstructor
18
public class CatalogDto {
19
    /**
20
     * Id
21
     */
22
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
23
    private UUID id;
24

  
25
    /**
26
     * Name of geographic entry
27
     */
28
    private String name;
29

  
30
    /**
31
     * Certainty
32
     */
33
    private int certainty;
34

  
35
    /**
36
     * Longitude
37
     */
38
    private double longitude;
39

  
40
    /**
41
     * Latitude
42
     */
43
    private double latitude;
44

  
45
    /**
46
     * Bibliography
47
     */
48
    private Set<String> bibliography = Collections.emptySet();
49

  
50
    /**
51
     * Countries
52
     */
53
    private Set<String> countries = Collections.emptySet();
54

  
55
    /**
56
     * Written forms
57
     */
58
    private Set<String> writtenForms = Collections.emptySet();
59

  
60
    /**
61
     * Alternative names
62
     */
63
    private Set<String> alternativeNames = Collections.emptySet();
64

  
65
    /**
66
     * Types
67
     */
68
    private Set<String> types = Collections.emptySet();
69

  
70
}
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogEntity.java
1
package cz.zcu.kiv.backendapi.catalog;
2

  
3
import cz.zcu.kiv.backendapi.alternativename.AlternativeNameEntity;
4
import cz.zcu.kiv.backendapi.bibliography.BibliographyEntity;
5
import cz.zcu.kiv.backendapi.country.CountryEntity;
6
import cz.zcu.kiv.backendapi.type.TypeEntity;
7
import cz.zcu.kiv.backendapi.writtenform.WrittenFormEntity;
8
import lombok.Getter;
9
import lombok.NoArgsConstructor;
10
import lombok.Setter;
11
import org.hibernate.annotations.LazyCollection;
12
import org.hibernate.annotations.LazyCollectionOption;
13

  
14
import javax.persistence.*;
15
import java.util.*;
16
import java.util.regex.Matcher;
17
import java.util.regex.Pattern;
18
import java.util.stream.Collectors;
19

  
20
/**
21
 * Catalog entity representing catalog
22
 */
23
//@Data
24
@Getter
25
@Setter
26
@NoArgsConstructor
27
@Entity
28
@Table(name = "catalog")
29
public class CatalogEntity {
30
    private static final String INTEGER_PATTERN = "\\d+";
31
    private static final String DOUBLE_PATTERN = "(\\d+[.]\\d+)|(\\d+)";
32
    private static final String EMPTY_ENTRY = "–";
33
    /**
34
     * Catalog entry id
35
     */
36
    @Id
37
    @GeneratedValue
38
    private UUID id;
39

  
40
    /**
41
     * Name of geographic entry
42
     */
43
    private String name;
44

  
45
    /**
46
     * Certainty
47
     */
48
    private int certainty;
49

  
50
    /**
51
     * Longitude
52
     */
53
    private double longitude;
54

  
55
    /**
56
     * Latitude
57
     */
58
    private double latitude;
59

  
60
    /**
61
     * Bibliography
62
     */
63
    @OneToMany(mappedBy = "catalog", cascade = CascadeType.ALL)
64
    @LazyCollection(LazyCollectionOption.FALSE)
65
    private Set<BibliographyEntity> bibliography = Collections.emptySet();
66

  
67
    /**
68
     * Countries
69
     */
70
    @OneToMany(mappedBy = "catalog", cascade = CascadeType.ALL)
71
    @LazyCollection(LazyCollectionOption.FALSE)
72
    private Set<CountryEntity> countries = Collections.emptySet();
73

  
74
    /**
75
     * Written forms
76
     */
77
    @OneToMany(mappedBy = "catalog", cascade = CascadeType.ALL)
78
    @LazyCollection(LazyCollectionOption.FALSE)
79
    private Set<WrittenFormEntity> writtenForms = Collections.emptySet();
80

  
81
    /**
82
     * Alternative names
83
     */
84
    @OneToMany(mappedBy = "catalog", cascade = CascadeType.ALL)
85
    @LazyCollection(LazyCollectionOption.FALSE)
86
    private Set<AlternativeNameEntity> alternativeNames = Collections.emptySet();
87

  
88
    /**
89
     * Set of user roles - many-to-many relationship
90
     */
91
    @ManyToMany(fetch = FetchType.EAGER)
92
    @JoinTable(
93
            name = "catalog_type",
94
            joinColumns = {
95
                    @JoinColumn(name = "catalog_id", referencedColumnName = "id")
96
            },
97
            inverseJoinColumns = {
98
                    @JoinColumn(name = "type", referencedColumnName = "type")
99
            }
100
    )
101
    private Set<TypeEntity> types = Collections.emptySet();
102

  
103
    public CatalogEntity(final List<String> csvFields) {
104

  
105
        this.name = csvFields.get(1);
106
        List<String> stringList = processListField(csvFields.get(2));
107
        this.alternativeNames = stringList.stream().map(s->new AlternativeNameEntity(s, this)).collect(Collectors.toSet());
108

  
109
        this.certainty = processIntField(csvFields.get(3));
110
        this.latitude = processDoubleField(csvFields.get(4));
111
        this.longitude = processDoubleField(csvFields.get(5));
112

  
113
        stringList = processListField(csvFields.get(6));
114
        this.writtenForms = stringList.stream().map(s->new WrittenFormEntity(s, this)).collect(Collectors.toSet());
115

  
116
        stringList = processListField(csvFields.get(7));
117
        this.types = stringList.stream().map(TypeEntity::new).collect(Collectors.toSet());
118

  
119
        stringList = processListField(csvFields.get(8));
120
        this.countries = stringList.stream().map(s->new CountryEntity(s, this)).collect(Collectors.toSet());
121

  
122
        stringList = processListField(csvFields.get(10));
123
        this.bibliography = stringList.stream().map(s->new BibliographyEntity(s, this)).collect(Collectors.toSet());
124
    }
125

  
126
    private int processIntField(String field) {
127
        Matcher matcher = Pattern.compile(INTEGER_PATTERN).matcher(field);
128
        if (matcher.find()) {
129
            return Integer.parseInt(matcher.group());
130
        } else {
131
            return 0;
132
        }
133
    }
134

  
135
    private double processDoubleField(String field) {
136
        Matcher matcher = Pattern.compile(DOUBLE_PATTERN).matcher(field);
137
        if (matcher.find()) {
138
            return Double.parseDouble(matcher.group());
139
        } else {
140
            return 0.0;
141
        }
142
    }
143

  
144
    private List<String> processListField(String field) {
145
        if (field.isEmpty() || field.equals(EMPTY_ENTRY)) {
146
            return new ArrayList<>();
147
        }
148
        return Arrays.stream(field.split(",")).map(String::trim).filter(item -> !item.isEmpty()).collect(Collectors.toList());
149
    }
150
}
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogEntry.java
1
package cz.zcu.kiv.backendapi.catalog;
2

  
3
import cz.zcu.kiv.backendapi.alternativename.AlternativeName;
4
import cz.zcu.kiv.backendapi.bibliography.Bibliography;
5
import cz.zcu.kiv.backendapi.country.Country;
6
import cz.zcu.kiv.backendapi.type.Type;
7
import cz.zcu.kiv.backendapi.writtenform.WrittenForm;
8
import lombok.Getter;
9
import lombok.NoArgsConstructor;
10
import lombok.Setter;
11
import org.hibernate.annotations.LazyCollection;
12
import org.hibernate.annotations.LazyCollectionOption;
13

  
14
import javax.persistence.*;
15
import java.util.*;
16
import java.util.regex.Matcher;
17
import java.util.regex.Pattern;
18
import java.util.stream.Collectors;
19

  
20
/**
21
 * Catalog entity representing catalog entry
22
 */
23
//@Data
24
@Getter
25
@Setter
26
@NoArgsConstructor
27
@Entity
28
@Table(name = "catalog")
29
public class CatalogEntry {
30
    private static final String INTEGER_PATTERN = "\\d+";
31
    private static final String DOUBLE_PATTERN = "(\\d+[.]\\d+)|(\\d+)";
32
    private static final String EMPTY_ENTRY = "–";
33
    /**
34
     * Catalog entry id
35
     */
36
    @Id
37
    @GeneratedValue
38
    private UUID id;
39

  
40
    /**
41
     * Name of geographic entry
42
     */
43
    private String name;
44

  
45
    /**
46
     * Certainty
47
     */
48
    private int certainty;
49

  
50
    /**
51
     * Longitude
52
     */
53
    private double longitude;
54

  
55
    /**
56
     * Latitude
57
     */
58
    private double latitude;
59

  
60
    /**
61
     * Bibliography
62
     */
63
    @OneToMany(mappedBy = "catalog", cascade = CascadeType.ALL)
64
    @LazyCollection(LazyCollectionOption.FALSE)
65
    private Set<Bibliography> bibliography = Collections.emptySet();
66

  
67
    /**
68
     * Countries
69
     */
70
    @OneToMany(mappedBy = "catalog", cascade = CascadeType.ALL)
71
    @LazyCollection(LazyCollectionOption.FALSE)
72
    private Set<Country> countries = Collections.emptySet();
73

  
74
    /**
75
     * Written forms
76
     */
77
    @OneToMany(mappedBy = "catalog", cascade = CascadeType.ALL)
78
    @LazyCollection(LazyCollectionOption.FALSE)
79
    private Set<WrittenForm> writtenForms = Collections.emptySet();
80

  
81
    /**
82
     * Alternative names
83
     */
84
    @OneToMany(mappedBy = "catalog", cascade = CascadeType.ALL)
85
    @LazyCollection(LazyCollectionOption.FALSE)
86
    private Set<AlternativeName> alternativeNames = Collections.emptySet();
87

  
88
    /**
89
     * Set of user roles - many-to-many relationship
90
     */
91
    @ManyToMany(fetch = FetchType.EAGER)
92
    @JoinTable(
93
            name = "catalog_type",
94
            joinColumns = {
95
                    @JoinColumn(name = "catalog_id", referencedColumnName = "id")
96
            },
97
            inverseJoinColumns = {
98
                    @JoinColumn(name = "type", referencedColumnName = "type")
99
            }
100
    )
101
    private Set<Type> types = Collections.emptySet();
102

  
103
    public CatalogEntry(final List<String> csvFields) {
104

  
105
        this.name = csvFields.get(1);
106
        List<String> stringList = processListField(csvFields.get(2));
107
        this.alternativeNames = stringList.stream().map(s->new AlternativeName(s, this)).collect(Collectors.toSet());
108

  
109
        this.certainty = processIntField(csvFields.get(3));
110
        this.latitude = processDoubleField(csvFields.get(4));
111
        this.longitude = processDoubleField(csvFields.get(5));
112

  
113
        stringList = processListField(csvFields.get(6));
114
        this.writtenForms = stringList.stream().map(s->new WrittenForm(s, this)).collect(Collectors.toSet());
115

  
116
        stringList = processListField(csvFields.get(7));
117
        this.types = stringList.stream().map(Type::new).collect(Collectors.toSet());
118

  
119
        stringList = processListField(csvFields.get(8));
120
        this.countries = stringList.stream().map(s->new Country(s, this)).collect(Collectors.toSet());
121

  
122
        stringList = processListField(csvFields.get(9));
123
        this.bibliography = stringList.stream().map(s->new Bibliography(s, this)).collect(Collectors.toSet());
124
    }
125

  
126
    private int processIntField(String field) {
127
        Matcher matcher = Pattern.compile(INTEGER_PATTERN).matcher(field);
128
        if (matcher.find()) {
129
            return Integer.parseInt(matcher.group());
130
        } else {
131
            return 0;
132
        }
133
    }
134

  
135
    private double processDoubleField(String field) {
136
        Matcher matcher = Pattern.compile(DOUBLE_PATTERN).matcher(field);
137
        if (matcher.find()) {
138
            return Double.parseDouble(matcher.group());
139
        } else {
140
            return 0.0;
141
        }
142
    }
143

  
144
    private List<String> processListField(String field) {
145
        if (field.isEmpty() || field.equals(EMPTY_ENTRY)) {
146
            return new ArrayList<>();
147
        }
148
        return Arrays.stream(field.split(",")).map(String::trim).filter(item -> !item.isEmpty()).collect(Collectors.toList());
149
    }
150
}
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogEntryDto.java
1
package cz.zcu.kiv.backendapi.catalog;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4
import lombok.AllArgsConstructor;
5
import lombok.Data;
6
import lombok.NoArgsConstructor;
7

  
8
import java.util.Collections;
9
import java.util.Set;
10
import java.util.UUID;
11

  
12
/**
13
 * Class representing catalog entry DTO
14
 */
15
@Data
16
@AllArgsConstructor
17
@NoArgsConstructor
18
public class CatalogEntryDto {
19
    /**
20
     * Id
21
     */
22
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
23
    private UUID id;
24

  
25
    /**
26
     * Name of geographic entry
27
     */
28
    private String name;
29

  
30
    /**
31
     * Certainty
32
     */
33
    private int certainty;
34

  
35
    /**
36
     * Longitude
37
     */
38
    private double longitude;
39

  
40
    /**
41
     * Latitude
42
     */
43
    private double latitude;
44

  
45
    /**
46
     * Bibliography
47
     */
48
    private Set<String> bibliography = Collections.emptySet();
49

  
50
    /**
51
     * Countries
52
     */
53
    private Set<String> countries = Collections.emptySet();
54

  
55
    /**
56
     * Written forms
57
     */
58
    private Set<String> writtenForms = Collections.emptySet();
59

  
60
    /**
61
     * Alternative names
62
     */
63
    private Set<String> alternativeNames = Collections.emptySet();
64

  
65
    /**
66
     * Types
67
     */
68
    private Set<String> types = Collections.emptySet();
69

  
70
}
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogEntryRepository.java
1
package cz.zcu.kiv.backendapi.catalog;
2

  
3
import org.springframework.data.jpa.repository.JpaRepository;
4
import org.springframework.data.jpa.repository.Query;
5
import org.springframework.stereotype.Repository;
6
import org.springframework.transaction.annotation.Transactional;
7

  
8
import java.util.Set;
9
import java.util.UUID;
10

  
11
/**
12
 * Catalog repository
13
 */
14
@Repository
15
@Transactional(readOnly = true)
16
public interface CatalogEntryRepository extends JpaRepository<CatalogEntry, UUID> {
17

  
18
    /**
19
     * Returns all catalog entries containing specific values
20
     *
21
     * @param name    name - optional
22
     * @param country country - optional
23
     * @param type    type - optional
24
     * @return set of catalog entries satisfying filter conditions
25
     */
26
    @Query("SELECT DISTINCT e FROM CatalogEntry e LEFT JOIN AlternativeName a ON e = a.catalog " +
27
            "LEFT JOIN Country c ON e = c.catalog " +
28
            "INNER JOIN e.types t " +
29
            "WHERE (?1 = '' OR e.name LIKE ?1 OR a.name LIKE ?1) " +
30
            "AND (?2 = '' OR c.name LIKE ?2) " +
31
            "AND (?3 = '' OR t.type LIKE ?3)")
32
    Set<CatalogEntry> filterCatalog(String name, String country, String type);
33
}
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogEntryServiceImpl.java
1
package cz.zcu.kiv.backendapi.catalog;
2

  
3
import cz.zcu.kiv.backendapi.alternativename.AlternativeName;
4
import cz.zcu.kiv.backendapi.bibliography.Bibliography;
5
import cz.zcu.kiv.backendapi.country.Country;
6
import cz.zcu.kiv.backendapi.exception.ApiRequestException;
7
import cz.zcu.kiv.backendapi.type.Type;
8
import cz.zcu.kiv.backendapi.type.ITypeService;
9
import cz.zcu.kiv.backendapi.writtenform.WrittenForm;
10
import lombok.RequiredArgsConstructor;
11
import lombok.extern.slf4j.Slf4j;
12
import org.springframework.http.HttpStatus;
13
import org.springframework.stereotype.Service;
14
import org.springframework.transaction.annotation.Transactional;
15

  
16
import java.util.List;
17
import java.util.Set;
18
import java.util.UUID;
19
import java.util.stream.Collectors;
20

  
21
/**
22
 * Catalog entry service implementation
23
 */
24
@Service
25
@Transactional
26
@RequiredArgsConstructor
27
@Slf4j
28
public class CatalogEntryServiceImpl implements ICatalogEntryService {
29
    /**
30
     * Message for exception when catalog entry is not found by id
31
     */
32
    private static final String CATALOG_ENTRY_NOT_FOUND = "Catalog entry not found";
33
    /**
34
     * Catalog repository
35
     */
36
    private final CatalogEntryRepository catalogEntryRepository;
37

  
38
    /**
39
     * Type service
40
     */
41
    private final ITypeService typeService;
42

  
43
    @Override
44
    public void saveCatalog(List<CatalogEntry> catalogEntities) {
45
        log.info("Saving catalog");
46
        catalogEntities.forEach(this::saveCatalogEntity);
47
    }
48

  
49
    @Override
50
    public void saveCatalogEntry(CatalogEntryDto catalogEntryDto) {
51
        log.info("Saving catalog entry");
52
        CatalogEntry catalogEntry = new CatalogEntry();
53
        convertDtoToEntity(catalogEntryDto, catalogEntry);
54
        saveCatalogEntity(catalogEntry);
55
    }
56

  
57
    @Override
58
    public void updateCatalogEntry(UUID id, CatalogEntryDto catalogEntryDto) {
59
        CatalogEntry catalogEntry = catalogEntryRepository.findById(id).orElseThrow(() -> {
60
            log.error(CATALOG_ENTRY_NOT_FOUND);
61
            throw new ApiRequestException(CATALOG_ENTRY_NOT_FOUND, HttpStatus.NOT_FOUND);
62
        });
63
        convertDtoToEntity(catalogEntryDto, catalogEntry);
64
        saveCatalogEntity(catalogEntry);
65
        log.info("Catalog entry updated");
66
    }
67

  
68
    @Override
69
    public void deleteCatalogEntry(UUID id) {
70
        CatalogEntry catalogEntry = catalogEntryRepository.findById(id).orElseThrow(() -> {
71
            log.error(CATALOG_ENTRY_NOT_FOUND);
72
            throw new ApiRequestException(CATALOG_ENTRY_NOT_FOUND, HttpStatus.NOT_FOUND);
73
        });
74
        catalogEntryRepository.delete(catalogEntry);
75
        log.info("Catalog entry deleted");
76
    }
77

  
78
    @Override
79
    public List<CatalogEntryDto> getCatalog(String name, String country, String type) {
80
        log.info("Retrieving catalog");
81
        Set<CatalogEntry> entities = catalogEntryRepository.filterCatalog(name, country, type);
82
        return entities.stream().map(this::convertEntityToDto).collect(Collectors.toList());
83
    }
84

  
85
    /**
86
     * Saves catalog entity to database
87
     *
88
     * @param catalogEntry catalog entity
89
     */
90
    private void saveCatalogEntity(CatalogEntry catalogEntry) {
91
        for (Type type : catalogEntry.getTypes()) {
92
            if (typeService.getTypeByName(type.getType()).isEmpty()) {
93
                typeService.saveType(type);
94
            }
95
        }
96
        catalogEntryRepository.save(catalogEntry);
97
    }
98

  
99
    /**
100
     * Converts catalog DTO to catalog entity
101
     *
102
     * @param catalogEntryDto    catalog DTO
103
     * @param catalogEntry catalog entity
104
     */
105
    private void convertDtoToEntity(CatalogEntryDto catalogEntryDto, CatalogEntry catalogEntry) {
106
        catalogEntry.setName(catalogEntryDto.getName());
107
        catalogEntry.setCertainty(catalogEntryDto.getCertainty());
108
        catalogEntry.setLatitude(catalogEntryDto.getLatitude());
109
        catalogEntry.setLongitude(catalogEntryDto.getLongitude());
110
        catalogEntry.setBibliography(catalogEntryDto.getBibliography()
111
                .stream().map(s -> new Bibliography(s, catalogEntry)).collect(Collectors.toSet()));
112
        catalogEntry.setTypes(catalogEntryDto.getTypes()
113
                .stream().map(Type::new).collect(Collectors.toSet()));
114
        catalogEntry.setCountries(catalogEntryDto.getCountries()
115
                .stream().map(s -> new Country(s, catalogEntry)).collect(Collectors.toSet()));
116
        catalogEntry.setAlternativeNames(catalogEntryDto.getAlternativeNames()
117
                .stream().map(s -> new AlternativeName(s, catalogEntry)).collect(Collectors.toSet()));
118
        catalogEntry.setWrittenForms(catalogEntryDto.getWrittenForms()
119
                .stream().map(s -> new WrittenForm(s, catalogEntry)).collect(Collectors.toSet()));
120
    }
121

  
122
    /**
123
     * Converts catalog entity to catalog DTO
124
     *
125
     * @param entity catalog entity
126
     * @return catalog DTO
127
     */
128
    private CatalogEntryDto convertEntityToDto(CatalogEntry entity) {
129
        CatalogEntryDto catalogEntryDto = new CatalogEntryDto();
130
        catalogEntryDto.setId(entity.getId());
131
        catalogEntryDto.setName(entity.getName());
132
        catalogEntryDto.setLatitude(entity.getLatitude());
133
        catalogEntryDto.setLongitude(entity.getLongitude());
134
        catalogEntryDto.setCertainty(entity.getCertainty());
135
        catalogEntryDto.setBibliography(entity.getBibliography()
136
                .stream().map(Bibliography::getSource).collect(Collectors.toSet()));
137
        catalogEntryDto.setTypes(entity.getTypes()
138
                .stream().map(Type::getType).collect(Collectors.toSet()));
139
        catalogEntryDto.setCountries(entity.getCountries()
140
                .stream().map(Country::getName).collect(Collectors.toSet()));
141
        catalogEntryDto.setAlternativeNames(entity.getAlternativeNames()
142
                .stream().map(AlternativeName::getName).collect(Collectors.toSet()));
143
        catalogEntryDto.setWrittenForms(entity.getWrittenForms()
144
                .stream().map(WrittenForm::getForm).collect(Collectors.toSet()));
145
        return catalogEntryDto;
146
    }
147

  
148
}
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogRepository.java
1
package cz.zcu.kiv.backendapi.catalog;
2

  
3
import org.springframework.data.jpa.repository.JpaRepository;
4
import org.springframework.data.jpa.repository.Query;
5
import org.springframework.stereotype.Repository;
6
import org.springframework.transaction.annotation.Transactional;
7

  
8
import java.util.Set;
9
import java.util.UUID;
10

  
11
/**
12
 * Catalog repository
13
 */
14
@Repository
15
@Transactional(readOnly = true)
16
public interface CatalogRepository extends JpaRepository<CatalogEntity, UUID> {
17

  
18
    /**
19
     * Returns all catalog entries containing specific values
20
     *
21
     * @param name    name - optional
22
     * @param country country - optional
23
     * @param type    type - optional
24
     * @return set of catalog entries satisfying filter conditions
25
     */
26
    @Query("SELECT DISTINCT e FROM CatalogEntity e LEFT JOIN AlternativeNameEntity a ON e = a.catalog " +
27
            "LEFT JOIN CountryEntity c ON e = c.catalog " +
28
            "INNER JOIN e.types t " +
29
            "WHERE (?1 = '' OR e.name LIKE ?1 OR a.name LIKE ?1) " +
30
            "AND (?2 = '' OR c.name LIKE ?2) " +
31
            "AND (?3 = '' OR t.type LIKE ?3)")
32
    Set<CatalogEntity> filterCatalog(String name, String country, String type);
33
}
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogServiceImpl.java
1
package cz.zcu.kiv.backendapi.catalog;
2

  
3
import cz.zcu.kiv.backendapi.alternativename.AlternativeNameEntity;
4
import cz.zcu.kiv.backendapi.bibliography.BibliographyEntity;
5
import cz.zcu.kiv.backendapi.country.CountryEntity;
6
import cz.zcu.kiv.backendapi.exception.ApiRequestException;
7
import cz.zcu.kiv.backendapi.type.TypeEntity;
8
import cz.zcu.kiv.backendapi.type.ITypeService;
9
import cz.zcu.kiv.backendapi.writtenform.WrittenFormEntity;
10
import lombok.RequiredArgsConstructor;
11
import lombok.extern.slf4j.Slf4j;
12
import org.springframework.http.HttpStatus;
13
import org.springframework.stereotype.Service;
14
import org.springframework.transaction.annotation.Transactional;
15

  
16
import java.util.List;
17
import java.util.Set;
18
import java.util.UUID;
19
import java.util.stream.Collectors;
20

  
21
/**
22
 * Catalog service implementation
23
 */
24
@Service
25
@Transactional
26
@RequiredArgsConstructor
27
@Slf4j
28
public class CatalogServiceImpl implements ICatalogService {
29
    /**
30
     * Message for exception when catalog entry is not found by id
31
     */
32
    private static final String CATALOG_ENTRY_NOT_FOUND = "Catalog entry not found";
33
    /**
34
     * Catalog repository
35
     */
36
    private final CatalogRepository catalogRepository;
37

  
38
    /**
39
     * Type service
40
     */
41
    private final ITypeService typeService;
42

  
43
    @Override
44
    public void saveCatalog(List<CatalogEntity> catalogEntities) {
45
        log.info("Saving catalog");
46
        catalogEntities.forEach(this::saveCatalogEntity);
47
    }
48

  
49
    @Override
50
    public void saveCatalogEntry(CatalogDto catalogDto) {
51
        log.info("Saving catalog entry");
52
        CatalogEntity catalogEntity = new CatalogEntity();
53
        convertDtoToEntity(catalogDto, catalogEntity);
54
        saveCatalogEntity(catalogEntity);
55
    }
56

  
57
    @Override
58
    public void updateCatalogEntry(UUID id, CatalogDto catalogDto) {
59
        CatalogEntity catalogEntity = catalogRepository.findById(id).orElseThrow(() -> {
60
            log.error(CATALOG_ENTRY_NOT_FOUND);
61
            throw new ApiRequestException(CATALOG_ENTRY_NOT_FOUND, HttpStatus.NOT_FOUND);
62
        });
63
        convertDtoToEntity(catalogDto, catalogEntity);
64
        saveCatalogEntity(catalogEntity);
65
        log.info("Catalog entry updated");
66
    }
67

  
68
    @Override
69
    public void deleteCatalogEntry(UUID id) {
70
        CatalogEntity catalogEntity = catalogRepository.findById(id).orElseThrow(() -> {
71
            log.error(CATALOG_ENTRY_NOT_FOUND);
72
            throw new ApiRequestException(CATALOG_ENTRY_NOT_FOUND, HttpStatus.NOT_FOUND);
73
        });
74
        catalogRepository.delete(catalogEntity);
75
        log.info("Catalog entry deleted");
76
    }
77

  
78
    @Override
79
    public List<CatalogDto> getCatalog(String name, String country, String type) {
80
        log.info("Retrieving catalog");
81
        Set<CatalogEntity> entities = catalogRepository.filterCatalog(name, country, type);
82
        return entities.stream().map(this::convertEntityToDto).collect(Collectors.toList());
83
    }
84

  
85
    /**
86
     * Saves catalog entity to database
87
     *
88
     * @param catalogEntity catalog entity
89
     */
90
    private void saveCatalogEntity(CatalogEntity catalogEntity) {
91
        for (TypeEntity type : catalogEntity.getTypes()) {
92
            if (typeService.getTypeByName(type.getType()).isEmpty()) {
93
                typeService.saveType(type);
94
            }
95
        }
96
        catalogRepository.save(catalogEntity);
97
    }
98

  
99
    /**
100
     * Converts catalog DTO to catalog entity
101
     *
102
     * @param catalogDto    catalog DTO
103
     * @param catalogEntity catalog entity
104
     */
105
    private void convertDtoToEntity(CatalogDto catalogDto, CatalogEntity catalogEntity) {
106
        catalogEntity.setName(catalogDto.getName());
107
        catalogEntity.setCertainty(catalogDto.getCertainty());
108
        catalogEntity.setLatitude(catalogDto.getLatitude());
109
        catalogEntity.setLongitude(catalogDto.getLongitude());
110
        catalogEntity.setBibliography(catalogDto.getBibliography()
111
                .stream().map(s -> new BibliographyEntity(s, catalogEntity)).collect(Collectors.toSet()));
112
        catalogEntity.setTypes(catalogDto.getTypes()
113
                .stream().map(TypeEntity::new).collect(Collectors.toSet()));
114
        catalogEntity.setCountries(catalogDto.getCountries()
115
                .stream().map(s -> new CountryEntity(s, catalogEntity)).collect(Collectors.toSet()));
116
        catalogEntity.setAlternativeNames(catalogDto.getAlternativeNames()
117
                .stream().map(s -> new AlternativeNameEntity(s, catalogEntity)).collect(Collectors.toSet()));
118
        catalogEntity.setWrittenForms(catalogDto.getWrittenForms()
119
                .stream().map(s -> new WrittenFormEntity(s, catalogEntity)).collect(Collectors.toSet()));
120
    }
121

  
122
    /**
123
     * Converts catalog entity to catalog DTO
124
     *
125
     * @param entity catalog entity
126
     * @return catalog DTO
127
     */
128
    private CatalogDto convertEntityToDto(CatalogEntity entity) {
129
        CatalogDto catalogDto = new CatalogDto();
130
        catalogDto.setId(entity.getId());
131
        catalogDto.setName(entity.getName());
132
        catalogDto.setLatitude(entity.getLatitude());
133
        catalogDto.setLongitude(entity.getLongitude());
134
        catalogDto.setCertainty(entity.getCertainty());
135
        catalogDto.setBibliography(entity.getBibliography()
136
                .stream().map(BibliographyEntity::getSource).collect(Collectors.toSet()));
137
        catalogDto.setTypes(entity.getTypes()
138
                .stream().map(TypeEntity::getType).collect(Collectors.toSet()));
139
        catalogDto.setCountries(entity.getCountries()
140
                .stream().map(CountryEntity::getName).collect(Collectors.toSet()));
141
        catalogDto.setAlternativeNames(entity.getAlternativeNames()
142
                .stream().map(AlternativeNameEntity::getName).collect(Collectors.toSet()));
143
        catalogDto.setWrittenForms(entity.getWrittenForms()
144
                .stream().map(WrittenFormEntity::getForm).collect(Collectors.toSet()));
145
        return catalogDto;
146
    }
147

  
148
}
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/ICatalogEntryService.java
1
package cz.zcu.kiv.backendapi.catalog;
2

  
3
import java.util.List;
4
import java.util.UUID;
5

  
6
/**
7
 * Catalog service interface
8
 */
9
public interface ICatalogEntryService {
10
    /**
11
     * Saves list of catalog entries
12
     *
13
     * @param catalogEntities catalog entris
14
     */
15
    void saveCatalog(List<CatalogEntry> catalogEntities);
16

  
17
    /**
18
     * Saves one catalog entry
19
     *
20
     * @param catalogEntryDto catalog DTO
21
     */
22
    void saveCatalogEntry(CatalogEntryDto catalogEntryDto);
23

  
24
    /**
25
     * Updates catalog entry with given ID
26
     *
27
     * @param id         ID
28
     * @param catalogEntryDto catalog DTO
29
     */
30
    void updateCatalogEntry(UUID id, CatalogEntryDto catalogEntryDto);
31

  
32
    /**
33
     * Deletes catalog entry with given ID
34
     *
35
     * @param id ID
36
     */
37
    void deleteCatalogEntry(UUID id);
38

  
39
    /**
40
     * Returns catalog entries satisfying given filter
41
     *
42
     * @param name    name - optional
43
     * @param country country - optional
44
     * @param type    type - optional
45
     * @return list of catalog entries satisfying given filter
46
     */
47
    List<CatalogEntryDto> getCatalog(String name, String country, String type);
48

  
49
}
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/ICatalogService.java
1
package cz.zcu.kiv.backendapi.catalog;
2

  
3
import java.util.List;
4
import java.util.UUID;
5

  
6
/**
7
 * Catalog service interface
8
 */
9
public interface ICatalogService {
10
    /**
11
     * Saves list of catalog entries
12
     *
13
     * @param catalogEntities catalog entris
14
     */
15
    void saveCatalog(List<CatalogEntity> catalogEntities);
16

  
17
    /**
18
     * Saves one catalog entry
19
     *
20
     * @param catalogDto catalog DTO
21
     */
22
    void saveCatalogEntry(CatalogDto catalogDto);
23

  
24
    /**
25
     * Updates catalog entry with given ID
26
     *
27
     * @param id         ID
28
     * @param catalogDto catalog DTO
29
     */
30
    void updateCatalogEntry(UUID id, CatalogDto catalogDto);
31

  
32
    /**
33
     * Deletes catalog entry with given ID
34
     *
35
     * @param id ID
36
     */
37
    void deleteCatalogEntry(UUID id);
38

  
39
    /**
40
     * Returns catalog entries satisfying given filter
41
     *
42
     * @param name    name - optional
43
     * @param country country - optional
44
     * @param type    type - optional
45
     * @return list of catalog entries satisfying given filter
46
     */
47
    List<CatalogDto> getCatalog(String name, String country, String type);
48

  
49
}
backend/src/main/java/cz/zcu/kiv/backendapi/config/DataInitiator.java
1 1
package cz.zcu.kiv.backendapi.config;
2 2

  
3
import cz.zcu.kiv.backendapi.catalog.CatalogEntity;
4
import cz.zcu.kiv.backendapi.type.TypeEntity;
5
import cz.zcu.kiv.backendapi.catalog.CatalogRepository;
6
import cz.zcu.kiv.backendapi.catalog.ICatalogService;
3
import cz.zcu.kiv.backendapi.catalog.CatalogEntry;
4
import cz.zcu.kiv.backendapi.type.Type;
5
import cz.zcu.kiv.backendapi.catalog.CatalogEntryRepository;
6
import cz.zcu.kiv.backendapi.catalog.ICatalogEntryService;
7 7
import cz.zcu.kiv.backendapi.type.ITypeService;
8 8
import cz.zcu.kiv.backendapi.user.UserEntity;
9 9
import cz.zcu.kiv.backendapi.user.UserRepository;
......
29 29
@RequiredArgsConstructor
30 30
public class DataInitiator implements ApplicationListener<ContextRefreshedEvent> {
31 31

  
32
    private final ICatalogService catalogService;
32
    private final ICatalogEntryService catalogService;
33 33

  
34 34
    private final ITypeService typeService;
35 35

  
36
    private final CatalogRepository catalogRepository;
36
    private final CatalogEntryRepository catalogEntryRepository;
37 37

  
38 38
    private final UserRepository userRepository;
39 39

  
......
42 42
    @Override
43 43
    @Transactional
44 44
    public void onApplicationEvent(ContextRefreshedEvent event) {
45
        List<TypeEntity> types = loadTypes();
45
        List<Type> types = loadTypes();
46 46
        typeService.saveTypes(types);
47
        List<CatalogEntity> catalog = loadCatalog();
47
        List<CatalogEntry> catalog = loadCatalog();
48 48
        catalogService.saveCatalog(catalog);
49 49

  
50 50
        UserEntity user1 = new UserEntity("admin", "admin", encoder.encode("password"), (byte) 7, true);
......
55 55

  
56 56
    }
57 57

  
58
    private List<CatalogEntity> loadCatalog() {
59
        List<CatalogEntity> catalogEntities = new ArrayList<>();
60
        File csvData = new File("AssyrianProject-AllNoDupl.csv");
58
    private List<CatalogEntry> loadCatalog() {
59
        List<CatalogEntry> catalogEntities = new ArrayList<>();
60
        File csvData = new File("AssyrianProject-AllNoDupl-22-03-28.csv");
61 61
        CSVParser parser;
62 62
        try {
63 63
            parser = CSVParser.parse(csvData, StandardCharsets.UTF_8, CSVFormat.Builder.create(CSVFormat.DEFAULT)
......
65 65
                    .setSkipHeaderRecord(true)
66 66
                    .build());
67 67
            for (CSVRecord csvRecord : parser) {
68
                catalogEntities.add(new CatalogEntity(csvRecord.toList()));
68
                catalogEntities.add(new CatalogEntry(csvRecord.toList()));
69 69
            }
70 70
        } catch (IOException e) {
71 71
            e.printStackTrace();
......
74 74

  
75 75
    }
76 76

  
77
    private List<TypeEntity> loadTypes() {
78
        List<TypeEntity> types = new ArrayList<>();
77
    private List<Type> loadTypes() {
78
        List<Type> types = new ArrayList<>();
79 79
        CSVParser parser;
80 80
        File csvData = new File("AssyrianProject-All.csv");
81 81
        try {
82 82
            parser = CSVParser.parse(csvData, Charset.defaultCharset(), CSVFormat.DEFAULT.builder().setSkipHeaderRecord(true).build());
83 83
            for (CSVRecord csvRecord : parser) {
84 84
                if (csvRecord.get(0).equals("10000")) {
85
                    types.add(new TypeEntity(csvRecord.get(2)));
85
                    types.add(new Type(csvRecord.get(2)));
86 86
                }
87 87
            }
88 88
        } catch (IOException e) {
backend/src/main/java/cz/zcu/kiv/backendapi/country/Country.java
1
package cz.zcu.kiv.backendapi.country;
2

  
3
import cz.zcu.kiv.backendapi.catalog.CatalogEntry;
4
import lombok.AllArgsConstructor;
5
import lombok.Data;
6
import lombok.NoArgsConstructor;
7

  
8
import javax.persistence.*;
9
import java.io.Serializable;
10

  
11
/**
12
 * Country entity representing country of geographic entry
13
 */
14
@Data
15
@NoArgsConstructor
16
@AllArgsConstructor
17
@Entity
18
@Table(name = "countries")
19
@IdClass(Country.class)
20
public class Country implements Serializable {
21
    /**
22
     * Name of country, serves as ID
23
     */
24
    @Id
25
    private String name;
26

  
27
    @ManyToOne
28
    @JoinColumn(name = "catalog_id")
29
    @Id
30
    private CatalogEntry catalog;
31
}
backend/src/main/java/cz/zcu/kiv/backendapi/country/CountryEntity.java
1
package cz.zcu.kiv.backendapi.country;
2

  
3
import cz.zcu.kiv.backendapi.catalog.CatalogEntity;
4
import lombok.AllArgsConstructor;
5
import lombok.Data;
6
import lombok.NoArgsConstructor;
7

  
8
import javax.persistence.*;
9
import java.io.Serializable;
10

  
11
/**
12
 * Country entity representing country of geographic entry
13
 */
14
@Data
15
@NoArgsConstructor
16
@AllArgsConstructor
17
@Entity
18
@Table(name = "countries")
19
@IdClass(CountryEntity.class)
20
public class CountryEntity implements Serializable {
21
    /**
22
     * Name of country, serves as ID
23
     */
24
    @Id
25
    private String name;
26

  
27
    @ManyToOne
28
    @JoinColumn(name = "catalog_id")
29
    @Id
30
    private CatalogEntity catalog;
31
}
backend/src/main/java/cz/zcu/kiv/backendapi/country/CountryRepository.java
9 9
 */
10 10
@Repository
11 11
@Transactional(readOnly = true)
12
public interface CountryRepository extends JpaRepository<CountryEntity, CountryEntity> {
12
public interface CountryRepository extends JpaRepository<Country, Country> {
13 13
}
backend/src/main/java/cz/zcu/kiv/backendapi/exception/ApiRequestException.java
12 12
        this.httpStatus = httpStatus;
13 13
    }
14 14

  
15
    public ApiRequestException(String message, Throwable cause, HttpStatus httpStatus) {
16
        super(message, cause);
17
        this.httpStatus = httpStatus;
18
    }
19 15
}
backend/src/main/java/cz/zcu/kiv/backendapi/password/PasswordDto.java
1
package cz.zcu.kiv.backendapi.password;
2

  
3
import com.fasterxml.jackson.annotation.JsonIgnore;
4
import cz.zcu.kiv.backendapi.validation.PasswordMatches;
5
import lombok.Data;
6
import lombok.NoArgsConstructor;
7

  
8
import javax.validation.constraints.NotEmpty;
9
import javax.validation.constraints.NotNull;
10
import javax.validation.constraints.Size;
11

  
12
/**
13
 * Password data object
14
 */
15
@Data
16
@PasswordMatches
17
@NoArgsConstructor
18
public class PasswordDto {
19
    /**
20
     * Minimal length for password
21
     */
22
    @JsonIgnore
23
    private  static final int MIN_PASSWORD_LENGTH = 8;
24

  
25
    /**
26
     * New password - must be strong enough
27
     */
28
    @NotNull(message = "Password must not be null")
29
    @NotEmpty(message = "Password must not be empty")
30
    @Size(min = MIN_PASSWORD_LENGTH, message = "Password must be at least " + MIN_PASSWORD_LENGTH + " characters long")
31
    private String password;
32

  
33
    /**
34
     * New password confirmation - must match new password
35
     */
36
    @NotNull(message = "Confirmation password must not be null")
37
    @NotEmpty(message = "Confirmation password must not be empty")
38
    private String confirmationPassword;
39

  
40
}
backend/src/main/java/cz/zcu/kiv/backendapi/security/SecurityConfig.java
8 8
import lombok.RequiredArgsConstructor;
9 9
import org.springframework.context.annotation.Bean;
10 10
import org.springframework.context.annotation.Configuration;
11
import org.springframework.http.HttpMethod;
11 12
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
12 13
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
13 14
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
......
61 62
                .and()
62 63
                .authorizeRequests()
63 64
                .antMatchers(permittedUrls).permitAll()
64
                .antMatchers("/admin/**").hasRole(Role.ADMIN.name())
65
                .antMatchers("/user/update-permissions/**", "/user/reset-password/**").hasRole(Role.ADMIN.name())
66
                .antMatchers(HttpMethod.DELETE, "/user/**").hasRole(Role.ADMIN.name())
65 67
                .antMatchers("/write/**").hasAuthority(Permission.WRITE.name())
66 68
                .antMatchers("/read/**").hasAuthority(Permission.READ.name())
67 69
                .antMatchers("/delete/**").hasAuthority(Permission.DELETE.name())
backend/src/main/java/cz/zcu/kiv/backendapi/security/jwt/JwtUtils.java
59 59
     * Claim authorities name
60 60
     */
61 61
    private String claimAuthoritiesName;
62

  
63
    public JwtUtils() {
64
    }
62
    
65 63

  
66 64
    /**
67 65
     * Returns algorithm for JWT
backend/src/main/java/cz/zcu/kiv/backendapi/type/ITypeService.java
8 8
 */
9 9
public interface ITypeService {
10 10

  
11
    void saveType(TypeEntity typeEntity);
11
    void saveType(Type type);
12 12

  
13
    void saveTypes(List<TypeEntity> typesEntities);
13
    void saveTypes(List<Type> typesEntities);
14 14

  
15
    Optional<TypeEntity> getTypeByName(String type);
15
    Optional<Type> getTypeByName(String type);
16 16
}
backend/src/main/java/cz/zcu/kiv/backendapi/type/Type.java
1
package cz.zcu.kiv.backendapi.type;
2

  
3
import lombok.AllArgsConstructor;
4
import lombok.Data;
5
import lombok.NoArgsConstructor;
6

  
7
import javax.persistence.Entity;
8
import javax.persistence.Id;
9
import javax.persistence.Table;
10

  
11
/**
12
 * Type entity representing type of geographic entry
13
 */
14
@Data
15
@NoArgsConstructor
16
@AllArgsConstructor
17
@Entity
18
@Table(name = "types")
19
public class Type {
20
    /**
21
     * Type (e.g. river), serves as ID
22
     */
23
    @Id
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff