Added courses saveing
This commit is contained in:
parent
bb3e9c536d
commit
368b4066c0
@ -3,6 +3,8 @@ package com.plannaplan;
|
|||||||
import com.plannaplan.interfaces.ProtectedAction;
|
import com.plannaplan.interfaces.ProtectedAction;
|
||||||
import com.plannaplan.models.ConfigData;
|
import com.plannaplan.models.ConfigData;
|
||||||
import com.plannaplan.models.FileData;
|
import com.plannaplan.models.FileData;
|
||||||
|
import com.plannaplan.services.CourseService;
|
||||||
|
import com.plannaplan.services.GroupService;
|
||||||
import com.plannaplan.services.LecturerService;
|
import com.plannaplan.services.LecturerService;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -16,13 +18,19 @@ public class Configurator implements ProtectedAction {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private LecturerService lecturerService;
|
private LecturerService lecturerService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CourseService courseService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GroupService groupService;
|
||||||
|
|
||||||
public Configurator() {
|
public Configurator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void config(ConfigData data) {
|
public void config(ConfigData data) {
|
||||||
FileReader reader = new FileReader(data.getFilestream());
|
FileReader reader = new FileReader(data.getFilestream());
|
||||||
FileData coursesData = reader.read();
|
FileData coursesData = reader.read();
|
||||||
FileToDatabaseMigrator mgtr = new FileToDatabaseMigrator(lecturerService);
|
FileToDatabaseMigrator mgtr = new FileToDatabaseMigrator(lecturerService, courseService, groupService);
|
||||||
mgtr.migrate(coursesData);
|
mgtr.migrate(coursesData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,8 +24,11 @@ public class FileToDatabaseMigrator {
|
|||||||
CourseService courseService;
|
CourseService courseService;
|
||||||
GroupService groupService;
|
GroupService groupService;
|
||||||
|
|
||||||
public FileToDatabaseMigrator(LecturerService lecturerService) {
|
public FileToDatabaseMigrator(LecturerService lecturerService, CourseService courseService,
|
||||||
|
GroupService groupService) {
|
||||||
this.lecturerService = lecturerService;
|
this.lecturerService = lecturerService;
|
||||||
|
this.groupService = groupService;
|
||||||
|
this.courseService = courseService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void migrate(FileData data) {
|
public void migrate(FileData data) {
|
||||||
@ -52,12 +55,19 @@ public class FileToDatabaseMigrator {
|
|||||||
String lecturer_surname = "";
|
String lecturer_surname = "";
|
||||||
String lecturer_name = "";
|
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) {
|
if (course == null) {
|
||||||
course = new Course();
|
course = new Course();
|
||||||
|
course.setName(course_name);
|
||||||
|
course.setSymbol(sym_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
courseService.save(course);
|
||||||
|
|
||||||
if (title_cell != null) {
|
if (title_cell != null) {
|
||||||
lecturer_title = title_cell.toString();
|
lecturer_title = title_cell.toString();
|
||||||
}
|
}
|
||||||
|
@ -14,4 +14,8 @@ public class CourseService {
|
|||||||
public Course getCourseByName(String name) {
|
public Course getCourseByName(String name) {
|
||||||
return this.repo.findByName(name);
|
return this.repo.findByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void save(Course course) {
|
||||||
|
this.repo.save(course);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user