Revize d6451c0a
Přidáno uživatelem Jakub Šmíd před asi 2 roky(ů)
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.EqualsAndHashCode; |
|
9 |
import lombok.Getter; |
|
9 | 10 |
import lombok.NoArgsConstructor; |
11 |
import lombok.Setter; |
|
10 | 12 |
import org.hibernate.annotations.Fetch; |
11 | 13 |
import org.hibernate.annotations.FetchMode; |
12 | 14 |
import org.hibernate.annotations.LazyCollection; |
... | ... | |
21 | 23 |
/** |
22 | 24 |
* Catalog entity representing catalog item |
23 | 25 |
*/ |
24 |
@Data |
|
26 |
@Getter |
|
27 |
@Setter |
|
28 |
@EqualsAndHashCode(onlyExplicitlyIncluded = true) |
|
25 | 29 |
@NoArgsConstructor |
26 | 30 |
@Entity |
27 | 31 |
@Table(name = "catalog_item") |
... | ... | |
33 | 37 |
* Catalog item id |
34 | 38 |
*/ |
35 | 39 |
@Id |
36 |
@GeneratedValue |
|
37 |
private UUID id; |
|
40 |
// @GeneratedValue |
|
41 |
@EqualsAndHashCode.Include |
|
42 |
private UUID id = UUID.randomUUID(); |
|
38 | 43 |
|
39 | 44 |
/** |
40 | 45 |
* Name of geographic item |
... | ... | |
68 | 73 |
@OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL) |
69 | 74 |
@LazyCollection(LazyCollectionOption.FALSE) |
70 | 75 |
@Fetch(FetchMode.SUBSELECT) |
71 |
private Set<Bibliography> bibliography = Collections.emptySet();
|
|
76 |
private Set<Bibliography> bibliography = new HashSet<>();
|
|
72 | 77 |
|
73 | 78 |
/** |
74 | 79 |
* Countries |
... | ... | |
76 | 81 |
@OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL) |
77 | 82 |
@LazyCollection(LazyCollectionOption.FALSE) |
78 | 83 |
@Fetch(FetchMode.SUBSELECT) |
79 |
private Set<Country> countries = Collections.emptySet();
|
|
84 |
private Set<Country> countries = new HashSet<>();
|
|
80 | 85 |
|
81 | 86 |
/** |
82 | 87 |
* Written forms |
... | ... | |
84 | 89 |
@OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL) |
85 | 90 |
@LazyCollection(LazyCollectionOption.FALSE) |
86 | 91 |
@Fetch(FetchMode.SUBSELECT) |
87 |
private Set<WrittenForm> writtenForms = Collections.emptySet();
|
|
92 |
private Set<WrittenForm> writtenForms = new HashSet<>();
|
|
88 | 93 |
|
89 | 94 |
/** |
90 | 95 |
* Alternative names |
... | ... | |
92 | 97 |
@OneToMany(mappedBy = "catalogItem", cascade = CascadeType.ALL) |
93 | 98 |
@LazyCollection(LazyCollectionOption.FALSE) |
94 | 99 |
@Fetch(FetchMode.SUBSELECT) |
95 |
private Set<AlternativeName> alternativeNames = Collections.emptySet();
|
|
100 |
private Set<AlternativeName> alternativeNames = new HashSet<>();
|
|
96 | 101 |
|
97 | 102 |
/** |
98 | 103 |
* Set of user roles - many-to-many relationship |
... | ... | |
108 | 113 |
@JoinColumn(name = "type", referencedColumnName = "type") |
109 | 114 |
} |
110 | 115 |
) |
111 |
private Set<Type> types = Collections.emptySet();
|
|
116 |
private Set<Type> types = new HashSet<>();
|
|
112 | 117 |
|
113 | 118 |
public CatalogItem(final List<String> csvFields) { |
114 | 119 |
|
115 | 120 |
this.name = csvFields.get(1); |
116 |
List<String> stringList = processListField(csvFields.get(2));
|
|
121 |
Set<String> stringList = processListField(csvFields.get(2));
|
|
117 | 122 |
this.alternativeNames = stringList.stream().map(s -> new AlternativeName(s, this)).collect(Collectors.toSet()); |
118 | 123 |
|
119 | 124 |
this.certainty = processIntField(csvFields.get(3)); |
... | ... | |
151 | 156 |
} |
152 | 157 |
} |
153 | 158 |
|
154 |
private List<String> processListField(String field) {
|
|
159 |
private Set<String> processListField(String field) {
|
|
155 | 160 |
if (field.isEmpty() || field.equals(EMPTY_ENTRY)) { |
156 |
return new ArrayList<>();
|
|
161 |
return new HashSet<>();
|
|
157 | 162 |
} |
158 |
return Arrays.stream(field.split(",")).map(String::trim).filter(item -> !item.isEmpty()).collect(Collectors.toList());
|
|
163 |
return Arrays.stream(field.split(",")).map(String::trim).filter(item -> !item.isEmpty()).collect(Collectors.toSet());
|
|
159 | 164 |
} |
160 | 165 |
} |
Také k dispozici: Unified diff
Added filter for written forms and some tests
re #9492