412 lines
10 KiB
Java
Executable File
412 lines
10 KiB
Java
Executable File
package com.plannaplan.entities;
|
|
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
|
|
import javax.persistence.Entity;
|
|
import javax.persistence.FetchType;
|
|
import javax.persistence.GeneratedValue;
|
|
import javax.persistence.GenerationType;
|
|
import javax.persistence.Id;
|
|
import javax.persistence.JoinColumn;
|
|
import javax.persistence.ManyToMany;
|
|
import javax.persistence.ManyToOne;
|
|
|
|
import com.plannaplan.types.GroupType;
|
|
import com.plannaplan.types.WeekDay;
|
|
|
|
/**
|
|
* Entity of Groups grouping of state ssociated about
|
|
* course,time,room,capacity,type,day
|
|
*/
|
|
|
|
@Entity
|
|
public class Groups {
|
|
private static final int DEFAULT_CLASS_TIME = 90;
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
private Long id;
|
|
@ManyToOne
|
|
@JoinColumn(name = "course_id")
|
|
private Course course;
|
|
private int time;
|
|
private int endTime;
|
|
private String room;
|
|
private int capacity;
|
|
private GroupType type;
|
|
private WeekDay day;
|
|
@ManyToOne
|
|
@JoinColumn(name = "lecturer_id")
|
|
private Lecturer lecturer;
|
|
private Integer zajCykId;
|
|
private Integer grNr;
|
|
@ManyToMany(mappedBy = "studentRegisteredGrups", fetch = FetchType.EAGER)
|
|
private Set<User> registeredStudents;
|
|
|
|
public Set<User> getRegisteredStudents() {
|
|
return this.registeredStudents;
|
|
}
|
|
|
|
public void assignUser(User user) {
|
|
if (this.registeredStudents == null) {
|
|
this.registeredStudents = new HashSet<>();
|
|
}
|
|
this.registeredStudents.add(user);
|
|
}
|
|
|
|
public Groups() {
|
|
}
|
|
|
|
public Integer getGrNr() {
|
|
return grNr;
|
|
}
|
|
|
|
public void setGrNr(Integer grNr) {
|
|
this.grNr = grNr;
|
|
}
|
|
|
|
public Integer getZajCykId() {
|
|
return zajCykId;
|
|
}
|
|
|
|
public void setZajCykId(Integer zajCykId) {
|
|
this.zajCykId = zajCykId;
|
|
}
|
|
|
|
/**
|
|
* Groups
|
|
*
|
|
* @param capacity capacity given to the groups
|
|
* @param room room given to the groups
|
|
* @param course course given to the groups
|
|
* @param time time given to the groups
|
|
* @param endTime end time of class in minutes
|
|
* @param day day given to the groups
|
|
* @param lecturer lecturer given to the groups
|
|
*/
|
|
public Groups(int capacity, String room, Course course, int time, int endTime, WeekDay day, Lecturer lecturer) {
|
|
this.capacity = capacity;
|
|
this.room = room;
|
|
this.course = course;
|
|
this.time = time;
|
|
this.endTime = endTime;
|
|
this.day = day;
|
|
this.lecturer = lecturer;
|
|
this.type = capacity >= 50 ? GroupType.LECTURE : GroupType.CLASS;
|
|
}
|
|
|
|
/**
|
|
* Groups
|
|
*
|
|
* @param capacity capacity given to the groups
|
|
* @param room room given to the groups
|
|
* @param course course given to the groups
|
|
* @param time time given to the groups
|
|
* @param endTime end time of class in minutes
|
|
* @param day day given to the groups
|
|
* @param lecturer lecturer given to the groups
|
|
* @param zajCykId number of class in the term
|
|
* @param grNr Number of class/course
|
|
* @param type type of class/cource
|
|
*/
|
|
public Groups(int capacity, String room, Course course, int time, int endTime, WeekDay day, Lecturer lecturer,
|
|
Integer zajCykId, Integer grNr, GroupType type) {
|
|
this(capacity, room, course, time, endTime, day, lecturer, zajCykId, grNr);
|
|
this.type = type;
|
|
}
|
|
|
|
/**
|
|
* Groups
|
|
*
|
|
* @param capacity capacity given to the groups
|
|
* @param room room given to the groups
|
|
* @param course course given to the groups
|
|
* @param time time given to the groups
|
|
* @param day day given to the groups
|
|
* @param lecturer lecturer given to the groups
|
|
* @param zajCykId number of class in the term
|
|
* @param grNr Number of class/course
|
|
* @param type type of class/cource
|
|
*/
|
|
public Groups(int capacity, String room, Course course, int time, WeekDay day, Lecturer lecturer,
|
|
Integer zajCykId, Integer grNr, GroupType type) {
|
|
this(capacity, room, course, time, time + DEFAULT_CLASS_TIME, day, lecturer, zajCykId, grNr);
|
|
this.type = type;
|
|
}
|
|
|
|
/**
|
|
* Groups
|
|
*
|
|
* @param capacity capacity given to the groups
|
|
* @param room room given to the groups
|
|
* @param course course given to the groups
|
|
* @param time time given to the groups
|
|
* @param endTime end time of class in minutes
|
|
* @param day day given to the groups
|
|
* @param lecturer lecturer given to the groups
|
|
* @param zajCykId number of class in the term
|
|
* @param grNr Number of class/course
|
|
*/
|
|
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.zajCykId = zajCykId;
|
|
this.grNr = grNr;
|
|
}
|
|
|
|
/**
|
|
* Groups
|
|
*
|
|
* @param capacity capacity given to the groups
|
|
* @param room room given to the groups
|
|
* @param course course given to the groups
|
|
* @param time time given to the groups
|
|
* @param day day given to the groups
|
|
* @param lecturer lecturer given to the groups
|
|
* @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, Integer zajCykId,
|
|
Integer grNr) {
|
|
this(capacity, room, course, time, time + DEFAULT_CLASS_TIME, day, lecturer);
|
|
this.zajCykId = zajCykId;
|
|
this.grNr = grNr;
|
|
}
|
|
|
|
/**
|
|
* Create groups with default class duration
|
|
*
|
|
* @param capacity capacity given to the groups
|
|
* @param room room given to the groups
|
|
* @param course course given to the groups
|
|
* @param time time given to the groups
|
|
* @param day day given to the groups
|
|
* @param lecturer lecturer given to the groups
|
|
*/
|
|
public Groups(int capacity, String room, Course course, int time, WeekDay day, Lecturer lecturer) {
|
|
this(capacity, room, course, time, time + DEFAULT_CLASS_TIME, day, lecturer);
|
|
}
|
|
|
|
/**
|
|
* Updates given values other that are not null
|
|
*
|
|
* @param capacity capacity given to the groups
|
|
* @param room room given to the groups
|
|
* @param course course given to the groups
|
|
* @param time time given to the groups
|
|
* @param endTime end time of class in minutes
|
|
* @param day day given to the groups
|
|
* @param lecturer lecturer given to the groups
|
|
* @param type type given to the groups
|
|
*/
|
|
public void update(Integer capacity, String room, Course course, Integer time, Integer endTime, WeekDay day,
|
|
Lecturer lecturer, GroupType type) {
|
|
if (capacity != null) {
|
|
this.capacity = capacity;
|
|
}
|
|
|
|
if (room != null) {
|
|
this.room = room;
|
|
}
|
|
|
|
if (course != null) {
|
|
this.course = course;
|
|
}
|
|
|
|
if (time != null) {
|
|
this.time = time;
|
|
}
|
|
|
|
if (endTime != null) {
|
|
this.endTime = endTime;
|
|
}
|
|
|
|
if (day != null) {
|
|
this.day = day;
|
|
}
|
|
|
|
if (lecturer != null) {
|
|
this.lecturer = lecturer;
|
|
}
|
|
|
|
if (type != null) {
|
|
this.type = type;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* get time of class end
|
|
*
|
|
* @return hour of class finish time in minutes
|
|
*/
|
|
public int getEndTime() {
|
|
return endTime;
|
|
}
|
|
|
|
/**
|
|
* getId
|
|
*
|
|
* @return id
|
|
*/
|
|
public Long getId() {
|
|
return this.id;
|
|
}
|
|
|
|
/**
|
|
* getLecturer
|
|
*
|
|
* @return lecturer
|
|
*/
|
|
public Lecturer getLecturer() {
|
|
return lecturer;
|
|
}
|
|
|
|
/**
|
|
* setLecturer
|
|
*
|
|
* @param lecturer set lecturer into groups
|
|
*/
|
|
public void setLecturer(Lecturer lecturer) {
|
|
this.lecturer = lecturer;
|
|
}
|
|
|
|
/**
|
|
* WeekDay
|
|
*
|
|
* @return day
|
|
*/
|
|
public WeekDay getDay() {
|
|
return day;
|
|
}
|
|
|
|
/**
|
|
* setLecturer
|
|
*
|
|
* @param day set day into groups
|
|
*/
|
|
public void setDay(WeekDay day) {
|
|
this.day = day;
|
|
}
|
|
|
|
/**
|
|
* GroupType
|
|
*
|
|
* @return type
|
|
*/
|
|
public GroupType getType() {
|
|
return type;
|
|
}
|
|
|
|
/**
|
|
* setType
|
|
*
|
|
* @param type set type into groups
|
|
*/
|
|
public void setType(GroupType type) {
|
|
this.type = type;
|
|
}
|
|
|
|
/**
|
|
* getCapacity
|
|
*
|
|
* @return capacity
|
|
*/
|
|
public int getCapacity() {
|
|
return capacity;
|
|
}
|
|
|
|
/**
|
|
* setCapacity
|
|
*
|
|
* @param capacity set capacity into groups
|
|
*/
|
|
public void setCapacity(int capacity) {
|
|
this.capacity = capacity;
|
|
}
|
|
|
|
/**
|
|
* getRoom
|
|
*
|
|
* @return room
|
|
*/
|
|
public String getRoom() {
|
|
return room;
|
|
}
|
|
|
|
/**
|
|
* setRoom
|
|
*
|
|
* @param room set room into groups
|
|
*/
|
|
public void setRoom(String room) {
|
|
this.room = room;
|
|
}
|
|
|
|
/**
|
|
* getTime
|
|
*
|
|
* @return time
|
|
*/
|
|
public int getTime() {
|
|
return time;
|
|
}
|
|
|
|
/**
|
|
* setTime
|
|
*
|
|
* @param time set time into groups
|
|
*/
|
|
public void setTime(int time) {
|
|
this.time = time;
|
|
}
|
|
|
|
/**
|
|
* getCourseId
|
|
*
|
|
* @return course
|
|
*/
|
|
public Course getCourseId() {
|
|
return course;
|
|
}
|
|
|
|
/**
|
|
* setCourseId
|
|
*
|
|
* @param courseId set courseId into groups
|
|
*/
|
|
public void setCourseId(Course courseId) {
|
|
this.course = courseId;
|
|
}
|
|
|
|
/**
|
|
* getTimeString
|
|
*
|
|
* @return time as formated String
|
|
*/
|
|
public String getTimeString() {
|
|
int minutes = this.getTime() % 60;
|
|
String hoursString = Integer.toString(this.getTime() / 60);
|
|
String minutesString = Integer.toString(minutes);
|
|
if (minutes < 10) {
|
|
minutesString = "0" + minutesString;
|
|
}
|
|
return String.format("%s.%s", hoursString, minutesString);
|
|
}
|
|
|
|
/**
|
|
* gets end time formated strins
|
|
*
|
|
* @return end time as formated String
|
|
*/
|
|
public String getEndTimeString() {
|
|
int minutes = this.getEndTime() % 60;
|
|
String hoursString = Integer.toString(this.getEndTime() / 60);
|
|
String minutesString = Integer.toString(minutes);
|
|
if (minutes < 10) {
|
|
minutesString = "0" + minutesString;
|
|
}
|
|
return String.format("%s.%s", hoursString, minutesString);
|
|
}
|
|
}
|