Added new column type with reading it and write groupType into DB

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2021-01-06 11:39:42 +01:00
parent 8c0b880412
commit 7813f148eb
Signed by: y0rune
GPG Key ID: F204C385F57EB348

View File

@ -8,6 +8,7 @@ import com.plannaplan.models.FileData;
import com.plannaplan.services.CourseService;
import com.plannaplan.services.GroupService;
import com.plannaplan.services.LecturerService;
import com.plannaplan.types.GroupType;
import com.plannaplan.types.WeekDay;
import org.apache.poi.ss.usermodel.Row;
@ -31,6 +32,7 @@ public class FileToDatabaseMigrator {
private static final String GROUP_TIME_STRING = "godz_od";
private static final String ROOM_STRING = "sala";
private static final String CAPACITY_STRING = "Mc";
private static final String TYPE_GROUP= "typ";
private static final String ZAJ_CYK_ID = "zaj_cyk_id";
private static final String GR_NR = "gr_nr";
@ -58,6 +60,7 @@ public class FileToDatabaseMigrator {
int timeIndex = data.getIndexOf(FileToDatabaseMigrator.GROUP_TIME_STRING);
int roomIndex = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
int capacityIndex = data.getIndexOf(FileToDatabaseMigrator.CAPACITY_STRING);
int typeGroupIndex = data.getIndexOf(FileToDatabaseMigrator.TYPE_GROUP);
int zajCykIdIndex = data.getIndexOf(FileToDatabaseMigrator.ZAJ_CYK_ID);
int grNrIndex = data.getIndexOf(FileToDatabaseMigrator.GR_NR);
@ -79,11 +82,12 @@ public class FileToDatabaseMigrator {
Integer grNr = row.getCell(grNrIndex) != null ? (int) Double.parseDouble(row.getCell(grNrIndex).toString().trim())
: null;
int day = (int) Double.parseDouble(row.getCell(dayIndex).toString());
int day = row.getCell(dayIndex) != null ? (int) Double.parseDouble(row.getCell(dayIndex).toString()) : 0;
WeekDay groupDay = WeekDay.getDay(day - 1);
int time = parseTimeToInt(row.getCell(timeIndex).toString());
String room = row.getCell(roomIndex).toString().trim();
int capacity = (int) Double.parseDouble(row.getCell(capacityIndex).toString());
GroupType typeGroup = GroupType.getType(row.getCell(typeGroupIndex).toString());
Course course = this.courseService.getCourseByName(courseName)
.orElseGet(() -> this.courseService.save(new Course(courseName, symbol)));
@ -93,9 +97,8 @@ public class FileToDatabaseMigrator {
.save(new Lecturer(lecturerTitle, lecturerName, lecturerSurname)));
Groups group = this.groupService.find(zajCykId, grNr).orElseGet(
() -> new Groups(capacity, room, course, time, groupDay, lecturer, zajCykId, grNr));
group.update(capacity, room, course, time, null, groupDay, lecturer);
() -> new Groups(capacity, room, course, time, capacity, groupDay, lecturer, zajCykId, grNr, typeGroup));
group.update(capacity, room, course, time, null, groupDay, lecturer, typeGroup);
this.groupService.save(group);