use of fi.otavanopisto.pyramus.dao.base.AcademicTermDAO in project pyramus by otavanopisto.
the class SearchStudentProjectModuleCoursesDialogViewController method process.
/**
* Processes the page request by including the corresponding JSP page to the response.
*
* @param pageRequestContext Page request context
*/
@SuppressWarnings("unchecked")
public void process(PageRequestContext pageRequestContext) {
CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
AcademicTermDAO academicTermDAO = DAOFactory.getInstance().getAcademicTermDAO();
Long moduleId = pageRequestContext.getLong("moduleId");
Long academicTermId = pageRequestContext.getLong("academicTermId");
Long studentId = pageRequestContext.getLong("studentId");
Module module = moduleDAO.findById(moduleId);
AcademicTerm academicTerm = null;
if (academicTermId != null && academicTermId >= 0)
academicTerm = academicTermDAO.findById(academicTermId);
Student student = studentDAO.findById(studentId);
List<Course> courses = courseDAO.listByModule(module);
Collections.sort(courses, new ReverseComparator(new Comparator<Course>() {
@Override
public int compare(Course o1, Course o2) {
int result = compareDates(o1.getBeginDate(), o2.getBeginDate());
if (result == 0) {
result = compareDates(o1.getEndDate(), o2.getEndDate());
}
return result;
}
private int compareDates(Date d1, Date d2) {
if (d1 == d2) {
return 0;
} else {
if (d1 == null)
return 1;
else if (d2 == null)
return -1;
else {
return d1.compareTo(d2);
}
}
}
}));
List<StudentProjectModuleCourseBean> studentProjectModuleCourses = new ArrayList<>();
int coursesInTimeFrame = 0;
for (Course course : courses) {
boolean withinTimeFrame = false;
if ((academicTerm != null) && (academicTerm.getStartDate() != null) && (academicTerm.getEndDate() != null) && (course.getBeginDate() != null) && (course.getEndDate() != null)) {
withinTimeFrame = isWithinTimeFrame(academicTerm.getStartDate(), academicTerm.getEndDate(), course.getBeginDate(), course.getEndDate());
if (withinTimeFrame)
coursesInTimeFrame++;
}
CourseParticipationType courseParticipationType = null;
CourseStudent courseStudent = courseStudentDAO.findByCourseAndStudent(course, student);
if (courseStudent != null)
courseParticipationType = courseStudent.getParticipationType();
Long courseStudentCount = courseStudentDAO.countByCourse(course);
Long maxCourseStudentCount = course.getMaxParticipantCount();
StudentProjectModuleCourseBean studentProjectModuleCourseBean = new StudentProjectModuleCourseBean(course, courseParticipationType, withinTimeFrame, courseStudentCount, maxCourseStudentCount);
studentProjectModuleCourses.add(studentProjectModuleCourseBean);
}
String message;
if (!courses.isEmpty()) {
message = Messages.getInstance().getText(pageRequestContext.getRequest().getLocale(), "projects.searchStudentProjectModuleCoursesDialog.coursesFound", new Object[] { courses.size(), coursesInTimeFrame });
} else {
message = Messages.getInstance().getText(pageRequestContext.getRequest().getLocale(), "projects.searchStudentProjectModuleCoursesDialog.noCoursesFound");
}
pageRequestContext.getRequest().setAttribute("message", message);
pageRequestContext.getRequest().setAttribute("studentProjectModuleCourses", studentProjectModuleCourses);
pageRequestContext.setIncludeJSP("/templates/projects/searchstudentprojectmodulecoursesdialog.jsp");
}
Aggregations