Search in sources :

Example 6 with CourseAssessmentRequest

use of fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest in project pyramus by otavanopisto.

the class StudentRESTService method findCourseAssessmentRequestById.

@Path("/students/{STUDENTID:[0-9]*}/courses/{COURSEID:[0-9]*}/assessmentRequests/{ID:[0-9]*}")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response findCourseAssessmentRequestById(@PathParam("STUDENTID") Long studentId, @PathParam("COURSEID") Long courseId, @PathParam("ID") Long id) {
    Student student = studentController.findStudentById(studentId);
    Status studentStatus = checkStudent(student);
    if (studentStatus != Status.OK)
        return Response.status(studentStatus).build();
    Course course = courseController.findCourseById(courseId);
    if (course == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (course.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!restSecurity.hasPermission(new String[] { CourseAssessmentPermissions.FIND_COURSEASSESSMENTREQUEST, StudentPermissions.STUDENT_OWNER }, student, Style.OR)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    CourseAssessmentRequest courseAssessmentRequest = assessmentController.findCourseAssessmentRequestById(id);
    if (!course.getId().equals(courseAssessmentRequest.getCourseStudent().getCourse().getId())) {
        return Response.status(Status.NOT_FOUND).entity("Could not find a course assessment for course student course").build();
    }
    if (!student.getId().equals(courseAssessmentRequest.getCourseStudent().getStudent().getId())) {
        return Response.status(Status.NOT_FOUND).entity("Could not find a course assessment for course student student").build();
    }
    return Response.ok(objectFactory.createModel(courseAssessmentRequest)).build();
}
Also used : Status(javax.ws.rs.core.Response.Status) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 7 with CourseAssessmentRequest

use of fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest in project pyramus by otavanopisto.

the class CompositeRESTService method listAssessmentRequestsByStaffMember.

/**
 * Returns a list of assessment requests directed at the given staff member.
 *
 * @param staffMemberId Staff member id
 *
 * @return A list of assessment requests directed at the given staff member
 */
@Path("/staffMembers/{STAFFMEMBERID:[0-9]*}/assessmentRequests")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response listAssessmentRequestsByStaffMember(@PathParam("STAFFMEMBERID") Long staffMemberId) {
    // Staff member must exist
    StaffMember staffMember = userController.findStaffMemberById(staffMemberId);
    if (staffMember == null || staffMember.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    // Staff member should be logged in
    User loggedUser = sessionController.getUser();
    if (loggedUser == null || !loggedUser.getId().equals(staffMember.getId())) {
        return Response.status(Status.FORBIDDEN).build();
    }
    // List course assessment requests of courses of the staff member
    List<CompositeAssessmentRequest> assessmentRequests = new ArrayList<CompositeAssessmentRequest>();
    List<Course> courses = courseController.listCoursesByStaffMember(staffMember);
    for (Course course : courses) {
        List<CourseAssessmentRequest> courseAssessmentRequests = assessmentController.listCourseAssessmentRequestsByCourseAndHandled(course, Boolean.FALSE);
        for (CourseAssessmentRequest courseAssessmentRequest : courseAssessmentRequests) {
            CourseAssessment courseAssessment = assessmentController.findLatestCourseAssessmentByCourseStudentAndArchived(courseAssessmentRequest.getCourseStudent(), Boolean.FALSE);
            CompositeAssessmentRequest assessmentRequest = new CompositeAssessmentRequest();
            assessmentRequest.setCourseStudentId(courseAssessmentRequest.getCourseStudent().getId());
            assessmentRequest.setAssessmentRequestDate(courseAssessmentRequest.getCreated());
            assessmentRequest.setCourseEnrollmentDate(courseAssessmentRequest.getCourseStudent().getEnrolmentTime());
            assessmentRequest.setEvaluationDate(courseAssessment == null ? null : courseAssessment.getDate());
            assessmentRequest.setPassing(courseAssessment != null && courseAssessment.getGrade() != null && courseAssessment.getGrade().getPassingGrade());
            assessmentRequest.setCourseId(course.getId());
            assessmentRequest.setCourseName(course.getName());
            assessmentRequest.setCourseNameExtension(course.getNameExtension());
            String firstName = courseAssessmentRequest.getCourseStudent().getStudent().getFirstName();
            if (courseAssessmentRequest.getCourseStudent().getStudent().getNickname() != null) {
                firstName = String.format("%s \"%s\"", firstName, courseAssessmentRequest.getCourseStudent().getStudent().getNickname());
            }
            assessmentRequest.setFirstName(firstName);
            assessmentRequest.setLastName(courseAssessmentRequest.getCourseStudent().getStudent().getLastName());
            assessmentRequest.setStudyProgramme(courseAssessmentRequest.getCourseStudent().getStudent().getStudyProgramme().getName());
            assessmentRequest.setUserId(courseAssessmentRequest.getCourseStudent().getStudent().getId());
            assessmentRequests.add(assessmentRequest);
        }
    }
    return Response.ok(assessmentRequests).build();
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) ArrayList(java.util.ArrayList) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CompositeAssessmentRequest(fi.otavanopisto.pyramus.rest.model.composite.CompositeAssessmentRequest) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 8 with CourseAssessmentRequest

use of fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest in project pyramus by otavanopisto.

the class CourseAssessmentRequestDAO method listByCourse.

public List<CourseAssessmentRequest> listByCourse(Course course) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CourseAssessmentRequest> criteria = criteriaBuilder.createQuery(CourseAssessmentRequest.class);
    Root<CourseAssessmentRequest> root = criteria.from(CourseAssessmentRequest.class);
    Join<CourseAssessmentRequest, CourseStudent> courseStudent = root.join(CourseAssessmentRequest_.courseStudent);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(courseStudent.get(CourseStudent_.course), course), criteriaBuilder.equal(courseStudent.get(CourseStudent_.archived), Boolean.FALSE), criteriaBuilder.equal(root.get(CourseAssessmentRequest_.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) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest)

Example 9 with CourseAssessmentRequest

use of fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest in project pyramus by otavanopisto.

the class CourseAssessmentRequestDAO method listByCourseAndStudent.

/**
 * Lists all student's course assessments excluding archived ones
 *
 * @return list of all students course assessments
 */
public List<CourseAssessmentRequest> listByCourseAndStudent(Course course, Student student) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CourseAssessmentRequest> criteria = criteriaBuilder.createQuery(CourseAssessmentRequest.class);
    Root<CourseAssessmentRequest> root = criteria.from(CourseAssessmentRequest.class);
    Join<CourseAssessmentRequest, CourseStudent> courseStudentJoin = root.join(CourseAssessmentRequest_.courseStudent);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(courseStudentJoin.get(CourseStudent_.course), course), criteriaBuilder.equal(courseStudentJoin.get(CourseStudent_.student), student), criteriaBuilder.equal(root.get(CourseAssessmentRequest_.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) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest)

Example 10 with CourseAssessmentRequest

use of fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest in project pyramus by otavanopisto.

the class CourseAssessmentRequestDAO method listByCourseAndHandled.

public List<CourseAssessmentRequest> listByCourseAndHandled(Course course, Boolean handled) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CourseAssessmentRequest> criteria = criteriaBuilder.createQuery(CourseAssessmentRequest.class);
    Root<CourseAssessmentRequest> root = criteria.from(CourseAssessmentRequest.class);
    Join<CourseAssessmentRequest, CourseStudent> courseStudent = root.join(CourseAssessmentRequest_.courseStudent);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(courseStudent.get(CourseStudent_.course), course), criteriaBuilder.equal(courseStudent.get(CourseStudent_.archived), Boolean.FALSE), criteriaBuilder.equal(root.get(CourseAssessmentRequest_.archived), Boolean.FALSE), criteriaBuilder.equal(root.get(CourseAssessmentRequest_.handled), handled)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest)

Aggregations

CourseAssessmentRequest (fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest)25 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)19 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)12 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)10 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)10 Path (javax.ws.rs.Path)10 StudentGroupStudent (fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent)8 EntityManager (javax.persistence.EntityManager)7 GET (javax.ws.rs.GET)7 CourseAssessment (fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment)6 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 ArrayList (java.util.ArrayList)5 Status (javax.ws.rs.core.Response.Status)5 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)4 CourseAssessmentRequestDAO (fi.otavanopisto.pyramus.dao.grading.CourseAssessmentRequestDAO)4 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)4 CreditLink (fi.otavanopisto.pyramus.domainmodel.grading.CreditLink)3 TransferCredit (fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit)3 HashMap (java.util.HashMap)3 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)2