Added new columns into a FileMigrator and etc

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2020-12-26 13:17:39 +01:00
parent 038d0b95d2
commit f51979484f
Signed by: y0rune
GPG Key ID: F204C385F57EB348
4 changed files with 40 additions and 21 deletions

View File

@ -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)));
}

View File

@ -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;
}
/**

View File

@ -28,6 +28,9 @@ public interface GroupRepository extends JpaRepository<Groups, Long> {
@Query("FROM Groups WHERE time = ?1 AND room = ?2 AND capacity = ?3")
Optional<Groups> find(@Param("time") int time, @Param("room") String room, @Param("capacity") int capacity);
@Query("FROM Groups WHERE zajCykId = ?1 AND grNr = ?2")
Optional<Groups> find(@Param("zajCykId") Integer zaj_cyk_id, @Param("grNr") Integer gr_nr);
@Query("FROM Groups WHERE course_id = ?1")
List<Groups> getByCourse(@Param("id") Long id);

View File

@ -30,6 +30,10 @@ public class GroupService {
return this.repo.find(time, room, capacity);
}
public Optional<Groups> find(Integer zajCykId, Integer nrGr ) {
return this.repo.find(zajCykId, nrGr);
}
public List<Groups> getGroupsByCourse(Long id) {
return this.repo.getByCourse(id);
}