use of fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType 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.domainmodel.base.CourseEducationType 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);
}
use of fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType in project pyramus by otavanopisto.
the class CoursesService method createCourse.
public CourseEntity createCourse(@WebParam(name = "moduleId") Long moduleId, @WebParam(name = "name") String name, @WebParam(name = "nameExtension") String nameExtension, @WebParam(name = "subjectId") Long subjectId, @WebParam(name = "courseNumber") Integer courseNumber, @WebParam(name = "beginDate") Date beginDate, @WebParam(name = "endDate") Date endDate, @WebParam(name = "courseLength") Double courseLength, @WebParam(name = "courseLengthTimeUnitId") Long courseLengthTimeUnitId, @WebParam(name = "description") String description, @WebParam(name = "creatingUserId") Long creatingUserId) {
StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
CourseComponentDAO componentDAO = DAOFactory.getInstance().getCourseComponentDAO();
CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
CourseEducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getCourseEducationTypeDAO();
CourseEducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getCourseEducationSubtypeDAO();
EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
Module module = moduleId == null ? null : moduleDAO.findById(moduleId);
Subject subject = subjectId == null ? null : subjectDAO.findById(subjectId);
EducationalTimeUnit courseLengthTimeUnit = courseLengthTimeUnitId == null ? null : educationalTimeUnitDAO.findById(courseLengthTimeUnitId);
User creatingUser = userDAO.findById(creatingUserId);
if (module != null) {
name = name == null ? module.getName() : name;
subject = subject == null ? module.getSubject() : subject;
courseNumber = courseNumber == null ? module.getCourseNumber() : courseNumber;
if (courseLength == null && module.getCourseLength() != null) {
courseLength = module.getCourseLength().getUnits();
courseLengthTimeUnit = module.getCourseLength().getUnit();
}
description = description == null ? module.getDescription() : description;
}
CourseState state = defaultsDAO.getDefaults().getInitialCourseState();
CourseType type = null;
// Course creation
Course course = courseDAO.create(module, name, nameExtension, state, type, subject, courseNumber, beginDate, endDate, courseLength, courseLengthTimeUnit, null, null, null, null, null, null, description, null, null, null, null, creatingUser);
validateEntity(course);
if (module != null) {
// Course Description copying from module to course
descriptionDAO.copy(module, course);
// Curriculums
courseDAO.updateCurriculums(course, new HashSet<Curriculum>(module.getCurriculums()));
// Components
List<ModuleComponent> moduleComponents = module.getModuleComponents();
if (moduleComponents != null) {
for (ModuleComponent moduleComponent : moduleComponents) {
EducationalLength educationalLength = moduleComponent.getLength();
CourseComponent courseComponent = componentDAO.create(course, educationalLength == null ? null : educationalLength.getUnits(), educationalLength == null ? null : educationalLength.getUnit(), moduleComponent.getName(), moduleComponent.getDescription());
validateEntity(courseComponent);
}
}
// Education types
List<CourseEducationType> typesInModule = module.getCourseEducationTypes();
if (typesInModule != null) {
for (CourseEducationType typeInModule : typesInModule) {
CourseEducationType typeInCourse = educationTypeDAO.create(course, typeInModule.getEducationType());
validateEntity(typeInCourse);
// Education subtypes
List<CourseEducationSubtype> subTypesInModule = typeInModule.getCourseEducationSubtypes();
if (subTypesInModule != null) {
for (CourseEducationSubtype subtypeInModule : subTypesInModule) {
CourseEducationSubtype courseEducationSubtype = educationSubtypeDAO.create(typeInCourse, subtypeInModule.getEducationSubtype());
validateEntity(courseEducationSubtype);
}
}
}
}
}
return EntityFactoryVault.buildFromDomainObject(course);
}
use of fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType in project pyramus by otavanopisto.
the class CoursesService method addCourseEducationSubtype.
public CourseEducationSubtypeEntity addCourseEducationSubtype(@WebParam(name = "courseEducationTypeId") Long courseEducationTypeId, @WebParam(name = "educationSubtypeId") Long educationSubtypeId) {
CourseEducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getCourseEducationTypeDAO();
CourseEducationSubtypeDAO courseEducationSubtypeDAO = DAOFactory.getInstance().getCourseEducationSubtypeDAO();
EducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getEducationSubtypeDAO();
CourseEducationType courseEducationType = educationTypeDAO.findById(courseEducationTypeId);
EducationSubtype educationSubtype = educationSubtypeDAO.findById(educationSubtypeId);
CourseEducationSubtype courseEducationSubtype = courseEducationSubtypeDAO.create(courseEducationType, educationSubtype);
validateEntity(courseEducationSubtype);
return EntityFactoryVault.buildFromDomainObject(courseEducationSubtype);
}
use of fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType in project pyramus by otavanopisto.
the class ModuleDAO method listByEducationType.
public List<Module> listByEducationType(EducationType educationType) {
// return s.createCriteria(CourseEducationType.class)
// .add(Restrictions.in("courseBase.id", s.createCriteria(Module.class).setProjection(Projections.id()).list()))
// .add(Restrictions.eq("educationType", educationType)).setProjection(Projections.property("courseBase")).list();
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Module> criteria = criteriaBuilder.createQuery(Module.class);
Root<Module> root = criteria.from(Module.class);
Root<CourseEducationType> eduType = criteria.from(CourseEducationType.class);
Join<CourseEducationType, CourseBase> eduTypeCourseBase = eduType.join(CourseEducationType_.courseBase);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(Module_.id), eduTypeCourseBase.get(CourseBase_.id)), criteriaBuilder.equal(eduType.get(CourseEducationType_.educationType), educationType)));
return entityManager.createQuery(criteria).getResultList();
}
Aggregations