Search in sources :

Example 1 with Subject

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

the class KoskiInternetixLukioStudentHandler method getSubjectMeanGrade.

private ArviointiasteikkoYleissivistava getSubjectMeanGrade(Student student, Subject subject, LukionOppiaineenSuoritus oppiaineenSuoritus) {
    // Jos aineesta on annettu korotettu arvosana, käytetään automaattisesti sitä
    ArviointiasteikkoYleissivistava korotettuArvosana = getSubjectGrade(student, subject);
    if (korotettuArvosana != null) {
        return korotettuArvosana;
    } else {
        List<ArviointiasteikkoYleissivistava> kurssiarvosanat = new ArrayList<>();
        for (LukionKurssinSuoritus kurssinSuoritus : oppiaineenSuoritus.getOsasuoritukset()) {
            List<KurssinArviointi> arvioinnit = kurssinSuoritus.getArviointi();
            Set<ArviointiasteikkoYleissivistava> arvosanat = arvioinnit.stream().map(arviointi -> arviointi.getArvosana().getValue()).collect(Collectors.toSet());
            kurssiarvosanat.add(ArviointiasteikkoYleissivistava.bestGrade(arvosanat));
        }
        return ArviointiasteikkoYleissivistava.meanGrade(kurssiarvosanat);
    }
}
Also used : StudentSubjectSelections(fi.otavanopisto.pyramus.koski.StudentSubjectSelections) Arrays(java.util.Arrays) KoskiPersonState(fi.otavanopisto.pyramus.domainmodel.koski.KoskiPersonState) Date(java.util.Date) KoskiStudentId(fi.otavanopisto.pyramus.koski.KoskiStudentId) LukionOpiskeluoikeus(fi.otavanopisto.pyramus.koski.model.lukio.LukionOpiskeluoikeus) LukionOppiaineenSuoritusEiTiedossa(fi.otavanopisto.pyramus.koski.model.lukio.LukionOppiaineenSuoritusEiTiedossa) LukionKurssit(fi.otavanopisto.pyramus.koski.koodisto.LukionKurssit) StringUtils(org.apache.commons.lang3.StringUtils) OpintojenRahoitus(fi.otavanopisto.pyramus.koski.koodisto.OpintojenRahoitus) KoskiStudyProgrammeHandler(fi.otavanopisto.pyramus.koski.KoskiStudyProgrammeHandler) LukionKurssinTunniste(fi.otavanopisto.pyramus.koski.model.lukio.LukionKurssinTunniste) OpiskelijanOPS(fi.otavanopisto.pyramus.koski.OpiskelijanOPS) LukionOppiaineenSuoritusVierasKieli(fi.otavanopisto.pyramus.koski.model.lukio.LukionOppiaineenSuoritusVierasKieli) Map(java.util.Map) Kielivalikoima(fi.otavanopisto.pyramus.koski.koodisto.Kielivalikoima) LukionOppiaineenArviointi(fi.otavanopisto.pyramus.koski.model.lukio.LukionOppiaineenArviointi) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) CreditStub(fi.otavanopisto.pyramus.koski.CreditStub) LukionOppiaineenSuoritusMuuValtakunnallinen(fi.otavanopisto.pyramus.koski.model.lukio.LukionOppiaineenSuoritusMuuValtakunnallinen) Predicate(java.util.function.Predicate) Kieli(fi.otavanopisto.pyramus.koski.koodisto.Kieli) Set(java.util.Set) LukionKurssinTyyppi(fi.otavanopisto.pyramus.koski.koodisto.LukionKurssinTyyppi) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) LukionKurssinSuoritus(fi.otavanopisto.pyramus.koski.model.lukio.LukionKurssinSuoritus) OppiaineenSuoritusWithCurriculum(fi.otavanopisto.pyramus.koski.OppiaineenSuoritusWithCurriculum) List(java.util.List) CreditStubCredit(fi.otavanopisto.pyramus.koski.CreditStubCredit) LukionOppiaineenSuoritus(fi.otavanopisto.pyramus.koski.model.lukio.LukionOppiaineenSuoritus) KurssinArviointi(fi.otavanopisto.pyramus.koski.model.KurssinArviointi) OrganisaationToimipisteOID(fi.otavanopisto.pyramus.koski.model.OrganisaationToimipisteOID) OppiaineMatematiikka(fi.otavanopisto.pyramus.koski.koodisto.OppiaineMatematiikka) LukionKurssitOPS2004Aikuiset(fi.otavanopisto.pyramus.koski.koodisto.LukionKurssitOPS2004Aikuiset) StudentSubjectGrade(fi.otavanopisto.pyramus.domainmodel.students.StudentSubjectGrade) KoskiOppiaineetYleissivistava(fi.otavanopisto.pyramus.koski.koodisto.KoskiOppiaineetYleissivistava) StudyEndReasonMapping(fi.otavanopisto.pyramus.koski.settings.StudyEndReasonMapping) KoskiStudyProgrammeHandlerParams(fi.otavanopisto.pyramus.koski.settings.KoskiStudyProgrammeHandlerParams) HashMap(java.util.HashMap) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) AbstractKoskiLukioStudentHandler(fi.otavanopisto.pyramus.koski.model.lukio.AbstractKoskiLukioStudentHandler) Credit(fi.otavanopisto.pyramus.domainmodel.grading.Credit) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) Inject(javax.inject.Inject) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) LukionOppiaineenSuoritusAidinkieli(fi.otavanopisto.pyramus.koski.model.lukio.LukionOppiaineenSuoritusAidinkieli) CollectionUtils(org.apache.commons.collections.CollectionUtils) EnumUtils(org.apache.commons.lang3.EnumUtils) LukionKurssinTunnisteValtakunnallinenOPS2004(fi.otavanopisto.pyramus.koski.model.lukio.LukionKurssinTunnisteValtakunnallinenOPS2004) OppiaineAidinkieliJaKirjallisuus(fi.otavanopisto.pyramus.koski.koodisto.OppiaineAidinkieliJaKirjallisuus) LukionOppiaineenSuoritusMatematiikka(fi.otavanopisto.pyramus.koski.model.lukio.LukionOppiaineenSuoritusMatematiikka) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) LukionOppiaineenSuoritusPaikallinen(fi.otavanopisto.pyramus.koski.model.lukio.LukionOppiaineenSuoritusPaikallinen) ArviointiasteikkoYleissivistava(fi.otavanopisto.pyramus.koski.koodisto.ArviointiasteikkoYleissivistava) LukionOppiaineenOppimaaranSuoritus(fi.otavanopisto.pyramus.koski.model.lukio.LukionOppiaineenOppimaaranSuoritus) LukionKurssinTunnistePaikallinen(fi.otavanopisto.pyramus.koski.model.lukio.LukionKurssinTunnistePaikallinen) PaikallinenKoodi(fi.otavanopisto.pyramus.koski.model.PaikallinenKoodi) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) LukionKurssinTunnisteValtakunnallinenOPS2015(fi.otavanopisto.pyramus.koski.model.lukio.LukionKurssinTunnisteValtakunnallinenOPS2015) LukionOppiaineenTunniste(fi.otavanopisto.pyramus.koski.model.lukio.LukionOppiaineenTunniste) KurssinArviointi(fi.otavanopisto.pyramus.koski.model.KurssinArviointi) ArrayList(java.util.ArrayList) LukionKurssinSuoritus(fi.otavanopisto.pyramus.koski.model.lukio.LukionKurssinSuoritus) ArviointiasteikkoYleissivistava(fi.otavanopisto.pyramus.koski.koodisto.ArviointiasteikkoYleissivistava)

Example 2 with Subject

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

the class KoskiLukioStudentHandler method getSubjectMeanGrade.

private ArviointiasteikkoYleissivistava getSubjectMeanGrade(Student student, Subject subject, LukionOppiaineenSuoritus oppiaineenSuoritus) {
    // Jos aineesta on annettu korotettu arvosana, käytetään automaattisesti sitä
    ArviointiasteikkoYleissivistava korotettuArvosana = getSubjectGrade(student, subject);
    if (korotettuArvosana != null) {
        return korotettuArvosana;
    } else {
        List<ArviointiasteikkoYleissivistava> kurssiarvosanat = new ArrayList<>();
        for (LukionKurssinSuoritus kurssinSuoritus : oppiaineenSuoritus.getOsasuoritukset()) {
            List<KurssinArviointi> arvioinnit = kurssinSuoritus.getArviointi();
            Set<ArviointiasteikkoYleissivistava> arvosanat = arvioinnit.stream().map(arviointi -> arviointi.getArvosana().getValue()).collect(Collectors.toSet());
            kurssiarvosanat.add(ArviointiasteikkoYleissivistava.bestGrade(arvosanat));
        }
        return ArviointiasteikkoYleissivistava.meanGrade(kurssiarvosanat);
    }
}
Also used : StudentSubjectSelections(fi.otavanopisto.pyramus.koski.StudentSubjectSelections) Opiskeluoikeus(fi.otavanopisto.pyramus.koski.model.Opiskeluoikeus) Arrays(java.util.Arrays) KoskiPersonState(fi.otavanopisto.pyramus.domainmodel.koski.KoskiPersonState) Date(java.util.Date) KoskiStudentId(fi.otavanopisto.pyramus.koski.KoskiStudentId) LukionKurssit(fi.otavanopisto.pyramus.koski.koodisto.LukionKurssit) StringUtils(org.apache.commons.lang3.StringUtils) OpintojenRahoitus(fi.otavanopisto.pyramus.koski.koodisto.OpintojenRahoitus) KoskiStudyProgrammeHandler(fi.otavanopisto.pyramus.koski.KoskiStudyProgrammeHandler) OpiskelijanOPS(fi.otavanopisto.pyramus.koski.OpiskelijanOPS) Map(java.util.Map) Kielivalikoima(fi.otavanopisto.pyramus.koski.koodisto.Kielivalikoima) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) CreditStub(fi.otavanopisto.pyramus.koski.CreditStub) LukionOppimaara(fi.otavanopisto.pyramus.koski.koodisto.LukionOppimaara) Collection(java.util.Collection) Kieli(fi.otavanopisto.pyramus.koski.koodisto.Kieli) Set(java.util.Set) LukionKurssinTyyppi(fi.otavanopisto.pyramus.koski.koodisto.LukionKurssinTyyppi) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) List(java.util.List) CreditStubCredit(fi.otavanopisto.pyramus.koski.CreditStubCredit) KurssinArviointi(fi.otavanopisto.pyramus.koski.model.KurssinArviointi) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) OrganisaationToimipiste(fi.otavanopisto.pyramus.koski.model.OrganisaationToimipiste) OrganisaationToimipisteOID(fi.otavanopisto.pyramus.koski.model.OrganisaationToimipisteOID) OppiaineMatematiikka(fi.otavanopisto.pyramus.koski.koodisto.OppiaineMatematiikka) LukionKurssitOPS2004Aikuiset(fi.otavanopisto.pyramus.koski.koodisto.LukionKurssitOPS2004Aikuiset) KoskiOppiaineetYleissivistava(fi.otavanopisto.pyramus.koski.koodisto.KoskiOppiaineetYleissivistava) StudyEndReasonMapping(fi.otavanopisto.pyramus.koski.settings.StudyEndReasonMapping) HashMap(java.util.HashMap) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) Inject(javax.inject.Inject) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CollectionUtils(org.apache.commons.collections.CollectionUtils) EnumUtils(org.apache.commons.lang3.EnumUtils) OppiaineAidinkieliJaKirjallisuus(fi.otavanopisto.pyramus.koski.koodisto.OppiaineAidinkieliJaKirjallisuus) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) KoskiConsts(fi.otavanopisto.pyramus.koski.KoskiConsts) ArviointiasteikkoYleissivistava(fi.otavanopisto.pyramus.koski.koodisto.ArviointiasteikkoYleissivistava) PaikallinenKoodi(fi.otavanopisto.pyramus.koski.model.PaikallinenKoodi) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) OppiaineenSuoritusWithSubject(fi.otavanopisto.pyramus.koski.OppiaineenSuoritusWithSubject) KurssinArviointi(fi.otavanopisto.pyramus.koski.model.KurssinArviointi) ArrayList(java.util.ArrayList) ArviointiasteikkoYleissivistava(fi.otavanopisto.pyramus.koski.koodisto.ArviointiasteikkoYleissivistava)

Example 3 with Subject

use of fi.otavanopisto.pyramus.domainmodel.base.Subject 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));
}
Also used : HashMap(java.util.HashMap) CourseDescriptionDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) CourseDescription(fi.otavanopisto.pyramus.domainmodel.courses.CourseDescription) ModuleComponentDAO(fi.otavanopisto.pyramus.dao.modules.ModuleComponentDAO) Vector(java.util.Vector) HashSet(java.util.HashSet) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) CourseEducationTypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationTypeDAO) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) CourseEducationTypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationTypeDAO) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) StaleObjectStateException(org.hibernate.StaleObjectStateException) HashMap(java.util.HashMap) Map(java.util.Map) User(fi.otavanopisto.pyramus.domainmodel.users.User) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) CourseDescriptionCategoryDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionCategoryDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) CourseDescriptionCategory(fi.otavanopisto.pyramus.domainmodel.courses.CourseDescriptionCategory) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) CourseEducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationSubtypeDAO) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) EducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO) CourseEducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationSubtypeDAO) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag)

Example 4 with Subject

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

the class SearchCoursesJSONRequestController method process.

/**
 * Processes the request to search courses.
 * The request should contain the either following parameters (for simple search):
 * <dl>
 *   <dt><code>text</code></dt>
 *   <dd>The text to search for</dd>
 * </dl>
 * or the following parameters (for advanced search):
 * <dl>
 *   <dt><code>name</code></dt>
 *   <dd>Course name to find.</dd>
 *   <dt><code>tags</code></dt>
 *   <dd>Tags to find.</dd>
 *   <dt><code>nameExtension</code></dt>
 *   <dd>The name extension to find.</dd>
 *   <dt><code>description</code></dt>
 *   <dd>The description to find.</dd>
 *   <dt><code>state</code></dt>
 *   <dd>The ID of the course state to find.</dd>
 *   <dt><code>subject</code></dt>
 *   <dd>The ID of the subject to find.</dd>
 *   <dt><code>timeframeStart</code></dt>
 *   <dd>The start of the timeframe to find.</dd>
 *   <dt><code>timeframeEnd</code></dt>
 *   <dd>The end of the timeframe to find.</dd>
 *   <dt><code>educationType</code></dt>
 *   <dd>The education type to find.</dd>
 *   <dt><code>educationSubtype</code></dt>
 *   <dd>The education subtype to find.</dd>
 *   <dt><code>timeframeMode</code></dt>
 *   <dd>The mode of the timeframe. Can be <code>INCLUSIVE</code>
 *   or <code>EXCLUSIVE</code>.</dd>
 * </dl>
 *
 * @param jsonRequestContext The JSON request context
 */
public void process(JSONRequestContext requestContext) {
    CourseDAO courseDAO = DAOFactory.getInstance().getCourseDAO();
    CourseStateDAO courseStateDAO = DAOFactory.getInstance().getCourseStateDAO();
    EducationTypeDAO educationTypeDAO = DAOFactory.getInstance().getEducationTypeDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    EducationSubtypeDAO educationSubtypeDAO = DAOFactory.getInstance().getEducationSubtypeDAO();
    // Determine the number of results shown per page. If not defined, default to ten results per page
    Integer resultsPerPage = NumberUtils.createInteger(requestContext.getRequest().getParameter("maxResults"));
    if (resultsPerPage == null)
        resultsPerPage = 10;
    // Determine the result page to be shown. If not defined, default to the first page
    Integer page = NumberUtils.createInteger(requestContext.getRequest().getParameter("page"));
    if (page == null) {
        page = 0;
    }
    SearchResult<Course> searchResult;
    if ("advanced".equals(requestContext.getRequest().getParameter("activeTab"))) {
        String name = requestContext.getString("name");
        String tags = requestContext.getString("tags");
        if (!StringUtils.isBlank(tags))
            tags = tags.replace(',', ' ');
        String nameExtension = requestContext.getString("nameExtension");
        String description = requestContext.getString("description");
        CourseState courseState = null;
        Long courseStateId = requestContext.getLong("state");
        if (courseStateId != null) {
            courseState = courseStateDAO.findById(courseStateId);
        }
        Subject subject = null;
        Long subjectId = requestContext.getLong("subject");
        if (subjectId != null) {
            subject = subjectDAO.findById(subjectId);
        }
        Date timeframeStart = null;
        String value = requestContext.getString("timeframeStart");
        if (NumberUtils.isNumber(value)) {
            timeframeStart = new Date(NumberUtils.createLong(value));
        }
        Date timeframeEnd = null;
        value = requestContext.getString("timeframeEnd");
        if (NumberUtils.isNumber(value)) {
            timeframeEnd = new Date(NumberUtils.createLong(value));
        }
        EducationType educationType = null;
        Long educationTypeId = requestContext.getLong("educationType");
        if (educationTypeId != null) {
            educationType = educationTypeDAO.findById(educationTypeId);
        }
        EducationSubtype educationSubtype = null;
        Long educationSubtypeId = requestContext.getLong("educationSubtype");
        if (educationSubtypeId != null) {
            educationSubtype = educationSubtypeDAO.findById(educationSubtypeId);
        }
        CourseTemplateFilter courseTemplateFilter = (CourseTemplateFilter) requestContext.getEnum("courseTemplateFilter", CourseTemplateFilter.class);
        SearchTimeFilterMode timeFilterMode = (SearchTimeFilterMode) requestContext.getEnum("timeframeMode", SearchTimeFilterMode.class);
        searchResult = courseDAO.searchCourses(resultsPerPage, page, name, tags, nameExtension, description, courseState, subject, timeFilterMode, timeframeStart, timeframeEnd, educationType, educationSubtype, true, courseTemplateFilter);
    } else {
        String text = requestContext.getRequest().getParameter("text");
        searchResult = courseDAO.searchCoursesBasic(resultsPerPage, page, text, true);
    }
    List<Map<String, Object>> results = new ArrayList<>();
    List<Course> courses = searchResult.getResults();
    for (Course course : courses) {
        Map<String, Object> courseInfo = new HashMap<>();
        courseInfo.put("id", course.getId());
        courseInfo.put("name", course.getName());
        courseInfo.put("nameExtension", course.getNameExtension());
        if (course.getBeginDate() != null) {
            courseInfo.put("beginDate", course.getBeginDate().getTime());
        }
        if (course.getEndDate() != null) {
            courseInfo.put("endDate", course.getEndDate().getTime());
        }
        results.add(courseInfo);
    }
    String statusMessage;
    Locale locale = requestContext.getRequest().getLocale();
    if (searchResult.getTotalHitCount() > 0) {
        statusMessage = Messages.getInstance().getText(locale, "courses.searchCourses.searchStatus", new Object[] { searchResult.getFirstResult() + 1, searchResult.getLastResult() + 1, searchResult.getTotalHitCount() });
    } else {
        statusMessage = Messages.getInstance().getText(locale, "courses.searchCourses.searchStatusNoMatches");
    }
    requestContext.addResponseParameter("results", results);
    requestContext.addResponseParameter("statusMessage", statusMessage);
    requestContext.addResponseParameter("pages", searchResult.getPages());
    requestContext.addResponseParameter("page", searchResult.getPage());
}
Also used : Locale(java.util.Locale) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) HashMap(java.util.HashMap) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) ArrayList(java.util.ArrayList) CourseStateDAO(fi.otavanopisto.pyramus.dao.courses.CourseStateDAO) SearchTimeFilterMode(fi.otavanopisto.pyramus.persistence.search.SearchTimeFilterMode) CourseState(fi.otavanopisto.pyramus.domainmodel.courses.CourseState) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) Date(java.util.Date) EducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO) CourseTemplateFilter(fi.otavanopisto.pyramus.dao.courses.CourseDAO.CourseTemplateFilter) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with Subject

use of fi.otavanopisto.pyramus.domainmodel.base.Subject 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);
}
Also used : User(fi.otavanopisto.pyramus.domainmodel.users.User) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) HashMap(java.util.HashMap) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) CourseDescriptionDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) CourseDescriptionCategoryDAO(fi.otavanopisto.pyramus.dao.courses.CourseDescriptionCategoryDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) ModuleComponentDAO(fi.otavanopisto.pyramus.dao.modules.ModuleComponentDAO) CourseDescriptionCategory(fi.otavanopisto.pyramus.domainmodel.courses.CourseDescriptionCategory) Vector(java.util.Vector) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) HashSet(java.util.HashSet) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) 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) EducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.EducationSubtypeDAO) CourseEducationSubtypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationSubtypeDAO) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) CourseEducationTypeDAO(fi.otavanopisto.pyramus.dao.base.CourseEducationTypeDAO) EducationTypeDAO(fi.otavanopisto.pyramus.dao.base.EducationTypeDAO) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) HashMap(java.util.HashMap) Map(java.util.Map)

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