Added new columns into a FileMigrator and etc
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
parent
038d0b95d2
commit
f51979484f
@ -32,6 +32,9 @@ public class FileToDatabaseMigrator {
|
|||||||
private static final String ROOM_STRING = "sala";
|
private static final String ROOM_STRING = "sala";
|
||||||
private static final String CAPACITY_STRING = "Mc";
|
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
|
@Autowired
|
||||||
private LecturerService lecturerService;
|
private LecturerService lecturerService;
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -56,6 +59,9 @@ public class FileToDatabaseMigrator {
|
|||||||
int roomIndex = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
|
int roomIndex = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
|
||||||
int capacityIndex = data.getIndexOf(FileToDatabaseMigrator.CAPACITY_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()) {
|
while (rows.hasNext()) {
|
||||||
Row row = rows.next();
|
Row row = rows.next();
|
||||||
|
|
||||||
@ -67,6 +73,12 @@ public class FileToDatabaseMigrator {
|
|||||||
String lecturerSurname = row.getCell(surnameIndex) != null ? row.getCell(surnameIndex).toString().trim()
|
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());
|
int day = (int) Double.parseDouble(row.getCell(dayIndex).toString());
|
||||||
WeekDay groupDay = WeekDay.getDay(day - 1);
|
WeekDay groupDay = WeekDay.getDay(day - 1);
|
||||||
int time = parseTimeToInt(row.getCell(timeIndex).toString());
|
int time = parseTimeToInt(row.getCell(timeIndex).toString());
|
||||||
@ -80,8 +92,8 @@ public class FileToDatabaseMigrator {
|
|||||||
.orElseGet(() -> this.lecturerService
|
.orElseGet(() -> this.lecturerService
|
||||||
.save(new Lecturer(lecturerTitle, lecturerName, lecturerSurname)));
|
.save(new Lecturer(lecturerTitle, lecturerName, lecturerSurname)));
|
||||||
|
|
||||||
this.groupService.find(time, capacity, room).orElseGet(
|
this.groupService.find(zajCykId, grNr).orElseGet(
|
||||||
() -> this.groupService.save(new Groups(capacity, room, course, time, groupDay, lecturer)));
|
() -> this.groupService.save(new Groups(capacity, room, course, time, groupDay, lecturer, zajCykId, grNr)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,26 +34,26 @@ public class Groups {
|
|||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "lecturer_id")
|
@JoinColumn(name = "lecturer_id")
|
||||||
private Lecturer lecturer;
|
private Lecturer lecturer;
|
||||||
private String zaj_cyk_id;
|
private Integer zajCykId;
|
||||||
private String gr_nr;
|
private Integer grNr;
|
||||||
|
|
||||||
public Groups() {
|
public Groups() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGr_nr() {
|
public Integer getGr_nr() {
|
||||||
return gr_nr;
|
return grNr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGr_nr(String gr_nr) {
|
public void setGr_nr(Integer grNr) {
|
||||||
this.gr_nr = gr_nr;
|
this.grNr = grNr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getZaj_cyk_id() {
|
public Integer getZaj_cyk_id() {
|
||||||
return zaj_cyk_id;
|
return zajCykId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setZaj_cyk_id(String zaj_cyk_id) {
|
public void setZaj_cyk_id(Integer zajCykId) {
|
||||||
this.zaj_cyk_id = zaj_cyk_id;
|
this.zajCykId = zajCykId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -89,13 +89,13 @@ public class Groups {
|
|||||||
* @param endTime end time of class in minutes
|
* @param endTime end time of class in minutes
|
||||||
* @param day day given to the groups
|
* @param day day given to the groups
|
||||||
* @param lecturer lecturer 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
|
* @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(capacity, room, course, time, endTime, day, lecturer);
|
||||||
this.zaj_cyk_id = zaj_cyk_id;
|
this.zajCykId = zajCykId;
|
||||||
this.gr_nr = gr_nr;
|
this.grNr = grNr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,13 +107,13 @@ public class Groups {
|
|||||||
* @param time time given to the groups
|
* @param time time given to the groups
|
||||||
* @param day day given to the groups
|
* @param day day given to the groups
|
||||||
* @param lecturer lecturer 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
|
* @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(capacity, room, course, time, time + DEFAULT_CLASS_TIME, day, lecturer);
|
||||||
this.zaj_cyk_id = zaj_cyk_id;
|
this.zajCykId = zajCykId;
|
||||||
this.gr_nr = gr_nr;
|
this.grNr = grNr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,6 +28,9 @@ public interface GroupRepository extends JpaRepository<Groups, Long> {
|
|||||||
@Query("FROM Groups WHERE time = ?1 AND room = ?2 AND capacity = ?3")
|
@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);
|
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")
|
@Query("FROM Groups WHERE course_id = ?1")
|
||||||
List<Groups> getByCourse(@Param("id") Long id);
|
List<Groups> getByCourse(@Param("id") Long id);
|
||||||
|
|
||||||
|
@ -30,6 +30,10 @@ public class GroupService {
|
|||||||
return this.repo.find(time, room, capacity);
|
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) {
|
public List<Groups> getGroupsByCourse(Long id) {
|
||||||
return this.repo.getByCourse(id);
|
return this.repo.getByCourse(id);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user