Search in sources :

Example 11 with CourseStudent

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;
}
Also used : DuplicateCourseStudentException(fi.otavanopisto.pyramus.exception.DuplicateCourseStudentException) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CourseStudentCreatedEvent(fi.otavanopisto.pyramus.events.CourseStudentCreatedEvent)

Example 12 with 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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)

Example 13 with CourseStudent

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)

Example 14 with CourseStudent

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course)

Example 15 with CourseStudent

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)

Aggregations

CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)75 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)39 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)33 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)29 EntityManager (javax.persistence.EntityManager)26 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)25 CourseAssessment (fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment)22 CourseAssessmentRequest (fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest)13 CourseDAO (fi.otavanopisto.pyramus.dao.courses.CourseDAO)12 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)12 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)12 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)12 Path (javax.ws.rs.Path)12 CourseParticipationType (fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType)11 Date (java.util.Date)10 CourseAssessmentDAO (fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO)8 Grade (fi.otavanopisto.pyramus.domainmodel.grading.Grade)8 StudentGroupStudent (fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent)8 ArrayList (java.util.ArrayList)8 Currency (java.util.Currency)8