Added new columns into a FileMigrator and etc

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
2020-12-26 13:17:39 +01:00
parent 038d0b95d2
commit f51979484f
4 changed files with 40 additions and 21 deletions

View File

@ -32,6 +32,9 @@ public class FileToDatabaseMigrator {
private static final String ROOM_STRING = "sala";
private static final String CAPACITY_STRING = "Mc";
private static final String ZAJ_CYK_ID = "zaj_cyk_id";
private static final String GR_NR = "gr_nr";
@Autowired
private LecturerService lecturerService;
@Autowired
@ -56,6 +59,9 @@ public class FileToDatabaseMigrator {
int roomIndex = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
int capacityIndex = data.getIndexOf(FileToDatabaseMigrator.CAPACITY_STRING);
int zajCykIdIndex = data.getIndexOf(FileToDatabaseMigrator.ZAJ_CYK_ID);
int grNrIndex = data.getIndexOf(FileToDatabaseMigrator.GR_NR);
while (rows.hasNext()) {
Row row = rows.next();
@ -67,6 +73,12 @@ public class FileToDatabaseMigrator {
String lecturerSurname = row.getCell(surnameIndex) != null ? row.getCell(surnameIndex).toString().trim()
: "";
Integer zajCykId = row.getCell(zajCykIdIndex) != null ? (int) Double.parseDouble(row.getCell(zajCykIdIndex).toString().trim())
: null;
Integer grNr = row.getCell(grNrIndex) != null ? (int) Double.parseDouble(row.getCell(grNrIndex).toString().trim())
: null;
int day = (int) Double.parseDouble(row.getCell(dayIndex).toString());
WeekDay groupDay = WeekDay.getDay(day - 1);
int time = parseTimeToInt(row.getCell(timeIndex).toString());
@ -80,8 +92,8 @@ public class FileToDatabaseMigrator {
.orElseGet(() -> this.lecturerService
.save(new Lecturer(lecturerTitle, lecturerName, lecturerSurname)));
this.groupService.find(time, capacity, room).orElseGet(
() -> this.groupService.save(new Groups(capacity, room, course, time, groupDay, lecturer)));
this.groupService.find(zajCykId, grNr).orElseGet(
() -> this.groupService.save(new Groups(capacity, room, course, time, groupDay, lecturer, zajCykId, grNr)));
}