Checkpoint
This commit is contained in:
parent
430e8c9e7d
commit
bb3e9c536d
@ -2,8 +2,11 @@ package com.plannaplan.configutils;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Lecturer;
|
||||
import com.plannaplan.models.FileData;
|
||||
import com.plannaplan.services.CourseService;
|
||||
import com.plannaplan.services.GroupService;
|
||||
import com.plannaplan.services.LecturerService;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
@ -14,7 +17,12 @@ public class FileToDatabaseMigrator {
|
||||
public static String LECTURER_SURNAME_STRING = "nazwisko";
|
||||
public static String LECTURER_TITLE_STRING = "tytul";
|
||||
|
||||
public static String COURSE_SYMBOL_STRING = "sym";
|
||||
public static String COURSE_NAME_STRING = "nazwa";
|
||||
|
||||
LecturerService lecturerService;
|
||||
CourseService courseService;
|
||||
GroupService groupService;
|
||||
|
||||
public FileToDatabaseMigrator(LecturerService lecturerService) {
|
||||
this.lecturerService = lecturerService;
|
||||
@ -23,6 +31,9 @@ public class FileToDatabaseMigrator {
|
||||
public void migrate(FileData data) {
|
||||
Iterator<Row> rows = data.getRows();
|
||||
|
||||
int course_name_index = data.getIndexOf(FileToDatabaseMigrator.COURSE_NAME_STRING);
|
||||
int sym_index = data.getIndexOf(FileToDatabaseMigrator.COURSE_SYMBOL_STRING);
|
||||
|
||||
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);
|
||||
@ -30,6 +41,9 @@ public class FileToDatabaseMigrator {
|
||||
while (rows.hasNext()) {
|
||||
Row row = rows.next();
|
||||
|
||||
Cell course_name_cell = row.getCell(course_name_index);
|
||||
Cell sym = row.getCell(sym_index);
|
||||
|
||||
Cell title_cell = row.getCell(title_index);
|
||||
Cell name_cell = row.getCell(name_index);
|
||||
Cell surname_cell = row.getCell(surname_index);
|
||||
@ -38,6 +52,12 @@ public class FileToDatabaseMigrator {
|
||||
String lecturer_surname = "";
|
||||
String lecturer_name = "";
|
||||
|
||||
Course course = this.courseService.getCourseByName("");
|
||||
|
||||
if (course == null) {
|
||||
course = new Course();
|
||||
}
|
||||
|
||||
if (title_cell != null) {
|
||||
lecturer_title = title_cell.toString();
|
||||
}
|
||||
|
@ -3,9 +3,12 @@ package com.plannaplan.repositories;
|
||||
import com.plannaplan.entities.Course;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface CourseRepository extends JpaRepository<Course, Long> {
|
||||
|
||||
@Query(value = "SELECT * FROM course WHERE name = :name", nativeQuery = true)
|
||||
Course findByName(@Param("name") String name);
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.repositories.CourseRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -9,4 +10,8 @@ import org.springframework.stereotype.Service;
|
||||
public class CourseService {
|
||||
@Autowired
|
||||
private CourseRepository repo;
|
||||
|
||||
public Course getCourseByName(String name) {
|
||||
return this.repo.findByName(name);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user