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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations