2020-07-23 17:27:20 +02:00
|
|
|
package com.plannaplan.configutils;
|
|
|
|
|
2020-07-28 18:04:38 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import com.plannaplan.entities.Lecturer;
|
2020-07-28 17:38:34 +02:00
|
|
|
import com.plannaplan.models.FileData;
|
2020-07-28 18:04:38 +02:00
|
|
|
import com.plannaplan.services.LecturerService;
|
|
|
|
|
|
|
|
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-07-23 17:27:20 +02:00
|
|
|
public FileToDatabaseMigrator() {
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
LecturerService lecturerService = new LecturerService();
|
|
|
|
|
|
|
|
while (rows.hasNext()) {
|
|
|
|
Row row = rows.next();
|
|
|
|
Lecturer newLecturer = new Lecturer(row.getCell(title_index).toString(), row.getCell(name_index).toString(),
|
|
|
|
row.getCell(surname_index).toString());
|
|
|
|
|
|
|
|
lecturerService.save(newLecturer);
|
|
|
|
}
|
2020-07-23 17:27:20 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|