Search in sources :

Example 21 with Subject

use of fi.otavanopisto.pyramus.domainmodel.base.Subject in project pyramus by otavanopisto.

the class SearchCoursesViewController method process.

public void process(PageRequestContext pageRequestContext) {
    CourseStateDAO courseStateDAO = DAOFactory.getInstance().getCourseStateDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
    EducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getEducationSubtypeDAO();
    List<EducationType> educationTypes = educationTypeDAO.listUnarchived();
    Collections.sort(educationTypes, new StringAttributeComparator("getName"));
    // Subjects
    Map<Long, List<Subject>> subjectsByEducationType = new HashMap<>();
    List<Subject> subjectsByNoEducationType = subjectDAO.listByEducationType(null);
    Collections.sort(subjectsByNoEducationType, new StringAttributeComparator("getName"));
    Map<Long, List<EducationSubtype>> educationSubtypesByEduType = new HashMap<>();
    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<EducationSubtype> educationSubtypes = educationSubtypeDAO.listByEducationType(educationType);
        educationSubtypesByEduType.put(educationType.getId(), educationSubtypes);
    }
    pageRequestContext.getRequest().setAttribute("educationTypes", educationTypes);
    pageRequestContext.getRequest().setAttribute("educationSubtypes", educationSubtypesByEduType);
    pageRequestContext.getRequest().setAttribute("subjectsByNoEducationType", subjectsByNoEducationType);
    pageRequestContext.getRequest().setAttribute("subjectsByEducationType", subjectsByEducationType);
    pageRequestContext.getRequest().setAttribute("states", courseStateDAO.listUnarchived());
    pageRequestContext.setIncludeJSP("/templates/courses/searchcourses.jsp");
}
Also used : EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) HashMap(java.util.HashMap) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) EducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO) CourseStateDAO(fi.otavanopisto.pyramus.dao.courses.CourseStateDAO) List(java.util.List) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO)

Example 22 with Subject

use of fi.otavanopisto.pyramus.domainmodel.base.Subject in project pyramus by otavanopisto.

the class CreateTransferCreditTemplateViewController 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) {
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
    List<Subject> subjects = subjectDAO.listUnarchived();
    Collections.sort(subjects, new StringAttributeComparator("getName"));
    List<EducationalTimeUnit> timeUnits = educationalTimeUnitDAO.listUnarchived();
    Collections.sort(timeUnits, new StringAttributeComparator("getName"));
    List<School> schools = schoolDAO.listUnarchived();
    Collections.sort(schools, new StringAttributeComparator("getName"));
    String jsonTimeUnits = new JSONArrayExtractor("name", "id").extractString(timeUnits);
    JSONArray jsonSubjects = new JSONArrayExtractor("name", "code", "id").extract(subjects);
    for (int i = 0; i < jsonSubjects.size(); i++) {
        JSONObject jsonSubject = jsonSubjects.getJSONObject(i);
        if (subjects.get(i).getEducationType() != null) {
            jsonSubject.put("educationTypeName", subjects.get(i).getEducationType().getName());
        }
    }
    List<Curriculum> curriculums = curriculumDAO.listUnarchived();
    Collections.sort(curriculums, new StringAttributeComparator("getName"));
    String jsonCurriculums = new JSONArrayExtractor("name", "id").extractString(curriculums);
    setJsDataVariable(pageRequestContext, "curriculums", jsonCurriculums);
    this.setJsDataVariable(pageRequestContext, "subjects", jsonSubjects.toString());
    this.setJsDataVariable(pageRequestContext, "timeUnits", jsonTimeUnits);
    pageRequestContext.getRequest().setAttribute("curriculums", curriculums);
    pageRequestContext.setIncludeJSP("/templates/settings/createtransfercredittemplate.jsp");
}
Also used : CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) JSONArray(net.sf.json.JSONArray) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) School(fi.otavanopisto.pyramus.domainmodel.base.School) JSONObject(net.sf.json.JSONObject) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) SchoolDAO(fi.otavanopisto.pyramus.dao.base.SchoolDAO) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)

Example 23 with Subject

use of fi.otavanopisto.pyramus.domainmodel.base.Subject in project pyramus by otavanopisto.

the class CourseAPI method create.

public Long create(Long organizationId, Long moduleId, Long typeId, String name, String nameExtension, String description, String subjectCode) throws InvalidScriptException {
    ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
    CourseTypeDAO courseTypeDAO = DAOFactory.getInstance().getCourseTypeDAO();
    OrganizationDAO organizationDAO = DAOFactory.getInstance().getOrganizationDAO();
    Module module = moduleDAO.findById(moduleId);
    if (module == null) {
        throw new InvalidScriptException("Module #" + moduleId + " not found.");
    }
    User loggedUser = userDAO.findById(loggedUserId);
    if (loggedUser == null) {
        throw new InvalidScriptException("Logged user not found.");
    }
    Subject subject = subjectDAO.findByCode(subjectCode);
    if (subject == null) {
        throw new InvalidScriptException("Subject by code '" + subjectCode + "' not found.");
    }
    Organization organization = organizationDAO.findById(organizationId);
    if (organization == null) {
        throw new InvalidScriptException("Default organization not found.");
    }
    CourseType type = typeId != null ? courseTypeDAO.findById(typeId) : null;
    // TODO: Add support for these:
    CourseState courseState = defaultsDAO.getDefaults().getInitialCourseState();
    Date beginDate = null;
    Date endDate = null;
    Double distanceTeachingDays = null;
    Double localTeachingDays = null;
    Double teachingHours = null;
    Double distanceTeachingHours = null;
    Double planningHours = null;
    Double assessingHours = null;
    Date enrolmentTimeEnd = null;
    BigDecimal courseFee = null;
    Currency courseFeeCurrency = null;
    return courseDAO.create(module, organization, name, nameExtension, courseState, type, subject, module.getCourseNumber(), beginDate, endDate, module.getCourseLength().getUnits(), module.getCourseLength().getUnit(), distanceTeachingDays, localTeachingDays, teachingHours, distanceTeachingHours, planningHours, assessingHours, description, module.getMaxParticipantCount(), courseFee, courseFeeCurrency, enrolmentTimeEnd, loggedUser).getId();
}
Also used : CourseTypeDAO(fi.otavanopisto.pyramus.dao.courses.CourseTypeDAO) User(fi.otavanopisto.pyramus.domainmodel.users.User) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) InvalidScriptException(fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) Date(java.util.Date) BigDecimal(java.math.BigDecimal) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Currency(java.util.Currency) CourseState(fi.otavanopisto.pyramus.domainmodel.courses.CourseState) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) CourseType(fi.otavanopisto.pyramus.domainmodel.courses.CourseType) OrganizationDAO(fi.otavanopisto.pyramus.dao.base.OrganizationDAO)

Example 24 with Subject

use of fi.otavanopisto.pyramus.domainmodel.base.Subject in project pyramus by otavanopisto.

the class SubjectAPI method findIdByCode.

public Long findIdByCode(String code) {
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    Subject subject = subjectDAO.findByCode(code);
    return subject != null ? subject.getId() : null;
}
Also used : SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject)

Example 25 with Subject

use of fi.otavanopisto.pyramus.domainmodel.base.Subject in project pyramus by otavanopisto.

the class ModuleAPI method create.

public Long create(String name, String description, Long maxParticipantCount, String subjectCode, Integer courseNumber) throws InvalidScriptException {
    ModuleDAO moduleDAO = DAOFactory.getInstance().getModuleDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    DefaultsDAO defaultsDAO = DAOFactory.getInstance().getDefaultsDAO();
    Subject subject = subjectDAO.findByCode(subjectCode);
    if (subject == null) {
        throw new InvalidScriptException("Subject by code '" + subjectCode + "' not found.");
    }
    User loggedUser = userDAO.findById(loggedUserId);
    if (loggedUser == null) {
        throw new InvalidScriptException("Logged user not found.");
    }
    EducationalTimeUnit timeUnit = defaultsDAO.getDefaults().getBaseTimeUnit();
    return moduleDAO.create(name, subject, courseNumber, 0d, timeUnit, description, maxParticipantCount, loggedUser).getId();
}
Also used : StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) User(fi.otavanopisto.pyramus.domainmodel.users.User) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) InvalidScriptException(fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)

Aggregations

Subject (fi.otavanopisto.pyramus.domainmodel.base.Subject)62 SubjectDAO (fi.otavanopisto.pyramus.dao.base.SubjectDAO)38 EducationType (fi.otavanopisto.pyramus.domainmodel.base.EducationType)26 EducationalTimeUnit (fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)24 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)22 HashMap (java.util.HashMap)22 EducationTypeDAO (fi.otavanopisto.pyramus.dao.base.EducationTypeDAO)18 EducationalTimeUnitDAO (fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO)18 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)17 Module (fi.otavanopisto.pyramus.domainmodel.modules.Module)17 Date (java.util.Date)17 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)16 List (java.util.List)16 CurriculumDAO (fi.otavanopisto.pyramus.dao.base.CurriculumDAO)15 EducationSubtype (fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype)15 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)15 HashSet (java.util.HashSet)15 ModuleDAO (fi.otavanopisto.pyramus.dao.modules.ModuleDAO)14 Map (java.util.Map)14 EducationSubtypeDAO (fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO)12