use of fi.otavanopisto.pyramus.domainmodel.base.AcademicTerm in project pyramus by otavanopisto.
the class AcademicTermsViewController 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) {
AcademicTermDAO academicTermDAO = DAOFactory.getInstance().getAcademicTermDAO();
List<AcademicTerm> academicTerms = academicTermDAO.listUnarchived();
Collections.sort(academicTerms, new Comparator<AcademicTerm>() {
public int compare(AcademicTerm o1, AcademicTerm o2) {
return o1.getStartDate() == null ? -1 : o2.getStartDate() == null ? 1 : o1.getStartDate().compareTo(o2.getStartDate());
}
});
JSONArray jsonAcademicTerms = new JSONArray();
for (AcademicTerm academicTerm : academicTerms) {
JSONObject jsonAcademicTerm = new JSONObject();
jsonAcademicTerm.put("name", academicTerm.getName());
if (academicTerm.getStartDate() != null) {
jsonAcademicTerm.put("startDate", academicTerm.getStartDate().getTime());
}
if (academicTerm.getEndDate() != null) {
jsonAcademicTerm.put("endDate", academicTerm.getEndDate().getTime());
}
jsonAcademicTerm.put("id", academicTerm.getId());
jsonAcademicTerms.add(jsonAcademicTerm);
}
this.setJsDataVariable(pageRequestContext, "academicTerms", jsonAcademicTerms.toString());
pageRequestContext.setIncludeJSP("/templates/settings/academicterms.jsp");
}
use of fi.otavanopisto.pyramus.domainmodel.base.AcademicTerm 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