Revize abaa5f46
Přidáno uživatelem Jakub Šmíd před asi 2 roky(ů)
- ID abaa5f461242c640ae1e7daaddb6bfc1b1419db9
- Rodič c1df89f5
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 { |
Také k dispozici: Unified diff
Experiment with database