1 package dst.ass1.jpa.model.impl;
3 import dst.ass1.jpa.model.*;
4 import dst.ass1.jpa.util.Constants;
6 import javax.persistence.*;
7 import java.math.BigDecimal;
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Date;
13 @Table(name = Constants.T_COURSE)
14 @NamedQuery(name = Constants.Q_ONGOING_AND_FREE_PLATFORM_COURSES, query = "SELECT c" +
15 " FROM " + Constants.T_COURSE + " c" +
16 " JOIN c.coursePlatform cp " +
17 " WHERE cp." + Constants.M_COURSEPLATFORM_NAME + " = :platformName " +
18 " AND c." + Constants.M_COURSE_STATUS + " = dst.ass1.jpa.model.CourseStatus.ONGOING" +
19 " AND c." + Constants.M_COURSE_CAPACITY + " > (SELECT count(*) FROM " + Constants.T_ENROLLMENT +
20 " WHERE c = " + Constants.I_COURSE + " group by " + Constants.I_COURSE + ")"
22 public class Course implements ICourse {
31 private Integer capacity;
34 private Boolean premium;
37 private BigDecimal cost;
40 private CourseStatus status;
48 // FIXME: TESTS VS DB-MODEL? (optional = false)
49 @ManyToOne(targetEntity = CoursePlatform.class)
50 @JoinColumn(name = Constants.I_COURSEPLATFORM)
51 private ICoursePlatform coursePlatform;
53 // FIXME: TESTS VS DB-MODEL? (optional = false)
54 @ManyToOne(targetEntity = Lecturer.class)
55 @JoinColumn(name = Constants.I_LECTURER)
56 private ILecturer lecturer;
58 @OneToMany(targetEntity = Lesson.class, mappedBy = Constants.M_LESSON_COURSE)
59 private Collection<ILesson> lessons = new ArrayList<>();
61 @OneToOne(targetEntity = Metadata.class, optional = false, cascade = CascadeType.ALL)
62 private IMetadata metadata;
64 // FIXME: TESTS VS DB-MODEL?
65 @OneToMany(targetEntity = Enrollment.class)
66 private Collection<IEnrollment> enrollments = new ArrayList<>();
75 public void setId(Long id) {
80 public String getName() {
85 public void setName(String name) {
90 public Integer getCapacity() {
95 public void setCapacity(Integer capacity) {
96 this.capacity = capacity;
100 public Boolean getPremium() {
105 public void setPremium(Boolean premium) {
106 this.premium = premium;
110 public BigDecimal getCost() {
115 public void setCost(BigDecimal cost) {
120 public CourseStatus getStatus() {
125 public void setStatus(CourseStatus status) {
126 this.status = status;
130 public Date getStart() {
135 public void setStart(Date start) {
140 public Date getEnd() {
145 public void setEnd(Date end) {
150 public ICoursePlatform getCoursePlatform() {
151 return coursePlatform;
155 public void setCoursePlatform(ICoursePlatform coursePlatform) {
156 this.coursePlatform = coursePlatform;
160 public ILecturer getLecturer() {
165 public void setLecturer(ILecturer lecturer) {
166 this.lecturer = lecturer;
170 public Collection<ILesson> getLessons() {
175 public void setLessons(Collection<ILesson> lessons) {
176 this.lessons = lessons;
180 public void addLesson(ILesson lesson) {
181 this.lessons.add(lesson);
185 public IMetadata getMetadata() {
190 public void setMetadata(IMetadata metadata) {
191 this.metadata = metadata;
195 public Collection<IEnrollment> getEnrollments() {
200 public void setEnrollments(Collection<IEnrollment> enrollments) {
201 this.enrollments = enrollments;
205 public void addEnrollment(IEnrollment enrollment) {
206 this.enrollments.add(enrollment);