Search in sources :

Example 6 with ModuleComponentDAO

use of fi.otavanopisto.pyramus.dao.modules.ModuleComponentDAO in project pyramus by otavanopisto.

the class ViewModuleViewController 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();
    ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
    ModuleComponentDAO moduleComponentDAO = DAOFactory.getInstance().getModuleComponentDAO();
    CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
    Module module = moduleDAO.findById(pageRequestContext.getLong("module"));
    List<Course> courses = courseDAO.listByModule(module);
    Collections.sort(courses, new StringAttributeComparator("getName", true));
    pageRequestContext.getRequest().setAttribute("module", module);
    pageRequestContext.getRequest().setAttribute("courses", courses);
    pageRequestContext.getRequest().setAttribute("moduleComponents", moduleComponentDAO.listByModule(module));
    pageRequestContext.getRequest().setAttribute("moduleDescriptions", descriptionDAO.listByCourseBase(module));
    pageRequestContext.setIncludeJSP("/templates/modules/viewmodule.jsp");
}
Also used : ModuleComponentDAO(fi.otavanopisto.pyramus.dao.modules.ModuleComponentDAO) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseDescriptionDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course)

Example 7 with ModuleComponentDAO

use of fi.otavanopisto.pyramus.dao.modules.ModuleComponentDAO in project pyramus by otavanopisto.

the class CreateCourseViewController 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) {
    ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
    CourseStaffMemberRoleDAO courseStaffMemberRoleDAO = DAOFactory.getInstance().getCourseStaffMemberRoleDAO();
    CourseDescriptionCategoryDAO descriptionCategoryDAO = DAOFactory.getInstance().getCourseDescriptionCategoryDAO();
    CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
    CourseStateDAO courseStateDAO = DAOFactory.getInstance().getCourseStateDAO();
    CourseTypeDAO courseTypeDAO = DAOFactory.getInstance().getCourseTypeDAO();
    CourseEnrolmentTypeDAO enrolmentTypeDAO = DAOFactory.getInstance().getCourseEnrolmentTypeDAO();
    CourseParticipationTypeDAO participationTypeDAO = DAOFactory.getInstance().getCourseParticipationTypeDAO();
    ModuleComponentDAO moduleComponentDAO = DAOFactory.getInstance().getModuleComponentDAO();
    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 module acting as the base of the new course
    Module module = moduleDAO.findById(NumberUtils.createLong(pageRequestContext.getRequest().getParameter("module")));
    pageRequestContext.getRequest().setAttribute("module", module);
    // Create a hashmap of the education types and education subtypes selected in the module so that the
    // course to be created has them selected as well
    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 : module.getCourseEducationTypes()) {
        for (CourseEducationSubtype moduleEducationSubtype : courseEducationType.getCourseEducationSubtypes()) {
            enabledEducationTypes.put(courseEducationType.getEducationType().getId() + "." + moduleEducationSubtype.getEducationSubtype().getId(), Boolean.TRUE);
        }
    }
    pageRequestContext.getRequest().setAttribute("enabledEducationTypes", enabledEducationTypes);
    // Module tags for the new course
    StringBuilder tagsBuilder = new StringBuilder();
    Iterator<Tag> tagIterator = module.getTags().iterator();
    while (tagIterator.hasNext()) {
        Tag tag = tagIterator.next();
        tagsBuilder.append(tag.getText());
        if (tagIterator.hasNext())
            tagsBuilder.append(' ');
    }
    pageRequestContext.getRequest().setAttribute("tags", tagsBuilder.toString());
    List<ModuleComponent> moduleComponents = moduleComponentDAO.listByModule(module);
    // 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);
        }
    }
    // Various lists of base entities from module, course, and resource DAOs
    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("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("courseLengthTimeUnits", educationalTimeUnits);
    pageRequestContext.getRequest().setAttribute("moduleComponents", moduleComponents);
    pageRequestContext.getRequest().setAttribute("courseDescriptions", descriptionDAO.listByCourseBase(module));
    pageRequestContext.getRequest().setAttribute("courseDescriptionCategories", descriptionCategoryDAO.listUnarchived());
    pageRequestContext.getRequest().setAttribute("currencies", currencies);
    pageRequestContext.getRequest().setAttribute("curriculums", curriculums);
    pageRequestContext.setIncludeJSP("/templates/courses/createcourse.jsp");
}
Also used : HashMap(java.util.HashMap) CourseDescriptionDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) ModuleComponentDAO(fi.otavanopisto.pyramus.dao.modules.ModuleComponentDAO) Currency(java.util.Currency) List(java.util.List) 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) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) CourseStaffMemberRoleDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberRoleDAO) ModuleComponent(fi.otavanopisto.pyramus.domainmodel.modules.ModuleComponent) CourseEnrolmentTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseEnrolmentTypeDAO) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) 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) CourseStateDAO(fi.otavanopisto.pyramus.dao.courses.CourseStateDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) 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) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag)

Example 8 with ModuleComponentDAO

use of fi.otavanopisto.pyramus.dao.modules.ModuleComponentDAO in project pyramus by otavanopisto.

the class EditModuleViewController method process.

/**
 * Processes the page request by including the corresponding JSP page to the response.
 * <p/>
 * In order for the JSP page to build the module editing view, a list of all education types and
 * subjects are added as request attributes.
 * <p/>
 * In addition, a hashmap containing the education types and education subtypes checked in the
 * module is constructed. In that hashmap, the key is in the form of
 * <code>educationTypeId.educationSubtypeId</code> and the value is <code>Boolean.TRUE</code>. The
 * JSP page could probably figure out the checked education types and subtypes on its own but the
 * hashmap makes it a little bit easier and more streamlined.
 *
 * @param pageRequestContext Page request context
 */
public void process(PageRequestContext pageRequestContext) {
    ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
    CourseDescriptionCategoryDAO descriptionCategoryDAO = DAOFactory.getInstance().getCourseDescriptionCategoryDAO();
    CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
    ModuleComponentDAO moduleComponentDAO = DAOFactory.getInstance().getModuleComponentDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
    EducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getEducationSubtypeDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
    Long moduleId = NumberUtils.createLong(pageRequestContext.getRequest().getParameter("module"));
    Module module = moduleDAO.findById(moduleId);
    StringBuilder tagsBuilder = new StringBuilder();
    Iterator<Tag> tagIterator = module.getTags().iterator();
    while (tagIterator.hasNext()) {
        Tag tag = tagIterator.next();
        tagsBuilder.append(tag.getText());
        if (tagIterator.hasNext())
            tagsBuilder.append(' ');
    }
    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 : module.getCourseEducationTypes()) {
        for (CourseEducationSubtype moduleEducationSubtype : courseEducationType.getCourseEducationSubtypes()) {
            enabledEducationTypes.put(courseEducationType.getEducationType().getId() + "." + moduleEducationSubtype.getEducationSubtype().getId(), Boolean.TRUE);
        }
    }
    // 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);
        }
    }
    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);
    }
    List<EducationalTimeUnit> educationalTimeUnits = educationalTimeUnitDAO.listUnarchived();
    Collections.sort(educationalTimeUnits, new StringAttributeComparator("getName"));
    List<Curriculum> curriculums = curriculumDAO.listUnarchived();
    Collections.sort(curriculums, new StringAttributeComparator("getName"));
    pageRequestContext.getRequest().setAttribute("educationSubtypes", educationSubtypes);
    pageRequestContext.getRequest().setAttribute("tags", tagsBuilder.toString());
    pageRequestContext.getRequest().setAttribute("module", module);
    pageRequestContext.getRequest().setAttribute("subjectsByNoEducationType", subjectsByNoEducationType);
    pageRequestContext.getRequest().setAttribute("subjectsByEducationType", subjectsByEducationType);
    pageRequestContext.getRequest().setAttribute("moduleLengthTimeUnits", educationalTimeUnits);
    pageRequestContext.getRequest().setAttribute("moduleComponents", moduleComponentDAO.listByModule(module));
    pageRequestContext.getRequest().setAttribute("enabledEducationTypes", enabledEducationTypes);
    pageRequestContext.getRequest().setAttribute("courseDescriptions", descriptionDAO.listByCourseBase(module));
    pageRequestContext.getRequest().setAttribute("courseDescriptionCategories", descriptionCategoryDAO.listUnarchived());
    pageRequestContext.getRequest().setAttribute("curriculums", curriculums);
    pageRequestContext.setIncludeJSP("/templates/modules/editmodule.jsp");
}
Also used : CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) HashMap(java.util.HashMap) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) CourseDescriptionDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) CourseDescriptionCategoryDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionCategoryDAO) ModuleComponentDAO(fi.otavanopisto.pyramus.dao.modules.ModuleComponentDAO) List(java.util.List) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) EducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module)

Aggregations

ModuleComponentDAO (fi.otavanopisto.pyramus.dao.modules.ModuleComponentDAO)8 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)6 ModuleDAO (fi.otavanopisto.pyramus.dao.modules.ModuleDAO)6 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)6 Module (fi.otavanopisto.pyramus.domainmodel.modules.Module)6 CourseDescriptionDAO (fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO)5 CurriculumDAO (fi.otavanopisto.pyramus.dao.base.CurriculumDAO)4 EducationSubtypeDAO (fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO)4 EducationTypeDAO (fi.otavanopisto.pyramus.dao.base.EducationTypeDAO)4 SubjectDAO (fi.otavanopisto.pyramus.dao.base.SubjectDAO)4 CourseDescriptionCategoryDAO (fi.otavanopisto.pyramus.dao.courses.CourseDescriptionCategoryDAO)4 CourseEducationType (fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType)4 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)4 EducationSubtype (fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype)4 EducationType (fi.otavanopisto.pyramus.domainmodel.base.EducationType)4 Subject (fi.otavanopisto.pyramus.domainmodel.base.Subject)4 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)4 ModuleComponent (fi.otavanopisto.pyramus.domainmodel.modules.ModuleComponent)4 HashMap (java.util.HashMap)4 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)3