Search in sources :

Example 16 with CourseAssessmentRequest

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

the class CompositeRESTService method listAssessmentRequestsByCourse.

@Path("/course/{COURSEID:[0-9]*}/assessmentRequests")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response listAssessmentRequestsByCourse(@PathParam("COURSEID") Long courseId, @QueryParam("courseStudentIds") String courseStudentIds) {
    Course course = courseController.findCourseById(courseId);
    if (course == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!sessionController.hasPermission(CourseAssessmentPermissions.LIST_STUDENT_COURSEASSESSMENTS, course)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    List<CourseStudent> courseStudents;
    if (courseStudentIds != null) {
        courseStudents = new ArrayList<CourseStudent>();
        // Empty courseStudentIds can be provided but is interpreted as empty array
        if (StringUtils.isNotBlank(courseStudentIds)) {
            String[] courseStudentIdArray = courseStudentIds.split(",");
            for (int i = 0; i < courseStudentIdArray.length; i++) {
                CourseStudent courseStudent = courseController.findCourseStudentById(new Long(courseStudentIdArray[i]));
                if (courseStudent != null && !courseStudent.getArchived() && !courseStudent.getStudent().getArchived()) {
                    courseStudents.add(courseStudent);
                }
            }
        }
    } else {
        courseStudents = courseController.listCourseStudentsByCourse(course);
    }
    List<CompositeAssessmentRequest> assessmentRequests = new ArrayList<CompositeAssessmentRequest>();
    if (CollectionUtils.isNotEmpty(courseStudents)) {
        boolean isStudyGuider = sessionController.hasEnvironmentPermission(StudentPermissions.FEATURE_OWNED_GROUP_STUDENTS_RESTRICTION);
        for (CourseStudent courseStudent : courseStudents) {
            if (isStudyGuider) {
                StaffMember staffMember = sessionController.getUser() instanceof StaffMember ? (StaffMember) sessionController.getUser() : null;
                if (staffMember == null || !studentController.isStudentGuider(staffMember, courseStudent.getStudent()))
                    continue;
            }
            CourseAssessmentRequest courseAssessmentRequest = assessmentController.findLatestCourseAssessmentRequestByCourseStudent(courseStudent);
            CourseAssessment courseAssessment = assessmentController.findLatestCourseAssessmentByCourseStudentAndArchived(courseStudent, Boolean.FALSE);
            CompositeAssessmentRequest assessmentRequest = new CompositeAssessmentRequest();
            assessmentRequest.setCourseStudentId(courseStudent.getId());
            assessmentRequest.setAssessmentRequestDate(courseAssessmentRequest == null ? null : courseAssessmentRequest.getCreated());
            assessmentRequest.setCourseEnrollmentDate(courseStudent.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 = courseStudent.getStudent().getFirstName();
            if (courseStudent.getStudent().getNickname() != null) {
                firstName = String.format("%s \"%s\"", firstName, courseStudent.getStudent().getNickname());
            }
            assessmentRequest.setFirstName(firstName);
            assessmentRequest.setLastName(courseStudent.getStudent().getLastName());
            assessmentRequest.setStudyProgramme(courseStudent.getStudent().getStudyProgramme().getName());
            assessmentRequest.setUserId(courseStudent.getStudent().getId());
            assessmentRequests.add(assessmentRequest);
        }
    }
    return Response.ok(assessmentRequests).build();
}
Also used : ArrayList(java.util.ArrayList) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CompositeAssessmentRequest(fi.otavanopisto.pyramus.rest.model.composite.CompositeAssessmentRequest) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 17 with CourseAssessmentRequest

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

the class StudentController method listCourseActivities.

/* Course activity */
public List<CourseActivity> listCourseActivities(List<CourseStudent> courseStudents, boolean includeTransferCredits) {
    if (courseStudents.isEmpty()) {
        return Collections.emptyList();
    }
    Student student = courseStudents.get(0).getStudent();
    List<CourseActivity> courseActivities = new ArrayList<>();
    List<CreditLink> linkedAssessments = creditLinkDAO.listByStudentAndType(student, CreditType.CourseAssessment);
    for (CourseStudent courseStudent : courseStudents) {
        Course course = courseStudent.getCourse();
        // Construct course base information and assume it's ongoing
        CourseActivity courseActivity = new CourseActivity();
        courseActivity.setCourseId(course.getId());
        courseActivity.setCurriculumIds(course.getCurriculums().stream().map(Curriculum::getId).collect(Collectors.toList()));
        String courseName = course.getName();
        if (!StringUtils.isEmpty(course.getNameExtension())) {
            courseName = String.format("%s (%s)", courseName, course.getNameExtension());
        }
        courseActivity.setCourseName(courseName);
        courseActivity.setActivityDate(courseStudent.getEnrolmentTime());
        courseActivity.setState(CourseActivityState.ONGOING);
        // Status override if course has been graded
        CourseAssessment courseAssessment = courseAssessmentDAO.findLatestByCourseStudentAndArchived(courseStudent, Boolean.FALSE);
        if (courseAssessment != null && courseAssessment.getGrade() != null) {
            courseActivity.setText(courseAssessment.getVerbalAssessment());
            courseActivity.setGrade(courseAssessment.getGrade().getName());
            courseActivity.setPassingGrade(courseAssessment.getGrade().getPassingGrade());
            courseActivity.setActivityDate(courseAssessment.getDate());
            courseActivity.setGradeDate(courseAssessment.getDate());
            courseActivity.setState(CourseActivityState.GRADED);
        }
        // Status override if course has been graded as linked credit
        CreditLink linkedAssessment = linkedAssessments.stream().filter(creditLink -> course.getId().equals(((CourseAssessment) creditLink.getCredit()).getCourseStudent().getCourse().getId())).findAny().orElse(null);
        if (linkedAssessment != null) {
            courseActivity.setText(((CourseAssessment) linkedAssessment.getCredit()).getVerbalAssessment());
            courseActivity.setGrade(((CourseAssessment) linkedAssessment.getCredit()).getGrade().getName());
            courseActivity.setPassingGrade(((CourseAssessment) linkedAssessment.getCredit()).getGrade().getPassingGrade());
            courseActivity.setActivityDate(linkedAssessment.getCreated());
            courseActivity.setGradeDate(linkedAssessment.getCreated());
            courseActivity.setState(CourseActivityState.GRADED);
        }
        // Status override if student has requested the course to be assessed
        CourseAssessmentRequest request = courseAssessmentRequestDAO.findLatestByCourseStudent(courseStudent);
        if (request != null && !request.getHandled() && request.getCreated().after(courseActivity.getActivityDate())) {
            courseActivity.setText(request.getRequestText());
            courseActivity.setActivityDate(request.getCreated());
            courseActivity.setState(CourseActivityState.ASSESSMENT_REQUESTED);
        }
        courseActivities.add(courseActivity);
    }
    if (includeTransferCredits) {
        List<TransferCredit> transferCredits = listStudentTransferCredits(student);
        for (TransferCredit transferCredit : transferCredits) {
            CourseActivity courseActivity = new CourseActivity();
            courseActivity.setCurriculumIds(Collections.emptyList());
            courseActivity.setCourseName(transferCredit.getCourseName());
            courseActivity.setGrade(transferCredit.getGrade().getName());
            courseActivity.setPassingGrade(transferCredit.getGrade().getPassingGrade());
            courseActivity.setActivityDate(transferCredit.getDate());
            courseActivity.setState(CourseActivityState.TRANSFERRED);
            courseActivities.add(courseActivity);
        }
        // Linked transfer credits
        List<CreditLink> linkedTransferCredits = includeTransferCredits ? listStudentLinkedTransferCredits(student) : Collections.emptyList();
        for (CreditLink creditLink : linkedTransferCredits) {
            TransferCredit transferCredit = (TransferCredit) creditLink.getCredit();
            CourseActivity courseActivity = new CourseActivity();
            courseActivity.setCurriculumIds(Collections.emptyList());
            courseActivity.setCourseName(transferCredit.getCourseName());
            courseActivity.setGrade(transferCredit.getGrade().getName());
            courseActivity.setPassingGrade(transferCredit.getGrade().getPassingGrade());
            courseActivity.setActivityDate(transferCredit.getDate());
            courseActivity.setState(CourseActivityState.TRANSFERRED);
            courseActivities.add(courseActivity);
        }
    }
    return courseActivities;
}
Also used : ArrayList(java.util.ArrayList) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseActivity(fi.otavanopisto.pyramus.rest.model.CourseActivity) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course)

Example 18 with CourseAssessmentRequest

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

the class StudentRESTService method listStudentAssessmentRequests.

@Path("/students/{STUDENTID:[0-9]*}/assessmentRequests/")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response listStudentAssessmentRequests(@PathParam("STUDENTID") Long studentId) {
    Student student = studentController.findStudentById(studentId);
    Status studentStatus = checkStudent(student);
    if (studentStatus != Status.OK)
        return Response.status(studentStatus).build();
    if (!restSecurity.hasPermission(new String[] { CourseAssessmentPermissions.LIST_COURSEASSESSMENTREQUESTS, StudentPermissions.STUDENT_OWNER }, student, Style.OR)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    List<CourseAssessmentRequest> assessmentRequests = assessmentController.listCourseAssessmentRequestsByStudent(student);
    return Response.ok(objectFactory.createModel(assessmentRequests)).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) 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 19 with CourseAssessmentRequest

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

the class AssessmentController method createCourseAssessment.

public CourseAssessment createCourseAssessment(CourseStudent courseStudent, StaffMember assessingUser, Grade grade, Date date, String verbalAssessment) {
    CourseAssessment courseAssessment = courseAssessmentDAO.create(courseStudent, assessingUser, grade, date, verbalAssessment);
    // Mark respective course assessment requests as handled
    List<CourseAssessmentRequest> courseAssessmentRequests = courseAssessmentRequestDAO.listByCourseStudentAndHandledAndArchived(courseStudent, Boolean.FALSE, Boolean.FALSE);
    for (CourseAssessmentRequest courseAssessmentRequest : courseAssessmentRequests) {
        courseAssessmentRequestDAO.updateHandled(courseAssessmentRequest, Boolean.TRUE);
    }
    return courseAssessment;
}
Also used : CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest)

Example 20 with CourseAssessmentRequest

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

the class AssessmentController method updateCourseAssessment.

public CourseAssessment updateCourseAssessment(CourseAssessment courseAssessment, StaffMember assessingUser, Grade grade, Date assessmentDate, String verbalAssessment) {
    // Update course assessment...
    courseAssessment = courseAssessmentDAO.update(courseAssessment, assessingUser, grade, assessmentDate, verbalAssessment);
    // ...and mark respective course assessment requests as handled
    List<CourseAssessmentRequest> courseAssessmentRequests = courseAssessmentRequestDAO.listByCourseStudentAndHandledAndArchived(courseAssessment.getCourseStudent(), Boolean.FALSE, Boolean.FALSE);
    for (CourseAssessmentRequest courseAssessmentRequest : courseAssessmentRequests) {
        courseAssessmentRequestDAO.updateHandled(courseAssessmentRequest, Boolean.TRUE);
    }
    return courseAssessment;
}
Also used : 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