2020-07-23 17:27:20 +02:00
|
|
|
package com.plannaplan.entities;
|
|
|
|
|
|
|
|
import javax.persistence.Entity;
|
|
|
|
import javax.persistence.GeneratedValue;
|
|
|
|
import javax.persistence.GenerationType;
|
|
|
|
import javax.persistence.Id;
|
2020-07-25 10:21:42 +02:00
|
|
|
import javax.persistence.JoinColumn;
|
|
|
|
import javax.persistence.ManyToOne;
|
2020-07-23 17:27:20 +02:00
|
|
|
|
2020-07-25 09:58:40 +02:00
|
|
|
import com.plannaplan.types.GroupType;
|
|
|
|
import com.plannaplan.types.WeekDay;
|
|
|
|
|
2020-11-18 09:01:45 +01:00
|
|
|
/**
|
2020-12-20 12:14:12 +01:00
|
|
|
* Entity of Groups grouping of state ssociated about
|
|
|
|
* course,time,room,capacity,type,day
|
2020-11-18 09:01:45 +01:00
|
|
|
*/
|
2020-09-21 17:45:52 +02:00
|
|
|
|
2020-07-23 17:27:20 +02:00
|
|
|
@Entity
|
|
|
|
public class Groups {
|
2020-12-20 12:14:12 +01:00
|
|
|
private static final int DEFAULT_CLASS_TIME = 90;
|
|
|
|
|
2020-07-23 17:27:20 +02:00
|
|
|
@Id
|
|
|
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
|
|
private Long id;
|
2020-07-25 10:56:11 +02:00
|
|
|
@ManyToOne
|
|
|
|
@JoinColumn(name = "course_id")
|
2020-09-21 17:45:52 +02:00
|
|
|
private Course course;
|
2020-07-23 17:27:20 +02:00
|
|
|
private int time;
|
2020-12-20 12:14:12 +01:00
|
|
|
private int endTime;
|
2020-07-23 17:27:20 +02:00
|
|
|
private String room;
|
|
|
|
private int capacity;
|
2020-07-25 09:58:40 +02:00
|
|
|
private GroupType type;
|
|
|
|
private WeekDay day;
|
2020-07-25 10:21:42 +02:00
|
|
|
@ManyToOne
|
|
|
|
@JoinColumn(name = "lecturer_id")
|
|
|
|
private Lecturer lecturer;
|
2020-07-23 17:27:20 +02:00
|
|
|
|
|
|
|
public Groups() {
|
|
|
|
}
|
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* Groups
|
|
|
|
*
|
|
|
|
* @param capacity capacity given to the groups
|
2020-12-20 12:14:12 +01:00
|
|
|
* @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
|
2020-11-27 17:05:47 +01:00
|
|
|
* @param lecturer lecturer given to the groups
|
|
|
|
*/
|
2020-12-20 12:14:12 +01:00
|
|
|
public Groups(int capacity, String room, Course course, int time, int endTime, WeekDay day, Lecturer lecturer) {
|
2020-09-21 17:45:52 +02:00
|
|
|
this.capacity = capacity;
|
|
|
|
this.room = room;
|
|
|
|
this.course = course;
|
|
|
|
this.time = time;
|
2020-12-20 12:14:12 +01:00
|
|
|
this.endTime = endTime;
|
2020-09-21 17:45:52 +02:00
|
|
|
this.day = day;
|
|
|
|
this.lecturer = lecturer;
|
|
|
|
this.type = capacity >= 50 ? GroupType.LECTURE : GroupType.CLASS;
|
|
|
|
}
|
|
|
|
|
2020-12-20 12:14:12 +01:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get time of class end
|
|
|
|
*
|
|
|
|
* @return hour of class finish time in minutes
|
|
|
|
*/
|
|
|
|
public int getEndTime() {
|
|
|
|
return endTime;
|
|
|
|
}
|
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* getId
|
2020-12-20 12:14:12 +01:00
|
|
|
*
|
2020-11-27 17:05:47 +01:00
|
|
|
* @return id
|
|
|
|
*/
|
2020-08-11 17:36:58 +02:00
|
|
|
public Long getId() {
|
|
|
|
return this.id;
|
|
|
|
}
|
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* getLecturer
|
2020-12-20 12:14:12 +01:00
|
|
|
*
|
2020-11-27 17:05:47 +01:00
|
|
|
* @return lecturer
|
|
|
|
*/
|
2020-07-25 10:21:42 +02:00
|
|
|
public Lecturer getLecturer() {
|
|
|
|
return lecturer;
|
|
|
|
}
|
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* setLecturer
|
2020-12-20 12:14:12 +01:00
|
|
|
*
|
2020-11-27 17:05:47 +01:00
|
|
|
* @param lecturer set lecturer into groups
|
|
|
|
*/
|
2020-07-25 10:21:42 +02:00
|
|
|
public void setLecturer(Lecturer lecturer) {
|
|
|
|
this.lecturer = lecturer;
|
|
|
|
}
|
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* WeekDay
|
2020-12-20 12:14:12 +01:00
|
|
|
*
|
2020-11-27 17:05:47 +01:00
|
|
|
* @return day
|
|
|
|
*/
|
2020-07-25 09:58:40 +02:00
|
|
|
public WeekDay getDay() {
|
|
|
|
return day;
|
|
|
|
}
|
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* setLecturer
|
2020-12-20 12:14:12 +01:00
|
|
|
*
|
2020-11-27 17:05:47 +01:00
|
|
|
* @param day set day into groups
|
|
|
|
*/
|
2020-07-25 09:58:40 +02:00
|
|
|
public void setDay(WeekDay day) {
|
|
|
|
this.day = day;
|
|
|
|
}
|
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* GroupType
|
2020-12-20 12:14:12 +01:00
|
|
|
*
|
2020-11-27 17:05:47 +01:00
|
|
|
* @return type
|
|
|
|
*/
|
2020-07-25 09:58:40 +02:00
|
|
|
public GroupType getType() {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* setType
|
2020-12-20 12:14:12 +01:00
|
|
|
*
|
2020-11-27 17:05:47 +01:00
|
|
|
* @param type set type into groups
|
|
|
|
*/
|
2020-07-25 09:58:40 +02:00
|
|
|
public void setType(GroupType type) {
|
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* getCapacity
|
2020-12-20 12:14:12 +01:00
|
|
|
*
|
2020-11-27 17:05:47 +01:00
|
|
|
* @return capacity
|
|
|
|
*/
|
2020-07-23 17:27:20 +02:00
|
|
|
public int getCapacity() {
|
|
|
|
return capacity;
|
|
|
|
}
|
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* setCapacity
|
2020-12-20 12:14:12 +01:00
|
|
|
*
|
2020-11-27 17:05:47 +01:00
|
|
|
* @param capacity set capacity into groups
|
|
|
|
*/
|
2020-07-23 17:27:20 +02:00
|
|
|
public void setCapacity(int capacity) {
|
|
|
|
this.capacity = capacity;
|
|
|
|
}
|
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* getRoom
|
2020-12-20 12:14:12 +01:00
|
|
|
*
|
2020-11-27 17:05:47 +01:00
|
|
|
* @return room
|
|
|
|
*/
|
2020-07-23 17:27:20 +02:00
|
|
|
public String getRoom() {
|
|
|
|
return room;
|
|
|
|
}
|
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* setRoom
|
2020-12-20 12:14:12 +01:00
|
|
|
*
|
2020-11-27 17:05:47 +01:00
|
|
|
* @param room set room into groups
|
|
|
|
*/
|
2020-07-23 17:27:20 +02:00
|
|
|
public void setRoom(String room) {
|
|
|
|
this.room = room;
|
|
|
|
}
|
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* getTime
|
2020-12-20 12:14:12 +01:00
|
|
|
*
|
2020-11-27 17:05:47 +01:00
|
|
|
* @return time
|
|
|
|
*/
|
2020-07-23 17:27:20 +02:00
|
|
|
public int getTime() {
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* setTime
|
2020-12-20 12:14:12 +01:00
|
|
|
*
|
2020-11-27 17:05:47 +01:00
|
|
|
* @param time set time into groups
|
|
|
|
*/
|
2020-07-23 17:27:20 +02:00
|
|
|
public void setTime(int time) {
|
|
|
|
this.time = time;
|
|
|
|
}
|
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* getCourseId
|
2020-12-20 12:14:12 +01:00
|
|
|
*
|
2020-11-27 17:05:47 +01:00
|
|
|
* @return course
|
|
|
|
*/
|
2020-07-25 10:56:11 +02:00
|
|
|
public Course getCourseId() {
|
2020-09-21 17:45:52 +02:00
|
|
|
return course;
|
2020-07-23 17:27:20 +02:00
|
|
|
}
|
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* setCourseId
|
2020-12-20 12:14:12 +01:00
|
|
|
*
|
2020-11-27 17:05:47 +01:00
|
|
|
* @param courseId set courseId into groups
|
|
|
|
*/
|
2020-07-25 10:56:11 +02:00
|
|
|
public void setCourseId(Course courseId) {
|
2020-09-21 17:45:52 +02:00
|
|
|
this.course = courseId;
|
2020-07-23 17:27:20 +02:00
|
|
|
}
|
2020-08-18 15:41:03 +02:00
|
|
|
|
2020-11-27 17:05:47 +01:00
|
|
|
/**
|
|
|
|
* getTimeString
|
2020-12-20 12:14:12 +01:00
|
|
|
*
|
2020-11-27 17:05:47 +01:00
|
|
|
* @return time as formated String
|
|
|
|
*/
|
2020-08-18 15:41:03 +02:00
|
|
|
public String getTimeString() {
|
|
|
|
int minutes = this.getTime() % 60;
|
2020-08-18 16:10:46 +02:00
|
|
|
String hoursString = Integer.toString(this.getTime() / 60);
|
2020-08-18 15:41:03 +02:00
|
|
|
String minutesString = Integer.toString(minutes);
|
|
|
|
if (minutes < 10) {
|
|
|
|
minutesString = "0" + minutesString;
|
|
|
|
}
|
2020-08-18 16:10:46 +02:00
|
|
|
return String.format("%s.%s", hoursString, minutesString);
|
2020-08-18 15:41:03 +02:00
|
|
|
}
|
2020-12-20 12:14:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
2020-09-21 17:45:52 +02:00
|
|
|
}
|