Search in sources :

Example 11 with AcademicTerm

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");
}
Also used : AcademicTerm(fi.otavanopisto.pyramus.domainmodel.base.AcademicTerm) JSONObject(net.sf.json.JSONObject) AcademicTermDAO(fi.otavanopisto.pyramus.dao.base.AcademicTermDAO) JSONArray(net.sf.json.JSONArray)

Example 12 with AcademicTerm

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");
}
Also used : CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) ArrayList(java.util.ArrayList) ReverseComparator(org.apache.commons.collections.comparators.ReverseComparator) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Date(java.util.Date) ReverseComparator(org.apache.commons.collections.comparators.ReverseComparator) Comparator(java.util.Comparator) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) AcademicTerm(fi.otavanopisto.pyramus.domainmodel.base.AcademicTerm) AcademicTermDAO(fi.otavanopisto.pyramus.dao.base.AcademicTermDAO) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseParticipationType(fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType)

Aggregations

AcademicTerm (fi.otavanopisto.pyramus.domainmodel.base.AcademicTerm)12 AcademicTermDAO (fi.otavanopisto.pyramus.dao.base.AcademicTermDAO)9 Date (java.util.Date)4 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)3 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)3 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)3 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)3 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)3 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)2 CourseDAO (fi.otavanopisto.pyramus.dao.courses.CourseDAO)2 ProjectAssessmentDAO (fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO)2 ModuleDAO (fi.otavanopisto.pyramus.dao.modules.ModuleDAO)2 StudentProjectDAO (fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO)2 StudentProjectModuleDAO (fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO)2 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)2 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)2 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)2 CourseParticipationType (fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType)2 Grade (fi.otavanopisto.pyramus.domainmodel.grading.Grade)2 ProjectAssessment (fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment)2