use of fi.otavanopisto.pyramus.dao.base.TagDAO in project pyramus by otavanopisto.
the class EditStudentProjectJSONRequestController method process.
public void process(JSONRequestContext jsonRequestContext) {
StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
StudentProjectDAO studentProjectDAO = DAOFactory.getInstance().getStudentProjectDAO();
StudentProjectModuleDAO studentProjectModuleDAO = DAOFactory.getInstance().getStudentProjectModuleDAO();
GradeDAO gradeDAO = DAOFactory.getInstance().getGradeDAO();
ProjectAssessmentDAO projectAssessmentDAO = DAOFactory.getInstance().getProjectAssessmentDAO();
EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
AcademicTermDAO academicTermDAO = DAOFactory.getInstance().getAcademicTermDAO();
TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
Defaults defaults = defaultsDAO.getDefaults();
// Project
Long studentProjectId = jsonRequestContext.getLong("studentProject");
StudentProject studentProject = studentProjectDAO.findById(studentProjectId);
// Version check
Long version = jsonRequestContext.getLong("version");
if (!studentProject.getVersion().equals(version))
throw new StaleObjectStateException(StudentProject.class.getName(), studentProject.getId());
String name = jsonRequestContext.getString("name");
String description = jsonRequestContext.getString("description");
StaffMember staffMember = staffMemberDAO.findById(jsonRequestContext.getLoggedUserId());
Long optionalStudiesLengthTimeUnitId = jsonRequestContext.getLong("optionalStudiesLengthTimeUnit");
EducationalTimeUnit optionalStudiesLengthTimeUnit = educationalTimeUnitDAO.findById(optionalStudiesLengthTimeUnitId);
Double optionalStudiesLength = jsonRequestContext.getDouble("optionalStudiesLength");
String tagsText = jsonRequestContext.getString("tags");
Long studentId = jsonRequestContext.getLong("student");
CourseOptionality projectOptionality = (CourseOptionality) jsonRequestContext.getEnum("projectOptionality", CourseOptionality.class);
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);
}
}
}
Student student = studentDAO.findById(studentId);
if (!studentProject.getStudent().equals(student)) {
studentProjectDAO.updateStudent(studentProject, student, staffMember);
}
studentProjectDAO.update(studentProject, name, description, optionalStudiesLength, optionalStudiesLengthTimeUnit, projectOptionality, staffMember);
// Tags
studentProjectDAO.updateTags(studentProject, tagEntities);
// ProjectAssessments
int rowCount = jsonRequestContext.getInteger("assessmentsTable.rowCount").intValue();
for (int i = 0; i < rowCount; i++) {
String colPrefix = "assessmentsTable." + i;
Long assessmentModified = jsonRequestContext.getLong(colPrefix + ".modified");
if ((assessmentModified != null) && (assessmentModified.intValue() == 1)) {
Long assessmentId = jsonRequestContext.getLong(colPrefix + ".assessmentId");
ProjectAssessment projectAssessment = ((assessmentId != null) && (assessmentId.intValue() != -1)) ? projectAssessmentDAO.findById(assessmentId) : null;
Long assessmentArchived = jsonRequestContext.getLong(colPrefix + ".deleted");
if ((assessmentArchived != null) && (assessmentArchived.intValue() == 1)) {
if (projectAssessment != null)
projectAssessmentDAO.archive(projectAssessment);
else
throw new SmvcRuntimeException(PyramusStatusCode.OK, "Assessment marked for delete does not exist.");
} else {
Date assessmentDate = jsonRequestContext.getDate(colPrefix + ".date");
Long assessmentGradeId = jsonRequestContext.getLong(colPrefix + ".grade");
Grade grade = assessmentGradeId != null ? gradeDAO.findById(assessmentGradeId) : null;
String verbalAssessment = projectAssessment != null ? projectAssessment.getVerbalAssessment() : null;
Long verbalAssessmentModified = jsonRequestContext.getLong(colPrefix + ".verbalModified");
if ((verbalAssessmentModified != null) && (verbalAssessmentModified.intValue() == 1))
verbalAssessment = jsonRequestContext.getString(colPrefix + ".verbalAssessment");
if (projectAssessment == null) {
projectAssessmentDAO.create(studentProject, staffMember, grade, assessmentDate, verbalAssessment);
} else {
projectAssessmentDAO.update(projectAssessment, staffMember, grade, assessmentDate, verbalAssessment);
}
}
}
}
// Student project modules
Set<Long> existingModuleIds = new HashSet<>();
rowCount = jsonRequestContext.getInteger("modulesTable.rowCount").intValue();
for (int i = 0; i < rowCount; i++) {
String colPrefix = "modulesTable." + i;
Long studentProjectModuleId = jsonRequestContext.getLong(colPrefix + ".studentProjectModuleId");
CourseOptionality optionality = (CourseOptionality) jsonRequestContext.getEnum(colPrefix + ".optionality", CourseOptionality.class);
Long studyTermId = jsonRequestContext.getLong(colPrefix + ".academicTerm");
AcademicTerm academicTerm = studyTermId == null ? null : academicTermDAO.findById(studyTermId);
if (studentProjectModuleId == -1) {
Long moduleId = jsonRequestContext.getLong(colPrefix + ".moduleId");
Module module = moduleDAO.findById(moduleId);
studentProjectModuleId = studentProjectModuleDAO.create(studentProject, module, academicTerm, optionality).getId();
} else {
studentProjectModuleDAO.update(studentProjectModuleDAO.findById(studentProjectModuleId), academicTerm, optionality);
}
existingModuleIds.add(studentProjectModuleId);
}
// Removed Student project modules
List<StudentProjectModule> studentProjectModules = studentProjectModuleDAO.listByStudentProject(studentProject);
for (StudentProjectModule studentProjectModule : studentProjectModules) {
if (!existingModuleIds.contains(studentProjectModule.getId())) {
studentProjectModuleDAO.delete(studentProjectModule);
}
}
// Student project courses
rowCount = jsonRequestContext.getInteger("coursesTable.rowCount").intValue();
for (int i = 0; i < rowCount; i++) {
String colPrefix = "coursesTable." + i;
Long courseId = jsonRequestContext.getLong(colPrefix + ".courseId");
CourseOptionality optionality = (CourseOptionality) jsonRequestContext.getEnum(colPrefix + ".optionality", CourseOptionality.class);
Course course = courseId == -1 ? null : courseDAO.findById(courseId);
CourseStudent courseStudent = courseStudentDAO.findByCourseAndStudent(course, studentProject.getStudent());
if (courseStudent == null) {
CourseEnrolmentType courseEnrolmentType = defaults.getInitialCourseEnrolmentType();
CourseParticipationType participationType = defaults.getInitialCourseParticipationType();
Date enrolmentDate = new Date(System.currentTimeMillis());
Boolean lodging = Boolean.FALSE;
String organization = null;
String additionalInfo = null;
Room room = null;
BigDecimal lodgingFee = null;
Currency lodgingFeeCurrency = null;
BigDecimal reservationFee = null;
Currency reservationFeeCurrency = null;
try {
courseStudent = courseStudentDAO.create(course, studentProject.getStudent(), courseEnrolmentType, participationType, enrolmentDate, lodging, optionality, null, organization, additionalInfo, room, lodgingFee, lodgingFeeCurrency, reservationFee, reservationFeeCurrency, Boolean.FALSE);
} catch (DuplicateCourseStudentException dcse) {
Locale locale = jsonRequestContext.getRequest().getLocale();
throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, Messages.getInstance().getText(locale, "generic.errors.duplicateCourseStudent", new Object[] { student.getFullName() }));
}
} else {
courseStudentDAO.updateOptionality(courseStudent, optionality);
}
}
jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
}
use of fi.otavanopisto.pyramus.dao.base.TagDAO in project pyramus by otavanopisto.
the class EditModuleJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
CourseDescriptionDAO courseDescriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
CourseDescriptionCategoryDAO descriptionCategoryDAO = DAOFactory.getInstance().getCourseDescriptionCategoryDAO();
CourseEducationTypeDAO courseEducationTypeDAO = DAOFactory.getInstance().getCourseEducationTypeDAO();
CourseEducationSubtypeDAO courseEducationSubtypeDAO = DAOFactory.getInstance().getCourseEducationSubtypeDAO();
ModuleComponentDAO moduleComponentDAO = DAOFactory.getInstance().getModuleComponentDAO();
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();
CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
Long moduleId = requestContext.getLong("moduleId");
Module module = moduleDAO.findById(moduleId);
Long version = requestContext.getLong("version");
if (!module.getVersion().equals(version))
throw new StaleObjectStateException(Module.class.getName(), module.getId());
// 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()) {
String 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);
}
}
}
// Course Descriptions
List<CourseDescriptionCategory> descriptionCategories = descriptionCategoryDAO.listUnarchived();
Set<CourseDescription> nonExistingDescriptions = new HashSet<>();
for (CourseDescriptionCategory cat : descriptionCategories) {
String varName = "courseDescription." + cat.getId().toString();
Long descriptionCatId = requestContext.getLong(varName + ".catId");
String descriptionText = requestContext.getString(varName + ".text");
CourseDescription oldDesc = courseDescriptionDAO.findByCourseAndCategory(module, cat);
if (descriptionCatId != null && descriptionCatId.intValue() != -1) {
// Description has been submitted from form
if (oldDesc != null)
courseDescriptionDAO.update(oldDesc, module, cat, descriptionText);
else
courseDescriptionDAO.create(module, cat, descriptionText);
} else {
// Description wasn't submitted from form, if it exists, it's marked for deletion
if (oldDesc != null)
nonExistingDescriptions.add(oldDesc);
}
}
// Delete non existing descriptions
for (CourseDescription desc : nonExistingDescriptions) {
courseDescriptionDAO.delete(desc);
}
// Remove education types and subtypes
List<CourseEducationType> courseEducationTypes = module.getCourseEducationTypes();
for (int i = courseEducationTypes.size() - 1; i >= 0; i--) {
CourseEducationType courseEducationType = courseEducationTypes.get(i);
if (!chosenEducationTypes.containsKey(courseEducationType.getEducationType().getId())) {
courseEducationTypeDAO.delete(courseEducationType);
} else {
Vector<Long> v = chosenEducationTypes.get(courseEducationType.getEducationType().getId());
List<CourseEducationSubtype> courseEducationSubtypes = courseEducationType.getCourseEducationSubtypes();
for (int j = courseEducationSubtypes.size() - 1; j >= 0; j--) {
CourseEducationSubtype moduleEducationSubtype = courseEducationSubtypes.get(j);
if (!v.contains(moduleEducationSubtype.getEducationSubtype().getId())) {
courseEducationType.removeSubtype(moduleEducationSubtype);
}
}
}
}
for (Map.Entry<Long, Vector<Long>> entry : chosenEducationTypes.entrySet()) {
EducationType educationType = educationTypeDAO.findById(entry.getKey());
CourseEducationType courseEducationType;
if (!module.contains(educationType)) {
courseEducationType = courseEducationTypeDAO.create(module, educationType);
} else {
courseEducationType = module.getCourseEducationTypeByEducationTypeId(entry.getKey());
}
for (Long educationSubtypeId : entry.getValue()) {
EducationSubtype educationSubtype = educationSubtypeDAO.findById(educationSubtypeId);
if (!courseEducationType.contains(educationSubtype)) {
courseEducationSubtypeDAO.create(courseEducationType, educationSubtype);
}
}
}
// Module components
int rowCount = requestContext.getInteger("componentsTable.rowCount");
for (int i = 0; i < rowCount; i++) {
String colPrefix = "componentsTable." + i;
String componentName = requestContext.getString(colPrefix + ".name");
Double componentLength = requestContext.getDouble(colPrefix + ".length");
String componentDescription = requestContext.getString(colPrefix + ".description");
Long componentId = requestContext.getLong(colPrefix + ".componentId");
// TODO Component length; should be just hours but it currently depends on the default time unit - ok?
EducationalTimeUnit componentTimeUnit = defaultsDAO.getDefaults().getBaseTimeUnit();
if (componentId == -1) {
componentId = moduleComponentDAO.create(module, componentLength, componentTimeUnit, componentName, componentDescription).getId();
} else {
moduleComponentDAO.update(moduleComponentDAO.findById(componentId), componentLength, componentTimeUnit, componentName, componentDescription);
}
}
// Module basic information
Long subjectId = requestContext.getLong("subject");
Subject subject = subjectDAO.findById(subjectId);
Integer courseNumber = requestContext.getInteger("courseNumber");
String name = requestContext.getString("name");
String description = requestContext.getString("description");
User loggedUser = userDAO.findById(requestContext.getLoggedUserId());
Double moduleLength = requestContext.getDouble("moduleLength");
Long moduleLengthTimeUnitId = requestContext.getLong("moduleLengthTimeUnit");
Long maxParticipantCount = requestContext.getLong("maxParticipantCount");
String tagsText = requestContext.getString("tags");
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);
}
}
}
EducationalTimeUnit moduleLengthTimeUnit = educationalTimeUnitDAO.findById(moduleLengthTimeUnitId);
moduleDAO.update(module, name, subject, courseNumber, moduleLength, moduleLengthTimeUnit, description, maxParticipantCount, loggedUser);
moduleDAO.updateCurriculums(module, curriculums);
// Tags
moduleDAO.updateTags(module, tagEntities);
requestContext.setRedirectURL(requestContext.getReferer(true));
}
use of fi.otavanopisto.pyramus.dao.base.TagDAO in project pyramus by otavanopisto.
the class CreateProjectJSONRequestController method process.
public void process(JSONRequestContext jsonRequestContext) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
ProjectModuleDAO projectModuleDAO = DAOFactory.getInstance().getProjectModuleDAO();
EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
// Project
String name = jsonRequestContext.getRequest().getParameter("name");
String description = jsonRequestContext.getRequest().getParameter("description");
String tagsText = jsonRequestContext.getString("tags");
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);
}
}
}
User loggedUser = userDAO.findById(jsonRequestContext.getLoggedUserId());
Long optionalStudiesLengthTimeUnitId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter("optionalStudiesLengthTimeUnit"));
EducationalTimeUnit optionalStudiesLengthTimeUnit = educationalTimeUnitDAO.findById(optionalStudiesLengthTimeUnitId);
Double optionalStudiesLength = NumberUtils.createDouble(jsonRequestContext.getRequest().getParameter("optionalStudiesLength"));
Project project = projectDAO.create(name, description, optionalStudiesLength, optionalStudiesLengthTimeUnit, loggedUser);
// Tags
projectDAO.updateTags(project, tagEntities);
// Project modules
int rowCount = NumberUtils.createInteger(jsonRequestContext.getRequest().getParameter("modulesTable.rowCount")).intValue();
for (int i = 0; i < rowCount; i++) {
String colPrefix = "modulesTable." + i;
Long moduleId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter(colPrefix + ".moduleId"));
Module module = moduleDAO.findById(moduleId);
int optionality = new Integer(jsonRequestContext.getRequest().getParameter(colPrefix + ".optionality")).intValue();
projectModuleDAO.create(project, module, ProjectModuleOptionality.getOptionality(optionality));
}
String redirectURL = jsonRequestContext.getRequest().getContextPath() + "/projects/editproject.page?project=" + project.getId();
String refererAnchor = jsonRequestContext.getRefererAnchor();
if (!StringUtils.isBlank(refererAnchor))
redirectURL += "#" + refererAnchor;
jsonRequestContext.setRedirectURL(redirectURL);
}
use of fi.otavanopisto.pyramus.dao.base.TagDAO in project pyramus by otavanopisto.
the class EditProjectJSONRequestController method process.
public void process(JSONRequestContext jsonRequestContext) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
ProjectDAO projectDAO = DAOFactory.getInstance().getProjectDAO();
ProjectModuleDAO projectModuleDAO = DAOFactory.getInstance().getProjectModuleDAO();
EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
// Project
Long projectId = jsonRequestContext.getLong("project");
Project project = projectDAO.findById(projectId);
// Version check
Long version = jsonRequestContext.getLong("version");
if (!project.getVersion().equals(version))
throw new StaleObjectStateException(Project.class.getName(), project.getId());
String name = jsonRequestContext.getRequest().getParameter("name");
String description = jsonRequestContext.getRequest().getParameter("description");
User user = userDAO.findById(jsonRequestContext.getLoggedUserId());
Long optionalStudiesLengthTimeUnitId = jsonRequestContext.getLong("optionalStudiesLengthTimeUnit");
EducationalTimeUnit optionalStudiesLengthTimeUnit = educationalTimeUnitDAO.findById(optionalStudiesLengthTimeUnitId);
Double optionalStudiesLength = jsonRequestContext.getDouble("optionalStudiesLength");
String tagsText = jsonRequestContext.getString("tags");
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);
}
}
}
if (optionalStudiesLength == null) {
Messages messages = Messages.getInstance();
Locale locale = jsonRequestContext.getRequest().getLocale();
jsonRequestContext.addMessage(Severity.ERROR, messages.getText(locale, "projects.editProject.projectOptionalStudiesLengthNotDefined"));
}
projectDAO.update(project, name, description, optionalStudiesLength, optionalStudiesLengthTimeUnit, user);
// Tags
projectDAO.updateTags(project, tagEntities);
// Project modules
Set<Long> existingIds = new HashSet<>();
int rowCount = jsonRequestContext.getInteger("modulesTable.rowCount").intValue();
for (int i = 0; i < rowCount; i++) {
String colPrefix = "modulesTable." + i;
int optionality = new Integer(jsonRequestContext.getRequest().getParameter(colPrefix + ".optionality")).intValue();
Long projectModuleId = jsonRequestContext.getLong(colPrefix + ".projectModuleId");
if (projectModuleId == -1) {
Long moduleId = jsonRequestContext.getLong(colPrefix + ".moduleId");
Module module = moduleDAO.findById(moduleId);
projectModuleId = projectModuleDAO.create(project, module, ProjectModuleOptionality.getOptionality(optionality)).getId();
} else {
projectModuleDAO.update(projectModuleDAO.findById(projectModuleId), ProjectModuleOptionality.getOptionality(optionality));
}
existingIds.add(projectModuleId);
}
List<ProjectModule> projectModules = projectModuleDAO.listByProject(project);
for (ProjectModule projectModule : projectModules) {
if (!existingIds.contains(projectModule.getId())) {
projectModuleDAO.delete(projectModule);
}
}
jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
}
use of fi.otavanopisto.pyramus.dao.base.TagDAO in project pyramus by otavanopisto.
the class CreateModuleJSONRequestController method process.
/**
* Processes the request to create a module.
*
* @param requestContext The JSON request context
*/
public void process(JSONRequestContext requestContext) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
CourseDescriptionCategoryDAO descriptionCategoryDAO = DAOFactory.getInstance().getCourseDescriptionCategoryDAO();
CourseEducationTypeDAO courseEducationTypeDAO = DAOFactory.getInstance().getCourseEducationTypeDAO();
CourseEducationSubtypeDAO courseEducationSubtypeDAO = DAOFactory.getInstance().getCourseEducationSubtypeDAO();
ModuleComponentDAO moduleComponentDAO = DAOFactory.getInstance().getModuleComponentDAO();
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();
CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
String name = requestContext.getString("name");
String description = requestContext.getString("description");
Subject subject = subjectDAO.findById(requestContext.getLong("subject"));
Integer courseNumber = requestContext.getInteger("courseNumber");
User loggedUser = userDAO.findById(requestContext.getLoggedUserId());
Long moduleLengthTimeUnitId = requestContext.getLong("moduleLengthTimeUnit");
Long maxParticipantCount = requestContext.getLong("maxParticipantCount");
EducationalTimeUnit moduleLengthTimeUnit = educationalTimeUnitDAO.findById(moduleLengthTimeUnitId);
Double moduleLength = requestContext.getDouble("moduleLength");
String tagsText = requestContext.getString("tags");
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);
}
}
}
Module module = moduleDAO.create(name, subject, courseNumber, moduleLength, moduleLengthTimeUnit, description, maxParticipantCount, loggedUser);
moduleDAO.updateCurriculums(module, curriculums);
// Tags
moduleDAO.updateTags(module, 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) {
descriptionDAO.create(module, cat, descriptionText);
}
}
// Module components
int rowCount = requestContext.getInteger("componentsTable.rowCount");
for (int i = 0; i < rowCount; i++) {
String colPrefix = "componentsTable." + i;
String componentName = requestContext.getString(colPrefix + ".name");
Double componentLength = requestContext.getDouble(colPrefix + ".length");
String componentDescription = requestContext.getString(colPrefix + ".description");
// TODO Component length; should be just hours but it currently depends on the default time unit - ok?
EducationalTimeUnit componentTimeUnit = defaultsDAO.getDefaults().getBaseTimeUnit();
moduleComponentDAO.create(module, componentLength, componentTimeUnit, componentName, componentDescription).getId();
}
// 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 (!module.contains(educationType)) {
courseEducationType = courseEducationTypeDAO.create(module, educationType);
} else {
courseEducationType = module.getCourseEducationTypeByEducationTypeId(entry.getKey());
}
for (Long educationSubtypeId : entry.getValue()) {
EducationSubtype educationSubtype = educationSubtypeDAO.findById(educationSubtypeId);
if (!courseEducationType.contains(educationSubtype)) {
courseEducationSubtypeDAO.create(courseEducationType, educationSubtype);
}
}
}
String redirectURL = requestContext.getRequest().getContextPath() + "/modules/editmodule.page?module=" + module.getId();
String refererAnchor = requestContext.getRefererAnchor();
if (!StringUtils.isBlank(refererAnchor))
redirectURL += "#" + refererAnchor;
requestContext.setRedirectURL(redirectURL);
}
Aggregations