diff --git a/buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java b/buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java index 5e2e095..0f9f033 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java +++ b/buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java @@ -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))); } diff --git a/buisnesslogic/src/main/java/com/plannaplan/entities/Groups.java b/buisnesslogic/src/main/java/com/plannaplan/entities/Groups.java index 725d126..c6bbf4e 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/entities/Groups.java +++ b/buisnesslogic/src/main/java/com/plannaplan/entities/Groups.java @@ -34,26 +34,26 @@ public class Groups { @ManyToOne @JoinColumn(name = "lecturer_id") private Lecturer lecturer; - private String zaj_cyk_id; - private String gr_nr; + private Integer zajCykId; + private Integer grNr; public Groups() { } - public String getGr_nr() { - return gr_nr; + public Integer getGr_nr() { + return grNr; } - public void setGr_nr(String gr_nr) { - this.gr_nr = gr_nr; + public void setGr_nr(Integer grNr) { + this.grNr = grNr; } - public String getZaj_cyk_id() { - return zaj_cyk_id; + public Integer getZaj_cyk_id() { + return zajCykId; } - public void setZaj_cyk_id(String zaj_cyk_id) { - this.zaj_cyk_id = zaj_cyk_id; + public void setZaj_cyk_id(Integer zajCykId) { + this.zajCykId = zajCykId; } @@ -89,13 +89,13 @@ public class Groups { * @param endTime end time of class in minutes * @param day day given to the groups * @param lecturer lecturer given to the groups - * @param zaj_cyk_id number of class in the term + * @param zajCykId number of class in the term * @param gr_nr Number of class/course */ - public Groups(int capacity, String room, Course course, int time, int endTime, WeekDay day, Lecturer lecturer, String zaj_cyk_id, String gr_nr) { + public Groups(int capacity, String room, Course course, int time, int endTime, WeekDay day, Lecturer lecturer, Integer zajCykId, Integer grNr) { this(capacity, room, course, time, endTime, day, lecturer); - this.zaj_cyk_id = zaj_cyk_id; - this.gr_nr = gr_nr; + this.zajCykId = zajCykId; + this.grNr = grNr; } /** @@ -107,13 +107,13 @@ public class Groups { * @param time time given to the groups * @param day day given to the groups * @param lecturer lecturer given to the groups - * @param zaj_cyk_id number of class in the term - * @param gr_nr Number of class/course + * @param zajCykId number of class in the term + * @param grNr Number of class/course */ - public Groups(int capacity, String room, Course course, int time, WeekDay day, Lecturer lecturer, String zaj_cyk_id, String gr_nr) { + public Groups(int capacity, String room, Course course, int time, WeekDay day, Lecturer lecturer, Integer zajCykId, Integer grNr) { this(capacity, room, course, time, time + DEFAULT_CLASS_TIME, day, lecturer); - this.zaj_cyk_id = zaj_cyk_id; - this.gr_nr = gr_nr; + this.zajCykId = zajCykId; + this.grNr = grNr; } /** diff --git a/buisnesslogic/src/main/java/com/plannaplan/repositories/GroupRepository.java b/buisnesslogic/src/main/java/com/plannaplan/repositories/GroupRepository.java index 019a6ad..4d20a56 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/repositories/GroupRepository.java +++ b/buisnesslogic/src/main/java/com/plannaplan/repositories/GroupRepository.java @@ -28,6 +28,9 @@ public interface GroupRepository extends JpaRepository { @Query("FROM Groups WHERE time = ?1 AND room = ?2 AND capacity = ?3") Optional find(@Param("time") int time, @Param("room") String room, @Param("capacity") int capacity); + @Query("FROM Groups WHERE zajCykId = ?1 AND grNr = ?2") + Optional find(@Param("zajCykId") Integer zaj_cyk_id, @Param("grNr") Integer gr_nr); + @Query("FROM Groups WHERE course_id = ?1") List getByCourse(@Param("id") Long id); diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java b/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java index 65ab5c8..c3e40ca 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java +++ b/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java @@ -30,6 +30,10 @@ public class GroupService { return this.repo.find(time, room, capacity); } + public Optional find(Integer zajCykId, Integer nrGr ) { + return this.repo.find(zajCykId, nrGr); + } + public List getGroupsByCourse(Long id) { return this.repo.getByCourse(id); }