use of fi.otavanopisto.pyramus.dao.courses.CourseEnrolmentTypeDAO 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");
}
use of fi.otavanopisto.pyramus.dao.courses.CourseEnrolmentTypeDAO 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");
}
Aggregations