Search in sources :

Example 1 with CourseStaffMember

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

the class EnvironmentPermissionResolver method hasCourseAccess.

private boolean hasCourseAccess(Course course, fi.otavanopisto.pyramus.domainmodel.users.User userEntity, Permission permission) {
    PyramusPermissionCollection permissionCollection = findCollection(permission.getName());
    if (permissionCollection != null) {
        try {
            String[] defaultRoles = permissionCollection.getDefaultRoles(permission.getName());
            // Is EnvironmentRole in the environment roles of the permission
            if ((userEntity.getRole() != null) && ArrayUtils.contains(defaultRoles, userEntity.getRole().toString())) {
                return true;
            }
            CourseRoleArchetype[] defaultCourseRoles = permissionCollection.getDefaultCourseRoles(permission.getName());
            if (userEntity instanceof Student) {
                CourseStudent courseStudent = courseStudentDAO.findByCourseAndStudent(course, (Student) userEntity);
                if (courseStudent != null) {
                    return ArrayUtils.contains(defaultCourseRoles, CourseRoleArchetype.STUDENT);
                } else {
                    return false;
                }
            } else if (userEntity instanceof StaffMember) {
                CourseStaffMember courseStaffMember = courseStaffMemberDAO.findByCourseAndStaffMember(course, (StaffMember) userEntity);
                if (courseStaffMember != null) {
                    return ArrayUtils.contains(defaultCourseRoles, CourseRoleArchetype.TEACHER);
                } else {
                    return false;
                }
            } else {
                logger.severe(String.format("UserEntity could not be casted to a student nor staffmember."));
            }
        } catch (NoSuchFieldException e) {
        }
    }
    return false;
}
Also used : CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember)

Example 2 with CourseStaffMember

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

the class CoursesService method createCourseUser.

public CourseUserEntity createCourseUser(@WebParam(name = "courseId") Long courseId, @WebParam(name = "userId") Long userId, @WebParam(name = "courseUserRoleId") Long courseUserRoleId) {
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    CourseStaffMemberDAO courseStaffMemberDAO = DAOFactory.getInstance().getCourseStaffMemberDAO();
    CourseStaffMemberRoleDAO courseStaffMemberRoleDAO = DAOFactory.getInstance().getCourseStaffMemberRoleDAO();
    Course course = courseDAO.findById(courseId);
    StaffMember staffMember = staffMemberDAO.findById(userId);
    CourseStaffMemberRole role = courseStaffMemberRoleDAO.findById(courseUserRoleId);
    CourseStaffMember courseUser = courseStaffMemberDAO.create(course, staffMember, role);
    validateEntity(courseUser);
    return EntityFactoryVault.buildFromDomainObject(courseUser);
}
Also used : CourseStaffMemberRole(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMemberRole) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) CourseStaffMemberDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) CourseStaffMemberDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) CourseStaffMemberRoleDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberRoleDAO)

Example 3 with CourseStaffMember

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

the class CourseStaffMemberDAO method create.

public CourseStaffMember create(Course course, StaffMember staffMember, CourseStaffMemberRole role) {
    CourseStaffMember courseStaffMember = new CourseStaffMember();
    courseStaffMember.setCourse(course);
    courseStaffMember.setStaffMember(staffMember);
    courseStaffMember.setRole(role);
    persist(courseStaffMember);
    courseStaffMemberCreatedEvent.fire(new CourseStaffMemberCreatedEvent(courseStaffMember.getId(), courseStaffMember.getCourse().getId(), courseStaffMember.getStaffMember().getId()));
    return courseStaffMember;
}
Also used : CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) CourseStaffMemberCreatedEvent(fi.otavanopisto.pyramus.events.CourseStaffMemberCreatedEvent)

Example 4 with CourseStaffMember

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

the class CourseStaffMemberDAO method listByCourse.

public List<CourseStaffMember> listByCourse(Course course) {
    EntityManager entityManager = getEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CourseStaffMember> criteria = criteriaBuilder.createQuery(CourseStaffMember.class);
    Root<CourseStaffMember> root = criteria.from(CourseStaffMember.class);
    Join<CourseStaffMember, StaffMember> staffMemberJoin = root.join(CourseStaffMember_.staffMember);
    criteria.select(root);
    criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(CourseStaffMember_.course), course), criteriaBuilder.equal(staffMemberJoin.get(StaffMember_.archived), Boolean.FALSE)));
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember)

Example 5 with CourseStaffMember

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

the class ViewCourseViewController method process.

/**
 * Processes the page request by including the corresponding JSP page to the response.
 *
 * @param pageRequestContext Page request context
 */
public void process(PageRequestContext pageRequestContext) {
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    CourseComponentDAO courseComponentDAO = DAOFactory.getInstance().getCourseComponentDAO();
    CourseStaffMemberDAO courseStaffMemberDAO = DAOFactory.getInstance().getCourseStaffMemberDAO();
    ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
    CourseAssessmentRequestDAO courseAssessmentRequestDAO = DAOFactory.getInstance().getCourseAssessmentRequestDAO();
    // The course to be edited
    Course course = courseDAO.findById(pageRequestContext.getLong("course"));
    pageRequestContext.getRequest().setAttribute("course", course);
    Map<Long, CourseAssessmentRequest> courseAssessmentRequests = new HashMap<>();
    List<CourseStudent> courseStudents = courseStudentDAO.listByCourse(course);
    Collections.sort(courseStudents, new Comparator<CourseStudent>() {

        @Override
        public int compare(CourseStudent o1, CourseStudent o2) {
            int cmp = o1.getStudent().getLastName().compareToIgnoreCase(o2.getStudent().getLastName());
            if (cmp == 0)
                cmp = o1.getStudent().getFirstName().compareToIgnoreCase(o2.getStudent().getFirstName());
            return cmp;
        }
    });
    List<CourseStaffMember> courseUsers = courseStaffMemberDAO.listByCourse(course);
    Collections.sort(courseUsers, new Comparator<CourseStaffMember>() {

        @Override
        public int compare(CourseStaffMember o1, CourseStaffMember o2) {
            int cmp = o1.getStaffMember().getLastName().compareToIgnoreCase(o2.getStaffMember().getLastName());
            if (cmp == 0)
                cmp = o1.getStaffMember().getFirstName().compareToIgnoreCase(o2.getStaffMember().getFirstName());
            return cmp;
        }
    });
    JSONArray courseReportsJSON = new JSONArray();
    List<Report> courseReports = reportDAO.listByContextType(ReportContextType.Course);
    Collections.sort(courseReports, new StringAttributeComparator("getName"));
    for (Report report : courseReports) {
        JSONObject obj = new JSONObject();
        obj.put("id", report.getId().toString());
        obj.put("name", report.getName());
        courseReportsJSON.add(obj);
    }
    for (CourseStudent courseStudent : courseStudents) {
        List<CourseAssessmentRequest> courseAssessmentRequestsByCourseStudent = courseAssessmentRequestDAO.listByCourseStudent(courseStudent);
        Collections.sort(courseAssessmentRequestsByCourseStudent, new Comparator<CourseAssessmentRequest>() {

            @Override
            public int compare(CourseAssessmentRequest o1, CourseAssessmentRequest o2) {
                return o2.getCreated().compareTo(o1.getCreated());
            }
        });
        if (!courseAssessmentRequestsByCourseStudent.isEmpty()) {
            courseAssessmentRequests.put(courseStudent.getId(), courseAssessmentRequestsByCourseStudent.get(0));
        }
    }
    setJsDataVariable(pageRequestContext, "courseReports", courseReportsJSON.toString());
    pageRequestContext.getRequest().setAttribute("courseStudents", courseStudents);
    pageRequestContext.getRequest().setAttribute("courseUsers", courseUsers);
    pageRequestContext.getRequest().setAttribute("courseComponents", courseComponentDAO.listByCourse(course));
    pageRequestContext.getRequest().setAttribute("courseDescriptions", descriptionDAO.listByCourseBase(course));
    pageRequestContext.getRequest().setAttribute("courseAssessmentRequests", courseAssessmentRequests);
    pageRequestContext.setIncludeJSP("/templates/courses/viewcourse.jsp");
}
Also used : HashMap(java.util.HashMap) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseDescriptionDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseComponentDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO) Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) JSONArray(net.sf.json.JSONArray) CourseAssessmentRequestDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentRequestDAO) JSONObject(net.sf.json.JSONObject) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) CourseStaffMemberDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO)

Aggregations

CourseStaffMember (fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember)11 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)6 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)6 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)5 CourseDAO (fi.otavanopisto.pyramus.dao.courses.CourseDAO)4 CourseStaffMemberDAO (fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO)4 HashMap (java.util.HashMap)4 CourseComponentDAO (fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO)3 CourseDescriptionDAO (fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO)3 CourseStaffMemberRoleDAO (fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberRoleDAO)3 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)3 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)3 CourseEducationSubtype (fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype)3 CourseEducationType (fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType)3 EducationSubtype (fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype)3 EducationType (fi.otavanopisto.pyramus.domainmodel.base.EducationType)3 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)3 Organization (fi.otavanopisto.pyramus.domainmodel.base.Organization)3 Subject (fi.otavanopisto.pyramus.domainmodel.base.Subject)3 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)3