Search in sources :

Example 16 with CourseParticipationType

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

the class EditCourseViewController 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();
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    CourseDescriptionCategoryDAO descriptionCategoryDAO = DAOFactory.getInstance().getCourseDescriptionCategoryDAO();
    CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
    CourseParticipationTypeDAO participationTypeDAO = DAOFactory.getInstance().getCourseParticipationTypeDAO();
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    CourseStateDAO courseStateDAO = DAOFactory.getInstance().getCourseStateDAO();
    CourseTypeDAO courseTypeDAO = DAOFactory.getInstance().getCourseTypeDAO();
    CourseStaffMemberDAO courseStaffMemberDAO = DAOFactory.getInstance().getCourseStaffMemberDAO();
    CourseStaffMemberRoleDAO courseStaffMemberRoleDAO = DAOFactory.getInstance().getCourseStaffMemberRoleDAO();
    CourseComponentDAO courseComponentDAO = DAOFactory.getInstance().getCourseComponentDAO();
    CourseEnrolmentTypeDAO enrolmentTypeDAO = DAOFactory.getInstance().getCourseEnrolmentTypeDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    EducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getEducationSubtypeDAO();
    CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
    OrganizationDAO organizationDAO = DAOFactory.getInstance().getOrganizationDAO();
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    // The course to be edited
    Course course = courseDAO.findById(NumberUtils.createLong(pageRequestContext.getRequest().getParameter("course")));
    pageRequestContext.getRequest().setAttribute("course", course);
    // Create a hashmap of the education types and education subtypes selected in the course
    List<EducationType> educationTypes = educationTypeDAO.listUnarchived();
    Collections.sort(educationTypes, new StringAttributeComparator("getName"));
    pageRequestContext.getRequest().setAttribute("educationTypes", educationTypes);
    Map<String, Boolean> enabledEducationTypes = new HashMap<>();
    for (CourseEducationType courseEducationType : course.getCourseEducationTypes()) {
        for (CourseEducationSubtype courseEducationSubtype : courseEducationType.getCourseEducationSubtypes()) {
            enabledEducationTypes.put(courseEducationType.getEducationType().getId() + "." + courseEducationSubtype.getEducationSubtype().getId(), Boolean.TRUE);
        }
    }
    pageRequestContext.getRequest().setAttribute("enabledEducationTypes", enabledEducationTypes);
    // Various lists of base entities from module, course, and resource DAOs
    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;
        }
    });
    StringBuilder tagsBuilder = new StringBuilder();
    Iterator<Tag> tagIterator = course.getTags().iterator();
    while (tagIterator.hasNext()) {
        Tag tag = tagIterator.next();
        tagsBuilder.append(tag.getText());
        if (tagIterator.hasNext())
            tagsBuilder.append(' ');
    }
    List<CourseComponent> courseComponents = courseComponentDAO.listByCourse(course);
    // course students students
    Map<Long, List<Student>> courseStudentsStudents = new HashMap<>();
    for (CourseStudent courseStudent : courseStudents) {
        courseStudentsStudents.put(courseStudent.getId(), studentDAO.listByPerson(courseStudent.getStudent().getPerson()));
    }
    // Subjects
    Map<Long, List<Subject>> subjectsByEducationType = new HashMap<>();
    List<Subject> subjectsByNoEducationType = subjectDAO.listByEducationType(null);
    Collections.sort(subjectsByNoEducationType, new StringAttributeComparator("getName"));
    for (EducationType educationType : educationTypes) {
        List<Subject> subjectsOfType = subjectDAO.listByEducationType(educationType);
        if (subjectsOfType != null && !subjectsOfType.isEmpty()) {
            Collections.sort(subjectsOfType, new StringAttributeComparator("getName"));
            subjectsByEducationType.put(educationType.getId(), subjectsOfType);
        }
    }
    List<EducationalTimeUnit> educationalTimeUnits = educationalTimeUnitDAO.listUnarchived();
    Collections.sort(educationalTimeUnits, new StringAttributeComparator("getName"));
    List<CourseParticipationType> courseParticipationTypes = participationTypeDAO.listUnarchived();
    Collections.sort(courseParticipationTypes, new Comparator<CourseParticipationType>() {

        public int compare(CourseParticipationType o1, CourseParticipationType o2) {
            return o1.getIndexColumn() == null ? -1 : o2.getIndexColumn() == null ? 1 : o1.getIndexColumn().compareTo(o2.getIndexColumn());
        }
    });
    Map<Long, List<EducationSubtype>> educationSubtypes = new HashMap<>();
    for (EducationType educationType : educationTypes) {
        List<EducationSubtype> subtypes = educationSubtypeDAO.listByEducationType(educationType);
        Collections.sort(subtypes, new StringAttributeComparator("getName"));
        educationSubtypes.put(educationType.getId(), subtypes);
    }
    // TODO: Support other currencies
    List<Currency> currencies = Arrays.asList(Currency.getInstance("EUR"));
    List<Curriculum> curriculums = curriculumDAO.listUnarchived();
    Collections.sort(curriculums, new StringAttributeComparator("getName"));
    // Organizations
    Long loggedUserId = pageRequestContext.getLoggedUserId();
    StaffMember user = staffMemberDAO.findById(loggedUserId);
    List<Organization> organizations;
    if (UserUtils.canAccessAllOrganizations(user)) {
        organizations = organizationDAO.listUnarchived();
    } else {
        organizations = Arrays.asList(user.getOrganization());
    }
    Collections.sort(organizations, new StringAttributeComparator("getName"));
    pageRequestContext.getRequest().setAttribute("organizations", organizations);
    pageRequestContext.getRequest().setAttribute("educationSubtypes", educationSubtypes);
    pageRequestContext.getRequest().setAttribute("tags", tagsBuilder.toString());
    pageRequestContext.getRequest().setAttribute("states", courseStateDAO.listUnarchived());
    pageRequestContext.getRequest().setAttribute("types", courseTypeDAO.listUnarchived());
    pageRequestContext.getRequest().setAttribute("roles", courseStaffMemberRoleDAO.listAll());
    pageRequestContext.getRequest().setAttribute("subjectsByNoEducationType", subjectsByNoEducationType);
    pageRequestContext.getRequest().setAttribute("subjectsByEducationType", subjectsByEducationType);
    pageRequestContext.getRequest().setAttribute("courseParticipationTypes", courseParticipationTypes);
    pageRequestContext.getRequest().setAttribute("courseEnrolmentTypes", enrolmentTypeDAO.listAll());
    pageRequestContext.getRequest().setAttribute("courseStudents", courseStudents);
    pageRequestContext.getRequest().setAttribute("courseUsers", courseUsers);
    pageRequestContext.getRequest().setAttribute("courseLengthTimeUnits", educationalTimeUnits);
    pageRequestContext.getRequest().setAttribute("courseComponents", courseComponents);
    pageRequestContext.getRequest().setAttribute("courseStudentsStudents", courseStudentsStudents);
    pageRequestContext.getRequest().setAttribute("courseDescriptions", descriptionDAO.listByCourseBase(course));
    pageRequestContext.getRequest().setAttribute("courseDescriptionCategories", descriptionCategoryDAO.listUnarchived());
    pageRequestContext.getRequest().setAttribute("currencies", currencies);
    pageRequestContext.getRequest().setAttribute("curriculums", curriculums);
    pageRequestContext.setIncludeJSP("/templates/courses/editcourse.jsp");
}
Also used : HashMap(java.util.HashMap) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseDescriptionDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) Currency(java.util.Currency) List(java.util.List) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) OrganizationDAO(fi.otavanopisto.pyramus.dao.base.OrganizationDAO) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) CourseParticipationTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseParticipationTypeDAO) CourseComponentDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) CourseStaffMemberRoleDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberRoleDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) CourseEnrolmentTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseEnrolmentTypeDAO) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) CourseStaffMemberDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO) CourseTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseTypeDAO) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) CourseDescriptionCategoryDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionCategoryDAO) CourseComponent(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent) CourseStateDAO(fi.otavanopisto.pyramus.dao.courses.CourseStateDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) CourseStaffMemberDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CourseParticipationType(fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) EducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag)

Example 17 with CourseParticipationType

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

the class CourseParticipationTypesViewController 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) {
    CourseParticipationTypeDAO participationTypeDAO = DAOFactory.getInstance().getCourseParticipationTypeDAO();
    DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
    CourseParticipationType initialCourseParticipationType = defaultsDAO.getDefaults().getInitialCourseParticipationType();
    List<CourseParticipationType> courseParticipationTypes = participationTypeDAO.listUnarchived();
    Collections.sort(courseParticipationTypes, new Comparator<CourseParticipationType>() {

        public int compare(CourseParticipationType o1, CourseParticipationType o2) {
            return o1.getIndexColumn() == null ? -1 : o2.getIndexColumn() == null ? 1 : o1.getIndexColumn().compareTo(o2.getIndexColumn());
        }
    });
    String jsonCourseParticipationTypes = new JSONArrayExtractor("name", "id").extractString(courseParticipationTypes);
    JSONObject joInitialCourseParticipationType = new JSONObject();
    if (initialCourseParticipationType == null) {
        joInitialCourseParticipationType.put("name", "");
        joInitialCourseParticipationType.put("id", -1);
    } else {
        joInitialCourseParticipationType.put("name", initialCourseParticipationType.getName());
        joInitialCourseParticipationType.put("id", initialCourseParticipationType.getId());
    }
    this.setJsDataVariable(pageRequestContext, "courseParticipationTypes", jsonCourseParticipationTypes);
    this.setJsDataVariable(pageRequestContext, "initialCourseParticipationType", joInitialCourseParticipationType.toString());
    pageRequestContext.setIncludeJSP("/templates/settings/courseparticipationtypes.jsp");
}
Also used : CourseParticipationTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseParticipationTypeDAO) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) CourseParticipationType(fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor)

Example 18 with CourseParticipationType

use of fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType 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)

Example 19 with CourseParticipationType

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

the class CourseParticipationTypeDAO method create.

public CourseParticipationType create(String name) {
    Integer indexColumn = findMaxIndexColumn();
    if (indexColumn == null)
        indexColumn = new Integer(0);
    else
        indexColumn++;
    EntityManager entityManager = getEntityManager();
    CourseParticipationType courseParticipationType = new CourseParticipationType();
    courseParticipationType.setName(name);
    courseParticipationType.setIndexColumn(indexColumn);
    entityManager.persist(courseParticipationType);
    return courseParticipationType;
}
Also used : EntityManager(javax.persistence.EntityManager) CourseParticipationType(fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType)

Aggregations

CourseParticipationType (fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType)19 CourseParticipationTypeDAO (fi.otavanopisto.pyramus.dao.courses.CourseParticipationTypeDAO)13 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)10 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)9 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)9 DefaultsDAO (fi.otavanopisto.pyramus.dao.base.DefaultsDAO)7 CourseDAO (fi.otavanopisto.pyramus.dao.courses.CourseDAO)7 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)7 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)7 CourseEnrolmentTypeDAO (fi.otavanopisto.pyramus.dao.courses.CourseEnrolmentTypeDAO)6 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)6 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)6 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)6 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)6 CourseEnrolmentType (fi.otavanopisto.pyramus.domainmodel.courses.CourseEnrolmentType)6 Module (fi.otavanopisto.pyramus.domainmodel.modules.Module)6 Currency (java.util.Currency)6 SmvcRuntimeException (fi.internetix.smvc.SmvcRuntimeException)5 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)5 ModuleDAO (fi.otavanopisto.pyramus.dao.modules.ModuleDAO)5