Search in sources :

Example 6 with CourseStudent

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

the class GradingService method getCourseAssessmentByCourseStudentId.

public CourseAssessmentEntity getCourseAssessmentByCourseStudentId(@WebParam(name = "courseStudentId") Long courseStudentId) {
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
    CourseStudent courseStudent = courseStudentDAO.findById(courseStudentId);
    CourseAssessment courseAssessment = courseAssessmentDAO.findLatestByCourseStudentAndArchived(courseStudent, Boolean.FALSE);
    return EntityFactoryVault.buildFromDomainObject(courseAssessment);
}
Also used : CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) CourseAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment)

Example 7 with CourseStudent

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

the class BillingDetailsDAO method listByStudent.

public List<BillingDetails> listByStudent(Student student) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<BillingDetails> criteria = criteriaBuilder.createQuery(BillingDetails.class);
    Root<CourseStudent> root = criteria.from(CourseStudent.class);
    criteria.select(root.get(CourseStudent_.billingDetails));
    criteria.where(criteriaBuilder.equal(root.get(CourseStudent_.student), student));
    criteria.groupBy(root.get(CourseStudent_.billingDetails));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) BillingDetails(fi.otavanopisto.pyramus.domainmodel.base.BillingDetails)

Example 8 with CourseStudent

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

the class StudentRESTService method listCourseStudents.

@Path("/students/{STUDENTID:[0-9]*}/courses")
@GET
@RESTPermit(StudentPermissions.LIST_COURSESTUDENTSBYSTUDENT)
public Response listCourseStudents(@PathParam("STUDENTID") Long studentId) {
    Student student = studentController.findStudentById(studentId);
    Status studentStatus = checkStudent(student);
    if (studentStatus != Status.OK)
        return Response.status(studentStatus).build();
    List<fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent> courseStudents = courseController.listCourseStudentsByStudent(student);
    if (courseStudents.isEmpty()) {
        return Response.status(Status.NO_CONTENT).build();
    }
    List<fi.otavanopisto.pyramus.domainmodel.courses.Course> courses = new ArrayList<>();
    for (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent courseStudent : courseStudents) {
        courses.add(courseStudent.getCourse());
    }
    return Response.status(Status.OK).entity(objectFactory.createModel(courses)).build();
}
Also used : Status(javax.ws.rs.core.Response.Status) ArrayList(java.util.ArrayList) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) 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 9 with CourseStudent

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

the class StudentRESTService method getStudentStudyActivity.

@Path("/students/{STUDENTID:[0-9]*}/courseActivity")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response getStudentStudyActivity(@PathParam("STUDENTID") Long studentId, @QueryParam("courseIds") String courseIds, @QueryParam("includeTransferCredits") boolean includeTransferCredits) {
    // Access check
    Student student = studentController.findStudentById(studentId);
    if (student == null || student.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!restSecurity.hasPermission(new String[] { StudentPermissions.GET_STUDENT_COURSEACTIVITY, UserPermissions.USER_OWNER }, student, Style.OR)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    if (!sessionController.hasEnvironmentPermission(OrganizationPermissions.ACCESS_ALL_ORGANIZATIONS)) {
        if (!UserUtils.isMemberOf(sessionController.getUser(), student.getOrganization())) {
            return Response.status(Status.FORBIDDEN).build();
        }
    }
    // Get courses of the student (all or those specified with courseIds)
    List<CourseStudent> courseStudents;
    if (StringUtils.isEmpty(courseIds)) {
        courseStudents = courseController.listByStudent(student);
    } else {
        courseStudents = new ArrayList<>();
        String[] courseIdArray = courseIds.split(",");
        for (int i = 0; i < courseIdArray.length; i++) {
            Course course = courseController.findCourseById(new Long(courseIdArray[i]));
            if (course != null) {
                CourseStudent courseStudent = courseController.findCourseStudentByCourseAndStudent(course, student);
                if (courseStudent != null) {
                    courseStudents.add(courseStudent);
                } else {
                    logger.warning(String.format("Course student not found asking activity for student %d in course %d", student.getId(), course.getId()));
                }
            }
        }
    }
    // Serve data
    List<CourseActivity> courseActivities = studentController.listCourseActivities(courseStudents, includeTransferCredits);
    return Response.ok(courseActivities).build();
}
Also used : CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) 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) CourseActivity(fi.otavanopisto.pyramus.rest.model.CourseActivity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 10 with CourseStudent

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

the class StudentRESTService method createCourseAssessmentRequest.

@Path("/students/{STUDENTID:[0-9]*}/courses/{COURSEID:[0-9]*}/assessmentRequests/")
@POST
@RESTPermit(handling = Handling.INLINE)
public Response createCourseAssessmentRequest(@PathParam("STUDENTID") Long studentId, @PathParam("COURSEID") Long courseId, fi.otavanopisto.pyramus.rest.model.CourseAssessmentRequest entity) {
    if (entity == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    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).entity("Could not find course").build();
    }
    if (course.getArchived()) {
        return Response.status(Status.NOT_FOUND).entity("Course is archived").build();
    }
    if (!restSecurity.hasPermission(new String[] { CourseAssessmentPermissions.CREATE_COURSEASSESSMENTREQUEST, StudentPermissions.STUDENT_OWNER }, student, Style.OR)) {
        return Response.status(Status.FORBIDDEN).build();
    }
    CourseStudent courseStudent = courseController.findCourseStudentById(entity.getCourseStudentId());
    if (courseStudent == null) {
        return Response.status(Status.BAD_REQUEST).entity("Could not find coursestudent").build();
    }
    if (courseStudent.getArchived()) {
        return Response.status(Status.BAD_REQUEST).entity("Coursestudent is archived").build();
    }
    if (!courseStudent.getStudent().getId().equals(student.getId())) {
        return Response.status(Status.BAD_REQUEST).entity("Coursestudent doesnt match student").build();
    }
    if (!courseStudent.getCourse().getId().equals(course.getId())) {
        return Response.status(Status.BAD_REQUEST).entity("Coursestudent doesnt match course").build();
    }
    CourseAssessmentRequest courseAssessmentRequest = assessmentController.createCourseAssessmentRequest(courseStudent, Date.from(entity.getCreated().toInstant()), entity.getRequestText());
    return Response.ok(objectFactory.createModel(courseAssessmentRequest)).build();
}
Also used : Status(javax.ws.rs.core.Response.Status) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) 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) POST(javax.ws.rs.POST)

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