SubjectClass.java

/**
 * TFG 75.678 - TFG Desarrollo web 2020 e-Learning for Schools
 * Copyright (C) 2020  Eduardo Rodriguez Carro
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.uoc.tfg.sel.repository.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
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.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.springframework.lang.NonNull;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

/**
 * Modelo de clases.
 *
 * @author Eduardo Rodriguez carro
 */
@JsonInclude(value = Include.NON_NULL)
@Entity
@Table(name = "subjectclass")
public class SubjectClass {

	/** The id. */
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "id")
	private Integer id;
	
	/** The teacher. */
	@ManyToOne(fetch = FetchType.EAGER)
	@NonNull
	@JoinColumn(name = "teacher_id")
	private User teacher;
	
	/** The subject. */
	@ManyToOne(fetch = FetchType.EAGER)
	@NonNull
	@JoinColumn(name = "subject_id")
	private Subject subject;
	
	/** The course. */
	@ManyToOne(fetch = FetchType.EAGER)
	@NonNull
	@JoinColumn(name = "course_id")
	private Course course;

	/** The students. */
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinTable(
		name = "student_subjectclass",
		inverseJoinColumns = { @JoinColumn(name = "student_id", referencedColumnName = "id") },
		joinColumns = { @JoinColumn(name = "subjectclass_id", referencedColumnName = "id") }
	)
	private List<User> students;
	
	/**
	 * Gets the id.
	 *
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * Sets the id.
	 *
	 * @param id the new id
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * Gets the teacher.
	 *
	 * @return the teacher
	 */
	public User getTeacher() {
		return teacher;
	}

	/**
	 * Sets the teacher.
	 *
	 * @param teacher the new teacher
	 */
	public void setTeacher(User teacher) {
		this.teacher = teacher;
	}

	/**
	 * Gets the subject.
	 *
	 * @return the subject
	 */
	public Subject getSubject() {
		return subject;
	}

	/**
	 * Sets the subject.
	 *
	 * @param subject the new subject
	 */
	public void setSubject(Subject subject) {
		this.subject = subject;
	}

	/**
	 * Gets the course.
	 *
	 * @return the course
	 */
	public Course getCourse() {
		return course;
	}

	/**
	 * Sets the course.
	 *
	 * @param course the new course
	 */
	public void setCourse(Course course) {
		this.course = course;
	}

	/**
	 * Gets the students.
	 *
	 * @return the students
	 */
	public List<User> getStudents() {
		return students;
	}

	/**
	 * Sets the students.
	 *
	 * @param students the new students
	 */
	public void setStudents(List<User> students) {
		this.students = students;
	}

	/**
	 * To string.
	 *
	 * @return the string
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("SubjectClass [id=").append(id).append(", teacher=").append(teacher).append(", subject=").append(subject).append("]");
		return builder.toString();
	}
	
	
}