Search in sources :

Example 1 with CourseComponentDAO

use of fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO in project pyramus by otavanopisto.

the class CoursesService method listCourseComponents.

public CourseComponentEntity[] listCourseComponents(@WebParam(name = "courseId") Long courseId) {
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    CourseComponentDAO componentDAO = DAOFactory.getInstance().getCourseComponentDAO();
    return (CourseComponentEntity[]) EntityFactoryVault.buildFromDomainObjects(componentDAO.listByCourse(courseDAO.findById(courseId)));
}
Also used : CourseComponentDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO)

Example 2 with CourseComponentDAO

use of fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO 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);
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseDescriptionDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) CourseComponent(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) CourseStaffMemberDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO) CourseState(fi.otavanopisto.pyramus.domainmodel.courses.CourseState) CourseType(fi.otavanopisto.pyramus.domainmodel.courses.CourseType) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) EducationalLength(fi.otavanopisto.pyramus.domainmodel.base.EducationalLength) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) CourseComponentDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) CourseEducationTypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationTypeDAO) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) CourseEducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationSubtypeDAO) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) ModuleComponent(fi.otavanopisto.pyramus.domainmodel.modules.ModuleComponent) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module)

Example 3 with CourseComponentDAO

use of fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO in project pyramus by otavanopisto.

the class ViewCourseViewController 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();
    CourseDescriptionDAO descriptionDAO = DAOFactory.getInstance().getCourseDescriptionDAO();
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    CourseComponentDAO courseComponentDAO = DAOFactory.getInstance().getCourseComponentDAO();
    CourseStaffMemberDAO courseStaffMemberDAO = DAOFactory.getInstance().getCourseStaffMemberDAO();
    ReportDAO reportDAO = DAOFactory.getInstance().getReportDAO();
    CourseAssessmentRequestDAO courseAssessmentRequestDAO = DAOFactory.getInstance().getCourseAssessmentRequestDAO();
    // The course to be edited
    Course course = courseDAO.findById(pageRequestContext.getLong("course"));
    pageRequestContext.getRequest().setAttribute("course", course);
    Map<Long, CourseAssessmentRequest> courseAssessmentRequests = new HashMap<>();
    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;
        }
    });
    JSONArray courseReportsJSON = new JSONArray();
    List<Report> courseReports = reportDAO.listByContextType(ReportContextType.Course);
    Collections.sort(courseReports, new StringAttributeComparator("getName"));
    for (Report report : courseReports) {
        JSONObject obj = new JSONObject();
        obj.put("id", report.getId().toString());
        obj.put("name", report.getName());
        courseReportsJSON.add(obj);
    }
    for (CourseStudent courseStudent : courseStudents) {
        List<CourseAssessmentRequest> courseAssessmentRequestsByCourseStudent = courseAssessmentRequestDAO.listByCourseStudent(courseStudent);
        Collections.sort(courseAssessmentRequestsByCourseStudent, new Comparator<CourseAssessmentRequest>() {

            @Override
            public int compare(CourseAssessmentRequest o1, CourseAssessmentRequest o2) {
                return o2.getCreated().compareTo(o1.getCreated());
            }
        });
        if (!courseAssessmentRequestsByCourseStudent.isEmpty()) {
            courseAssessmentRequests.put(courseStudent.getId(), courseAssessmentRequestsByCourseStudent.get(0));
        }
    }
    setJsDataVariable(pageRequestContext, "courseReports", courseReportsJSON.toString());
    pageRequestContext.getRequest().setAttribute("courseStudents", courseStudents);
    pageRequestContext.getRequest().setAttribute("courseUsers", courseUsers);
    pageRequestContext.getRequest().setAttribute("courseComponents", courseComponentDAO.listByCourse(course));
    pageRequestContext.getRequest().setAttribute("courseDescriptions", descriptionDAO.listByCourseBase(course));
    pageRequestContext.getRequest().setAttribute("courseAssessmentRequests", courseAssessmentRequests);
    pageRequestContext.setIncludeJSP("/templates/courses/viewcourse.jsp");
}
Also used : HashMap(java.util.HashMap) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) CourseDescriptionDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseComponentDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO) Report(fi.otavanopisto.pyramus.domainmodel.reports.Report) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) JSONArray(net.sf.json.JSONArray) CourseAssessmentRequestDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentRequestDAO) JSONObject(net.sf.json.JSONObject) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) CourseStaffMemberDAO(fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO) ReportDAO(fi.otavanopisto.pyramus.dao.reports.ReportDAO)

Example 4 with CourseComponentDAO

use of fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO in project pyramus by otavanopisto.

the class CoursesService method updateCourseComponent.

public void updateCourseComponent(@WebParam(name = "courseComponentId") Long courseComponentId, @WebParam(name = "componentLength") Double componentLength, @WebParam(name = "componentLengthTimeUnitId") Long componentLengthTimeUnitId, @WebParam(name = "name") String name, @WebParam(name = "description") String description) {
    CourseComponentDAO componentDAO = DAOFactory.getInstance().getCourseComponentDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    CourseComponent courseComponent = componentDAO.findById(courseComponentId);
    EducationalTimeUnit componentLengthTimeUnit = componentLengthTimeUnitId == null ? null : educationalTimeUnitDAO.findById(componentLengthTimeUnitId);
    componentDAO.update(courseComponent, componentLength, componentLengthTimeUnit, name, description);
    validateEntity(courseComponent);
}
Also used : CourseComponentDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) CourseComponent(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)

Example 5 with CourseComponentDAO

use of fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO in project pyramus by otavanopisto.

the class CoursesService method createCourseComponent.

public CourseComponentEntity createCourseComponent(@WebParam(name = "courseId") Long courseId, @WebParam(name = "componentLength") Double componentLength, @WebParam(name = "componentLengthTimeUnitId") Long componentLengthTimeUnitId, @WebParam(name = "name") String name, @WebParam(name = "description") String description) {
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    CourseComponentDAO componentDAO = DAOFactory.getInstance().getCourseComponentDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    Course course = courseDAO.findById(courseId);
    EducationalTimeUnit componentLengthTimeUnit = componentLengthTimeUnitId == null ? null : educationalTimeUnitDAO.findById(componentLengthTimeUnitId);
    CourseComponent courseComponent = componentDAO.create(course, componentLength, componentLengthTimeUnit, name, description);
    validateEntity(courseComponent);
    return EntityFactoryVault.buildFromDomainObject(courseComponent);
}
Also used : CourseComponentDAO(fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseComponent(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)

Aggregations

CourseComponentDAO (fi.otavanopisto.pyramus.dao.courses.CourseComponentDAO)9 CourseDAO (fi.otavanopisto.pyramus.dao.courses.CourseDAO)7 CourseComponent (fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent)7 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)6 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)6 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)6 CourseDescriptionDAO (fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO)5 CourseStaffMemberDAO (fi.otavanopisto.pyramus.dao.courses.CourseStaffMemberDAO)5 SubjectDAO (fi.otavanopisto.pyramus.dao.base.SubjectDAO)4 CourseStudentDAO (fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO)4 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)4 CourseEducationType (fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType)4 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)4 Subject (fi.otavanopisto.pyramus.domainmodel.base.Subject)4 HashMap (java.util.HashMap)4 CourseEducationSubtypeDAO (fi.otavanopisto.pyramus.dao.base.CourseEducationSubtypeDAO)3 CourseEducationTypeDAO (fi.otavanopisto.pyramus.dao.base.CourseEducationTypeDAO)3 CurriculumDAO (fi.otavanopisto.pyramus.dao.base.CurriculumDAO)3 DefaultsDAO (fi.otavanopisto.pyramus.dao.base.DefaultsDAO)3 EducationSubtypeDAO (fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO)3