Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions src/main/java/com/example/gimmegonghakauth/InitFileData.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Profile;
Expand Down Expand Up @@ -46,14 +47,11 @@ private void inputCoursesCsv(String csvFilePath) throws IOException {
String cvsSplitBy = ",";

try (BufferedReader br = new BufferedReader(new FileReader(csvFilePath))) {
// Skip the header line

while ((line = br.readLine()) != null) {
String[] data = line.split(cvsSplitBy);
// Create and map GonghakCoursesDomain object
try {
CoursesDomain course = mapToCoursesDomain(data);
// Save to repository
coursesDao.save(course);
} catch (Exception e) {
continue;
Expand All @@ -77,16 +75,15 @@ private void inputGonghakCoursesCsv(String csvFilePath) {
String cvsSplitBy = ",";

try (BufferedReader br = new BufferedReader(new FileReader(csvFilePath))) {
// Skip the header line
br.readLine();

while ((line = br.readLine()) != null) {
String[] data = line.split(cvsSplitBy);
// Create and map GonghakCoursesDomain object
try {
GonghakCoursesDomain course = mapToGonghakCoursesDomain(data);
// Save to repository
gonghakCorusesDao.save(course);
Optional<GonghakCoursesDomain> course = mapToGonghakCoursesDomain(data);
if (course.isPresent()) {
gonghakCorusesDao.save(course.get());
}
} catch (Exception e) {
continue;
}
Expand All @@ -96,16 +93,39 @@ private void inputGonghakCoursesCsv(String csvFilePath) {
}
}

private GonghakCoursesDomain mapToGonghakCoursesDomain(String[] data) {
// Assuming data format is consistent and matches the domain structure
// Adjust indices according to your CSV file's column order
return GonghakCoursesDomain.builder()
private Optional<GonghakCoursesDomain> mapToGonghakCoursesDomain(String[] data) {

CoursesDomain courseDomain = coursesDao.findByName(data[6].replaceAll("\\s+", ""));
if (courseDomain == null) {
return Optional.empty();
}

// course_category_const
String courseCategory = data[4];

switch (courseCategory) {
case "์ค‘ํ•ตํ•„์ˆ˜", "๊ต์–‘ํ•„์ˆ˜", "๊ต์–‘์„ ํƒ", "๊ต์–‘์„ ํƒI", "๊ต์–‘":
courseCategory = "์ „๋ฌธ๊ต์–‘";
break;
case "์ „๊ณต๊ธฐ์ดˆ๊ต์–‘", "ํ•™๋ฌธ๊ธฐ์ดˆ๊ต์–‘":
courseCategory = "BSM";
break;
case "์ „๊ณตํ•„์ˆ˜", "์ „๊ณต์„ ํƒ", "์ „๊ณต(์„ค๊ณ„)", "์ „๊ณต์ฃผ์ œ", "์ „๊ณต๊ธฐ์ดˆ":
courseCategory = "์ „๊ณต";
break;
default:
break;
}

GonghakCoursesDomain gonghakCourse = GonghakCoursesDomain.builder()
.year(Integer.parseInt(data[0]))
.majorsDomain(majorsDao.findByMajor(data[2]))
.coursesDomain(coursesDao.findByName(data[6]))
.courseCategory(CourseCategoryConst.valueOf(data[4]))
.passCategory(data[5])
.coursesDomain(courseDomain)
.courseCategory(CourseCategoryConst.valueOf(courseCategory))
.passCategory(data[5].substring(0, 2))
.designCredit(Double.parseDouble(data[8]))
.build();

return Optional.of(gonghakCourse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

public enum MajorName {
ELEC_INFO("์ „์ž์ •๋ณดํ†ต์‹ ๊ณตํ•™๊ณผ"),
COMPUTER("์ปดํ“จํ„ฐ๊ณตํ•™๊ณผ");
COMPUTER("์ปดํ“จํ„ฐ๊ณตํ•™๊ณผ"),
SOFTWARE("์†Œํ”„ํŠธ์›จ์–ดํ•™๊ณผ"),
DATA_SCIENCE("๋ฐ์ดํ„ฐ์‚ฌ์ด์–ธ์Šคํ•™๊ณผ");

private final String name;
MajorName(String name) {
Expand Down