use of fi.otavanopisto.pyramus.dao.courses.CourseTypeDAO in project pyramus by otavanopisto.
the class CreateCourseJSONRequestController method process.
/**
* Processes a JSON request.
* The request should contain the following parameters:
* <dl>
* <dt><code>name</code></dt>
* <dd>The name of the course.</dd>
* <dt><code>nameExtension</code></dt>
* <dd>The name extension of the course.</dd>
* <dt><code>state</code></dt>
* <dd>The ID of the initial course state.</dd>
* <dt><code>description</code></dt>
* <dd>The description of the course, in HTML.</dd>
* <dt><code>module</code></dt>
* <dd>The ID of the module the course is associated with.</dd>
* <dt><code>subject</code></dt>
* <dd>The ID of the subject of the course.</dd>
* <dt><code>courseNumber</code></dt>
* <dd>The course number of the course.</dd>
* <dt><code>beginDate</code></dt>
* <dd>The beginning date of the course, as a timestamp in ms.</dd>
* <dt><code>endDate</code></dt>
* <dd>The end date of the course, as a timestamp in ms.</dd>
* <dt><code>enrolmentTimeEnd</code></dt>
* <dd>The time when enrollment for the course ends, as a timestamp in ms.</dd>
* <dt><code>courseLength</code></dt>
* <dd>The length of the course, in units specified in <code>courseLengthTimeUnit</code>.</dd>
* <dt><code>courseLengthTimeUnit</code></dt>
* <dd>The ID of the time unit for the courses.</dd>
* <dt><code>maxParticipantCount</code></dt>
* <dd>The maximum number of participants for this course.</dd>
* <dt><code>distanceTeachingDays</code></dt>
* <dd>The number of days of distance teaching.</dd>
* <dt><code>localTeachingDays</code></dt>
* <dd>The number of days of local teaching.</dd>
* <dt><code>teachingHours</code></dt>
* <dd>The total number of teaching hours.</dd>
* <dt><code>planningHours</code></dt>
* <dd>The total number of hours used for planning.
* <dt><code>assessingHours</code></dt>
* <dd>The total number of hours used for assessing.
* <dt><code>tags</code></dt>
* <dd>The tags associated with the course, separated by spaces.</dd>
* </dl>
* The following are not single but multiple parameters, arranged
* as collections of objects. Each parameter is defined by the
* following scheme (zero indexed):<br/>
* <code>
* <i>collection name</i>.<i>property name</i>
* </code>
* or<br/>
* <code>
* <i>collection name</i>.<i>object index</i>.<i>property name</i>
* </code>
* <dl>
* <dt><code>courseDescription.*.catId</code></dt>
* <dd>The course description category ID to add the description to.
* <dt><code>courseDescription.*.text</code></dt>
* <dd>The description of the course.</dd>
* <dt><code>personnelTable.rowCount</code></dt>
* <dd>The number of personnel in the course.</dd>
* <dt><code>personnelTable.*.userId</code></dt>
* <dd>The ID of the user in the personnel table.</dd>
* <dt><code>personnelTable.*.roleId</code></dt>
* <dd>The role ID of the user in the personnel table.</dd>
* <dt><code>components.componentCount</code></dt>
* <dd>The number of course components in this course.</dd>
* <dt><code>components.*.0.name</code></dt>
* <dd>The name of the course component.</dd>
* <dt><code>components.*.0.length</code></dt>
* <dd>The length of the course component, in default time units.</dd>
* <dt><code>components.*.0.description</code></dt>
* <dd>The description of the course component.</dd>
* <dt><code>components.*.resourceCategoryCount</code></dt>
* <dd>The number of resource categories in the course component.</dd>
* <dt><code>components.*.*.resources.rowCount</code></dt>
* <dd>The number of resources in the resource category.</dd>
* <dt><code>components.*.*.resources.*.resourceId</code></dt>
* <dd>The ID of the resource.</dd>
* <dt><code>components.*.*.resources.*.quantity</code></dt>
* <dd>The quantity of the resource.</dd>
* <dt><code>components.*.*.resources.*.usage</code></dt>
* <dd>The usage of the resource.</dd>
* <dt><code>educationType.*.*</code></dt>
* <dd>The education types and subtypes (as numerical IDs) of the course.</dd>
* <dt><code>basicResourcesTable.rowCount</code></dt>
* <dd>The number of basic resources associated with the course.</dd>
* <dt><code>basicResourcesTable.*.hours</code></dt>
* <dd>The number of hours the resource is used.</dd>
* <dt><code>basicResourcesTable.*.hourlyCost</code></dt>
* <dd>The hourly cost of the resource.</dd>
* <dt><code>basicResourcesTable.*.units</code></dt>
* <dd>The number of units of the resource used.</dd>
* <dt><code>basicResourcesTable.*.unitCost</code></dt>
* <dd>The cost of a single unit of the resource.</dd>
* <dt><code>basicResourcesTable.*.resourceId</code></dt>
* <dd>The ID of the resource.</dd>
* <dt><code>studentResourcesTable.rowCount</code></dt>
* <dd>The number of student resources associated with the course.</dd>
* <dt><code>studentResourcesTable.*.hours</code></dt>
* <dd>The number of hours the resource is used.</dd>
* <dt><code>studentResourcesTable.*.hourlyCost</code></dt>
* <dd>The hourly cost of the resource.</dd>
* <dt><code>studentResourcesTable.*.unitCost</code></dt>
* <dd>The cost of a single unit of the resource.</dd>
* <dt><code>studentResourcesTable.*.resourceId</code></dt>
* <dd>The ID of the resource.</dd>
* <dt><code>gradeResourcesTable.rowCount</code></dt>
* <dd>The number of grade resources associated with the course.</dd>
* <dt><code>gradeResourcesTable.*.hours</code></dt>
* <dd>The number of hours the resource is used.</dd>
* <dt><code>gradeResourcesTable.*.hourlyCost</code></dt>
* <dd>The hourly cost of the resource.</dd>
* <dt><code>gradeResourcesTable.*.unitCost</code></dt>
* <dd>The cost of a single unit of the resource.</dd>
* <dt><code>gradeResourcesTable.*.resourceId</code></dt>
* <dd>The ID of the resource.</dd>
* <dt><code>otherCostsTable.rowCount</code></dt>
* <dd>The number of other costs associated with this course.</dd>
* <dt><code>otherCostsTable.*.name</code></dt>
* <dd>The name of the cost.</dd>
* <dt><code>otherCostsTable.*.count</code></dt>
* <dd>The amount of the cost.</dd>
* <dt><code>studentsTable.rowCount</code></dt>
* <dd>The number of students attending this course.</dd>
* <dt><code>studentsTable.*.studentId</code></dt>
* <dd>The ID of the student.</dd>
* <dt><code>studentsTable.*.enrolmentDate</code></dt>
* <dd>The enrollment date of the student, as a timestamp in ms.</dd>
* <dt><code>studentsTable.*.enrolmentType</code></dt>
* <dd>The ID of the enrollment type of the student.</dd>
* <dt><code>studentsTable.*.participationType</code></dt>
* <dd>The ID of the participation type of the student.</dd>
* <dt><code>studentsTable.*.lodging</code></dt>
* <dd><code>true</code> if the student is lodging on campus.</dd>
* <dt><code>studentsTable.*.optionality</code></dt>
* <dd>The optionality of the course for the student:
* <code>MANDATORY</code> or <code>OPTIONAL</code></dd>
* </dl>
*
* @param binaryRequestContext The context of the binary request.
*/
public void process(JSONRequestContext requestContext) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
ResourceDAO resourceDAO = DAOFactory.getInstance().getResourceDAO();
CourseStateDAO courseStateDAO = DAOFactory.getInstance().getCourseStateDAO();
CourseTypeDAO courseTypeDAO = DAOFactory.getInstance().getCourseTypeDAO();
CourseParticipationTypeDAO participationTypeDAO = DAOFactory.getInstance().getCourseParticipationTypeDAO();
CourseEnrolmentTypeDAO enrolmentTypeDAO = DAOFactory.getInstance().getCourseEnrolmentTypeDAO();
CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
CourseStaffMemberDAO courseStaffMemberDAO = DAOFactory.getInstance().getCourseStaffMemberDAO();
CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
CourseDescriptionCategoryDAO descriptionCategoryDAO = DAOFactory.getInstance().getCourseDescriptionCategoryDAO();
CourseComponentDAO componentDAO = DAOFactory.getInstance().getCourseComponentDAO();
CourseComponentResourceDAO componentResourceDAO = DAOFactory.getInstance().getCourseComponentResourceDAO();
OtherCostDAO otherCostDAO = DAOFactory.getInstance().getOtherCostDAO();
BasicCourseResourceDAO basicCourseResourceDAO = DAOFactory.getInstance().getBasicCourseResourceDAO();
StudentCourseResourceDAO studentCourseResourceDAO = DAOFactory.getInstance().getStudentCourseResourceDAO();
GradeCourseResourceDAO gradeCourseResourceDAO = DAOFactory.getInstance().getGradeCourseResourceDAO();
CourseEducationTypeDAO courseEducationTypeDAO = DAOFactory.getInstance().getCourseEducationTypeDAO();
CourseEducationSubtypeDAO courseEducationSubtypeDAO = DAOFactory.getInstance().getCourseEducationSubtypeDAO();
EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
EducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getEducationSubtypeDAO();
SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
CourseStaffMemberRoleDAO courseStaffMemberRoleDAO = DAOFactory.getInstance().getCourseStaffMemberRoleDAO();
CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
OrganizationDAO organizationDAO = DAOFactory.getInstance().getOrganizationDAO();
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
User loggedUser = staffMemberDAO.findById(requestContext.getLoggedUserId());
Organization organization = organizationDAO.findById(requestContext.getLong("organizationId"));
if (!UserUtils.canAccessOrganization(loggedUser, organization)) {
throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Invalid organization.");
}
// Course basic information
String name = requestContext.getString("name");
String nameExtension = requestContext.getString("nameExtension");
Long courseStateId = requestContext.getLong("state");
Long courseTypeId = requestContext.getLong("type");
CourseState courseState = courseStateDAO.findById(courseStateId);
CourseType courseType = courseTypeId != null ? courseTypeDAO.findById(courseTypeId) : null;
String description = requestContext.getString("description");
Module module = moduleDAO.findById(requestContext.getLong("module"));
Subject subject = subjectDAO.findById(requestContext.getLong("subject"));
Integer courseNumber = requestContext.getInteger("courseNumber");
Date beginDate = requestContext.getDate("beginDate");
Date endDate = requestContext.getDate("endDate");
Date enrolmentTimeEnd = requestContext.getDate("enrolmentTimeEnd");
Double courseLength = requestContext.getDouble("courseLength");
Long courseLengthTimeUnitId = requestContext.getLong("courseLengthTimeUnit");
Long maxParticipantCount = requestContext.getLong("maxParticipantCount");
EducationalTimeUnit courseLengthTimeUnit = educationalTimeUnitDAO.findById(courseLengthTimeUnitId);
Double distanceTeachingDays = requestContext.getDouble("distanceTeachingDays");
Double localTeachingDays = requestContext.getDouble("localTeachingDays");
Double teachingHours = requestContext.getDouble("teachingHours");
Double distanceTeachingHours = requestContext.getDouble("distanceTeachingHours");
Double planningHours = requestContext.getDouble("planningHours");
Double assessingHours = requestContext.getDouble("assessingHours");
String tagsText = requestContext.getString("tags");
BigDecimal courseFee = requestContext.getBigDecimal("courseFee");
Currency courseFeeCurrency = requestContext.getCurrency("courseFeeCurrency");
List<Curriculum> allCurriculums = curriculumDAO.listUnarchived();
Set<Curriculum> curriculums = new HashSet<>();
for (Curriculum curriculum : allCurriculums) {
if ("1".equals(requestContext.getString("curriculum." + curriculum.getId()))) {
curriculums.add(curriculum);
}
}
Set<Tag> tagEntities = new HashSet<>();
if (!StringUtils.isBlank(tagsText)) {
List<String> tags = Arrays.asList(tagsText.split("[\\ ,]"));
for (String tag : tags) {
if (!StringUtils.isBlank(tag)) {
Tag tagEntity = tagDAO.findByText(tag.trim());
if (tagEntity == null)
tagEntity = tagDAO.create(tag);
tagEntities.add(tagEntity);
}
}
}
Course course = courseDAO.create(module, organization, name, nameExtension, courseState, courseType, subject, courseNumber, beginDate, endDate, courseLength, courseLengthTimeUnit, distanceTeachingDays, localTeachingDays, teachingHours, distanceTeachingHours, planningHours, assessingHours, description, maxParticipantCount, courseFee, courseFeeCurrency, enrolmentTimeEnd, loggedUser);
// Curriculums
courseDAO.updateCurriculums(course, curriculums);
// Tags
courseDAO.setCourseTags(course, tagEntities);
// Course Descriptions
List<CourseDescriptionCategory> descriptionCategories = descriptionCategoryDAO.listUnarchived();
for (CourseDescriptionCategory cat : descriptionCategories) {
String varName = "courseDescription." + cat.getId().toString();
Long descriptionCatId = requestContext.getLong(varName + ".catId");
String descriptionText = requestContext.getString(varName + ".text");
if (descriptionCatId != null && descriptionCatId.intValue() != -1) {
// Description has been submitted from form
descriptionDAO.create(course, cat, descriptionText);
}
}
// Personnel
int rowCount = requestContext.getInteger("personnelTable.rowCount");
for (int i = 0; i < rowCount; i++) {
String colPrefix = "personnelTable." + i;
Long userId = requestContext.getLong(colPrefix + ".userId");
Long roleId = requestContext.getLong(colPrefix + ".roleId");
StaffMember staffMember = userDAO.findById(userId);
CourseStaffMemberRole role = courseStaffMemberRoleDAO.findById(roleId);
courseStaffMemberDAO.create(course, staffMember, role);
}
// Course components
rowCount = requestContext.getInteger("components.componentCount").intValue();
for (int i = 0; i < rowCount; i++) {
String colPrefix = "components.component." + i;
String componentName = requestContext.getString(colPrefix + ".0.name");
Double componentLength = requestContext.getDouble(colPrefix + ".0.length");
String componentDescription = requestContext.getString(colPrefix + ".0.description");
// TODO Component length; should be just hours but it currently depends on the default time unit - ok?
EducationalTimeUnit componentTimeUnit = defaultsDAO.getDefaults().getBaseTimeUnit();
CourseComponent courseComponent = componentDAO.create(course, componentLength, componentTimeUnit, componentName, componentDescription);
Long resourceCategoryCount = requestContext.getLong(colPrefix + ".resourceCategoryCount");
for (int categoryIndex = 0; categoryIndex < resourceCategoryCount; categoryIndex++) {
String resourcesPrefix = colPrefix + "." + categoryIndex + ".resources";
Long resourcesCount = requestContext.getLong(resourcesPrefix + ".rowCount");
for (int j = 0; j < resourcesCount; j++) {
String resourcePrefix = resourcesPrefix + "." + j;
Long resourceId = requestContext.getLong(resourcePrefix + ".resourceId");
Resource resource = resourceDAO.findById(resourceId);
Double usagePercent;
if (resource.getResourceType() == ResourceType.MATERIAL_RESOURCE) {
usagePercent = requestContext.getDouble(resourcePrefix + ".quantity") * 100;
} else {
usagePercent = requestContext.getDouble(resourcePrefix + ".usage");
}
componentResourceDAO.create(courseComponent, resource, usagePercent);
}
}
}
// Education types and subtypes submitted from the web page
Map<Long, Vector<Long>> chosenEducationTypes = new HashMap<>();
Enumeration<String> parameterNames = requestContext.getRequest().getParameterNames();
while (parameterNames.hasMoreElements()) {
name = (String) parameterNames.nextElement();
if (name.startsWith("educationType.")) {
String[] nameElements = name.split("\\.");
Long educationTypeId = new Long(nameElements[1]);
Long educationSubtypeId = new Long(nameElements[2]);
Vector<Long> v = chosenEducationTypes.containsKey(educationTypeId) ? chosenEducationTypes.get(educationTypeId) : new Vector<Long>();
v.add(educationSubtypeId);
if (!chosenEducationTypes.containsKey(educationTypeId)) {
chosenEducationTypes.put(educationTypeId, v);
}
}
}
for (Map.Entry<Long, Vector<Long>> entry : chosenEducationTypes.entrySet()) {
EducationType educationType = educationTypeDAO.findById(entry.getKey());
CourseEducationType courseEducationType;
if (!course.contains(educationType)) {
courseEducationType = courseEducationTypeDAO.create(course, educationType);
} else {
courseEducationType = course.getCourseEducationTypeByEducationTypeId(entry.getKey());
}
for (Long educationSubtypeId : entry.getValue()) {
EducationSubtype educationSubtype = educationSubtypeDAO.findById(educationSubtypeId);
if (!courseEducationType.contains(educationSubtype)) {
courseEducationSubtypeDAO.create(courseEducationType, educationSubtype);
}
}
}
// Basic course resources
int basicResourcesTableRowCount = requestContext.getInteger("basicResourcesTable.rowCount");
for (int i = 0; i < basicResourcesTableRowCount; i++) {
String colPrefix = "basicResourcesTable." + i;
Double hours = requestContext.getDouble(colPrefix + ".hours");
if (hours == null) {
hours = 0.0;
}
MonetaryAmount hourlyCost = new MonetaryAmount();
hourlyCost.setAmount(requestContext.getDouble(colPrefix + ".hourlyCost"));
Integer units = requestContext.getInteger(colPrefix + ".units");
if (units == null) {
units = 0;
}
MonetaryAmount unitCost = new MonetaryAmount();
unitCost.setAmount(requestContext.getDouble(colPrefix + ".unitCost"));
Long resourceId = requestContext.getLong(colPrefix + ".resourceId");
Resource resource = resourceDAO.findById(resourceId);
basicCourseResourceDAO.create(course, resource, hours, hourlyCost, units, unitCost);
}
// Student course resources
int studentResourcesTableRowCount = requestContext.getInteger("studentResourcesTable.rowCount");
for (int i = 0; i < studentResourcesTableRowCount; i++) {
String colPrefix = "studentResourcesTable." + i;
Double hours = requestContext.getDouble(colPrefix + ".hours");
if (hours == null) {
hours = 0.0;
}
MonetaryAmount hourlyCost = new MonetaryAmount();
hourlyCost.setAmount(requestContext.getDouble(colPrefix + ".hourlyCost"));
MonetaryAmount unitCost = new MonetaryAmount();
unitCost.setAmount(requestContext.getDouble(colPrefix + ".unitCost"));
Long resourceId = NumberUtils.createLong(requestContext.getRequest().getParameter(colPrefix + ".resourceId"));
Resource resource = resourceDAO.findById(resourceId);
studentCourseResourceDAO.create(course, resource, hours, hourlyCost, unitCost);
}
// Grade course resources
int gradeResourcesTableRowCount = requestContext.getInteger("gradeResourcesTable.rowCount");
for (int i = 0; i < gradeResourcesTableRowCount; i++) {
String colPrefix = "gradeResourcesTable." + i;
Double hours = requestContext.getDouble(colPrefix + ".hours");
if (hours == null) {
hours = 0.0;
}
MonetaryAmount hourlyCost = new MonetaryAmount();
hourlyCost.setAmount(requestContext.getDouble(colPrefix + ".hourlyCost"));
MonetaryAmount unitCost = new MonetaryAmount();
unitCost.setAmount(requestContext.getDouble(colPrefix + ".unitCost"));
Long resourceId = requestContext.getLong(colPrefix + ".resourceId");
Resource resource = resourceDAO.findById(resourceId);
gradeCourseResourceDAO.create(course, resource, hours, hourlyCost, unitCost);
}
// Other costs
int otherCostsTableRowCount = requestContext.getInteger("otherCostsTable.rowCount");
for (int i = 0; i < otherCostsTableRowCount; i++) {
String colPrefix = "otherCostsTable." + i;
name = requestContext.getString(colPrefix + ".name");
MonetaryAmount cost = new MonetaryAmount();
cost.setAmount(requestContext.getDouble(colPrefix + ".cost"));
otherCostDAO.create(course, name, cost);
}
// Students
int studentsTableRowCount = requestContext.getInteger("studentsTable.rowCount");
for (int i = 0; i < studentsTableRowCount; i++) {
String colPrefix = "studentsTable." + i;
Long studentId = requestContext.getLong(colPrefix + ".studentId");
Date enrolmentDate = requestContext.getDate(colPrefix + ".enrolmentDate");
Long enrolmentTypeId = requestContext.getLong(colPrefix + ".enrolmentType");
Long participationTypeId = requestContext.getLong(colPrefix + ".participationType");
Boolean lodging = requestContext.getBoolean(colPrefix + ".lodging");
String organizationName = null;
String additionalInfo = null;
Room room = null;
BigDecimal lodgingFee = null;
Currency lodgingFeeCurrency = null;
BigDecimal reservationFee = null;
Currency reservationFeeCurrency = null;
Student student = studentDAO.findById(studentId);
CourseEnrolmentType enrolmentType = enrolmentTypeId != null ? enrolmentTypeDAO.findById(enrolmentTypeId) : null;
CourseParticipationType participationType = participationTypeId != null ? participationTypeDAO.findById(participationTypeId) : null;
CourseOptionality optionality = (CourseOptionality) requestContext.getEnum(colPrefix + ".optionality", CourseOptionality.class);
try {
courseStudentDAO.create(course, student, enrolmentType, participationType, enrolmentDate, lodging, optionality, null, organizationName, additionalInfo, room, lodgingFee, lodgingFeeCurrency, reservationFee, reservationFeeCurrency, Boolean.FALSE);
} catch (DuplicateCourseStudentException dcse) {
Locale locale = requestContext.getRequest().getLocale();
throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, Messages.getInstance().getText(locale, "generic.errors.duplicateCourseStudent", new Object[] { student.getFullName() }));
}
}
String redirectURL = requestContext.getRequest().getContextPath() + "/courses/editcourse.page?course=" + course.getId();
String refererAnchor = requestContext.getRefererAnchor();
if (!StringUtils.isBlank(refererAnchor))
redirectURL += "#" + refererAnchor;
requestContext.setRedirectURL(redirectURL);
}
use of fi.otavanopisto.pyramus.dao.courses.CourseTypeDAO in project pyramus by otavanopisto.
the class SaveCourseTypesJSONRequestController method process.
public void process(JSONRequestContext jsonRequestContext) {
CourseTypeDAO courseTypeDAO = DAOFactory.getInstance().getCourseTypeDAO();
int rowCount = jsonRequestContext.getInteger("courseTypesTable.rowCount").intValue();
for (int i = 0; i < rowCount; i++) {
CourseType courseType;
String colPrefix = "courseTypesTable." + i;
Long courseTypeId = jsonRequestContext.getLong(colPrefix + ".courseTypeId");
String name = jsonRequestContext.getRequest().getParameter(colPrefix + ".name");
if (courseTypeId == -1) {
courseType = courseTypeDAO.create(name);
} else {
courseType = courseTypeDAO.findById(courseTypeId);
courseTypeDAO.updateName(courseType, name);
}
}
jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
}
use of fi.otavanopisto.pyramus.dao.courses.CourseTypeDAO 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.CourseTypeDAO 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");
}
use of fi.otavanopisto.pyramus.dao.courses.CourseTypeDAO in project pyramus by otavanopisto.
the class CourseTypesViewController 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) {
CourseTypeDAO courseTypeDAO = DAOFactory.getInstance().getCourseTypeDAO();
List<CourseType> courseTypes = courseTypeDAO.listUnarchived();
String jsonCourseStates = new JSONArrayExtractor("name", "id").extractString(courseTypes);
setJsDataVariable(pageRequestContext, "courseTypes", jsonCourseStates);
pageRequestContext.setIncludeJSP("/templates/settings/coursetypes.jsp");
}
Aggregations