Revize abaa5f46
Přidáno uživatelem Jakub Šmíd před asi 3 roky(ů)
- ID abaa5f461242c640ae1e7daaddb6bfc1b1419db9
- Rodič c1df89f5
backend/Dockerfile | ||
---|---|---|
3 | 3 |
ENV PORT 8080 |
4 | 4 |
EXPOSE 8080 |
5 | 5 |
COPY target/*.jar /opt/app.jar |
6 |
#COPY dump.sql /docker-entrypoint-initdb.d/ |
|
6 | 7 |
ENTRYPOINT exec java $JAVA_OPTS -jar app.jar |
backend/docker-compose.yml | ||
---|---|---|
12 | 12 |
- 5432 |
13 | 13 |
ports: |
14 | 14 |
- "5432:5432" # expose port 5432 (PostgreSQL) out of the docker container to the local machine |
15 |
volumes: |
|
16 |
- ./init.sql:/docker-entrypoint-initdb.d/init.sql |
|
17 |
- db-data:/var/lib/postgresql/data |
|
15 | 18 |
|
16 | 19 |
|
17 | 20 |
app: # Spring boot application |
backend/src/main/java/cz/zcu/kiv/backendapi/alternativename/AlternativeName.java | ||
---|---|---|
1 | 1 |
package cz.zcu.kiv.backendapi.alternativename; |
2 | 2 |
|
3 | 3 |
import cz.zcu.kiv.backendapi.catalog.CatalogItem; |
4 |
import lombok.*; |
|
4 |
import lombok.Getter; |
|
5 |
import lombok.NoArgsConstructor; |
|
6 |
import lombok.Setter; |
|
5 | 7 |
|
6 | 8 |
import javax.persistence.*; |
7 |
import java.io.Serializable;
|
|
9 |
import java.util.UUID;
|
|
8 | 10 |
|
9 | 11 |
/** |
10 | 12 |
* Alternative name entity representing alternative name of catalog item |
11 | 13 |
*/ |
12 |
@Data |
|
13 |
@EqualsAndHashCode(exclude = "catalogItem") |
|
14 |
@ToString(exclude = "catalogItem") |
|
14 |
@Getter |
|
15 |
@Setter |
|
15 | 16 |
@NoArgsConstructor |
16 |
@AllArgsConstructor |
|
17 | 17 |
@Entity |
18 | 18 |
@Table(name = "alternative_names") |
19 |
@IdClass(AlternativeName.class) |
|
20 |
public class AlternativeName implements Serializable { |
|
19 |
public class AlternativeName { |
|
21 | 20 |
/** |
22 |
* Name, serves as ID
|
|
21 |
* Id
|
|
23 | 22 |
*/ |
24 | 23 |
@Id |
24 |
@GeneratedValue |
|
25 |
private UUID id; |
|
26 |
|
|
27 |
/** |
|
28 |
* Name |
|
29 |
*/ |
|
25 | 30 |
private String name; |
26 | 31 |
|
27 | 32 |
/** |
28 | 33 |
* Catalog entity |
29 | 34 |
*/ |
30 |
@ManyToOne |
|
35 |
@ManyToOne(fetch = FetchType.LAZY)
|
|
31 | 36 |
@JoinColumn(name = "catalog_item_id") |
32 |
@Id |
|
33 | 37 |
private CatalogItem catalogItem; |
38 |
|
|
39 |
/** |
|
40 |
* Creates new alternative name with name and catalog item |
|
41 |
* |
|
42 |
* @param name name |
|
43 |
* @param catalogItem catalog item |
|
44 |
*/ |
|
45 |
public AlternativeName(String name, CatalogItem catalogItem) { |
|
46 |
this.name = name; |
|
47 |
this.catalogItem = catalogItem; |
|
48 |
} |
|
34 | 49 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/alternativename/AlternativeNameRepository.java | ||
---|---|---|
3 | 3 |
import org.springframework.data.jpa.repository.JpaRepository; |
4 | 4 |
import org.springframework.stereotype.Repository; |
5 | 5 |
|
6 |
import java.util.UUID; |
|
7 |
|
|
6 | 8 |
/** |
7 | 9 |
* Alternative name repository |
8 | 10 |
*/ |
9 | 11 |
@Repository |
10 |
public interface AlternativeNameRepository extends JpaRepository<AlternativeName, AlternativeName> {
|
|
12 |
public interface AlternativeNameRepository extends JpaRepository<AlternativeName, UUID> {
|
|
11 | 13 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/alternativename/AlternativeNameServiceImpl.java | ||
---|---|---|
1 |
package cz.zcu.kiv.backendapi.alternativename; |
|
2 |
|
|
3 |
import lombok.RequiredArgsConstructor; |
|
4 |
import org.springframework.stereotype.Service; |
|
5 |
import org.springframework.transaction.annotation.Transactional; |
|
6 |
|
|
7 |
/** |
|
8 |
* Alternative name service implementation |
|
9 |
*/ |
|
10 |
@Service |
|
11 |
@Transactional |
|
12 |
@RequiredArgsConstructor |
|
13 |
public class AlternativeNameServiceImpl implements IAlternativeNameService { |
|
14 |
|
|
15 |
/** |
|
16 |
* Alternative name repository |
|
17 |
*/ |
|
18 |
private final AlternativeNameRepository alternativeNameRepository; |
|
19 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/alternativename/IAlternativeNameService.java | ||
---|---|---|
1 |
package cz.zcu.kiv.backendapi.alternativename; |
|
2 |
|
|
3 |
/** |
|
4 |
* Alternative name service interface |
|
5 |
*/ |
|
6 |
public interface IAlternativeNameService { |
|
7 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/bibliography/Bibliography.java | ||
---|---|---|
1 | 1 |
package cz.zcu.kiv.backendapi.bibliography; |
2 | 2 |
|
3 | 3 |
import cz.zcu.kiv.backendapi.catalog.CatalogItem; |
4 |
import lombok.*; |
|
4 |
import lombok.Getter; |
|
5 |
import lombok.NoArgsConstructor; |
|
6 |
import lombok.Setter; |
|
5 | 7 |
|
6 | 8 |
import javax.persistence.*; |
7 | 9 |
import java.io.Serializable; |
10 |
import java.util.UUID; |
|
8 | 11 |
|
9 | 12 |
/** |
10 | 13 |
* Bibliography entity representing bibliography |
11 | 14 |
*/ |
12 |
@Data |
|
13 |
@EqualsAndHashCode(exclude = "catalogItem") |
|
14 |
@ToString(exclude = "catalogItem") |
|
15 |
@Getter |
|
16 |
@Setter |
|
15 | 17 |
@NoArgsConstructor |
16 |
@AllArgsConstructor |
|
17 | 18 |
@Entity |
18 | 19 |
@Table(name = "bibliography") |
19 |
@IdClass(Bibliography.class) |
|
20 | 20 |
public class Bibliography implements Serializable { |
21 | 21 |
/** |
22 |
* Source, serves as ID
|
|
22 |
* Id
|
|
23 | 23 |
*/ |
24 | 24 |
@Id |
25 |
@GeneratedValue |
|
26 |
private UUID id; |
|
27 |
|
|
28 |
/** |
|
29 |
* Source |
|
30 |
*/ |
|
25 | 31 |
private String source; |
26 | 32 |
|
27 |
@ManyToOne |
|
33 |
/** |
|
34 |
* Catalog item |
|
35 |
*/ |
|
36 |
@ManyToOne(fetch = FetchType.LAZY) |
|
28 | 37 |
@JoinColumn(name = "catalog_item_id") |
29 | 38 |
private CatalogItem catalogItem; |
39 |
|
|
40 |
/** |
|
41 |
* Creates new bibliography with source and catalog item |
|
42 |
* |
|
43 |
* @param source source |
|
44 |
* @param catalogItem catalog item |
|
45 |
*/ |
|
46 |
public Bibliography(String source, CatalogItem catalogItem) { |
|
47 |
this.source = source; |
|
48 |
this.catalogItem = catalogItem; |
|
49 |
} |
|
30 | 50 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/bibliography/BibliographyRepository.java | ||
---|---|---|
3 | 3 |
import org.springframework.data.jpa.repository.JpaRepository; |
4 | 4 |
import org.springframework.stereotype.Repository; |
5 | 5 |
|
6 |
import java.util.UUID; |
|
7 |
|
|
6 | 8 |
/** |
7 | 9 |
* Bibliography repository |
8 | 10 |
*/ |
9 | 11 |
@Repository |
10 |
public interface BibliographyRepository extends JpaRepository<Bibliography, Bibliography> {
|
|
12 |
public interface BibliographyRepository extends JpaRepository<Bibliography, UUID> {
|
|
11 | 13 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/bibliography/BibliographyServiceImpl.java | ||
---|---|---|
1 |
package cz.zcu.kiv.backendapi.bibliography; |
|
2 |
|
|
3 |
import lombok.RequiredArgsConstructor; |
|
4 |
import org.springframework.stereotype.Service; |
|
5 |
import org.springframework.transaction.annotation.Transactional; |
|
6 |
|
|
7 |
/** |
|
8 |
* Bibliography service implementation |
|
9 |
*/ |
|
10 |
@Service |
|
11 |
@Transactional |
|
12 |
@RequiredArgsConstructor |
|
13 |
public class BibliographyServiceImpl implements IBibliographyService { |
|
14 |
/** |
|
15 |
* Bibliography repository |
|
16 |
*/ |
|
17 |
private final BibliographyRepository bibliographyRepository; |
|
18 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/bibliography/IBibliographyService.java | ||
---|---|---|
1 |
package cz.zcu.kiv.backendapi.bibliography; |
|
2 |
|
|
3 |
/** |
|
4 |
* Bibliography service interface |
|
5 |
*/ |
|
6 |
public interface IBibliographyService { |
|
7 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogController.java | ||
---|---|---|
44 | 44 |
@GetMapping("") |
45 | 45 |
@Operation(summary = "returns catalog items based on filter") |
46 | 46 |
public ResponseEntity<List<CatalogItemDto>> getCatalog(@RequestParam(defaultValue = "") String name, @RequestParam(defaultValue = "") String country, @RequestParam(defaultValue = "") String type) { |
47 |
return new ResponseEntity<>(catalogService.getCatalog(name, country, type), HttpStatus.OK); |
|
47 |
|
|
48 |
List<CatalogItemDto> catalog = null; |
|
49 |
long start = System.currentTimeMillis(); |
|
50 |
catalog = catalogService.getCatalog3(name, country, type); |
|
51 |
System.out.println(catalog.size()); |
|
52 |
long time1 = System.currentTimeMillis() - start; |
|
53 |
start = System.currentTimeMillis(); |
|
54 |
catalog = catalogService.getCatalog2(name, country, type); |
|
55 |
System.out.println(catalog.size()); |
|
56 |
|
|
57 |
long time2 = System.currentTimeMillis() - start; |
|
58 |
start = System.currentTimeMillis(); |
|
59 |
catalog = catalogService.getCatalog(name, country, type); |
|
60 |
System.out.println(catalog.size()); |
|
61 |
|
|
62 |
long time3 = System.currentTimeMillis() - start; |
|
63 |
System.out.println(time1 + "\t" + time2 + "\t" + time3); |
|
64 |
return new ResponseEntity<>(catalog, HttpStatus.OK); |
|
48 | 65 |
} |
49 | 66 |
|
50 | 67 |
/** |
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogItem.java | ||
---|---|---|
5 | 5 |
import cz.zcu.kiv.backendapi.country.Country; |
6 | 6 |
import cz.zcu.kiv.backendapi.type.Type; |
7 | 7 |
import cz.zcu.kiv.backendapi.writtenform.WrittenForm; |
8 |
import lombok.Data;
|
|
8 |
import lombok.Getter;
|
|
9 | 9 |
import lombok.NoArgsConstructor; |
10 |
import lombok.Setter; |
|
10 | 11 |
import org.hibernate.annotations.Fetch; |
11 | 12 |
import org.hibernate.annotations.FetchMode; |
12 | 13 |
import org.hibernate.annotations.LazyCollection; |
13 | 14 |
import org.hibernate.annotations.LazyCollectionOption; |
14 | 15 |
|
15 | 16 |
import javax.persistence.*; |
16 |
import java.util.*; |
|
17 |
import java.util.regex.Matcher; |
|
18 |
import java.util.regex.Pattern; |
|
19 |
import java.util.stream.Collectors; |
|
17 |
import java.util.HashSet; |
|
18 |
import java.util.Set; |
|
19 |
import java.util.UUID; |
|
20 | 20 |
|
21 | 21 |
/** |
22 | 22 |
* Catalog entity representing catalog item |
23 | 23 |
*/ |
24 |
@Data |
|
24 |
@Getter |
|
25 |
@Setter |
|
25 | 26 |
@NoArgsConstructor |
26 | 27 |
@Entity |
27 |
@Table(name = "catalog_item") |
|
28 |
//@NamedEntityGraph(name = "graph", attributeNodes = { |
|
29 |
// @NamedAttributeNode("bibliography"), |
|
30 |
// @NamedAttributeNode("alternativeNames"), |
|
31 |
// @NamedAttributeNode("countries"), |
|
32 |
// @NamedAttributeNode("writtenForms"), |
|
33 |
// @NamedAttributeNode("types"), |
|
34 |
//}) |
|
28 |
@Table(name = "catalog_items") |
|
35 | 29 |
public class CatalogItem { |
36 |
private static final String INTEGER_PATTERN = "\\d+"; |
|
37 |
private static final String DOUBLE_PATTERN = "(\\d+[.]\\d+)|(\\d+)"; |
|
38 |
private static final String EMPTY_ENTRY = "–"; |
|
39 | 30 |
/** |
40 | 31 |
* Catalog item id |
41 | 32 |
*/ |
... | ... | |
66 | 57 |
/** |
67 | 58 |
* Bibliography |
68 | 59 |
*/ |
69 |
@OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL)
|
|
60 |
@OneToMany(mappedBy = "catalogItem", orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
|
70 | 61 |
@LazyCollection(LazyCollectionOption.FALSE) |
71 | 62 |
@Fetch(FetchMode.SUBSELECT) |
72 |
private Set<Bibliography> bibliography = Collections.emptySet();
|
|
63 |
private Set<Bibliography> bibliography = new HashSet<>();
|
|
73 | 64 |
|
74 | 65 |
/** |
75 | 66 |
* Countries |
76 | 67 |
*/ |
77 |
@OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL)
|
|
68 |
@OneToMany(mappedBy = "catalogItem", orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
|
78 | 69 |
@LazyCollection(LazyCollectionOption.FALSE) |
79 | 70 |
@Fetch(FetchMode.SUBSELECT) |
80 |
private Set<Country> countries = Collections.emptySet();
|
|
71 |
private Set<Country> countries = new HashSet<>();
|
|
81 | 72 |
|
82 | 73 |
/** |
83 | 74 |
* Written forms |
84 | 75 |
*/ |
85 |
@OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL)
|
|
76 |
@OneToMany(mappedBy = "catalogItem", orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
|
86 | 77 |
@LazyCollection(LazyCollectionOption.FALSE) |
87 | 78 |
@Fetch(FetchMode.SUBSELECT) |
88 |
private Set<WrittenForm> writtenForms = Collections.emptySet();
|
|
79 |
private Set<WrittenForm> writtenForms = new HashSet<>();
|
|
89 | 80 |
|
90 | 81 |
/** |
91 | 82 |
* Alternative names |
92 | 83 |
*/ |
93 |
@OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL)
|
|
84 |
@OneToMany(mappedBy = "catalogItem", orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
|
94 | 85 |
@LazyCollection(LazyCollectionOption.FALSE) |
95 | 86 |
@Fetch(FetchMode.SUBSELECT) |
96 |
private Set<AlternativeName> alternativeNames = Collections.emptySet(); |
|
97 |
|
|
87 |
private Set<AlternativeName> alternativeNames = new HashSet<>(); |
|
98 | 88 |
/** |
99 | 89 |
* Set of user roles - many-to-many relationship |
100 | 90 |
*/ |
... | ... | |
109 | 99 |
@JoinColumn(name = "type", referencedColumnName = "type") |
110 | 100 |
} |
111 | 101 |
) |
112 |
private Set<Type> types = Collections.emptySet(); |
|
113 |
|
|
114 |
public CatalogItem(final List<String> csvFields) { |
|
115 |
|
|
116 |
this.name = csvFields.get(1); |
|
117 |
List<String> stringList = processListField(csvFields.get(2)); |
|
118 |
this.alternativeNames = stringList.stream().map(s -> new AlternativeName(s, this)).collect(Collectors.toSet()); |
|
119 |
|
|
120 |
this.certainty = processIntField(csvFields.get(3)); |
|
121 |
this.latitude = processDoubleField(csvFields.get(4)); |
|
122 |
this.longitude = processDoubleField(csvFields.get(5)); |
|
123 |
|
|
124 |
stringList = processListField(csvFields.get(6)); |
|
125 |
this.writtenForms = stringList.stream().map(s -> new WrittenForm(s, this)).collect(Collectors.toSet()); |
|
126 |
|
|
127 |
stringList = processListField(csvFields.get(7)); |
|
128 |
this.types = stringList.stream().map(Type::new).collect(Collectors.toSet()); |
|
129 |
|
|
130 |
stringList = processListField(csvFields.get(8)); |
|
131 |
this.countries = stringList.stream().map(s -> new Country(s, this)).collect(Collectors.toSet()); |
|
132 |
|
|
133 |
stringList = processListField(csvFields.get(9)); |
|
134 |
this.bibliography = stringList.stream().map(s -> new Bibliography(s, this)).collect(Collectors.toSet()); |
|
135 |
} |
|
136 |
|
|
137 |
private int processIntField(String field) { |
|
138 |
Matcher matcher = Pattern.compile(INTEGER_PATTERN).matcher(field); |
|
139 |
if (matcher.find()) { |
|
140 |
return Integer.parseInt(matcher.group()); |
|
141 |
} else { |
|
142 |
return 0; |
|
143 |
} |
|
144 |
} |
|
145 |
|
|
146 |
private double processDoubleField(String field) { |
|
147 |
Matcher matcher = Pattern.compile(DOUBLE_PATTERN).matcher(field); |
|
148 |
if (matcher.find()) { |
|
149 |
return Double.parseDouble(matcher.group()); |
|
150 |
} else { |
|
151 |
return 0.0; |
|
152 |
} |
|
153 |
} |
|
154 |
|
|
155 |
private List<String> processListField(String field) { |
|
156 |
if (field.isEmpty() || field.equals(EMPTY_ENTRY)) { |
|
157 |
return new ArrayList<>(); |
|
158 |
} |
|
159 |
return Arrays.stream(field.split(",")).map(String::trim).filter(item -> !item.isEmpty()).collect(Collectors.toList()); |
|
160 |
} |
|
102 |
private Set<Type> types = new HashSet<>(); |
|
161 | 103 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogItemDto.java | ||
---|---|---|
5 | 5 |
import lombok.Data; |
6 | 6 |
import lombok.NoArgsConstructor; |
7 | 7 |
|
8 |
import java.util.Collections; |
|
9 |
import java.util.Set; |
|
10 |
import java.util.UUID; |
|
8 |
import java.util.*; |
|
9 |
import java.util.regex.Matcher; |
|
10 |
import java.util.regex.Pattern; |
|
11 |
import java.util.stream.Collectors; |
|
11 | 12 |
|
12 | 13 |
/** |
13 | 14 |
* Class representing catalog item DTO |
... | ... | |
16 | 17 |
@AllArgsConstructor |
17 | 18 |
@NoArgsConstructor |
18 | 19 |
public class CatalogItemDto { |
20 |
private static final String INTEGER_PATTERN = "\\d+"; |
|
21 |
private static final String DOUBLE_PATTERN = "(\\d+[.]\\d+)|(\\d+)"; |
|
22 |
private static final String EMPTY_ENTRY = "–"; |
|
19 | 23 |
/** |
20 | 24 |
* Id |
21 | 25 |
*/ |
... | ... | |
67 | 71 |
*/ |
68 | 72 |
private Set<String> types = Collections.emptySet(); |
69 | 73 |
|
74 |
public CatalogItemDto(List<String> csvFields) { |
|
75 |
this.name = csvFields.get(1); |
|
76 |
Set<String> stringList = processListField(csvFields.get(2)); |
|
77 |
this.alternativeNames = new HashSet<>(stringList); |
|
78 |
|
|
79 |
this.certainty = processIntField(csvFields.get(3)); |
|
80 |
this.latitude = processDoubleField(csvFields.get(4)); |
|
81 |
this.longitude = processDoubleField(csvFields.get(5)); |
|
82 |
|
|
83 |
stringList = processListField(csvFields.get(6)); |
|
84 |
this.writtenForms = new HashSet<>(stringList); |
|
85 |
|
|
86 |
stringList = processListField(csvFields.get(7)); |
|
87 |
this.types = new HashSet<>(stringList); |
|
88 |
|
|
89 |
stringList = processListField(csvFields.get(8)); |
|
90 |
this.countries = new HashSet<>(stringList); |
|
91 |
|
|
92 |
stringList = processListField(csvFields.get(9)); |
|
93 |
this.bibliography = new HashSet<>(stringList); |
|
94 |
} |
|
95 |
|
|
96 |
private int processIntField(String field) { |
|
97 |
Matcher matcher = Pattern.compile(INTEGER_PATTERN).matcher(field); |
|
98 |
if (matcher.find()) { |
|
99 |
return Integer.parseInt(matcher.group()); |
|
100 |
} else { |
|
101 |
return 0; |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
private double processDoubleField(String field) { |
|
106 |
Matcher matcher = Pattern.compile(DOUBLE_PATTERN).matcher(field); |
|
107 |
if (matcher.find()) { |
|
108 |
return Double.parseDouble(matcher.group()); |
|
109 |
} else { |
|
110 |
return 0.0; |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
private Set<String> processListField(String field) { |
|
115 |
if (field.isEmpty() || field.equals(EMPTY_ENTRY)) { |
|
116 |
return new HashSet<>(); |
|
117 |
} |
|
118 |
return Arrays.stream(field.split(",")).map(String::trim).filter(item -> !item.isEmpty()).collect(Collectors.toSet()); |
|
119 |
} |
|
120 |
|
|
70 | 121 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogItemRepository.java | ||
---|---|---|
3 | 3 |
import org.springframework.data.jpa.repository.JpaRepository; |
4 | 4 |
import org.springframework.data.jpa.repository.Query; |
5 | 5 |
import org.springframework.stereotype.Repository; |
6 |
import org.springframework.transaction.annotation.Transactional; |
|
6 | 7 |
|
7 |
import java.util.Set;
|
|
8 |
import java.util.List;
|
|
8 | 9 |
import java.util.UUID; |
9 | 10 |
|
10 | 11 |
/** |
11 | 12 |
* Catalog repository |
12 | 13 |
*/ |
13 |
@Repository |
|
14 |
@Repository()
|
|
14 | 15 |
public interface CatalogItemRepository extends JpaRepository<CatalogItem, UUID> { |
15 | 16 |
|
16 | 17 |
/** |
... | ... | |
22 | 23 |
* @return set of catalog items satisfying filter conditions |
23 | 24 |
*/ |
24 | 25 |
@Query("SELECT DISTINCT e FROM CatalogItem e " + |
25 |
"LEFT JOIN FETCH AlternativeName a ON e = a.catalogItem " +
|
|
26 |
"LEFT JOIN FETCH Country c ON e = c.catalogItem " +
|
|
27 |
"INNER JOIN FETCH e.types t " +
|
|
26 |
"LEFT JOIN e.alternativeNames a " +
|
|
27 |
"LEFT JOIN e.countries c " +
|
|
28 |
"LEFT JOIN e.types t " +
|
|
28 | 29 |
"WHERE (?1 = '' OR UPPER(e.name) LIKE UPPER(?1) OR UPPER(a.name) LIKE UPPER(?1)) " + |
29 | 30 |
"AND (?2 = '' OR UPPER(c.name) LIKE UPPER(?2)) " + |
30 | 31 |
"AND (?3 = '' OR UPPER(t.type) LIKE UPPER(?3))") |
31 |
Set<CatalogItem> filterCatalog(String name, String country, String type); |
|
32 |
@Transactional(readOnly = true) |
|
33 |
List<CatalogItem> filterCatalog(String name, String country, String type); |
|
34 |
|
|
35 |
@Query("SELECT DISTINCT e FROM CatalogItem e " + |
|
36 |
"LEFT JOIN e.alternativeNames a " + |
|
37 |
"LEFT JOIN e.countries c " + |
|
38 |
"WHERE (?1 = '' OR UPPER(e.name) LIKE UPPER(?1) OR UPPER(a.name) LIKE UPPER(?1)) " + |
|
39 |
"AND (?2 = '' OR UPPER(c.name) LIKE UPPER(?2))") |
|
40 |
List<CatalogItem> filterCatalog2(String name, String country); |
|
32 | 41 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogItemServiceImpl.java | ||
---|---|---|
11 | 11 |
import lombok.extern.slf4j.Slf4j; |
12 | 12 |
import org.springframework.http.HttpStatus; |
13 | 13 |
import org.springframework.stereotype.Service; |
14 |
import org.springframework.transaction.annotation.Transactional; |
|
15 | 14 |
|
16 | 15 |
import java.util.List; |
17 |
import java.util.Set; |
|
18 | 16 |
import java.util.UUID; |
17 |
import java.util.function.Predicate; |
|
18 |
import java.util.regex.Pattern; |
|
19 | 19 |
import java.util.stream.Collectors; |
20 | 20 |
|
21 | 21 |
/** |
22 | 22 |
* Catalog item service implementation |
23 | 23 |
*/ |
24 | 24 |
@Service |
25 |
@Transactional
|
|
25 |
//@Transactional(readOnly = true)
|
|
26 | 26 |
@RequiredArgsConstructor |
27 | 27 |
@Slf4j |
28 | 28 |
public class CatalogItemServiceImpl implements ICatalogItemService { |
... | ... | |
62 | 62 |
private final ITypeService typeService; |
63 | 63 |
|
64 | 64 |
@Override |
65 |
public void saveCatalog(List<CatalogItem> catalogItems) { |
|
65 |
public void saveCatalog(List<CatalogItemDto> catalogItems) {
|
|
66 | 66 |
log.info("Saving catalog"); |
67 |
catalogItems.forEach(this::saveCatalogEntity); |
|
67 |
|
|
68 |
catalogItems.forEach(this::saveCatalogItem); |
|
68 | 69 |
} |
69 | 70 |
|
70 | 71 |
@Override |
... | ... | |
98 | 99 |
|
99 | 100 |
@Override |
100 | 101 |
public List<CatalogItemDto> getCatalog(String name, String country, String type) { |
101 |
log.info("Retrieving catalog"); |
|
102 |
List<CatalogItem> catalogItems; |
|
103 |
// if (name.equals("") && country.equals("") && type.equals("")) { |
|
104 |
// catalogItems = catalogItemRepository.findAll(); |
|
105 |
// } else { |
|
102 | 106 |
name = name.replaceAll(WILDCARD_CHARACTER_REGEX, WILDCARD_CHARACTER_REGEX_SQL); |
103 | 107 |
name = name.replaceAll(WILDCARD_CHARACTERS_REGEX, WILDCARD_CHARACTERS_REGEX_SQL); |
104 | 108 |
country = country.replaceAll(WILDCARD_CHARACTER_REGEX, WILDCARD_CHARACTER_REGEX_SQL); |
105 | 109 |
country = country.replaceAll(WILDCARD_CHARACTERS_REGEX, WILDCARD_CHARACTERS_REGEX_SQL); |
106 | 110 |
type = type.replaceAll(WILDCARD_CHARACTER_REGEX, WILDCARD_CHARACTER_REGEX_SQL); |
107 | 111 |
type = type.replaceAll(WILDCARD_CHARACTERS_REGEX, WILDCARD_CHARACTERS_REGEX_SQL); |
108 |
Set<CatalogItem> entities = catalogItemRepository.filterCatalog(name, country, type); |
|
109 |
return entities.stream().map(this::convertEntityToDto).collect(Collectors.toList()); |
|
112 |
long start = System.currentTimeMillis(); |
|
113 |
catalogItems = catalogItemRepository.filterCatalog(name, country, type); |
|
114 |
catalogItemRepository.flush(); |
|
115 |
// System.out.println("time: " + (System.currentTimeMillis() - start)); |
|
116 |
// } |
|
117 |
return catalogItems.stream().map(this::convertEntityToDto).collect(Collectors.toList()); |
|
118 |
} |
|
119 |
|
|
120 |
public List<CatalogItemDto> getCatalog2(String name, String country, String type) { |
|
121 |
List<CatalogItem> catalogItems; |
|
122 |
// if (name.equals("") && country.equals("") && type.equals("")) { |
|
123 |
// catalogItems = catalogItemRepository.findAll(); |
|
124 |
// } else { |
|
125 |
name = name.replaceAll(WILDCARD_CHARACTER_REGEX, WILDCARD_CHARACTER_REGEX_SQL); |
|
126 |
name = name.replaceAll(WILDCARD_CHARACTERS_REGEX, WILDCARD_CHARACTERS_REGEX_SQL); |
|
127 |
country = country.replaceAll(WILDCARD_CHARACTER_REGEX, WILDCARD_CHARACTER_REGEX_SQL); |
|
128 |
country = country.replaceAll(WILDCARD_CHARACTERS_REGEX, WILDCARD_CHARACTERS_REGEX_SQL); |
|
129 |
type = type.replaceAll(WILDCARD_CHARACTER_REGEX, "."); |
|
130 |
// type = type.replaceAll(WILDCARD_CHARACTERS_REGEX, WILDCARD_CHARACTERS_REGEX_SQL); |
|
131 |
long start = System.currentTimeMillis(); |
|
132 |
catalogItems = catalogItemRepository.filterCatalog2(name, country); |
|
133 |
if (!type.equals("")) { |
|
134 |
Pattern pattern = Pattern.compile(type); |
|
135 |
catalogItems = catalogItems.stream().filter(i -> i.getTypes().stream().anyMatch(t -> pattern.matcher(t.getType()).matches())).collect(Collectors.toList()); |
|
136 |
} |
|
137 |
// System.out.println("time: " + (System.currentTimeMillis() - start)); |
|
138 |
// } |
|
139 |
return catalogItems.stream().map(this::convertEntityToDto).collect(Collectors.toList()); |
|
140 |
} |
|
141 |
|
|
142 |
public List<CatalogItemDto> getCatalog3(String name, String country, String type) { |
|
143 |
List<CatalogItem> catalogItems; |
|
144 |
// if (name.equals("") && country.equals("") && type.equals("")) { |
|
145 |
// catalogItems = catalogItemRepository.findAll(); |
|
146 |
// } else { |
|
147 |
|
|
148 |
name = name.replaceAll(WILDCARD_CHARACTER_REGEX, "."); |
|
149 |
country = country.replaceAll(WILDCARD_CHARACTER_REGEX, "."); |
|
150 |
type = type.replaceAll(WILDCARD_CHARACTER_REGEX, "."); |
|
151 |
name = name.replaceAll(WILDCARD_CHARACTERS_REGEX, ".*"); |
|
152 |
country = country.replaceAll(WILDCARD_CHARACTERS_REGEX, ".*"); |
|
153 |
type = type.replaceAll(WILDCARD_CHARACTERS_REGEX, ".*"); |
|
154 |
Pattern patternName = Pattern.compile(name, Pattern.CASE_INSENSITIVE); |
|
155 |
Pattern patternCountry = Pattern.compile(country, Pattern.CASE_INSENSITIVE); |
|
156 |
Pattern patternType = Pattern.compile(type, Pattern.CASE_INSENSITIVE); |
|
157 |
long start = System.currentTimeMillis(); |
|
158 |
catalogItems = catalogItemRepository.findAll(); |
|
159 |
String finalType = type; |
|
160 |
Predicate<CatalogItem> predicateType = i -> finalType.equals("") || i.getTypes().stream().anyMatch(t -> patternType.matcher(t.getType()).matches()); |
|
161 |
String finalCountry = country; |
|
162 |
Predicate<CatalogItem> predicateCountry = i -> finalCountry.equals("") || i.getCountries().stream().anyMatch(t -> patternCountry.matcher(t.getName()).matches()); |
|
163 |
String finalName = name; |
|
164 |
Predicate<CatalogItem> predicateName = i -> finalName.equals("") || patternName.matcher(i.getName()).matches() || i.getAlternativeNames().stream().anyMatch(t -> patternName.matcher(t.getName()).matches()); |
|
165 |
// System.out.println("time: " + (System.currentTimeMillis() - start)); |
|
166 |
// } |
|
167 |
catalogItems = catalogItems.stream().filter(predicateName.and(predicateCountry).and(predicateType)).collect(Collectors.toList()); |
|
168 |
return catalogItems.stream().map(this::convertEntityToDto).collect(Collectors.toList()); |
|
110 | 169 |
} |
111 | 170 |
|
112 | 171 |
/** |
... | ... | |
134 | 193 |
catalogItem.setCertainty(catalogItemDto.getCertainty()); |
135 | 194 |
catalogItem.setLatitude(catalogItemDto.getLatitude()); |
136 | 195 |
catalogItem.setLongitude(catalogItemDto.getLongitude()); |
137 |
catalogItem.setBibliography(catalogItemDto.getBibliography() |
|
138 |
.stream().map(s -> new Bibliography(s, catalogItem)).collect(Collectors.toSet())); |
|
139 |
catalogItem.setTypes(catalogItemDto.getTypes() |
|
140 |
.stream().map(Type::new).collect(Collectors.toSet())); |
|
141 |
catalogItem.setCountries(catalogItemDto.getCountries() |
|
142 |
.stream().map(s -> new Country(s, catalogItem)).collect(Collectors.toSet())); |
|
143 |
catalogItem.setAlternativeNames(catalogItemDto.getAlternativeNames() |
|
144 |
.stream().map(s -> new AlternativeName(s, catalogItem)).collect(Collectors.toSet())); |
|
145 |
catalogItem.setWrittenForms(catalogItemDto.getWrittenForms() |
|
146 |
.stream().map(s -> new WrittenForm(s, catalogItem)).collect(Collectors.toSet())); |
|
196 |
|
|
197 |
catalogItem.getBibliography().clear(); |
|
198 |
catalogItem.getBibliography().addAll((catalogItemDto.getBibliography() |
|
199 |
.stream().map(s -> new Bibliography(s, catalogItem)).collect(Collectors.toSet()))); |
|
200 |
|
|
201 |
catalogItem.getTypes().clear(); |
|
202 |
catalogItem.getTypes().addAll((catalogItemDto.getTypes() |
|
203 |
.stream().map(Type::new).collect(Collectors.toSet()))); |
|
204 |
|
|
205 |
catalogItem.getCountries().clear(); |
|
206 |
catalogItem.getCountries().addAll((catalogItemDto.getCountries() |
|
207 |
.stream().map(s -> new Country(s, catalogItem)).collect(Collectors.toSet()))); |
|
208 |
|
|
209 |
catalogItem.getAlternativeNames().clear(); |
|
210 |
catalogItem.getAlternativeNames().addAll((catalogItemDto.getAlternativeNames() |
|
211 |
.stream().map(s -> new AlternativeName(s, catalogItem)).collect(Collectors.toSet()))); |
|
212 |
|
|
213 |
catalogItem.getWrittenForms().clear(); |
|
214 |
catalogItem.getWrittenForms().addAll((catalogItemDto.getWrittenForms() |
|
215 |
.stream().map(s -> new WrittenForm(s, catalogItem)).collect(Collectors.toSet()))); |
|
147 | 216 |
} |
148 | 217 |
|
149 | 218 |
/** |
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/ICatalogItemService.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
public interface ICatalogItemService { |
10 | 10 |
/** |
11 |
* Saves list of catalog items |
|
11 |
* Saves list of catalog items DTOs
|
|
12 | 12 |
* |
13 |
* @param catalogItems catalog items |
|
13 |
* @param catalogItems catalog items DTOs
|
|
14 | 14 |
*/ |
15 |
void saveCatalog(List<CatalogItem> catalogItems); |
|
15 |
void saveCatalog(List<CatalogItemDto> catalogItems);
|
|
16 | 16 |
|
17 | 17 |
/** |
18 | 18 |
* Saves one catalog item |
... | ... | |
46 | 46 |
*/ |
47 | 47 |
List<CatalogItemDto> getCatalog(String name, String country, String type); |
48 | 48 |
|
49 |
List<CatalogItemDto> getCatalog2(String name, String country, String type); |
|
50 |
|
|
51 |
List<CatalogItemDto> getCatalog3(String name, String country, String type); |
|
52 |
|
|
49 | 53 |
} |
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.CatalogItem; |
|
3 |
import cz.zcu.kiv.backendapi.catalog.CatalogItemDto;
|
|
4 | 4 |
import cz.zcu.kiv.backendapi.catalog.CatalogItemRepository; |
5 | 5 |
import cz.zcu.kiv.backendapi.catalog.ICatalogItemService; |
6 | 6 |
import cz.zcu.kiv.backendapi.titlepage.ITitlePageService; |
... | ... | |
15 | 15 |
import org.apache.commons.csv.CSVRecord; |
16 | 16 |
import org.springframework.context.ApplicationListener; |
17 | 17 |
import org.springframework.context.event.ContextRefreshedEvent; |
18 |
import org.springframework.jdbc.core.JdbcTemplate; |
|
18 | 19 |
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
19 | 20 |
import org.springframework.stereotype.Component; |
20 | 21 |
import org.springframework.transaction.annotation.Transactional; |
... | ... | |
24 | 25 |
import java.nio.charset.Charset; |
25 | 26 |
import java.nio.charset.StandardCharsets; |
26 | 27 |
import java.util.ArrayList; |
28 |
import java.util.HashSet; |
|
27 | 29 |
import java.util.List; |
30 |
import java.util.Set; |
|
28 | 31 |
|
29 | 32 |
//TODO comment or delete |
30 | 33 |
@Component |
... | ... | |
43 | 46 |
|
44 | 47 |
private final BCryptPasswordEncoder encoder; |
45 | 48 |
|
49 |
private final JdbcTemplate jdbcTemplate; |
|
50 |
|
|
51 |
|
|
46 | 52 |
@Override |
47 | 53 |
@Transactional |
48 | 54 |
public void onApplicationEvent(ContextRefreshedEvent event) { |
49 |
List<Type> types = loadTypes();
|
|
55 |
Set<Type> types = loadTypes();
|
|
50 | 56 |
for (Type type : types) { |
57 |
System.out.println(type.getType()); |
|
51 | 58 |
typeService.saveType(type); |
52 | 59 |
} |
53 |
List<CatalogItem> catalog = loadCatalog(); |
|
60 |
List<CatalogItemDto> catalog = loadCatalog();
|
|
54 | 61 |
catalogService.saveCatalog(catalog); |
55 | 62 |
|
56 | 63 |
titlePageService.updateTitlePage(new TitlePage(1L, "", "")); |
... | ... | |
61 | 68 |
UserEntity user2 = new UserEntity("normal", "normal", encoder.encode("password"), (byte) 1, false); |
62 | 69 |
userRepository.save(user2); |
63 | 70 |
|
71 |
File dump = new File("init.sql"); |
|
72 |
if (dump.exists()) { |
|
73 |
dump.delete(); |
|
74 |
} |
|
75 |
// jdbcTemplate.execute("script '" + dump.getAbsolutePath() + "'"); |
|
76 |
|
|
64 | 77 |
} |
65 | 78 |
|
66 |
private List<CatalogItem> loadCatalog() { |
|
67 |
List<CatalogItem> catalogEntities = new ArrayList<>();
|
|
79 |
private List<CatalogItemDto> loadCatalog() {
|
|
80 |
List<CatalogItemDto> catalogItemDtos = new ArrayList<>();
|
|
68 | 81 |
File csvData = new File("AssyrianProject-AllNoDupl-22-03-28.csv"); |
69 | 82 |
CSVParser parser; |
70 | 83 |
try { |
... | ... | |
73 | 86 |
.setSkipHeaderRecord(true) |
74 | 87 |
.build()); |
75 | 88 |
for (CSVRecord csvRecord : parser) { |
76 |
catalogEntities.add(new CatalogItem(csvRecord.toList()));
|
|
89 |
catalogItemDtos.add(new CatalogItemDto(csvRecord.toList()));
|
|
77 | 90 |
} |
78 | 91 |
} catch (IOException e) { |
79 | 92 |
e.printStackTrace(); |
80 | 93 |
} |
81 |
return catalogEntities;
|
|
94 |
return catalogItemDtos;
|
|
82 | 95 |
|
83 | 96 |
} |
84 | 97 |
|
85 |
private List<Type> loadTypes() {
|
|
86 |
List<Type> types = new ArrayList<>();
|
|
98 |
private Set<Type> loadTypes() {
|
|
99 |
Set<Type> types = new HashSet<>();
|
|
87 | 100 |
CSVParser parser; |
88 | 101 |
File csvData = new File("AssyrianProject-All.csv"); |
89 | 102 |
try { |
backend/src/main/java/cz/zcu/kiv/backendapi/country/Country.java | ||
---|---|---|
1 | 1 |
package cz.zcu.kiv.backendapi.country; |
2 | 2 |
|
3 | 3 |
import cz.zcu.kiv.backendapi.catalog.CatalogItem; |
4 |
import lombok.*; |
|
4 |
import lombok.Getter; |
|
5 |
import lombok.NoArgsConstructor; |
|
6 |
import lombok.Setter; |
|
5 | 7 |
|
6 | 8 |
import javax.persistence.*; |
7 |
import java.io.Serializable;
|
|
9 |
import java.util.UUID;
|
|
8 | 10 |
|
9 | 11 |
/** |
10 | 12 |
* Country entity representing country of catalog item |
11 | 13 |
*/ |
12 |
@Data |
|
13 |
@EqualsAndHashCode(exclude = "catalogItem") |
|
14 |
@ToString(exclude = "catalogItem") |
|
14 |
@Getter |
|
15 |
@Setter |
|
15 | 16 |
@NoArgsConstructor |
16 |
@AllArgsConstructor |
|
17 | 17 |
@Entity |
18 | 18 |
@Table(name = "countries") |
19 |
@IdClass(Country.class) |
|
20 |
public class Country implements Serializable { |
|
19 |
public class Country { |
|
21 | 20 |
/** |
22 |
* Name of country, serves as ID
|
|
21 |
* Id
|
|
23 | 22 |
*/ |
24 | 23 |
@Id |
24 |
@GeneratedValue |
|
25 |
private UUID uuid; |
|
26 |
|
|
27 |
/** |
|
28 |
* Name of country |
|
29 |
*/ |
|
25 | 30 |
private String name; |
26 | 31 |
|
27 |
@ManyToOne |
|
32 |
/** |
|
33 |
* Catalog item |
|
34 |
*/ |
|
35 |
@ManyToOne(fetch = FetchType.LAZY) |
|
28 | 36 |
@JoinColumn(name = "catalog_item_id") |
29 |
@Id |
|
30 | 37 |
private CatalogItem catalogItem; |
38 |
|
|
39 |
/** |
|
40 |
* Creates new country with name and catalog item |
|
41 |
* |
|
42 |
* @param name name of country |
|
43 |
* @param catalogItem catalog item |
|
44 |
*/ |
|
45 |
public Country(String name, CatalogItem catalogItem) { |
|
46 |
this.name = name; |
|
47 |
this.catalogItem = catalogItem; |
|
48 |
} |
|
31 | 49 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/country/CountryRepository.java | ||
---|---|---|
3 | 3 |
import org.springframework.data.jpa.repository.JpaRepository; |
4 | 4 |
import org.springframework.stereotype.Repository; |
5 | 5 |
|
6 |
import java.util.UUID; |
|
7 |
|
|
6 | 8 |
/** |
7 | 9 |
* Country repository |
8 | 10 |
*/ |
9 | 11 |
@Repository |
10 |
public interface CountryRepository extends JpaRepository<Country, Country> {
|
|
12 |
public interface CountryRepository extends JpaRepository<Country, UUID> {
|
|
11 | 13 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/country/CountryServiceImpl.java | ||
---|---|---|
1 |
package cz.zcu.kiv.backendapi.country; |
|
2 |
|
|
3 |
import lombok.RequiredArgsConstructor; |
|
4 |
import org.springframework.stereotype.Service; |
|
5 |
import org.springframework.transaction.annotation.Transactional; |
|
6 |
|
|
7 |
/** |
|
8 |
* Country service implementation |
|
9 |
*/ |
|
10 |
@Service |
|
11 |
@Transactional |
|
12 |
@RequiredArgsConstructor |
|
13 |
public class CountryServiceImpl implements ICountryService { |
|
14 |
|
|
15 |
/** |
|
16 |
* Country repository |
|
17 |
*/ |
|
18 |
private final CountryRepository countryRepository; |
|
19 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/country/ICountryService.java | ||
---|---|---|
1 |
package cz.zcu.kiv.backendapi.country; |
|
2 |
|
|
3 |
/** |
|
4 |
* Country service interface |
|
5 |
*/ |
|
6 |
public interface ICountryService { |
|
7 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/security/SecurityConfig.java | ||
---|---|---|
1 | 1 |
package cz.zcu.kiv.backendapi.security; |
2 | 2 |
|
3 |
import cz.zcu.kiv.backendapi.security.jwt.JwtTokenVerifier; |
|
4 | 3 |
import cz.zcu.kiv.backendapi.security.jwt.JwtUsernameAndPasswordAuthenticationFilter; |
5 | 4 |
import cz.zcu.kiv.backendapi.security.jwt.JwtUtils; |
6 |
import cz.zcu.kiv.backendapi.user.Role; |
|
7 |
import cz.zcu.kiv.backendapi.user.permission.Permission; |
|
8 | 5 |
import lombok.RequiredArgsConstructor; |
9 | 6 |
import org.springframework.context.annotation.Bean; |
10 | 7 |
import org.springframework.context.annotation.Configuration; |
11 |
import org.springframework.http.HttpMethod; |
|
12 | 8 |
import org.springframework.security.authentication.dao.DaoAuthenticationProvider; |
13 | 9 |
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; |
14 | 10 |
import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
... | ... | |
59 | 55 |
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) |
60 | 56 |
.and() |
61 | 57 |
.addFilter(new JwtUsernameAndPasswordAuthenticationFilter(authenticationManager(), jwtUtils)) |
62 |
.addFilterAfter(new JwtTokenVerifier(jwtUtils, permittedUrls), JwtUsernameAndPasswordAuthenticationFilter.class) |
|
58 |
// .addFilterAfter(new JwtTokenVerifier(jwtUtils, permittedUrls), JwtUsernameAndPasswordAuthenticationFilter.class)
|
|
63 | 59 |
.authorizeRequests() |
64 |
.antMatchers(permittedUrls).permitAll() |
|
65 |
.antMatchers("/user/update-permissions/**", "/user/reset-password/**").hasRole(Role.ADMIN.name()) |
|
66 |
.antMatchers(HttpMethod.DELETE, "/user/**").hasRole(Role.ADMIN.name()) |
|
67 |
.antMatchers("/write/**").hasAuthority(Permission.WRITE.name()) |
|
68 |
.antMatchers("/read/**").hasAuthority(Permission.READ.name()) |
|
69 |
.antMatchers("/delete/**").hasAuthority(Permission.DELETE.name()) |
|
70 |
.anyRequest() |
|
71 |
.authenticated(); |
|
60 |
// .antMatchers(permittedUrls).permitAll() |
|
61 |
// .antMatchers("/user/update-permissions/**", "/user/reset-password/**").hasRole(Role.ADMIN.name()) |
|
62 |
// .antMatchers(HttpMethod.DELETE, "/user/**").hasRole(Role.ADMIN.name()) |
|
63 |
// .antMatchers("/write/**").hasAuthority(Permission.WRITE.name()) |
|
64 |
// .antMatchers("/read/**").hasAuthority(Permission.READ.name()) |
|
65 |
// .antMatchers("/delete/**").hasAuthority(Permission.DELETE.name()) |
|
66 |
// .anyRequest() |
|
67 |
// .authenticated(); |
|
68 |
.anyRequest().permitAll(); |
|
72 | 69 |
} |
73 | 70 |
|
74 | 71 |
/** |
backend/src/main/java/cz/zcu/kiv/backendapi/type/Type.java | ||
---|---|---|
1 | 1 |
package cz.zcu.kiv.backendapi.type; |
2 | 2 |
|
3 |
import lombok.AllArgsConstructor; |
|
4 |
import lombok.Data; |
|
5 |
import lombok.NoArgsConstructor; |
|
3 |
import lombok.*; |
|
6 | 4 |
|
7 | 5 |
import javax.persistence.Entity; |
8 | 6 |
import javax.persistence.Id; |
7 |
import javax.persistence.Index; |
|
9 | 8 |
import javax.persistence.Table; |
10 | 9 |
|
11 | 10 |
/** |
12 | 11 |
* Type entity representing type of catalog item |
13 | 12 |
*/ |
14 |
@Data |
|
13 |
@Getter |
|
14 |
@Setter |
|
15 |
@EqualsAndHashCode |
|
15 | 16 |
@NoArgsConstructor |
16 | 17 |
@AllArgsConstructor |
17 | 18 |
@Entity |
18 |
@Table(name = "types") |
|
19 |
@Table(name = "types", indexes = @Index(name = "type_index", columnList = "type", unique = true))
|
|
19 | 20 |
public class Type { |
20 | 21 |
/** |
21 | 22 |
* Type (e.g. river), serves as ID |
backend/src/main/java/cz/zcu/kiv/backendapi/writtenform/IWrittenFormService.java | ||
---|---|---|
1 |
package cz.zcu.kiv.backendapi.writtenform; |
|
2 |
|
|
3 |
/** |
|
4 |
* Written form service interface |
|
5 |
*/ |
|
6 |
public interface IWrittenFormService { |
|
7 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/writtenform/WrittenForm.java | ||
---|---|---|
1 | 1 |
package cz.zcu.kiv.backendapi.writtenform; |
2 | 2 |
|
3 | 3 |
import cz.zcu.kiv.backendapi.catalog.CatalogItem; |
4 |
import lombok.*; |
|
4 |
import lombok.Getter; |
|
5 |
import lombok.NoArgsConstructor; |
|
6 |
import lombok.Setter; |
|
5 | 7 |
|
6 | 8 |
import javax.persistence.*; |
7 |
import java.io.Serializable;
|
|
9 |
import java.util.UUID;
|
|
8 | 10 |
|
9 | 11 |
/** |
10 | 12 |
* Written form entity representing written form of catalog item |
11 | 13 |
*/ |
12 |
@Data |
|
13 |
@EqualsAndHashCode(exclude = "catalogItem") |
|
14 |
@ToString(exclude = "catalogItem") |
|
14 |
@Getter |
|
15 |
@Setter |
|
15 | 16 |
@NoArgsConstructor |
16 |
@AllArgsConstructor |
|
17 | 17 |
@Entity |
18 | 18 |
@Table(name = "written_forms") |
19 |
@IdClass(WrittenForm.class) |
|
20 |
public class WrittenForm implements Serializable { |
|
19 |
public class WrittenForm { |
|
21 | 20 |
/** |
22 |
* Written form, serves as ID
|
|
21 |
* Id
|
|
23 | 22 |
*/ |
24 | 23 |
@Id |
24 |
@GeneratedValue |
|
25 |
private UUID id; |
|
26 |
|
|
27 |
/** |
|
28 |
* Written form |
|
29 |
*/ |
|
25 | 30 |
private String form; |
26 | 31 |
|
27 |
@ManyToOne |
|
32 |
/** |
|
33 |
* Catalog item |
|
34 |
*/ |
|
35 |
@ManyToOne(fetch = FetchType.LAZY) |
|
28 | 36 |
@JoinColumn(name = "catalog_item_id") |
29 |
@Id |
|
30 | 37 |
private CatalogItem catalogItem; |
38 |
|
|
39 |
/** |
|
40 |
* Creates new written form with form name and catalog item |
|
41 |
* |
|
42 |
* @param form form name |
|
43 |
* @param catalogItem catalog item |
|
44 |
*/ |
|
45 |
public WrittenForm(String form, CatalogItem catalogItem) { |
|
46 |
this.form = form; |
|
47 |
this.catalogItem = catalogItem; |
|
48 |
} |
|
31 | 49 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/writtenform/WrittenFormRepository.java | ||
---|---|---|
3 | 3 |
import org.springframework.data.jpa.repository.JpaRepository; |
4 | 4 |
import org.springframework.stereotype.Repository; |
5 | 5 |
|
6 |
import java.util.UUID; |
|
7 |
|
|
6 | 8 |
/** |
7 | 9 |
* Written form repository |
8 | 10 |
*/ |
9 | 11 |
@Repository |
10 |
public interface WrittenFormRepository extends JpaRepository<WrittenForm, WrittenForm> {
|
|
12 |
public interface WrittenFormRepository extends JpaRepository<WrittenForm, UUID> {
|
|
11 | 13 |
} |
backend/src/main/java/cz/zcu/kiv/backendapi/writtenform/WrittenFormServiceImpl.java | ||
---|---|---|
1 |
package cz.zcu.kiv.backendapi.writtenform; |
|
2 |
|
|
3 |
import lombok.RequiredArgsConstructor; |
|
4 |
import org.springframework.stereotype.Service; |
|
5 |
import org.springframework.transaction.annotation.Transactional; |
|
6 |
|
|
7 |
/** |
|
8 |
* Written form service implementation |
|
9 |
*/ |
|
10 |
@Service |
|
11 |
@Transactional |
|
12 |
@RequiredArgsConstructor |
|
13 |
public class WrittenFormServiceImpl implements IWrittenFormService { |
|
14 |
|
|
15 |
/** |
|
16 |
* Written form repository |
|
17 |
*/ |
|
18 |
private final WrittenFormRepository writtenFormRepository; |
|
19 |
} |
backend/src/main/resources/application.properties | ||
---|---|---|
9 | 9 |
spring.jpa.properties.hibernate.format_sql=true |
10 | 10 |
#spring.jpa.show-sql=true |
11 | 11 |
|
12 |
|
|
13 | 12 |
application.jwt.secretKey=securesecuresecuresecuresecuresecuresecuresecuresecuresecuresecuresecuresecure |
14 | 13 |
application.jwt.tokenPrefix=Bearer |
15 | 14 |
application.jwt.tokenExpirationAfterMinutes=15 |
backend/src/test/java/cz/zcu/kiv/backendapi/catalog/CatalogItemRepositoryTest.java | ||
---|---|---|
1 | 1 |
package cz.zcu.kiv.backendapi.catalog; |
2 | 2 |
|
3 | 3 |
import cz.zcu.kiv.backendapi.alternativename.AlternativeName; |
4 |
import cz.zcu.kiv.backendapi.alternativename.AlternativeNameRepository; |
|
5 |
import cz.zcu.kiv.backendapi.bibliography.Bibliography; |
|
6 |
import cz.zcu.kiv.backendapi.bibliography.BibliographyRepository; |
|
4 | 7 |
import cz.zcu.kiv.backendapi.country.Country; |
8 |
import cz.zcu.kiv.backendapi.country.CountryRepository; |
|
5 | 9 |
import cz.zcu.kiv.backendapi.type.Type; |
6 | 10 |
import cz.zcu.kiv.backendapi.type.TypeRepository; |
11 |
import cz.zcu.kiv.backendapi.writtenform.WrittenForm; |
|
12 |
import cz.zcu.kiv.backendapi.writtenform.WrittenFormRepository; |
|
7 | 13 |
import org.junit.jupiter.api.AfterEach; |
8 | 14 |
import org.junit.jupiter.api.BeforeEach; |
9 | 15 |
import org.junit.jupiter.api.Test; |
... | ... | |
11 | 17 |
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
12 | 18 |
|
13 | 19 |
import java.util.List; |
14 |
import java.util.Set; |
|
20 |
import java.util.stream.Collectors; |
|
21 |
import java.util.stream.Stream; |
|
15 | 22 |
|
16 | 23 |
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
17 |
import static org.junit.jupiter.api.Assertions.*;
|
|
24 |
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
18 | 25 |
|
19 | 26 |
@DataJpaTest |
20 | 27 |
class CatalogItemRepositoryTest { |
... | ... | |
25 | 32 |
@Autowired |
26 | 33 |
private TypeRepository typeRepository; |
27 | 34 |
|
35 |
@Autowired |
|
36 |
private CountryRepository countryRepository; |
|
37 |
|
|
38 |
@Autowired |
|
39 |
private WrittenFormRepository writtenFormRepository; |
|
40 |
|
|
41 |
@Autowired |
|
42 |
private AlternativeNameRepository alternativeNameRepository; |
|
43 |
|
|
44 |
@Autowired |
|
45 |
private BibliographyRepository bibliographyRepository; |
|
46 |
|
|
28 | 47 |
private CatalogItem catalogItem1; |
29 | 48 |
private CatalogItem catalogItem2; |
30 | 49 |
private CatalogItem catalogItem3; |
... | ... | |
63 | 82 |
catalogItem5 = new CatalogItem(); |
64 | 83 |
|
65 | 84 |
catalogItem1.setName(nameFirst); |
66 |
catalogItem1.setTypes(Set.of(typeCountry, typeCity));
|
|
67 |
catalogItem1.setCountries(Set.of(new Country(countryAaa, catalogItem1), new Country(countryDcd, catalogItem1)));
|
|
85 |
catalogItem1.setTypes(Stream.of(typeCountry, typeCity).collect(Collectors.toSet()));
|
|
86 |
catalogItem1.setCountries(Stream.of(new Country(countryAaa, catalogItem1), new Country(countryDcd, catalogItem1)).collect(Collectors.toSet()));
|
|
68 | 87 |
|
69 | 88 |
catalogItem2.setName(nameSecond); |
70 |
catalogItem2.setAlternativeNames(Set.of(new AlternativeName(nameTwelve, catalogItem2), new AlternativeName(nameThird, catalogItem2))); |
|
71 |
catalogItem2.setTypes(Set.of(typeCountry, typeCityUpper)); |
|
72 |
catalogItem2.setCountries(Set.of(new Country(countryAaa, catalogItem2), new Country(countryBbb, catalogItem2))); |
|
89 |
catalogItem2.setAlternativeNames(Stream.of(new AlternativeName(nameTwelve, catalogItem2), new AlternativeName(nameThird, catalogItem2)).collect(Collectors.toSet())); |
|
90 |
catalogItem2.setTypes(Stream.of(typeCountry, typeCityUpper).collect(Collectors.toSet())); |
|
91 |
catalogItem2.setCountries(Stream.of(new Country(countryAaa, catalogItem2), new Country(countryBbb, catalogItem2)).collect(Collectors.toSet())); |
|
92 |
catalogItem2.setBibliography(Stream.of(new Bibliography("bibl", catalogItem2)).collect(Collectors.toSet())); |
|
93 |
catalogItem2.setWrittenForms(Stream.of(new WrittenForm("wr", catalogItem2), new WrittenForm("wr2", catalogItem2)).collect(Collectors.toSet())); |
|
73 | 94 |
|
74 | 95 |
catalogItem3.setName(nameThird); |
75 |
catalogItem3.setAlternativeNames(Set.of(new AlternativeName(nameTwentyUpper, catalogItem3), new AlternativeName(nameSedond, catalogItem3)));
|
|
76 |
catalogItem3.setTypes(Set.of(typeCountri, typeCapitalCity));
|
|
77 |
catalogItem3.setCountries(Set.of(new Country(countryAaaUpper, catalogItem3), new Country(countryCcc, catalogItem3)));
|
|
96 |
catalogItem3.setAlternativeNames(Stream.of(new AlternativeName(nameTwentyUpper, catalogItem3), new AlternativeName(nameSedond, catalogItem3)).collect(Collectors.toSet()));
|
|
97 |
catalogItem3.setTypes(Stream.of(typeCountri, typeCapitalCity).collect(Collectors.toSet()));
|
|
98 |
catalogItem3.setCountries(Stream.of(new Country(countryAaaUpper, catalogItem3), new Country(countryCcc, catalogItem3)).collect(Collectors.toSet()));
|
|
78 | 99 |
|
79 | 100 |
|
80 |
catalogItem4.setAlternativeNames(Set.of(new AlternativeName(nameTwelve, catalogItem4), new AlternativeName(nameFirstUpper, catalogItem4)));
|
|
81 |
catalogItem4.setTypes(Set.of(typeCountri, typeCountry));
|
|
82 |
catalogItem4.setCountries(Set.of(new Country(countryBccb, catalogItem4), new Country(countryDdd, catalogItem4)));
|
|
101 |
catalogItem4.setAlternativeNames(Stream.of(new AlternativeName(nameTwelve, catalogItem4), new AlternativeName(nameFirstUpper, catalogItem4)).collect(Collectors.toSet()));
|
|
102 |
catalogItem4.setTypes(Stream.of(typeCountri, typeCountry).collect(Collectors.toSet()));
|
|
103 |
catalogItem4.setCountries(Stream.of(new Country(countryBccb, catalogItem4), new Country(countryDdd, catalogItem4)).collect(Collectors.toSet()));
|
|
83 | 104 |
|
84 | 105 |
|
85 | 106 |
catalogItem5.setName(nameSedond); |
86 |
catalogItem5.setAlternativeNames(Set.of(new AlternativeName(nameThird, catalogItem5)));
|
|
87 |
catalogItem5.setTypes(Set.of(typeCountri));
|
|
107 |
catalogItem5.setAlternativeNames(Stream.of(new AlternativeName(nameThird, catalogItem5)).collect(Collectors.toSet()));
|
|
108 |
catalogItem5.setTypes(Stream.of(typeCountri).collect(Collectors.toSet()));
|
|
88 | 109 |
|
89 | 110 |
underTest.saveAll(List.of(catalogItem1, catalogItem2, catalogItem3, catalogItem4, catalogItem5)); |
90 | 111 |
|
... | ... | |
104 | 125 |
String type = ""; |
105 | 126 |
|
106 | 127 |
// when |
107 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
128 |
List<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
108 | 129 |
|
109 | 130 |
// then |
110 | 131 |
assertThat(filterResult.size()).isEqualTo(5); |
... | ... | |
118 | 139 |
String type = ""; |
119 | 140 |
|
120 | 141 |
// when |
121 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
142 |
List<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
122 | 143 |
|
123 | 144 |
// then |
124 | 145 |
assertThat(filterResult.size()).isEqualTo(2); |
... | ... | |
134 | 155 |
String type = ""; |
135 | 156 |
|
136 | 157 |
// when |
137 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
158 |
List<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
138 | 159 |
|
139 | 160 |
// then |
140 | 161 |
assertThat(filterResult.size()).isEqualTo(3); |
... | ... | |
151 | 172 |
String type = ""; |
152 | 173 |
|
153 | 174 |
// when |
154 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
175 |
List<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
155 | 176 |
|
156 | 177 |
// then |
157 | 178 |
assertThat(filterResult.size()).isEqualTo(3); |
... | ... | |
168 | 189 |
String type = ""; |
169 | 190 |
|
170 | 191 |
// when |
171 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
192 |
List<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
172 | 193 |
|
173 | 194 |
// then |
174 | 195 |
assertThat(filterResult.size()).isEqualTo(3); |
... | ... | |
185 | 206 |
String type = ""; |
186 | 207 |
|
187 | 208 |
// when |
188 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
209 |
List<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
189 | 210 |
|
190 | 211 |
// then |
191 | 212 |
assertThat(filterResult.size()).isEqualTo(2); |
... | ... | |
201 | 222 |
String type = ""; |
202 | 223 |
|
203 | 224 |
// when |
204 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
225 |
List<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
205 | 226 |
|
206 | 227 |
// then |
207 | 228 |
assertThat(filterResult.size()).isEqualTo(2); |
... | ... | |
218 | 239 |
String type = "city"; |
219 | 240 |
|
220 | 241 |
// when |
221 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
242 |
List<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
222 | 243 |
|
223 | 244 |
// then |
224 | 245 |
assertThat(filterResult.size()).isEqualTo(2); |
... | ... | |
234 | 255 |
String type = "countr_"; |
235 | 256 |
|
236 | 257 |
// when |
237 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
258 |
List<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
238 | 259 |
|
239 | 260 |
// then |
240 | 261 |
assertThat(filterResult.size()).isEqualTo(5); |
... | ... | |
253 | 274 |
String type = "%city%"; |
254 | 275 |
|
255 | 276 |
// when |
256 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
277 |
List<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
257 | 278 |
|
258 | 279 |
// then |
259 | 280 |
assertThat(filterResult.size()).isEqualTo(3); |
... | ... | |
270 | 291 |
String type = ""; |
271 | 292 |
|
272 | 293 |
// when |
273 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
294 |
List<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
274 | 295 |
|
275 | 296 |
// then |
276 | 297 |
assertThat(filterResult.size()).isEqualTo(2); |
... | ... | |
286 | 307 |
String type = "countri"; |
287 | 308 |
|
288 | 309 |
// when |
289 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
310 |
List<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
290 | 311 |
|
291 | 312 |
// then |
292 | 313 |
assertThat(filterResult.size()).isEqualTo(2); |
... | ... | |
302 | 323 |
String type = "country"; |
303 | 324 |
|
304 | 325 |
// when |
305 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
326 |
List<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
306 | 327 |
|
307 | 328 |
// then |
308 | 329 |
assertThat(filterResult.size()).isEqualTo(1); |
... | ... | |
317 | 338 |
String type = "countri"; |
318 | 339 |
|
319 | 340 |
// when |
320 |
Set<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
341 |
List<CatalogItem> filterResult = underTest.filterCatalog(name, country, type);
|
|
321 | 342 |
|
322 | 343 |
// then |
323 | 344 |
assertThat(filterResult.size()).isEqualTo(1); |
324 | 345 |
assertTrue(filterResult.contains(catalogItem3)); |
325 | 346 |
} |
347 |
|
|
348 |
@Test |
|
349 |
void testUpdate() { |
|
350 |
// given |
|
351 |
int originalCountriesCount = countryRepository.findAll().size(); |
|
352 |
int originalNamesCount = alternativeNameRepository.findAll().size(); |
|
353 |
int originalWrittenFormsCount = writtenFormRepository.findAll().size(); |
|
354 |
int originalTypesCount = typeRepository.findAll().size(); |
|
355 |
int originalBibliographyCount = bibliographyRepository.findAll().size(); |
|
356 |
|
|
357 |
// when |
|
358 |
catalogItem2.getCountries().clear(); |
|
359 |
catalogItem2.getCountries().addAll(Stream.of(new Country("aaa", catalogItem2)).collect(Collectors.toSet())); |
|
360 |
|
|
361 |
catalogItem2.getAlternativeNames().clear(); |
|
362 |
catalogItem2.getAlternativeNames().addAll(Stream.of(new AlternativeName("aaa", catalogItem2)).collect(Collectors.toSet())); |
|
363 |
|
|
364 |
catalogItem2.getWrittenForms().clear(); |
|
365 |
catalogItem2.getWrittenForms().addAll(Stream.of(new WrittenForm("aaa", catalogItem2), new WrittenForm("aaaa", catalogItem2), new WrittenForm("aaaaa", catalogItem2)).collect(Collectors.toSet())); |
|
366 |
|
|
367 |
catalogItem2.getBibliography().clear(); |
|
368 |
catalogItem2.getBibliography().addAll(Stream.of(new Bibliography("aaa", catalogItem2), new Bibliography("aaaa", catalogItem2)).collect(Collectors.toSet())); |
|
369 |
|
|
370 |
catalogItem2.getTypes().clear(); |
|
371 |
catalogItem2.getTypes().addAll(Stream.of(new Type("country")).collect(Collectors.toSet())); |
|
372 |
|
|
373 |
underTest.save(catalogItem2); |
|
374 |
|
|
375 |
// then |
|
376 |
assertThat(typeRepository.findAll().size()).isEqualTo(originalTypesCount); |
|
377 |
assertThat(countryRepository.findAll().size()).isEqualTo(originalCountriesCount - 1); |
|
378 |
assertThat(alternativeNameRepository.findAll().size()).isEqualTo(originalNamesCount - 1); |
|
379 |
assertThat(bibliographyRepository.findAll().size()).isEqualTo(originalBibliographyCount + 1); |
|
380 |
assertThat(writtenFormRepository.findAll().size()).isEqualTo(originalWrittenFormsCount + 1); |
|
381 |
|
|
382 |
} |
|
383 |
|
|
384 |
@Test |
|
385 |
void testDelete() { |
|
386 |
// given |
|
387 |
int expectedCountriesCount = countryRepository.findAll().size() - catalogItem2.getCountries().size(); |
|
388 |
int expectedNamesCount = alternativeNameRepository.findAll().size() - catalogItem2.getAlternativeNames().size(); |
|
389 |
int expectedWrittenFormsCount = writtenFormRepository.findAll().size() - catalogItem2.getWrittenForms().size(); |
|
390 |
int expectedTypesCount = typeRepository.findAll().size(); |
|
391 |
int expectedBibliographyCount = bibliographyRepository.findAll().size() - catalogItem2.getBibliography().size(); |
|
392 |
|
|
393 |
// when |
|
394 |
underTest.delete(catalogItem2); |
|
395 |
|
|
396 |
// then |
|
397 |
assertThat(typeRepository.findAll().size()).isEqualTo(expectedTypesCount); |
|
398 |
assertThat(countryRepository.findAll().size()).isEqualTo(expectedCountriesCount); |
|
399 |
assertThat(alternativeNameRepository.findAll().size()).isEqualTo(expectedNamesCount); |
|
400 |
assertThat(bibliographyRepository.findAll().size()).isEqualTo(expectedBibliographyCount); |
|
401 |
assertThat(writtenFormRepository.findAll().size()).isEqualTo(expectedWrittenFormsCount); |
|
402 |
|
|
403 |
} |
|
326 | 404 |
} |
backend/src/test/java/cz/zcu/kiv/backendapi/catalog/CatalogItemServiceImplTest.java | ||
---|---|---|
10 | 10 |
import org.junit.jupiter.api.BeforeEach; |
11 | 11 |
import org.junit.jupiter.api.Test; |
12 | 12 |
import org.junit.jupiter.api.extension.ExtendWith; |
13 |
import org.mockito.*; |
|
13 |
import org.mockito.ArgumentCaptor; |
|
14 |
import org.mockito.Mock; |
|
14 | 15 |
import org.mockito.junit.jupiter.MockitoExtension; |
15 | 16 |
|
17 |
import java.util.ArrayList; |
|
16 | 18 |
import java.util.List; |
17 | 19 |
import java.util.Optional; |
18 |
import java.util.Set; |
|
19 | 20 |
import java.util.UUID; |
21 |
import java.util.stream.Collectors; |
|
22 |
import java.util.stream.Stream; |
|
20 | 23 |
|
21 | 24 |
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
22 | 25 |
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; |
... | ... | |
48 | 51 |
void saveCatalog() { |
49 | 52 |
// given |
50 | 53 |
Type type = new Type("type"); |
54 |
CatalogItemDto catalogItemDto = new CatalogItemDto(); |
|
55 |
catalogItemDto.setName("aaacbbbbbbbaa"); |
|
56 |
catalogItemDto.setBibliography(Stream.of("bibl").collect(Collectors.toSet())); |
|
57 |
catalogItemDto.setTypes(Stream.of("type").collect(Collectors.toSet())); |
|
58 |
catalogItemDto.setAlternativeNames(Stream.of("altName").collect(Collectors.toSet())); |
|
59 |
catalogItemDto.setCountries(Stream.of("aaaabbaa").collect(Collectors.toSet())); |
|
60 |
catalogItemDto.setWrittenForms(Stream.of("written").collect(Collectors.toSet())); |
|
61 |
catalogItemDto.setCertainty(0); |
|
62 |
catalogItemDto.setLatitude(0.1); |
|
63 |
catalogItemDto.setLongitude(0.2); |
|
64 |
|
|
65 |
CatalogItemDto catalogItemDto2 = new CatalogItemDto(); |
|
66 |
catalogItemDto2.setName("name"); |
|
67 |
catalogItemDto2.setBibliography(Stream.of("bibl").collect(Collectors.toSet())); |
Také k dispozici: Unified diff
Experiment with database