Search in sources :

Example 1 with StudyActivityItemRestModel

use of fi.otavanopisto.pyramus.rest.model.hops.StudyActivityItemRestModel in project pyramus by otavanopisto.

the class MuikkuRESTService method getTransferCreditActivityItem.

private StudyActivityItemRestModel getTransferCreditActivityItem(TransferCredit transferCredit) {
    StudyActivityItemRestModel item = new StudyActivityItemRestModel();
    item.setCourseName(transferCredit.getCourseName());
    if (transferCredit.getCourseNumber() != null && transferCredit.getCourseNumber() > 0) {
        item.setCourseNumber(transferCredit.getCourseNumber());
    }
    item.setDate(transferCredit.getDate());
    if (transferCredit.getGrade() != null) {
        item.setGrade(transferCredit.getGrade().getName());
    }
    item.setStatus(StudyActivityItemStatus.TRANSFERRED);
    item.setSubject(transferCredit.getSubject().getCode());
    return item;
}
Also used : StudyActivityItemRestModel(fi.otavanopisto.pyramus.rest.model.hops.StudyActivityItemRestModel)

Example 2 with StudyActivityItemRestModel

use of fi.otavanopisto.pyramus.rest.model.hops.StudyActivityItemRestModel in project pyramus by otavanopisto.

the class MuikkuRESTService method getStudentStudyActivity.

@Path("/students/{ID:[0-9]*}/studyActivity")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response getStudentStudyActivity(@PathParam("ID") Long id) {
    // Access check
    Student student = studentController.findStudentById(id);
    if (student == null || student.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!restSecurity.hasPermission(new String[] { MuikkuPermissions.GET_STUDENT_COURSE_ACTIVITY, 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();
        }
    }
    Map<String, StudyActivityItemRestModel> items = new HashMap<>();
    // Transfer credits
    List<TransferCredit> transferCredits = transferCreditDAO.listByStudent(student);
    transferCredits.sort(Comparator.comparing(TransferCredit::getDate).reversed());
    for (TransferCredit transferCredit : transferCredits) {
        String key = getActivityItemKey(transferCredit.getSubject(), transferCredit.getCourseNumber());
        StudyActivityItemRestModel item = getTransferCreditActivityItem(transferCredit);
        if (!items.containsKey(key) || items.get(key).getDate().getTime() < item.getDate().getTime()) {
            items.put(key, item);
        }
    }
    // Course assessments
    List<CourseAssessment> courseAssessments = courseAssessmentDAO.listByStudent(student);
    courseAssessments.sort(Comparator.comparing(CourseAssessment::getDate).reversed());
    for (CourseAssessment courseAssessment : courseAssessments) {
        Course course = courseAssessment.getCourseStudent().getCourse();
        String key = getActivityItemKey(course.getSubject(), course.getCourseNumber());
        StudyActivityItemRestModel item = getCourseAssessmentActivityItem(courseAssessment);
        if (!items.containsKey(key) || items.get(key).getDate().getTime() < item.getDate().getTime()) {
            items.put(key, item);
        }
    }
    // Linked credits
    List<CreditLink> creditLinks = creditLinkDAO.listByStudent(student);
    for (CreditLink creditLink : creditLinks) {
        Credit credit = creditLink.getCredit();
        if (credit.getCreditType() == CreditType.CourseAssessment) {
            CourseAssessment courseAssessment = (CourseAssessment) credit;
            Course course = courseAssessment.getCourseStudent().getCourse();
            String key = getActivityItemKey(course.getSubject(), course.getCourseNumber());
            StudyActivityItemRestModel item = getCourseAssessmentActivityItem(courseAssessment);
            if (!items.containsKey(key) || items.get(key).getDate().getTime() < item.getDate().getTime()) {
                items.put(key, item);
            }
        } else if (credit.getCreditType() == CreditType.TransferCredit) {
            TransferCredit transferCredit = (TransferCredit) credit;
            String key = getActivityItemKey(transferCredit.getSubject(), transferCredit.getCourseNumber());
            StudyActivityItemRestModel item = getTransferCreditActivityItem(transferCredit);
            if (!items.containsKey(key) || items.get(key).getDate().getTime() < item.getDate().getTime()) {
                items.put(key, item);
            }
        }
    }
    // Courses
    List<CourseStudent> courseStudents = courseStudentDAO.listByStudent(student);
    for (CourseStudent courseStudent : courseStudents) {
        Course course = courseStudent.getCourse();
        String key = getActivityItemKey(course.getSubject(), course.getCourseNumber());
        if (!items.containsKey(key)) {
            StudyActivityItemRestModel item = new StudyActivityItemRestModel();
            item.setCourseId(course.getId());
            item.setCourseName(course.getName());
            if (course.getCourseNumber() != null && course.getCourseNumber() > 0) {
                item.setCourseNumber(course.getCourseNumber());
            }
            item.setDate(courseStudent.getEnrolmentTime());
            item.setStatus(StudyActivityItemStatus.ONGOING);
            item.setSubject(course.getSubject().getCode());
            items.put(key, item);
        }
    }
    return Response.ok(items.values()).build();
}
Also used : StudyActivityItemRestModel(fi.otavanopisto.pyramus.rest.model.hops.StudyActivityItemRestModel) HashMap(java.util.HashMap) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) Credit(fi.otavanopisto.pyramus.domainmodel.grading.Credit) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 3 with StudyActivityItemRestModel

use of fi.otavanopisto.pyramus.rest.model.hops.StudyActivityItemRestModel in project pyramus by otavanopisto.

the class MuikkuRESTService method getCourseAssessmentActivityItem.

private StudyActivityItemRestModel getCourseAssessmentActivityItem(CourseAssessment courseAssessment) {
    Course course = courseAssessment.getCourseStudent().getCourse();
    StudyActivityItemRestModel item = new StudyActivityItemRestModel();
    item.setCourseId(course.getId());
    item.setCourseName(course.getName());
    if (course.getCourseNumber() != null && course.getCourseNumber() > 0) {
        item.setCourseNumber(course.getCourseNumber());
    }
    item.setDate(courseAssessment.getDate());
    if (courseAssessment.getGrade() != null) {
        item.setGrade(courseAssessment.getGrade().getName());
    }
    item.setStatus(StudyActivityItemStatus.GRADED);
    item.setSubject(course.getSubject().getCode());
    return item;
}
Also used : StudyActivityItemRestModel(fi.otavanopisto.pyramus.rest.model.hops.StudyActivityItemRestModel) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course)

Aggregations

StudyActivityItemRestModel (fi.otavanopisto.pyramus.rest.model.hops.StudyActivityItemRestModel)3 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)2 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)1 CourseAssessment (fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment)1 Credit (fi.otavanopisto.pyramus.domainmodel.grading.Credit)1 CreditLink (fi.otavanopisto.pyramus.domainmodel.grading.CreditLink)1 TransferCredit (fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit)1 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)1 StudentGroupStudent (fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent)1 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1