use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent in project pyramus by otavanopisto.
the class CourseStudentDAO method create.
/**
* Adds a course student to the database.
*
* @param course The course
* @param student The student
* @param courseEnrolmentType Student enrolment type
* @param participationType Student participation type
* @param enrolmentDate The enrolment date
* @param optionality
* @param billingDetails
* @param archived
* @param room
*
* @return The created course student
* @throws DuplicateCourseStudentException
*/
public CourseStudent create(Course course, Student student, CourseEnrolmentType courseEnrolmentType, CourseParticipationType participationType, Date enrolmentDate, Boolean lodging, CourseOptionality optionality, BillingDetails billingDetails, String organization, String additionalInfo, Room room, BigDecimal lodgingFee, Currency lodgingFeeCurrency, BigDecimal reservationFee, Currency reservationFeeCurrency, Boolean archived) throws DuplicateCourseStudentException {
List<CourseStudent> courseStudents = listByCourseAndStudent(course, student);
if (!courseStudents.isEmpty())
throw new DuplicateCourseStudentException();
CourseStudent courseStudent = new CourseStudent();
courseStudent.setCourse(course);
courseStudent.setArchived(archived);
courseStudent.setBillingDetails(billingDetails);
courseStudent.setCourseEnrolmentType(courseEnrolmentType);
courseStudent.setEnrolmentTime(enrolmentDate);
courseStudent.setParticipationType(participationType);
courseStudent.setLodging(lodging);
courseStudent.setOptionality(optionality);
courseStudent.setStudent(student);
courseStudent.setRoom(room);
courseStudent.setLodgingFee(lodgingFee);
courseStudent.setLodgingFeeCurrency(lodgingFeeCurrency);
courseStudent.setReservationFee(reservationFee);
courseStudent.setReservationFeeCurrency(reservationFeeCurrency);
courseStudent.setOrganization(organization);
courseStudent.setAdditionalInfo(additionalInfo);
persist(courseStudent);
courseStudentCreatedEvent.fire(new CourseStudentCreatedEvent(courseStudent.getId(), courseStudent.getCourse().getId(), courseStudent.getStudent().getId()));
return courseStudent;
}
use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent in project pyramus by otavanopisto.
the class CourseStudentDAO method listByCourse.
/**
* Returns a list of the students in the given course.
*
* @param course The course
*
* @return A list of the students in the given course
*/
public List<CourseStudent> listByCourse(Course course) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<CourseStudent> criteria = criteriaBuilder.createQuery(CourseStudent.class);
Root<CourseStudent> root = criteria.from(CourseStudent.class);
Join<CourseStudent, Student> student = root.join(CourseStudent_.student);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(CourseStudent_.course), course), criteriaBuilder.equal(root.get(CourseStudent_.archived), Boolean.FALSE), criteriaBuilder.equal(student.get(Student_.archived), Boolean.FALSE)));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent in project pyramus by otavanopisto.
the class CourseStudentDAO method listByCourseAndParticipationTypes.
public List<CourseStudent> listByCourseAndParticipationTypes(Course course, List<CourseParticipationType> participationTypes) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<CourseStudent> criteria = criteriaBuilder.createQuery(CourseStudent.class);
Root<CourseStudent> root = criteria.from(CourseStudent.class);
Join<CourseStudent, Student> student = root.join(CourseStudent_.student);
criteria.select(root);
criteria.where(criteriaBuilder.and(root.get(CourseStudent_.participationType).in(participationTypes), criteriaBuilder.equal(root.get(CourseStudent_.course), course), criteriaBuilder.equal(root.get(CourseStudent_.archived), Boolean.FALSE), criteriaBuilder.equal(student.get(Student_.archived), Boolean.FALSE)));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent in project pyramus by otavanopisto.
the class CourseStudentDAO method listByStudentAndCourseCurriculum.
public List<CourseStudent> listByStudentAndCourseCurriculum(Student student, Curriculum curriculum) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<CourseStudent> criteria = criteriaBuilder.createQuery(CourseStudent.class);
Root<CourseStudent> root = criteria.from(CourseStudent.class);
Join<CourseStudent, Student> studentJoin = root.join(CourseStudent_.student);
Join<CourseStudent, Course> courseJoin = root.join(CourseStudent_.course);
SetJoin<Course, Curriculum> curriculumJoin = courseJoin.join(Course_.curriculums);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(curriculumJoin, curriculum), criteriaBuilder.equal(root.get(CourseStudent_.student), student), criteriaBuilder.equal(root.get(CourseStudent_.archived), Boolean.FALSE), criteriaBuilder.equal(courseJoin.get(Course_.archived), Boolean.FALSE), criteriaBuilder.equal(studentJoin.get(Student_.archived), Boolean.FALSE)));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent in project pyramus by otavanopisto.
the class CourseStudentDAO method countByCourse.
public Long countByCourse(Course course) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> criteria = criteriaBuilder.createQuery(Long.class);
Root<CourseStudent> root = criteria.from(CourseStudent.class);
Join<CourseStudent, Student> studentJoin = root.join(CourseStudent_.student);
criteria.select(criteriaBuilder.count(root));
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(CourseStudent_.course), course), criteriaBuilder.equal(root.get(CourseStudent_.archived), Boolean.FALSE), criteriaBuilder.equal(studentJoin.get(Student_.archived), Boolean.FALSE)));
return entityManager.createQuery(criteria).getSingleResult();
}
Aggregations