From ac0851ae290f6b9f8cf33c7af6d38a9fb0e8465c Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Sat, 8 Aug 2020 00:08:36 +0200 Subject: [PATCH] Config worksgit add .git add . --- .../configutils/FileToDatabaseMigrator.java | 51 ++++++++++++++----- .../repositories/GroupRepository.java | 2 +- .../com/plannaplan/services/GroupService.java | 3 ++ 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java b/buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java index ba0d3d3..749d3d8 100644 --- a/buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java +++ b/buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java @@ -9,6 +9,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.Cell; @@ -78,20 +79,12 @@ public class FileToDatabaseMigrator { int day = (int) Double.parseDouble(day_cell.toString()); WeekDay group_day = WeekDay.getDay(day); String room = room_cell.toString(); - int time = 480; + int time = this.parseTimeToInt(time_cell.toString()); + int capacity = (int) Double.parseDouble(capacity_cell.toString()); Groups group = groupService.find(time, capacity, room); - if (group == null) { - group = new Groups(); - group.setCapacity(capacity); - group.setTime(time); - group.setRoom(room); - } - - groupService.save(group); - Course course = this.courseService.getCourseByName(course_name); if (course == null) { @@ -112,12 +105,44 @@ public class FileToDatabaseMigrator { lecturer_surname = surname_cell.toString(); } - if (lecturerService.getLecturer(lecturer_title, lecturer_name, lecturer_surname) == null) { - Lecturer newLecturer = new Lecturer(lecturer_title, lecturer_name, lecturer_surname); - lecturerService.save(newLecturer); + Lecturer lecturer = lecturerService.getLecturer(lecturer_title, lecturer_name, lecturer_surname); + + if (lecturer == null) { + lecturer = new Lecturer(lecturer_title, lecturer_name, lecturer_surname); + lecturerService.save(lecturer); + } + + if (group == null) { + group = new Groups(); + group.setCapacity(capacity); + group.setRoom(room); + group.setCourseId(course); + group.setTime(time); + if (capacity >= 50) { + group.setType(GroupType.LECTURE); + } else { + group.setType(GroupType.CLASS); + } + group.setDay(group_day); + group.setLecturer(lecturer); + + groupService.save(group); } } } + + private Integer parseTimeToInt(String time) { + String times[] = time.split("\\."); + if (times.length == 2) { + return Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]); + } + times = time.split("\\:"); + if (times.length == 2) { + return Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]); + } + + return 0; + } } \ No newline at end of file diff --git a/buisnesslogic/src/main/java/com/plannaplan/repositories/GroupRepository.java b/buisnesslogic/src/main/java/com/plannaplan/repositories/GroupRepository.java index d733239..c222bfc 100644 --- a/buisnesslogic/src/main/java/com/plannaplan/repositories/GroupRepository.java +++ b/buisnesslogic/src/main/java/com/plannaplan/repositories/GroupRepository.java @@ -9,6 +9,6 @@ import org.springframework.stereotype.Repository; @Repository public interface GroupRepository extends JpaRepository { - @Query(value = "SELECT * FROM groups WHERE name = :name AND surname = :surname AND title = :title ", nativeQuery = true) + @Query(value = "SELECT * FROM groups WHERE time = :time AND room = :room AND capacity = :capacity ", nativeQuery = true) Groups find(@Param("time") int time, @Param("room") String room, @Param("capacity") int capacity); } \ No newline at end of file diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java b/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java index b4ebe2b..9136994 100644 --- a/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java +++ b/buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java @@ -11,6 +11,9 @@ public class GroupService { @Autowired private GroupRepository repo; + public GroupService() { + } + public Groups find(int time, int capacity, String room) { return this.repo.find(time, room, capacity); }