Revize cf12d561
Přidáno uživatelem Jakub Šmíd před asi 2 roky(ů)
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 |
} |
Také k dispozici: Unified diff
Catalog change
- one-to-many associations now persist order
- text for search persists separators
re #9751
re #9754