2020-07-23 17:27:20 +02:00
|
|
|
package com.plannaplan.configutils;
|
|
|
|
|
2020-07-28 18:04:38 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
|
2020-08-05 21:29:48 +02:00
|
|
|
import com.plannaplan.entities.Course;
|
2020-08-06 15:18:18 +02:00
|
|
|
import com.plannaplan.entities.Groups;
|
2020-07-28 18:04:38 +02:00
|
|
|
import com.plannaplan.entities.Lecturer;
|
2020-07-28 17:38:34 +02:00
|
|
|
import com.plannaplan.models.FileData;
|
2020-08-05 21:29:48 +02:00
|
|
|
import com.plannaplan.services.CourseService;
|
|
|
|
import com.plannaplan.services.GroupService;
|
2020-07-28 18:04:38 +02:00
|
|
|
import com.plannaplan.services.LecturerService;
|
2020-08-06 15:18:18 +02:00
|
|
|
import com.plannaplan.types.WeekDay;
|
2020-07-28 18:04:38 +02:00
|
|
|
|
2020-08-04 17:56:59 +02:00
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
2020-07-28 18:04:38 +02:00
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
2020-07-23 17:27:20 +02:00
|
|
|
|
|
|
|
public class FileToDatabaseMigrator {
|
2020-07-28 18:04:38 +02:00
|
|
|
public static String LECTURER_NAME_STRING = "imie";
|
|
|
|
public static String LECTURER_SURNAME_STRING = "nazwisko";
|
|
|
|
public static String LECTURER_TITLE_STRING = "tytul";
|
|
|
|
|
2020-08-05 21:29:48 +02:00
|
|
|
public static String COURSE_SYMBOL_STRING = "sym";
|
|
|
|
public static String COURSE_NAME_STRING = "nazwa";
|
|
|
|
|
2020-08-06 15:18:18 +02:00
|
|
|
public static String GROUP_DAY_STRING = "dzien";
|
|
|
|
public static String GROUP_TIME_STRING = "godz_od";
|
|
|
|
public static String ROOM_STRING = "sala";
|
|
|
|
public static String CAPACITY_STRING = "Mc";
|
|
|
|
|
2020-08-04 17:30:03 +02:00
|
|
|
LecturerService lecturerService;
|
2020-08-05 21:29:48 +02:00
|
|
|
CourseService courseService;
|
|
|
|
GroupService groupService;
|
2020-08-04 17:30:03 +02:00
|
|
|
|
2020-08-06 14:32:41 +02:00
|
|
|
public FileToDatabaseMigrator(LecturerService lecturerService, CourseService courseService,
|
|
|
|
GroupService groupService) {
|
2020-08-04 17:30:03 +02:00
|
|
|
this.lecturerService = lecturerService;
|
2020-08-06 14:32:41 +02:00
|
|
|
this.groupService = groupService;
|
|
|
|
this.courseService = courseService;
|
2020-07-23 17:27:20 +02:00
|
|
|
}
|
|
|
|
|
2020-07-28 17:38:34 +02:00
|
|
|
public void migrate(FileData data) {
|
2020-07-28 18:04:38 +02:00
|
|
|
Iterator<Row> rows = data.getRows();
|
|
|
|
|
2020-08-05 21:29:48 +02:00
|
|
|
int course_name_index = data.getIndexOf(FileToDatabaseMigrator.COURSE_NAME_STRING);
|
|
|
|
int sym_index = data.getIndexOf(FileToDatabaseMigrator.COURSE_SYMBOL_STRING);
|
|
|
|
|
2020-07-28 18:04:38 +02:00
|
|
|
int title_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_TITLE_STRING);
|
|
|
|
int surname_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_SURNAME_STRING);
|
|
|
|
int name_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_NAME_STRING);
|
|
|
|
|
2020-08-06 15:18:18 +02:00
|
|
|
int day_index = data.getIndexOf(FileToDatabaseMigrator.GROUP_DAY_STRING);
|
|
|
|
int time_index = data.getIndexOf(FileToDatabaseMigrator.GROUP_TIME_STRING);
|
|
|
|
int room_index = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
|
|
|
|
int capacity_index = data.getIndexOf(FileToDatabaseMigrator.CAPACITY_STRING);
|
|
|
|
|
2020-07-28 18:04:38 +02:00
|
|
|
while (rows.hasNext()) {
|
|
|
|
Row row = rows.next();
|
2020-08-04 18:15:00 +02:00
|
|
|
|
2020-08-05 21:29:48 +02:00
|
|
|
Cell course_name_cell = row.getCell(course_name_index);
|
|
|
|
Cell sym = row.getCell(sym_index);
|
|
|
|
|
2020-08-04 17:56:59 +02:00
|
|
|
Cell title_cell = row.getCell(title_index);
|
|
|
|
Cell name_cell = row.getCell(name_index);
|
|
|
|
Cell surname_cell = row.getCell(surname_index);
|
|
|
|
|
2020-08-06 15:18:18 +02:00
|
|
|
Cell day_cell = row.getCell(day_index);
|
|
|
|
Cell time_cell = row.getCell(time_index);
|
|
|
|
Cell room_cell = row.getCell(room_index);
|
|
|
|
Cell capacity_cell = row.getCell(capacity_index);
|
|
|
|
|
2020-08-04 17:56:59 +02:00
|
|
|
String lecturer_title = "";
|
|
|
|
String lecturer_surname = "";
|
|
|
|
String lecturer_name = "";
|
|
|
|
|
2020-08-06 14:32:41 +02:00
|
|
|
String course_name = course_name_cell.toString();
|
|
|
|
String sym_str = sym.toString();
|
|
|
|
|
2020-08-06 15:18:18 +02:00
|
|
|
int day = (int) Double.parseDouble(day_cell.toString());
|
|
|
|
WeekDay group_day = WeekDay.getDay(day);
|
|
|
|
String room = room_cell.toString();
|
|
|
|
int time = 480;
|
|
|
|
int capacity = (int) Double.parseDouble(capacity_cell.toString());
|
|
|
|
|
|
|
|
Groups group = groupService.find(time, capacity, room);
|
|
|
|
|
|
|
|
if (group == null) {
|
|
|
|
group = new Groups();
|
|
|
|
group.setCapacity(capacity);
|
|
|
|
group.setTime(time);
|
|
|
|
group.setRoom(room);
|
|
|
|
}
|
|
|
|
|
|
|
|
groupService.save(group);
|
|
|
|
|
2020-08-06 14:32:41 +02:00
|
|
|
Course course = this.courseService.getCourseByName(course_name);
|
2020-08-05 21:29:48 +02:00
|
|
|
|
|
|
|
if (course == null) {
|
|
|
|
course = new Course();
|
2020-08-06 14:32:41 +02:00
|
|
|
course.setName(course_name);
|
|
|
|
course.setSymbol(sym_str);
|
2020-08-05 21:29:48 +02:00
|
|
|
}
|
|
|
|
|
2020-08-06 14:32:41 +02:00
|
|
|
courseService.save(course);
|
|
|
|
|
2020-08-04 17:56:59 +02:00
|
|
|
if (title_cell != null) {
|
|
|
|
lecturer_title = title_cell.toString();
|
|
|
|
}
|
|
|
|
if (name_cell != null) {
|
|
|
|
lecturer_name = name_cell.toString();
|
|
|
|
}
|
|
|
|
if (surname_cell != null) {
|
|
|
|
lecturer_surname = surname_cell.toString();
|
|
|
|
}
|
|
|
|
|
2020-08-04 18:15:00 +02:00
|
|
|
if (lecturerService.getLecturer(lecturer_title, lecturer_name, lecturer_surname) == null) {
|
|
|
|
Lecturer newLecturer = new Lecturer(lecturer_title, lecturer_name, lecturer_surname);
|
|
|
|
lecturerService.save(newLecturer);
|
|
|
|
}
|
|
|
|
|
2020-07-28 18:04:38 +02:00
|
|
|
}
|
2020-07-23 17:27:20 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|