Projekt

Obecné

Profil

« Předchozí | Další » 

Revize cf12d561

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

Catalog change
- one-to-many associations now persist order
- text for search persists separators

re #9751
re #9754

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.CatalogItem;
4
import lombok.AllArgsConstructor;
5
import lombok.Getter;
6
import lombok.NoArgsConstructor;
7
import lombok.Setter;
8

  
9
import javax.persistence.*;
10

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

  
28
    /**
29
     * Catalog entity
30
     */
31
    @ManyToOne(fetch = FetchType.LAZY)
32
    @Id
33
    @JoinColumn(name = "catalog_item_id")
34
    private CatalogItem catalogItem;
35
}
backend/src/main/java/cz/zcu/kiv/backendapi/alternativename/AlternativeNamePK.java
1
package cz.zcu.kiv.backendapi.alternativename;
2

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

  
7
import java.io.Serializable;
8
import java.util.UUID;
9

  
10
/**
11
 * Class representing alternative name primary key
12
 */
13
@EqualsAndHashCode
14
@AllArgsConstructor
15
@NoArgsConstructor
16
public class AlternativeNamePK implements Serializable {
17
    /**
18
     * Name
19
     */
20
    private String name;
21

  
22
    /**
23
     * ID of catalog item
24
     */
25
    private UUID catalogItem;
26
}
backend/src/main/java/cz/zcu/kiv/backendapi/alternativename/CatalogItemName.java
1
package cz.zcu.kiv.backendapi.alternativename;
2

  
3
import cz.zcu.kiv.backendapi.catalog.CatalogItem;
4
import lombok.AllArgsConstructor;
5
import lombok.Getter;
6
import lombok.NoArgsConstructor;
7
import lombok.Setter;
8

  
9
import javax.persistence.*;
10

  
11
/**
12
 * Catalog item name entity representing alternative name of catalog item
13
 */
14
@Getter
15
@Setter
16
@NoArgsConstructor
17
@AllArgsConstructor
18
@Entity
19
@Table(name = "catalog_item_names")
20
@IdClass(CatalogItemNamePK.class)
21
public class CatalogItemName {
22
    /**
23
     * Name, serves as ID
24
     */
25
    @Id
26
    private String name;
27

  
28
    /**
29
     * Catalog item
30
     */
31
    @ManyToOne(fetch = FetchType.LAZY)
32
    @Id
33
    @JoinColumn(name = "catalog_item_id")
34
    private CatalogItem catalogItem;
35

  
36
    /**
37
     * Order of name for given catalog item
38
     */
39
    private int entryOrder;
40
}
backend/src/main/java/cz/zcu/kiv/backendapi/alternativename/CatalogItemNamePK.java
1
package cz.zcu.kiv.backendapi.alternativename;
2

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

  
7
import java.io.Serializable;
8
import java.util.UUID;
9

  
10
/**
11
 * Class representing catalog item name primary key
12
 */
13
@EqualsAndHashCode
14
@AllArgsConstructor
15
@NoArgsConstructor
16
public class CatalogItemNamePK implements Serializable {
17
    /**
18
     * Name
19
     */
20
    private String name;
21

  
22
    /**
23
     * ID of catalog item
24
     */
25
    private UUID catalogItem;
26
}
backend/src/main/java/cz/zcu/kiv/backendapi/bibliography/Bibliography.java
29 29
    @Id
30 30
    @JoinColumn(name = "catalog_item_id")
31 31
    private CatalogItem catalogItem;
32

  
33
    /**
34
     * Order of bibliography for given catalog item
35
     */
36
    private int entryOrder;
32 37
}
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogItem.java
1 1
package cz.zcu.kiv.backendapi.catalog;
2 2

  
3
import cz.zcu.kiv.backendapi.alternativename.AlternativeName;
3
import cz.zcu.kiv.backendapi.alternativename.CatalogItemName;
4 4
import cz.zcu.kiv.backendapi.bibliography.Bibliography;
5 5
import cz.zcu.kiv.backendapi.country.Country;
6 6
import cz.zcu.kiv.backendapi.type.Type;
......
16 16

  
17 17
import javax.persistence.*;
18 18
import java.util.*;
19
import java.util.concurrent.atomic.AtomicInteger;
19 20
import java.util.regex.Matcher;
20 21
import java.util.regex.Pattern;
21 22
import java.util.stream.Collectors;
22 23

  
23 24
/**
24
 * Catalog entity representing catalog item
25
 * Catalog item entity representing catalog item
25 26
 */
26 27
@Getter
27 28
@Setter
......
73 74
    @OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
74 75
    @LazyCollection(LazyCollectionOption.FALSE)
75 76
    @Fetch(FetchMode.SUBSELECT)
76
    private Set<Bibliography> bibliography = new HashSet<>();
77
    @OrderBy("entryOrder")
78
    private Set<Bibliography> bibliography = new LinkedHashSet<>(0);
77 79

  
78 80
    /**
79 81
     * Countries
......
81 83
    @OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
82 84
    @LazyCollection(LazyCollectionOption.FALSE)
83 85
    @Fetch(FetchMode.SUBSELECT)
84
    private Set<Country> countries = new HashSet<>();
86
    @OrderBy("entryOrder")
87
    private Set<Country> countries = new LinkedHashSet<>(0);
85 88

  
86 89
    /**
87 90
     * Written forms
......
89 92
    @OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
90 93
    @LazyCollection(LazyCollectionOption.FALSE)
91 94
    @Fetch(FetchMode.SUBSELECT)
92
    private Set<WrittenForm> writtenForms = new HashSet<>();
95
    @OrderBy("entryOrder")
96
    private Set<WrittenForm> writtenForms = new LinkedHashSet<>(0);
93 97

  
94 98
    /**
95
     * Alternative names
99
     * All names
96 100
     */
97 101
    @OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
98 102
    @LazyCollection(LazyCollectionOption.FALSE)
99 103
    @Fetch(FetchMode.SUBSELECT)
100
    private Set<AlternativeName> alternativeNames = new HashSet<>();
104
    @OrderBy("entryOrder")
105
    private Set<CatalogItemName> allNames = new LinkedHashSet<>(0);
101 106

  
102 107
    /**
103 108
     * Set of user roles - many-to-many relationship
......
113 118
                    @JoinColumn(name = "type", referencedColumnName = "type")
114 119
            }
115 120
    )
116
    private Set<Type> types = new HashSet<>();
121
    private Set<Type> types = new LinkedHashSet<>(0);
117 122

  
118 123
    public CatalogItem(List<String> csvFields) {
124
        AtomicInteger counter = new AtomicInteger(1);
119 125

  
120 126
        this.name = csvFields.get(1);
121
        Set<String> stringList = processListField(csvFields.get(2));
122
        stringList.add(this.name);
123
        this.alternativeNames = stringList.stream().map(s -> new AlternativeName(s, this)).collect(Collectors.toSet());
127
        Set<String> stringLinkedSet = new LinkedHashSet<>();
128
        stringLinkedSet.add(this.name);
129
        stringLinkedSet.addAll(processListField(csvFields.get(2)));
130
        this.allNames = stringLinkedSet.stream().map(s -> new CatalogItemName(s, this, counter.getAndIncrement())).collect(Collectors.toCollection(LinkedHashSet::new));
124 131

  
125 132
        this.certainty = processIntField(csvFields.get(3));
126 133
        this.latitude = processDoubleField(csvFields.get(4));
127 134
        this.longitude = processDoubleField(csvFields.get(5));
128 135

  
129
        stringList = processListField(csvFields.get(6));
130
        this.writtenForms = stringList.stream().map(s -> new WrittenForm(s, this)).collect(Collectors.toSet());
136
        stringLinkedSet = processListField(csvFields.get(6));
137
        counter.set(1);
138
        this.writtenForms = stringLinkedSet.stream().map(s -> new WrittenForm(s, this, counter.getAndIncrement())).collect(Collectors.toCollection(LinkedHashSet::new));
131 139

  
132
        stringList = processListField(csvFields.get(7));
133
        this.types = stringList.stream().map(Type::new).collect(Collectors.toSet());
140
        stringLinkedSet = processListField(csvFields.get(7));
141
        this.types = stringLinkedSet.stream().map(Type::new).collect(Collectors.toCollection(LinkedHashSet::new));
134 142

  
135
        stringList = processListField(csvFields.get(8));
136
        this.countries = stringList.stream().map(s -> new Country(s, this)).collect(Collectors.toSet());
143
        stringLinkedSet = processListField(csvFields.get(8));
144
        counter.set(1);
145
        this.countries = stringLinkedSet.stream().map(s -> new Country(s, this, counter.getAndIncrement())).collect(Collectors.toCollection(LinkedHashSet::new));
137 146

  
138
        stringList = processListField(csvFields.get(9));
139
        this.bibliography = stringList.stream().map(s -> new Bibliography(s, this)).collect(Collectors.toSet());
147
        stringLinkedSet = processListField(csvFields.get(9));
148
        counter.set(1);
149
        this.bibliography = stringLinkedSet.stream().map(s -> new Bibliography(s, this, counter.getAndIncrement())).collect(Collectors.toCollection(LinkedHashSet::new));
140 150
    }
141 151

  
142 152
    private Integer processIntField(String field) {
......
159 169

  
160 170
    private Set<String> processListField(String field) {
161 171
        if (field.isEmpty() || field.equals(EMPTY_ENTRY)) {
162
            return new HashSet<>();
172
            return new LinkedHashSet<>();
163 173
        }
164
        return Arrays.stream(field.split(",")).map(String::trim).filter(item -> !item.isEmpty()).collect(Collectors.toSet());
174
        return Arrays.stream(field.split(",")).map(String::trim).filter(item -> !item.isEmpty()).collect(Collectors.toCollection(LinkedHashSet::new));
165 175
    }
166 176
}
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;
8
import java.util.LinkedHashSet;
10 9
import java.util.UUID;
11 10

  
12 11
/**
......
28 27
    private String name = "";
29 28

  
30 29
    /**
31
     * Alternative names
30
     * All names
32 31
     */
33
    private Set<String> alternativeNames = Collections.emptySet();
32
    private LinkedHashSet<String> allNames = new LinkedHashSet<>();
34 33

  
35 34
    /**
36 35
     * Written forms
37 36
     */
38
    private Set<String> writtenForms = Collections.emptySet();
37
    private LinkedHashSet<String> writtenForms = new LinkedHashSet<>();
39 38

  
40 39
    /**
41 40
     * Types
42 41
     */
43
    private Set<String> types = Collections.emptySet();
42
    private LinkedHashSet<String> types = new LinkedHashSet<>();
44 43

  
45 44
    /**
46 45
     * Countries
47 46
     */
48
    private Set<String> countries = Collections.emptySet();
47
    private LinkedHashSet<String> countries = new LinkedHashSet<>();
49 48

  
50 49
    /**
51 50
     * Bibliography
52 51
     */
53
    private Set<String> bibliography = Collections.emptySet();
52
    private LinkedHashSet<String> bibliography = new LinkedHashSet<>();
54 53

  
55 54
    /**
56 55
     * Longitude
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogItemRepository.java
19 19
     * @param name name
20 20
     * @return list of catalog items with given name
21 21
     */
22
    @Query("SELECT DISTINCT a.catalogItem FROM AlternativeName a WHERE ?1 = a.name")
22
    @Query("SELECT DISTINCT a.catalogItem FROM CatalogItemName a WHERE ?1 = a.name")
23 23
    List<CatalogItem> getItemsByName(String name);
24 24
}
backend/src/main/java/cz/zcu/kiv/backendapi/catalog/CatalogItemServiceImpl.java
1 1
package cz.zcu.kiv.backendapi.catalog;
2 2

  
3
import cz.zcu.kiv.backendapi.alternativename.AlternativeName;
3
import cz.zcu.kiv.backendapi.alternativename.CatalogItemName;
4 4
import cz.zcu.kiv.backendapi.bibliography.Bibliography;
5 5
import cz.zcu.kiv.backendapi.country.Country;
6 6
import cz.zcu.kiv.backendapi.exception.ApiRequestException;
......
10 10
import cz.zcu.kiv.backendapi.writtenform.WrittenForm;
11 11
import lombok.RequiredArgsConstructor;
12 12
import lombok.extern.slf4j.Slf4j;
13
import org.apache.commons.lang3.StringUtils;
13 14
import org.springframework.http.HttpStatus;
14 15
import org.springframework.stereotype.Service;
15 16
import org.springframework.transaction.annotation.Transactional;
16 17

  
17
import java.util.ArrayList;
18
import java.util.List;
19
import java.util.Set;
20
import java.util.UUID;
18
import java.util.*;
19
import java.util.concurrent.atomic.AtomicInteger;
21 20
import java.util.function.Predicate;
22 21
import java.util.regex.Matcher;
23 22
import java.util.regex.Pattern;
......
140 139

  
141 140
        Set<String> types = typeService.getAllTypesAsString();
142 141

  
143
        String[] tokens = text.split("\\s+");
142
        String[] tokens = text.split("((?<=\\s)|(?=\\s+))");
144 143
        for (String token : tokens) {
144
            if (StringUtils.isBlank(token)) {
145
                highlightedText.append(token);
146
                continue;
147
            }
145 148
            Matcher matcherStart = START_PUNCTUATION_PATTERN.matcher(token);
146 149
            Matcher matcherEnd = END_PUNCTUATION_PATTERN.matcher(token);
147 150
            String prefix = "";
......
162 165
            }
163 166

  
164 167
            if (endTextIndex < startTextIndex) {
165
                highlightedText.append(prefix).append(" ");
168
                highlightedText.append(prefix);
166 169
                continue;
167 170
            }
168 171

  
......
181 184
                    foundCatalogItems.add(foundItems.stream().map(this::convertEntityToDto).collect(Collectors.toList()));
182 185
                }
183 186
            }
184
            highlightedText.append(prefix).append(textToFind).append(suffix).append(" ");
187
            highlightedText.append(prefix).append(textToFind).append(suffix);
185 188
        }
186
        highlightedText.setLength(highlightedText.length() - 1);
187 189

  
188 190
        pathDto.setText(highlightedText.toString());
189 191
        pathDto.setFoundCatalogItems(foundCatalogItems);
......
207 209

  
208 210
        Predicate<CatalogItem> predicateType = i -> finalType.equals("") || i.getTypes().stream().anyMatch(t -> patternType.matcher(t.getType()).matches());
209 211
        Predicate<CatalogItem> predicateCountry = i -> finalCountry.equals("") || i.getCountries().stream().anyMatch(t -> patternCountry.matcher(t.getName()).matches());
210
        Predicate<CatalogItem> predicateName = i -> finalName.equals("") || patternName.matcher(i.getName()).matches() || i.getAlternativeNames().stream().anyMatch(t -> patternName.matcher(t.getName()).matches());
212
        Predicate<CatalogItem> predicateName = i -> finalName.equals("") || patternName.matcher(i.getName()).matches() || i.getAllNames().stream().anyMatch(t -> patternName.matcher(t.getName()).matches());
211 213
        Predicate<CatalogItem> predicateWrittenForm = i -> finalWrittenForm.equals("") || i.getWrittenForms().stream().anyMatch(t -> patternWrittenForm.matcher(t.getForm()).matches());
212 214

  
213 215
        catalogItems = catalogItems.stream().filter(predicateName.and(predicateCountry).and(predicateType).and(predicateWrittenForm)).collect(Collectors.toList());
......
215 217
    }
216 218

  
217 219
    /**
218
     * Saves catalog entity to database
220
     * Saves catalog item to database
219 221
     *
220
     * @param catalogItem catalog entity
222
     * @param catalogItem catalog item
221 223
     */
222 224
    private void saveCatalogEntity(CatalogItem catalogItem) {
223 225
        for (Type type : catalogItem.getTypes()) {
......
235 237
     * @param catalogItem    catalog item entity
236 238
     */
237 239
    private void convertDtoToEntity(CatalogItemDto catalogItemDto, CatalogItem catalogItem) {
240
        AtomicInteger counter = new AtomicInteger(1);
241

  
238 242
        catalogItem.setName(catalogItemDto.getName());
239 243
        catalogItem.setCertainty(catalogItemDto.getCertainty());
240 244
        catalogItem.setLatitude(catalogItemDto.getLatitude());
......
242 246

  
243 247
        catalogItem.getBibliography().clear();
244 248
        catalogItem.getBibliography().addAll(catalogItemDto.getBibliography()
245
                .stream().map(s -> new Bibliography(s, catalogItem)).collect(Collectors.toSet()));
249
                .stream().map(s -> new Bibliography(s, catalogItem, counter.getAndIncrement())).collect(Collectors.toCollection(LinkedHashSet::new)));
246 250

  
247 251
        catalogItem.getTypes().clear();
248 252
        catalogItem.getTypes().addAll(catalogItemDto.getTypes()
249
                .stream().map(Type::new).collect(Collectors.toSet()));
253
                .stream().map(Type::new).collect(Collectors.toCollection(LinkedHashSet::new)));
250 254

  
251 255
        catalogItem.getCountries().clear();
256
        counter.set(1);
252 257
        catalogItem.getCountries().addAll(catalogItemDto.getCountries()
253
                .stream().map(s -> new Country(s, catalogItem)).collect(Collectors.toSet()));
258
                .stream().map(s -> new Country(s, catalogItem, counter.getAndIncrement())).collect(Collectors.toCollection(LinkedHashSet::new)));
254 259

  
255
        catalogItemDto.getAlternativeNames().add(catalogItemDto.getName());
256
        catalogItem.getAlternativeNames().clear();
257
        catalogItem.getAlternativeNames().addAll(catalogItemDto.getAlternativeNames()
258
                .stream().map(s -> new AlternativeName(s, catalogItem)).collect(Collectors.toSet()));
260
        catalogItem.getAllNames().clear();
261
        counter.set(1);
262
        Set<String> allNames = new LinkedHashSet<>();
263
        allNames.add(catalogItemDto.getName());
264
        allNames.addAll(catalogItemDto.getAllNames());
265
        catalogItem.getAllNames().addAll(allNames
266
                .stream().map(s -> new CatalogItemName(s, catalogItem, counter.getAndIncrement())).collect(Collectors.toCollection(LinkedHashSet::new)));
259 267

  
260 268
        catalogItem.getWrittenForms().clear();
269
        counter.set(1);
261 270
        catalogItem.getWrittenForms().addAll(catalogItemDto.getWrittenForms()
262
                .stream().map(s -> new WrittenForm(s, catalogItem)).collect(Collectors.toSet()));
271
                .stream().map(s -> new WrittenForm(s, catalogItem, counter.getAndIncrement())).collect(Collectors.toCollection(LinkedHashSet::new)));
263 272

  
264 273
        catalogItem.setDescription(catalogItemDto.getDescription());
265 274
    }
......
278 287
        catalogItemDto.setLongitude(catalogItem.getLongitude());
279 288
        catalogItemDto.setCertainty(catalogItem.getCertainty());
280 289
        catalogItemDto.setBibliography(catalogItem.getBibliography()
281
                .stream().map(Bibliography::getSource).collect(Collectors.toSet()));
290
                .stream().map(Bibliography::getSource).collect(Collectors.toCollection(LinkedHashSet::new)));
282 291
        catalogItemDto.setTypes(catalogItem.getTypes()
283
                .stream().map(Type::getType).collect(Collectors.toSet()));
292
                .stream().map(Type::getType).collect(Collectors.toCollection(LinkedHashSet::new)));
284 293
        catalogItemDto.setCountries(catalogItem.getCountries()
285
                .stream().map(Country::getName).collect(Collectors.toSet()));
286
        catalogItemDto.setAlternativeNames(catalogItem.getAlternativeNames()
287
                .stream().map(AlternativeName::getName).collect(Collectors.toSet()));
294
                .stream().map(Country::getName).collect(Collectors.toCollection(LinkedHashSet::new)));
295
        catalogItemDto.setAllNames(catalogItem.getAllNames()
296
                .stream().map(CatalogItemName::getName).collect(Collectors.toCollection(LinkedHashSet::new)));
288 297
        catalogItemDto.setWrittenForms(catalogItem.getWrittenForms()
289
                .stream().map(WrittenForm::getForm).collect(Collectors.toSet()));
298
                .stream().map(WrittenForm::getForm).collect(Collectors.toCollection(LinkedHashSet::new)));
290 299
        catalogItemDto.setDescription(catalogItem.getDescription());
291 300
        return catalogItemDto;
292 301
    }
backend/src/main/java/cz/zcu/kiv/backendapi/country/Country.java
29 29
    @Id
30 30
    @JoinColumn(name = "catalog_item_id")
31 31
    private CatalogItem catalogItem;
32

  
33
    /**
34
     * Order of country for given catalog item
35
     */
36
    private int entryOrder;
32 37
}
backend/src/main/java/cz/zcu/kiv/backendapi/writtenform/WrittenForm.java
29 29
    @Id
30 30
    @JoinColumn(name = "catalog_item_id")
31 31
    private CatalogItem catalogItem;
32

  
33
    /**
34
     * Order of written form for given catalog item
35
     */
36
    private int entryOrder;
32 37
}
backend/src/test/java/cz/zcu/kiv/backendapi/catalog/CatalogItemRepositoryTest.java
1 1
package cz.zcu.kiv.backendapi.catalog;
2 2

  
3
import cz.zcu.kiv.backendapi.alternativename.AlternativeName;
3
import cz.zcu.kiv.backendapi.alternativename.CatalogItemName;
4 4
import org.junit.jupiter.api.Test;
5 5
import org.springframework.beans.factory.annotation.Autowired;
6 6
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
7 7

  
8
import java.util.LinkedHashSet;
8 9
import java.util.List;
9
import java.util.Set;
10
import java.util.stream.Collectors;
11
import java.util.stream.Stream;
10 12

  
11 13
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
12 14
import static org.junit.jupiter.api.Assertions.assertTrue;
......
37 39
        catalogItem1.setName(nameFirst);
38 40

  
39 41
        catalogItem2.setName(nameSecond);
40
        catalogItem2.setAlternativeNames(Set.of(new AlternativeName(nameTwelve, catalogItem2), new AlternativeName(nameThird, catalogItem2)));
42
        catalogItem2.setAllNames(Stream.of(new CatalogItemName(nameTwelve, catalogItem2, 1), new CatalogItemName(nameThird, catalogItem2, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
41 43

  
42 44
        catalogItem3.setName(nameThird);
43
        catalogItem3.setAlternativeNames(Set.of(new AlternativeName(nameTwentyUpper, catalogItem3), new AlternativeName(nameSedond, catalogItem3)));
45
        catalogItem3.setAllNames(Stream.of(new CatalogItemName(nameTwentyUpper, catalogItem3, 1), new CatalogItemName(nameSedond, catalogItem3, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
44 46

  
45
        catalogItem4.setAlternativeNames(Set.of(new AlternativeName(nameTwelve, catalogItem4), new AlternativeName(nameFirstUpper, catalogItem4)));
47
        catalogItem4.setAllNames(Stream.of(new CatalogItemName(nameTwelve, catalogItem4, 1), new CatalogItemName(nameFirstUpper, catalogItem4, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
46 48

  
47 49
        catalogItem5.setName(nameSedond);
48
        catalogItem5.setAlternativeNames(Set.of(new AlternativeName(nameThird, catalogItem5)));
50
        catalogItem5.setAllNames(Stream.of(new CatalogItemName(nameThird, catalogItem5, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
49 51

  
50 52
        underTest.saveAll(List.of(catalogItem1, catalogItem2, catalogItem3, catalogItem4, catalogItem5));
51 53

  
backend/src/test/java/cz/zcu/kiv/backendapi/catalog/CatalogItemServiceImplFilterTest.java
1 1
package cz.zcu.kiv.backendapi.catalog;
2 2

  
3
import cz.zcu.kiv.backendapi.alternativename.AlternativeName;
3
import cz.zcu.kiv.backendapi.alternativename.CatalogItemName;
4 4
import cz.zcu.kiv.backendapi.country.Country;
5 5
import cz.zcu.kiv.backendapi.type.Type;
6 6
import cz.zcu.kiv.backendapi.type.TypeServiceImpl;
......
11 11
import org.mockito.Mock;
12 12
import org.mockito.junit.jupiter.MockitoExtension;
13 13

  
14
import java.util.Collections;
14
import java.util.LinkedHashSet;
15 15
import java.util.List;
16
import java.util.Set;
17 16
import java.util.UUID;
17
import java.util.stream.Collectors;
18
import java.util.stream.Stream;
18 19

  
19 20
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
20 21
import static org.junit.jupiter.api.Assertions.assertTrue;
......
92 93
        catalogItem5.setId(catalogItemId5);
93 94

  
94 95
        catalogItem1.setName(nameFirst);
95
        catalogItem1.setTypes(Set.of(typeCountry, typeCity));
96
        catalogItem1.setCountries(Set.of(new Country(countryAaa, catalogItem1), new Country(countryDcd, catalogItem1)));
97
        catalogItem1.setWrittenForms(Set.of(new WrittenForm(writtenForm, catalogItem1)));
96
        catalogItem1.setTypes(Stream.of(typeCountry, typeCity).collect(Collectors.toCollection(LinkedHashSet::new)));
97
        catalogItem1.setCountries(Stream.of(new Country(countryAaa, catalogItem1, 1), new Country(countryDcd, catalogItem1, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
98
        catalogItem1.setWrittenForms(Stream.of(new WrittenForm(writtenForm, catalogItem1, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
98 99

  
99
        catalogItemDto1 = new CatalogItemDto(catalogItemId1, nameFirst, Collections.emptySet(), Set.of(writtenForm), Set.of(country, city), Set.of(countryAaa, countryDcd), Collections.emptySet(), null, null, null, "");
100
        catalogItemDto1 = new CatalogItemDto(catalogItemId1, nameFirst, new LinkedHashSet<>(), Stream.of(writtenForm).collect(Collectors.toCollection(LinkedHashSet::new)),
101
                Stream.of(country, city).collect(Collectors.toCollection(LinkedHashSet::new)), Stream.of(countryAaa, countryDcd).collect(Collectors.toCollection(LinkedHashSet::new)),
102
                new LinkedHashSet<>(), null, null, null, "");
100 103

  
101 104
        catalogItem2.setName(nameSecond);
102
        catalogItem2.setAlternativeNames(Set.of(new AlternativeName(nameTwelve, catalogItem2), new AlternativeName(nameThird, catalogItem2)));
103
        catalogItem2.setTypes(Set.of(typeCountry, typeCityUpper));
104
        catalogItem2.setCountries(Set.of(new Country(countryAaa, catalogItem2), new Country(countryBbb, catalogItem2)));
105
        catalogItem2.setWrittenForms(Set.of(new WrittenForm(writtenFormUpper, catalogItem2)));
105
        catalogItem2.setAllNames(Stream.of(new CatalogItemName(nameTwelve, catalogItem2, 1), new CatalogItemName(nameThird, catalogItem2, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
106
        catalogItem2.setTypes(Stream.of(typeCountry, typeCityUpper).collect(Collectors.toCollection(LinkedHashSet::new)));
107
        catalogItem2.setCountries(Stream.of(new Country(countryAaa, catalogItem2, 1), new Country(countryBbb, catalogItem2, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
108
        catalogItem2.setWrittenForms(Stream.of(new WrittenForm(writtenFormUpper, catalogItem2, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
106 109

  
107
        catalogItemDto2 = new CatalogItemDto(catalogItemId2, nameSecond, Set.of(nameTwelve, nameThird), Set.of(writtenFormUpper), Set.of(country, cityUpper), Set.of(countryAaa, countryBbb), Collections.emptySet(), null, null, null, "");
110
        catalogItemDto2 = new CatalogItemDto(catalogItemId2, nameSecond, Stream.of(nameTwelve, nameThird).collect(Collectors.toCollection(LinkedHashSet::new)),
111
                Stream.of(writtenFormUpper).collect(Collectors.toCollection(LinkedHashSet::new)), Stream.of(country, cityUpper).collect(Collectors.toCollection(LinkedHashSet::new)),
112
                Stream.of(countryAaa, countryBbb).collect(Collectors.toCollection(LinkedHashSet::new)), new LinkedHashSet<>(),
113
                null, null, null, "");
108 114

  
109 115
        catalogItem3.setName(nameThird);
110
        catalogItem3.setAlternativeNames(Set.of(new AlternativeName(nameTwentyUpper, catalogItem3), new AlternativeName(nameSedond, catalogItem3)));
111
        catalogItem3.setTypes(Set.of(typeCountri, typeCapitalCity));
112
        catalogItem3.setCountries(Set.of(new Country(countryAaaUpper, catalogItem3), new Country(countryCcc, catalogItem3)));
113
        catalogItem3.setWrittenForms(Set.of(new WrittenForm(writtenFormForOr, catalogItem3)));
114

  
115
        catalogItemDto3 = new CatalogItemDto(catalogItemId3, nameThird, Set.of(nameTwentyUpper, nameSedond), Set.of(writtenFormForOr), Set.of(countri, capitalCityNew), Set.of(countryAaaUpper, countryCcc), Collections.emptySet(), null, null, null, "");
116

  
117
        catalogItem4.setAlternativeNames(Set.of(new AlternativeName(nameTwelve, catalogItem4), new AlternativeName(nameFirstUpper, catalogItem4)));
118
        catalogItem4.setTypes(Set.of(typeCountri, typeCountry));
119
        catalogItem4.setCountries(Set.of(new Country(countryBccb, catalogItem4), new Country(countryDdd, catalogItem4)));
120
        catalogItem4.setWrittenForms(Set.of(new WrittenForm(writtenForm, catalogItem4), new WrittenForm(writtenFormForOr, catalogItem4)));
121

  
122
        catalogItemDto4 = new CatalogItemDto(catalogItemId4, "", Set.of(nameTwelve, nameFirstUpper), Set.of(writtenForm, writtenFormForOr), Set.of(countri, country), Set.of(countryBccb, countryDdd), Collections.emptySet(), null, null, null, "");
116
        catalogItem3.setAllNames(Stream.of(new CatalogItemName(nameTwentyUpper, catalogItem3, 1), new CatalogItemName(nameSedond, catalogItem3, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
117
        catalogItem3.setTypes(Stream.of(typeCountri, typeCapitalCity).collect(Collectors.toCollection(LinkedHashSet::new)));
118
        catalogItem3.setCountries(Stream.of(new Country(countryAaaUpper, catalogItem3, 1), new Country(countryCcc, catalogItem3, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
119
        catalogItem3.setWrittenForms(Stream.of(new WrittenForm(writtenFormForOr, catalogItem3, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
120

  
121
        catalogItemDto3 = new CatalogItemDto(catalogItemId3, nameThird, Stream.of(nameTwentyUpper, nameSedond).collect(Collectors.toCollection(LinkedHashSet::new)),
122
                Stream.of(writtenFormForOr).collect(Collectors.toCollection(LinkedHashSet::new)), Stream.of(countri, capitalCityNew).collect(Collectors.toCollection(LinkedHashSet::new)),
123
                Stream.of(countryAaaUpper, countryCcc).collect(Collectors.toCollection(LinkedHashSet::new)), new LinkedHashSet<>(),
124
                null, null, null, "");
125

  
126
        catalogItem4.setAllNames(Stream.of(new CatalogItemName(nameTwelve, catalogItem4, 1), new CatalogItemName(nameFirstUpper, catalogItem4, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
127
        catalogItem4.setTypes(Stream.of(typeCountri, typeCountry).collect(Collectors.toCollection(LinkedHashSet::new)));
128
        catalogItem4.setCountries(Stream.of(new Country(countryBccb, catalogItem4, 1), new Country(countryDdd, catalogItem4, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
129
        catalogItem4.setWrittenForms(Stream.of(new WrittenForm(writtenForm, catalogItem4, 1), new WrittenForm(writtenFormForOr, catalogItem4, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
130

  
131
        catalogItemDto4 = new CatalogItemDto(catalogItemId4, "", Stream.of(nameTwelve, nameFirstUpper).collect(Collectors.toCollection(LinkedHashSet::new)),
132
                Stream.of(writtenForm, writtenFormForOr).collect(Collectors.toCollection(LinkedHashSet::new)), Stream.of(countri, country).collect(Collectors.toCollection(LinkedHashSet::new)),
133
                Stream.of(countryBccb, countryDdd).collect(Collectors.toCollection(LinkedHashSet::new)), new LinkedHashSet<>(),
134
                null, null, null, "");
123 135

  
124 136
        catalogItem5.setName(nameSedond);
125
        catalogItem5.setAlternativeNames(Set.of(new AlternativeName(nameThird, catalogItem5)));
126
        catalogItem5.setTypes(Set.of(typeCountri));
137
        catalogItem5.setAllNames(Stream.of(new CatalogItemName(nameThird, catalogItem5, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
138
        catalogItem5.setTypes(Stream.of(typeCountri).collect(Collectors.toCollection(LinkedHashSet::new)));
127 139

  
128
        catalogItemDto5 = new CatalogItemDto(catalogItemId5, nameSedond, Set.of(nameThird), Collections.emptySet(), Set.of(countri), Collections.emptySet(), Collections.emptySet(), null, null, null, "");
140
        catalogItemDto5 = new CatalogItemDto(catalogItemId5, nameSedond, Stream.of(nameThird).collect(Collectors.toCollection(LinkedHashSet::new)),
141
                new LinkedHashSet<>(), Stream.of(countri).collect(Collectors.toCollection(LinkedHashSet::new)),
142
                new LinkedHashSet<>(), new LinkedHashSet<>(),
143
                null, null, null, "");
129 144

  
130 145
        given(catalogItemRepository.findAll()).willReturn(List.of(catalogItem1, catalogItem2, catalogItem3, catalogItem4, catalogItem5));
131 146
    }
backend/src/test/java/cz/zcu/kiv/backendapi/catalog/CatalogItemServiceImplTest.java
1 1
package cz.zcu.kiv.backendapi.catalog;
2 2

  
3
import cz.zcu.kiv.backendapi.alternativename.AlternativeName;
3
import cz.zcu.kiv.backendapi.alternativename.CatalogItemName;
4 4
import cz.zcu.kiv.backendapi.bibliography.Bibliography;
5 5
import cz.zcu.kiv.backendapi.country.Country;
6 6
import cz.zcu.kiv.backendapi.exception.ApiRequestException;
......
50 50

  
51 51
        CatalogItem catalogItem = new CatalogItem();
52 52
        catalogItem.setName("aaacbbbbbbbaa");
53
        catalogItem.setBibliography(Set.of(new Bibliography("bibl", catalogItem)));
54
        catalogItem.setTypes(Set.of(type));
55
        catalogItem.setAlternativeNames(Set.of(new AlternativeName("altName", catalogItem)));
56
        catalogItem.setCountries(Set.of(new Country("aaaabbaa", catalogItem)));
57
        catalogItem.setWrittenForms(Set.of(new WrittenForm("written", catalogItem)));
53
        catalogItem.setBibliography(Stream.of(new Bibliography("bibl", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
54
        catalogItem.setTypes(Stream.of(type).collect(Collectors.toCollection(LinkedHashSet::new)));
55
        catalogItem.setAllNames(Stream.of(new CatalogItemName("altName", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
56
        catalogItem.setCountries(Stream.of(new Country("aaaabbaa", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
57
        catalogItem.setWrittenForms(Stream.of(new WrittenForm("written", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
58 58
        catalogItem.setCertainty(0);
59 59
        catalogItem.setLatitude(0.1);
60 60
        catalogItem.setLongitude(0.2);
61 61

  
62 62
        CatalogItem catalogItem2 = new CatalogItem();
63 63
        catalogItem2.setName("name");
64
        catalogItem2.setBibliography(Set.of(new Bibliography("bibl", catalogItem2)));
65
        catalogItem2.setTypes(Set.of(type));
66
        catalogItem2.setAlternativeNames(Set.of(new AlternativeName("aaaabbbbbbaa", catalogItem2)));
67
        catalogItem2.setCountries(Set.of(new Country("aaaabbcccefaa", catalogItem2)));
68
        catalogItem2.setWrittenForms(Set.of(new WrittenForm("written", catalogItem2)));
64
        catalogItem2.setBibliography(Stream.of(new Bibliography("bibl", catalogItem2, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
65
        catalogItem2.setTypes(Stream.of(type).collect(Collectors.toCollection(LinkedHashSet::new)));
66
        catalogItem2.setAllNames(Stream.of(new CatalogItemName("aaaabbbbbbaa", catalogItem2, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
67
        catalogItem2.setCountries(Stream.of(new Country("aaaabbcccefaa", catalogItem2, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
68
        catalogItem2.setWrittenForms(Stream.of(new WrittenForm("written", catalogItem2, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
69 69
        catalogItem2.setCertainty(1);
70 70
        catalogItem2.setLatitude(1.1);
71 71
        catalogItem2.setLongitude(1.2);
......
88 88
        // given
89 89
        CatalogItemDto catalogItemDto = new CatalogItemDto();
90 90
        catalogItemDto.setName("name");
91
        catalogItemDto.setBibliography(Stream.of("bibl").collect(Collectors.toSet()));
92
        catalogItemDto.setTypes(Stream.of("type").collect(Collectors.toSet()));
93
        catalogItemDto.setAlternativeNames(Stream.of("altName").collect(Collectors.toSet()));
94
        catalogItemDto.setCountries(Stream.of("country").collect(Collectors.toSet()));
95
        catalogItemDto.setWrittenForms(Stream.of("written").collect(Collectors.toSet()));
91
        catalogItemDto.setBibliography(Stream.of("bibl").collect(Collectors.toCollection(LinkedHashSet::new)));
92
        catalogItemDto.setTypes(Stream.of("type").collect(Collectors.toCollection(LinkedHashSet::new)));
93
        catalogItemDto.setAllNames(Stream.of("altName").collect(Collectors.toCollection(LinkedHashSet::new)));
94
        catalogItemDto.setCountries(Stream.of("country").collect(Collectors.toCollection(LinkedHashSet::new)));
95
        catalogItemDto.setWrittenForms(Stream.of("written").collect(Collectors.toCollection(LinkedHashSet::new)));
96 96
        catalogItemDto.setCertainty(0);
97 97
        catalogItemDto.setLatitude(0.1);
98 98
        catalogItemDto.setLongitude(0.2);
......
102 102

  
103 103
        CatalogItem catalogItem = new CatalogItem();
104 104
        catalogItem.setName("name");
105
        catalogItem.setBibliography(Stream.of(new Bibliography("bibl", catalogItem)).collect(Collectors.toSet()));
106
        catalogItem.setTypes(Stream.of(type).collect(Collectors.toSet()));
107
        catalogItem.setAlternativeNames(Stream.of(new AlternativeName("altName", catalogItem), new AlternativeName("name", catalogItem)).collect(Collectors.toSet()));
108
        catalogItem.setCountries(Stream.of(new Country("country", catalogItem)).collect(Collectors.toSet()));
109
        catalogItem.setWrittenForms(Stream.of(new WrittenForm("written", catalogItem)).collect(Collectors.toSet()));
105
        catalogItem.setBibliography(Stream.of(new Bibliography("bibl", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
106
        catalogItem.setTypes(Stream.of(type).collect(Collectors.toCollection(LinkedHashSet::new)));
107
        catalogItem.setAllNames(Stream.of(new CatalogItemName("altName", catalogItem, 1), new CatalogItemName("name", catalogItem, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
108
        catalogItem.setCountries(Stream.of(new Country("country", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
109
        catalogItem.setWrittenForms(Stream.of(new WrittenForm("written", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
110 110
        catalogItem.setCertainty(0);
111 111
        catalogItem.setLatitude(0.1);
112 112
        catalogItem.setLongitude(0.2);
......
129 129
        assertThat(capturedItem.getLongitude()).isEqualTo(catalogItem.getLongitude());
130 130
        assertThat(capturedItem.getLatitude()).isEqualTo(catalogItem.getLatitude());
131 131
        assertThat(capturedItem.getCertainty()).isEqualTo(catalogItem.getCertainty());
132
        assertThat(capturedItem.getAlternativeNames().size()).isEqualTo(catalogItem.getAlternativeNames().size());
132
        assertThat(capturedItem.getAllNames().size()).isEqualTo(catalogItem.getAllNames().size());
133 133
        assertThat(capturedItem.getBibliography().size()).isEqualTo(catalogItem.getBibliography().size());
134 134
        assertThat(capturedItem.getCountries().size()).isEqualTo(catalogItem.getCountries().size());
135 135
        assertThat(capturedItem.getWrittenForms().size()).isEqualTo(catalogItem.getWrittenForms().size());
......
177 177

  
178 178
        CatalogItemDto catalogItemDto = new CatalogItemDto();
179 179
        catalogItemDto.setName("name");
180
        catalogItemDto.setBibliography(Stream.of("bibl").collect(Collectors.toSet()));
181
        catalogItemDto.setTypes(Stream.of("type").collect(Collectors.toSet()));
182
        catalogItemDto.setAlternativeNames(Stream.of("altName").collect(Collectors.toSet()));
183
        catalogItemDto.setCountries(Stream.of("country").collect(Collectors.toSet()));
184
        catalogItemDto.setWrittenForms(Stream.of("written").collect(Collectors.toSet()));
180
        catalogItemDto.setBibliography(Stream.of("bibl").collect(Collectors.toCollection(LinkedHashSet::new)));
181
        catalogItemDto.setTypes(Stream.of("type").collect(Collectors.toCollection(LinkedHashSet::new)));
182
        catalogItemDto.setAllNames(Stream.of("altName").collect(Collectors.toCollection(LinkedHashSet::new)));
183
        catalogItemDto.setCountries(Stream.of("country").collect(Collectors.toCollection(LinkedHashSet::new)));
184
        catalogItemDto.setWrittenForms(Stream.of("written").collect(Collectors.toCollection(LinkedHashSet::new)));
185 185
        catalogItemDto.setCertainty(0);
186 186
        catalogItemDto.setLatitude(0.1);
187 187
        catalogItemDto.setLongitude(0.2);
......
193 193
        CatalogItem catalogItem = new CatalogItem();
194 194
        catalogItem.setId(id);
195 195
        catalogItem.setName("name");
196
        catalogItem.setBibliography(Stream.of(new Bibliography("bibl", catalogItem)).collect(Collectors.toSet()));
197
        catalogItem.setTypes(Stream.of(type).collect(Collectors.toSet()));
198
        catalogItem.setAlternativeNames(Stream.of(new AlternativeName("altName", catalogItem)).collect(Collectors.toSet()));
199
        catalogItem.setCountries(Stream.of(new Country("country", catalogItem)).collect(Collectors.toSet()));
200
        catalogItem.setWrittenForms(Stream.of(new WrittenForm("written", catalogItem)).collect(Collectors.toSet()));
196
        catalogItem.setBibliography(Stream.of(new Bibliography("bibl", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
197
        catalogItem.setTypes(Stream.of(type).collect(Collectors.toCollection(LinkedHashSet::new)));
198
        catalogItem.setAllNames(Stream.of(new CatalogItemName("altName", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
199
        catalogItem.setCountries(Stream.of(new Country("country", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
200
        catalogItem.setWrittenForms(Stream.of(new WrittenForm("written", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
201 201
        catalogItem.setCertainty(0);
202 202
        catalogItem.setLatitude(0.1);
203 203
        catalogItem.setLongitude(0.2);
......
206 206
        CatalogItem oldCatalogItem = new CatalogItem();
207 207
        oldCatalogItem.setId(id);
208 208
        oldCatalogItem.setName("old");
209
        oldCatalogItem.setBibliography(Stream.of(new Bibliography("old", oldCatalogItem)).collect(Collectors.toSet()));
210
        oldCatalogItem.setTypes(Stream.of(typeOld).collect(Collectors.toSet()));
211
        oldCatalogItem.setAlternativeNames(Stream.of(new AlternativeName("old", oldCatalogItem)).collect(Collectors.toSet()));
212
        oldCatalogItem.setCountries(Stream.of(new Country("old", oldCatalogItem)).collect(Collectors.toSet()));
213
        oldCatalogItem.setWrittenForms(Stream.of(new WrittenForm("old", catalogItem)).collect(Collectors.toSet()));
209
        oldCatalogItem.setBibliography(Stream.of(new Bibliography("old", oldCatalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
210
        oldCatalogItem.setTypes(Stream.of(typeOld).collect(Collectors.toCollection(LinkedHashSet::new)));
211
        oldCatalogItem.setAllNames(Stream.of(new CatalogItemName("old", oldCatalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
212
        oldCatalogItem.setCountries(Stream.of(new Country("old", oldCatalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
213
        oldCatalogItem.setWrittenForms(Stream.of(new WrittenForm("old", catalogItem, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
214 214
        oldCatalogItem.setCertainty(10);
215 215
        oldCatalogItem.setLatitude(10.1);
216 216
        oldCatalogItem.setLongitude(10.2);
......
236 236
        assertThat(capturedCatalogItem.getLatitude()).isEqualTo(catalogItem.getLatitude());
237 237
        assertThat(capturedCatalogItem.getLongitude()).isEqualTo(catalogItem.getLongitude());
238 238
        assertThat(capturedCatalogItem.getDescription()).isEqualTo(catalogItem.getDescription());
239
        assertThat(capturedCatalogItem.getTypes().stream().map(Type::getType).collect(Collectors.toSet())).isEqualTo(catalogItem.getTypes().stream().map(Type::getType).collect(Collectors.toSet()));
240
        Set<String> alternativeNamesEntity = catalogItem.getAlternativeNames().stream().map(AlternativeName::getName).collect(Collectors.toSet());
239
        assertThat(capturedCatalogItem.getTypes().stream().map(Type::getType).collect(Collectors.toSet())).isEqualTo(catalogItem.getTypes().stream().map(Type::getType).collect(Collectors.toCollection(LinkedHashSet::new)));
240
        Set<String> alternativeNamesEntity = catalogItem.getAllNames().stream().map(CatalogItemName::getName).collect(Collectors.toCollection(LinkedHashSet::new));
241 241
        alternativeNamesEntity.add(catalogItem.getName());
242
        assertThat(capturedCatalogItem.getAlternativeNames().stream().map(AlternativeName::getName).collect(Collectors.toSet())).isEqualTo(alternativeNamesEntity);
243
        assertThat(capturedCatalogItem.getCountries().stream().map(Country::getName).collect(Collectors.toSet())).isEqualTo(catalogItem.getCountries().stream().map(Country::getName).collect(Collectors.toSet()));
244
        assertThat(capturedCatalogItem.getBibliography().stream().map(Bibliography::getSource).collect(Collectors.toSet())).isEqualTo(catalogItem.getBibliography().stream().map(Bibliography::getSource).collect(Collectors.toSet()));
245
        assertThat(capturedCatalogItem.getWrittenForms().stream().map(WrittenForm::getForm).collect(Collectors.toSet())).isEqualTo(catalogItem.getWrittenForms().stream().map(WrittenForm::getForm).collect(Collectors.toSet()));
242
        assertThat(capturedCatalogItem.getAllNames().stream().map(CatalogItemName::getName).collect(Collectors.toSet())).isEqualTo(alternativeNamesEntity);
243
        assertThat(capturedCatalogItem.getCountries().stream().map(Country::getName).collect(Collectors.toSet())).isEqualTo(catalogItem.getCountries().stream().map(Country::getName).collect(Collectors.toCollection(LinkedHashSet::new)));
244
        assertThat(capturedCatalogItem.getBibliography().stream().map(Bibliography::getSource).collect(Collectors.toSet())).isEqualTo(catalogItem.getBibliography().stream().map(Bibliography::getSource).collect(Collectors.toCollection(LinkedHashSet::new)));
245
        assertThat(capturedCatalogItem.getWrittenForms().stream().map(WrittenForm::getForm).collect(Collectors.toSet())).isEqualTo(catalogItem.getWrittenForms().stream().map(WrittenForm::getForm).collect(Collectors.toCollection(LinkedHashSet::new)));
246 246
    }
247 247

  
248 248
    @Test
......
252 252

  
253 253
        CatalogItemDto catalogItemDto = new CatalogItemDto();
254 254
        catalogItemDto.setName("name");
255
        catalogItemDto.setBibliography(Set.of("bibl"));
256
        catalogItemDto.setTypes(Set.of("type"));
257
        catalogItemDto.setAlternativeNames(Set.of("altName"));
258
        catalogItemDto.setCountries(Set.of("country"));
259
        catalogItemDto.setWrittenForms(Set.of("written"));
255
        catalogItemDto.setBibliography(Stream.of("bibl").collect(Collectors.toCollection(LinkedHashSet::new)));
256
        catalogItemDto.setTypes(Stream.of("type").collect(Collectors.toCollection(LinkedHashSet::new)));
257
        catalogItemDto.setAllNames(Stream.of("altName").collect(Collectors.toCollection(LinkedHashSet::new)));
258
        catalogItemDto.setCountries(Stream.of("country").collect(Collectors.toCollection(LinkedHashSet::new)));
259
        catalogItemDto.setWrittenForms(Stream.of("written").collect(Collectors.toCollection(LinkedHashSet::new)));
260 260
        catalogItemDto.setCertainty(0);
261 261
        catalogItemDto.setLatitude(0.1);
262 262
        catalogItemDto.setLongitude(0.2);
......
300 300
    }
301 301

  
302 302

  
303

  
304 303
    @Test
305 304
    void testSearchedTest() {
306 305
        // given
307
        String text = "The city of Azbar was found in first century near the ocean. " +
308
                "⌈U-re-me-re⌉, another town, was found " +
309
                "in 1956. The location of Huga and Duga is not known, but it was probably near Puga.";
310
        String highlightedText = "The <b>city</b> of <span style='color:green'>Azbar</span> was found in first century near the <b>ocean</b>. " +
311
                "⌈<span style='color:green'>U-re-me-re</span>⌉, another town, was found " +
312
                "in 1956. The location of <span style='color:red'>Huga</span> and <span style='color:red'>Duga</span> is not known, but it was probably near Puga.";
306
        String text = "The city of Azbar was found in first century near the ocean.  " +
307
                "⌈U-re-me-re⌉, another town , was found " +
308
                "in 1956.\nThe location of Huga and Duga is not known, but it was probably near Puga.";
309
        String highlightedText = "The <b>city</b> of <span style='color:green'>Azbar</span> was found in first century near the <b>ocean</b>.  " +
310
                "⌈<span style='color:green'>U-re-me-re</span>⌉, another town , was found " +
311
                "in 1956.\nThe location of <span style='color:red'>Huga</span> and <span style='color:red'>Duga</span> is not known, but it was probably near Puga.";
313 312

  
314 313
        CatalogItem catalogItem1 = new CatalogItem();
315
        catalogItem1.setAlternativeNames(Stream.of(new AlternativeName("Azbar", catalogItem1)).collect(Collectors.toSet()));
314
        catalogItem1.setAllNames(Stream.of(new CatalogItemName("Azbar", catalogItem1, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
316 315
        catalogItem1.setLatitude(5.0);
317 316
        catalogItem1.setLongitude(5.0);
318 317

  
319 318
        CatalogItem catalogItem2 = new CatalogItem();
320
        catalogItem2.setAlternativeNames(Stream.of(new AlternativeName("Azbar", catalogItem2), new AlternativeName("Azbarasdf", catalogItem2)).collect(Collectors.toSet()));
319
        catalogItem2.setAllNames(Stream.of(new CatalogItemName("Azbar", catalogItem2, 1), new CatalogItemName("Azbarasdf", catalogItem2, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
321 320
        catalogItem2.setLatitude(null);
322 321
        catalogItem2.setLongitude(null);
323 322

  
324 323
        CatalogItem catalogItem3 = new CatalogItem();
325
        catalogItem3.setAlternativeNames(Stream.of(new AlternativeName("U-re-me-re", catalogItem3)).collect(Collectors.toSet()));
324
        catalogItem3.setAllNames(Stream.of(new CatalogItemName("U-re-me-re", catalogItem3, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
326 325
        catalogItem3.setLatitude(55.0);
327 326
        catalogItem3.setLongitude(68.0);
328 327

  
329 328
        CatalogItem catalogItem4 = new CatalogItem();
330
        catalogItem4.setAlternativeNames(Stream.of(new AlternativeName("Huga", catalogItem4)).collect(Collectors.toSet()));
329
        catalogItem4.setAllNames(Stream.of(new CatalogItemName("Huga", catalogItem4, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
331 330
        catalogItem4.setLatitude(null);
332 331
        catalogItem4.setLongitude(null);
333 332

  
334 333
        CatalogItem catalogItem5 = new CatalogItem();
335
        catalogItem5.setAlternativeNames(Stream.of(new AlternativeName("Huga", catalogItem5), new AlternativeName("Hugaa", catalogItem5)).collect(Collectors.toSet()));
334
        catalogItem5.setAllNames(Stream.of(new CatalogItemName("Huga", catalogItem5, 1), new CatalogItemName("Hugaa", catalogItem5, 2)).collect(Collectors.toCollection(LinkedHashSet::new)));
336 335
        catalogItem5.setLatitude(null);
337 336
        catalogItem5.setLongitude(null);
338 337

  
339 338
        CatalogItem catalogItem6 = new CatalogItem();
340
        catalogItem6.setAlternativeNames(Stream.of(new AlternativeName("Duga", catalogItem6)).collect(Collectors.toSet()));
339
        catalogItem6.setAllNames(Stream.of(new CatalogItemName("Duga", catalogItem6, 1)).collect(Collectors.toCollection(LinkedHashSet::new)));
341 340
        catalogItem6.setLatitude(null);
342 341
        catalogItem6.setLongitude(null);
343 342

  
344 343
        CatalogItemDto catalogItemDto1 = new CatalogItemDto();
345 344
        catalogItemDto1.setId(catalogItem1.getId());
346
        catalogItemDto1.setAlternativeNames(Stream.of("Azbar").collect(Collectors.toSet()));
345
        catalogItemDto1.setAllNames(Stream.of("Azbar").collect(Collectors.toCollection(LinkedHashSet::new)));
347 346
        catalogItemDto1.setLatitude(5.0);
348 347
        catalogItemDto1.setLongitude(5.0);
349 348

  
350 349
        CatalogItemDto catalogItemDto2 = new CatalogItemDto();
351 350
        catalogItemDto2.setId(catalogItem2.getId());
352
        catalogItemDto2.setAlternativeNames(Stream.of("Azbar", "Azbarasdf").collect(Collectors.toSet()));
351
        catalogItemDto2.setAllNames(Stream.of("Azbar", "Azbarasdf").collect(Collectors.toCollection(LinkedHashSet::new)));
353 352
        catalogItemDto2.setLatitude(null);
354 353
        catalogItemDto2.setLongitude(null);
355 354

  
356 355
        CatalogItemDto catalogItemDto3 = new CatalogItemDto();
357 356
        catalogItemDto3.setId(catalogItem3.getId());
358
        catalogItemDto3.setAlternativeNames(Stream.of("U-re-me-re").collect(Collectors.toSet()));
357
        catalogItemDto3.setAllNames(Stream.of("U-re-me-re").collect(Collectors.toCollection(LinkedHashSet::new)));
359 358
        catalogItemDto3.setLatitude(55.0);
360 359
        catalogItemDto3.setLongitude(68.0);
361 360

  
362 361
        CatalogItemDto catalogItemDto4 = new CatalogItemDto();
363 362
        catalogItemDto4.setId(catalogItem4.getId());
364
        catalogItemDto4.setAlternativeNames(Stream.of("Huga").collect(Collectors.toSet()));
363
        catalogItemDto4.setAllNames(Stream.of("Huga").collect(Collectors.toCollection(LinkedHashSet::new)));
365 364
        catalogItemDto4.setLatitude(null);
366 365
        catalogItemDto4.setLongitude(null);
367 366

  
368 367
        CatalogItemDto catalogItemDto5 = new CatalogItemDto();
369 368
        catalogItemDto5.setId(catalogItem5.getId());
370
        catalogItemDto5.setAlternativeNames(Stream.of("Huga", "Hugaa").collect(Collectors.toSet()));
369
        catalogItemDto5.setAllNames(Stream.of("Huga", "Hugaa").collect(Collectors.toCollection(LinkedHashSet::new)));
371 370
        catalogItemDto5.setLatitude(null);
372 371
        catalogItemDto5.setLongitude(null);
373 372

  
374 373
        CatalogItemDto catalogItemDto6 = new CatalogItemDto();
375 374
        catalogItemDto6.setId(catalogItem6.getId());
376
        catalogItemDto6.setAlternativeNames(Stream.of("Duga").collect(Collectors.toSet()));
375
        catalogItemDto6.setAllNames(Stream.of("Duga").collect(Collectors.toCollection(LinkedHashSet::new)));
377 376
        catalogItemDto6.setLatitude(null);
378 377
        catalogItemDto6.setLongitude(null);
379 378

  
380 379

  
381
        given(typeService.getAllTypesAsString()).willReturn(Stream.of("city", "ocean").collect(Collectors.toSet()));
380
        given(typeService.getAllTypesAsString()).willReturn(Stream.of("city", "ocean").collect(Collectors.toCollection(LinkedHashSet::new)));
382 381
        given(catalogItemRepository.getItemsByName(anyString())).willReturn(Collections.emptyList());
383 382
        given(catalogItemRepository.getItemsByName("Azbar")).willReturn(Stream.of(catalogItem1, catalogItem2).collect(Collectors.toList()));
384 383
        given(catalogItemRepository.getItemsByName("U-re-me-re")).willReturn(Stream.of(catalogItem3).collect(Collectors.toList()));

Také k dispozici: Unified diff