diff --git a/buisnesslogic/src/main/java/com/plannaplan/Configurator.java b/buisnesslogic/src/main/java/com/plannaplan/Configurator.java index 79de217..21367d8 100644 --- a/buisnesslogic/src/main/java/com/plannaplan/Configurator.java +++ b/buisnesslogic/src/main/java/com/plannaplan/Configurator.java @@ -3,6 +3,8 @@ package com.plannaplan; import com.plannaplan.interfaces.ProtectedAction; import com.plannaplan.models.ConfigData; import com.plannaplan.models.FileData; +import com.plannaplan.services.CourseService; +import com.plannaplan.services.GroupService; import com.plannaplan.services.LecturerService; import org.springframework.beans.factory.annotation.Autowired; @@ -16,13 +18,19 @@ public class Configurator implements ProtectedAction { @Autowired private LecturerService lecturerService; + @Autowired + private CourseService courseService; + + @Autowired + private GroupService groupService; + public Configurator() { } public void config(ConfigData data) { FileReader reader = new FileReader(data.getFilestream()); FileData coursesData = reader.read(); - FileToDatabaseMigrator mgtr = new FileToDatabaseMigrator(lecturerService); + FileToDatabaseMigrator mgtr = new FileToDatabaseMigrator(lecturerService, courseService, groupService); mgtr.migrate(coursesData); } diff --git a/buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java b/buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java index c54a5df..02f20ff 100644 --- a/buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java +++ b/buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java @@ -24,8 +24,11 @@ public class FileToDatabaseMigrator { CourseService courseService; GroupService groupService; - public FileToDatabaseMigrator(LecturerService lecturerService) { + public FileToDatabaseMigrator(LecturerService lecturerService, CourseService courseService, + GroupService groupService) { this.lecturerService = lecturerService; + this.groupService = groupService; + this.courseService = courseService; } public void migrate(FileData data) { @@ -52,12 +55,19 @@ public class FileToDatabaseMigrator { String lecturer_surname = ""; String lecturer_name = ""; - Course course = this.courseService.getCourseByName(""); + String course_name = course_name_cell.toString(); + String sym_str = sym.toString(); + + Course course = this.courseService.getCourseByName(course_name); if (course == null) { course = new Course(); + course.setName(course_name); + course.setSymbol(sym_str); } + courseService.save(course); + if (title_cell != null) { lecturer_title = title_cell.toString(); } diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/CourseService.java b/buisnesslogic/src/main/java/com/plannaplan/services/CourseService.java index 80c0cc9..9be0ba8 100644 --- a/buisnesslogic/src/main/java/com/plannaplan/services/CourseService.java +++ b/buisnesslogic/src/main/java/com/plannaplan/services/CourseService.java @@ -14,4 +14,8 @@ public class CourseService { public Course getCourseByName(String name) { return this.repo.findByName(name); } + + public void save(Course course) { + this.repo.save(course); + } } \ No newline at end of file