Checkpoint
This commit is contained in:
@ -1,12 +1,37 @@
|
||||
package com.plannaplan.configutils;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.plannaplan.entities.Lecturer;
|
||||
import com.plannaplan.models.FileData;
|
||||
import com.plannaplan.services.LecturerService;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
|
||||
public class FileToDatabaseMigrator {
|
||||
public static String LECTURER_NAME_STRING = "imie";
|
||||
public static String LECTURER_SURNAME_STRING = "nazwisko";
|
||||
public static String LECTURER_TITLE_STRING = "tytul";
|
||||
|
||||
public FileToDatabaseMigrator() {
|
||||
}
|
||||
|
||||
public void migrate(FileData data) {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -14,9 +14,6 @@ public class Lecturer {
|
||||
private String name;
|
||||
private String surname;
|
||||
|
||||
public Lecturer() {
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
@ -41,4 +38,10 @@ public class Lecturer {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public Lecturer(String title, String name, String surname) {
|
||||
this.title = title;
|
||||
this.name = name;
|
||||
this.surname = surname;
|
||||
}
|
||||
|
||||
}
|
@ -31,4 +31,9 @@ public class FileData {
|
||||
this.keys = keys;
|
||||
}
|
||||
|
||||
public int getIndexOf(String key) {
|
||||
int index = this.keys.get(key);
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import com.plannaplan.entities.Lecturer;
|
||||
import com.plannaplan.repositories.LecturerRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -9,4 +10,8 @@ import org.springframework.stereotype.Service;
|
||||
public class LecturerService {
|
||||
@Autowired
|
||||
private LecturerRepository repo;
|
||||
|
||||
public void save(Lecturer lecturer) {
|
||||
repo.save(lecturer);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user