Search in sources :

Example 16 with CourseStudent

use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent in project pyramus by otavanopisto.

the class CourseStudentDAO method listByStudent.

public List<CourseStudent> listByStudent(Student student) {
    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);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(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) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course)

Example 17 with CourseStudent

use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent in project pyramus by otavanopisto.

the class CourseRESTService method findCourseStudentById.

@Path("/courses/{CID:[0-9]*}/students/{ID:[0-9]*}")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response findCourseStudentById(@PathParam("CID") Long courseId, @PathParam("ID") Long id) {
    Course course = courseController.findCourseById(courseId);
    if (course == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent courseStudent = courseController.findCourseStudentById(id);
    if (courseStudent == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!courseStudent.getCourse().getId().equals(courseId)) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (courseStudent.getArchived() || courseStudent.getStudent().getArchived() || courseStudent.getCourse().getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!restSecurity.hasPermission(new String[] { CoursePermissions.FIND_COURSESTUDENT, PersonPermissions.PERSON_OWNER }, courseStudent.getStudent().getPerson(), Style.OR)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    if (!restSecurity.hasPermission(new String[] { StudentPermissions.FIND_STUDENT, UserPermissions.USER_OWNER }, courseStudent.getStudent(), Style.OR)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    return Response.status(Status.OK).entity(objectFactory.createModel(courseStudent)).build();
}
Also used : Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 18 with CourseStudent

use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent in project pyramus by otavanopisto.

the class CourseRESTService method isActiveStudent.

private boolean isActiveStudent(CourseStudent courseStudent) {
    Student student = courseStudent.getStudent();
    Date studyStartDate = student.getStudyStartDate();
    Date studyEndDate = student.getStudyEndDate();
    if (studyStartDate == null && studyEndDate == null) {
        // It's a never ending study programme
        return true;
    }
    boolean hasStarted = studyStartDate != null && studyStartDate.before(new Date());
    boolean hasFinished = studyEndDate != null && studyEndDate.before(new Date());
    return hasStarted && !hasFinished;
}
Also used : CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Date(java.util.Date)

Example 19 with CourseStudent

use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent in project pyramus by otavanopisto.

the class CourseRESTService method createCourseStudent.

@Path("/courses/{COURSEID:[0-9]*}/students")
@POST
@RESTPermit(handling = Handling.INLINE)
public // @RESTPermit (CoursePermissions.CREATE_COURSESTUDENT)
Response createCourseStudent(@PathParam("COURSEID") Long courseId, fi.otavanopisto.pyramus.rest.model.CourseStudent entity) {
    if (entity == null) {
        return Response.status(Status.BAD_REQUEST).entity("Request payload missing").build();
    }
    if (entity.getStudentId() == null) {
        return Response.status(Status.BAD_REQUEST).entity("studentId is missing").build();
    }
    if (entity.getLodging() == null) {
        return Response.status(Status.BAD_REQUEST).entity("lodging is missing").build();
    }
    if (entity.getEnrolmentTime() == null) {
        return Response.status(Status.BAD_REQUEST).entity("enrolmentTime is missing").build();
    }
    if (!restSecurity.hasPermission(new String[] { CoursePermissions.CREATE_COURSESTUDENT, UserPermissions.USER_OWNER }, entity, Style.OR)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    Course course = courseController.findCourseById(courseId);
    if (course == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (course.isCourseTemplate()) {
        return Response.status(Status.BAD_REQUEST).entity("Cannot add student to a course template").build();
    }
    Student student = studentController.findStudentById(entity.getStudentId());
    if (student == null) {
        return Response.status(Status.BAD_REQUEST).entity("could not find the student #" + entity.getStudentId()).build();
    }
    if (courseController.findCourseStudentByCourseAndStudent(course, student) != null) {
        return Response.status(Status.BAD_REQUEST).entity("student #" + entity.getStudentId() + " is already on course #" + courseId).build();
    }
    BillingDetails billingDetails = null;
    if (entity.getBillingDetailsId() != null) {
        billingDetails = commonController.findBillingDetailsById(entity.getBillingDetailsId());
        if (billingDetails == null) {
            return Response.status(Status.BAD_REQUEST).entity("could not find billingDetails #" + entity.getBillingDetailsId()).build();
        }
    }
    fi.otavanopisto.pyramus.domainmodel.courses.CourseEnrolmentType enrolmentType;
    if (entity.getEnrolmentTypeId() != null) {
        enrolmentType = courseController.findCourseEnrolmentTypeById(entity.getEnrolmentTypeId());
        if (enrolmentType == null) {
            return Response.status(Status.BAD_REQUEST).entity("could not find enrolmentType #" + entity.getEnrolmentTypeId()).build();
        }
    } else {
        enrolmentType = courseController.getDefaultCourseEnrolmentType();
    }
    fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality optionality = entity.getOptionality() != null ? fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality.valueOf(entity.getOptionality().name()) : null;
    fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType participantionType;
    if (entity.getParticipationTypeId() != null) {
        participantionType = courseController.findCourseParticipationTypeById(entity.getParticipationTypeId());
        if (participantionType == null) {
            return Response.status(Status.BAD_REQUEST).entity("could not find participationType #" + entity.getParticipationTypeId()).build();
        }
    } else {
        participantionType = courseController.getDefaultCourseParticipationType();
    }
    // TODO: Add support for room, organization, additionalInfo and lodging fee
    String organization = null;
    String additionalInfo = null;
    Room room = null;
    BigDecimal lodgingFee = null;
    Currency lodgingFeeCurrency = null;
    BigDecimal reservationFee = null;
    Currency reservationFeeCurrency = null;
    try {
        return Response.status(Status.OK).entity(objectFactory.createModel(courseController.createCourseStudent(course, student, enrolmentType, participantionType, toDate(entity.getEnrolmentTime()), entity.getLodging(), optionality, billingDetails, lodgingFee, lodgingFeeCurrency, reservationFee, reservationFeeCurrency, organization, additionalInfo, room))).build();
    } catch (DuplicateCourseStudentException dcse) {
        logger.log(Level.SEVERE, "Attempt to add CourseStudent when it already exists (student=" + entity.getStudentId() + ", course=" + courseId + ".", dcse);
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity("Student is already member of the course.").build();
    }
}
Also used : DuplicateCourseStudentException(fi.otavanopisto.pyramus.exception.DuplicateCourseStudentException) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) BillingDetails(fi.otavanopisto.pyramus.domainmodel.base.BillingDetails) BigDecimal(java.math.BigDecimal) CourseParticipationType(fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType) Currency(java.util.Currency) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) Room(fi.otavanopisto.pyramus.domainmodel.accommodation.Room) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) POST(javax.ws.rs.POST)

Example 20 with CourseStudent

use of fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent in project pyramus by otavanopisto.

the class CourseAssessmentDAO method listByStudentAndSubject.

/**
 * Lists all student's course assessments excluding archived ones
 *
 * @return list of all students course assessments
 */
public List<CourseAssessment> listByStudentAndSubject(Student student, Subject subject) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CourseAssessment> criteria = criteriaBuilder.createQuery(CourseAssessment.class);
    Root<CourseAssessment> root = criteria.from(CourseAssessment.class);
    Join<CourseAssessment, CourseStudent> courseStudentJoin = root.join(CourseAssessment_.courseStudent);
    Join<CourseStudent, Course> courseJoin = courseStudentJoin.join(CourseStudent_.course);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(courseStudentJoin.get(CourseStudent_.student), student), criteriaBuilder.equal(root.get(CourseAssessment_.archived), Boolean.FALSE), criteriaBuilder.equal(courseStudentJoin.get(CourseStudent_.archived), Boolean.FALSE), criteriaBuilder.equal(courseJoin.get(Course_.archived), Boolean.FALSE), criteriaBuilder.equal(courseJoin.get(Course_.subject), subject)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment)

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