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