Search in sources :

Example 1 with Student

use of fi.otavanopisto.pyramus.domainmodel.students.Student 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 Student

use of fi.otavanopisto.pyramus.domainmodel.students.Student 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 Student

use of fi.otavanopisto.pyramus.domainmodel.students.Student in project pyramus by otavanopisto.

the class EnvironmentPermissionResolver method hasCourseAccess.

private boolean hasCourseAccess(Course course, fi.otavanopisto.pyramus.domainmodel.users.User userEntity, Permission permission) {
    PyramusPermissionCollection permissionCollection = findCollection(permission.getName());
    if (permissionCollection != null) {
        try {
            String[] defaultRoles = permissionCollection.getDefaultRoles(permission.getName());
            // Is EnvironmentRole in the environment roles of the permission
            if ((userEntity.getRole() != null) && ArrayUtils.contains(defaultRoles, userEntity.getRole().toString())) {
                return true;
            }
            CourseRoleArchetype[] defaultCourseRoles = permissionCollection.getDefaultCourseRoles(permission.getName());
            if (userEntity instanceof Student) {
                CourseStudent courseStudent = courseStudentDAO.findByCourseAndStudent(course, (Student) userEntity);
                if (courseStudent != null) {
                    return ArrayUtils.contains(defaultCourseRoles, CourseRoleArchetype.STUDENT);
                } else {
                    return false;
                }
            } else if (userEntity instanceof StaffMember) {
                CourseStaffMember courseStaffMember = courseStaffMemberDAO.findByCourseAndStaffMember(course, (StaffMember) userEntity);
                if (courseStaffMember != null) {
                    return ArrayUtils.contains(defaultCourseRoles, CourseRoleArchetype.TEACHER);
                } else {
                    return false;
                }
            } else {
                logger.severe(String.format("UserEntity could not be casted to a student nor staffmember."));
            }
        } catch (NoSuchFieldException e) {
        }
    }
    return false;
}
Also used : CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember)

Example 4 with Student

use of fi.otavanopisto.pyramus.domainmodel.students.Student 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));
}
Also used : Locale(java.util.Locale) DuplicateCourseStudentException(fi.otavanopisto.pyramus.exception.DuplicateCourseStudentException) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) CourseDAO(fi.otavanopisto.pyramus.dao.courses.CourseDAO) StudentProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO) ModuleDAO(fi.otavanopisto.pyramus.dao.modules.ModuleDAO) StudentProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) AcademicTermDAO(fi.otavanopisto.pyramus.dao.base.AcademicTermDAO) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Currency(java.util.Currency) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseParticipationType(fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType) Room(fi.otavanopisto.pyramus.domainmodel.accommodation.Room) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) HashSet(java.util.HashSet) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) CourseEnrolmentType(fi.otavanopisto.pyramus.domainmodel.courses.CourseEnrolmentType) Grade(fi.otavanopisto.pyramus.domainmodel.grading.Grade) GradeDAO(fi.otavanopisto.pyramus.dao.grading.GradeDAO) DefaultsDAO(fi.otavanopisto.pyramus.dao.base.DefaultsDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) Date(java.util.Date) BigDecimal(java.math.BigDecimal) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) Defaults(fi.otavanopisto.pyramus.domainmodel.base.Defaults) AcademicTerm(fi.otavanopisto.pyramus.domainmodel.base.AcademicTerm) StudentProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.StudentProjectModule) ProjectAssessment(fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.StudentProjectModule) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) StaleObjectStateException(org.hibernate.StaleObjectStateException) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject)

Example 5 with Student

use of fi.otavanopisto.pyramus.domainmodel.students.Student in project pyramus by otavanopisto.

the class UpdateApplicationStateJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    try {
        StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
        StaffMember staffMember = requestContext.getLoggedUserId() == null ? null : staffMemberDAO.findById(requestContext.getLoggedUserId());
        if (staffMember == null) {
            fail(requestContext, "Et ole kirjautunut sisään");
            return;
        }
        Long id = requestContext.getLong("id");
        if (id == null) {
            fail(requestContext, "Puuttuva hakemustunnus");
            return;
        }
        ApplicationState applicationState = ApplicationState.valueOf(requestContext.getString("state"));
        Boolean lockApplication = requestContext.getBoolean("lockApplication");
        Boolean setHandler = requestContext.getBoolean("setHandler");
        Boolean removeHandler = requestContext.getBoolean("removeHandler");
        // Application update
        ApplicationDAO applicationDAO = DAOFactory.getInstance().getApplicationDAO();
        Application application = applicationDAO.findById(id);
        if (application == null) {
            fail(requestContext, "Puuttuva hakemus");
            return;
        }
        if (application.getState() != applicationState) {
            if (applicationState == ApplicationState.APPROVED_BY_SCHOOL) {
                // Gather required dynamic data from the application form
                JSONObject formData = JSONObject.fromObject(application.getFormData());
                String line = ApplicationUtils.applicationLineUiValue(application.getLine());
                String applicantName = String.format("%s %s", getFormValue(formData, "field-first-names"), getFormValue(formData, "field-last-name"));
                String ssn = ApplicationUtils.constructSSN(getFormValue(formData, "field-birthday"), getFormValue(formData, "field-ssn-end"));
                String address = String.format("%s, %s %s, %s", getFormValue(formData, "field-street-address"), getFormValue(formData, "field-zip-code"), getFormValue(formData, "field-city"), getFormValue(formData, "field-country"));
                String municipality = ApplicationUtils.municipalityUiValue(getFormValue(formData, "field-municipality"));
                String nationality = ApplicationUtils.nationalityUiValue(getFormValue(formData, "field-nationality"));
                String phone = getFormValue(formData, "field-phone");
                String email = StringUtils.lowerCase(StringUtils.trim(getFormValue(formData, "field-email")));
                String nickname = getFormValue(formData, "field-nickname");
                String guardianMail = getFormValue(formData, "field-underage-email");
                // Make sure we have application signatures and school approval
                ApplicationSignaturesDAO applicationSignaturesDAO = DAOFactory.getInstance().getApplicationSignaturesDAO();
                ApplicationSignatures applicationSignatures = applicationSignaturesDAO.findByApplication(application);
                if (applicationSignatures == null || applicationSignatures.getStaffDocumentState() != ApplicationSignatureState.SIGNED) {
                    logger.log(Level.WARNING, String.format("Application %s not signed by staff", application.getApplicationId()));
                    fail(requestContext, "Oppilaitos ei ole vielä allekirjoittanut hyväksymisasiakirjaa");
                    return;
                }
                OnnistuuClient onnistuuClient = OnnistuuClient.getInstance();
                // Create Onnistuu document (if not done before)
                String documentId = null;
                if (applicationSignatures.getApplicantDocumentId() == null) {
                    documentId = onnistuuClient.createDocument(String.format("Vastaanotto: %s", applicantName));
                    applicationSignatures = applicationSignaturesDAO.updateApplicantDocument(applicationSignatures, documentId, null, null, ApplicationSignatureState.DOCUMENT_CREATED);
                } else {
                    documentId = applicationSignatures.getApplicantDocumentId();
                }
                if (applicationSignatures.getApplicantDocumentState() == ApplicationSignatureState.DOCUMENT_CREATED) {
                    byte[] pdf = onnistuuClient.generateApplicantSignatureDocument(requestContext, line, applicantName, ssn, address, municipality, nationality, phone, email);
                    onnistuuClient.addPdf(documentId, pdf);
                    applicationSignatures = applicationSignaturesDAO.updateApplicantDocument(applicationSignatures, documentId, null, null, ApplicationSignatureState.PDF_UPLOADED);
                }
                if (applicationSignatures.getApplicantDocumentState() == ApplicationSignatureState.PDF_UPLOADED) {
                    OnnistuuClient.Invitation invitation = onnistuuClient.createInvitation(documentId, email);
                    applicationSignatures = applicationSignaturesDAO.updateApplicantDocument(applicationSignatures, documentId, invitation.getUuid(), invitation.getPassphrase(), ApplicationSignatureState.INVITATION_CREATED);
                }
                // Construct accepted mail template
                String staffDocUrl = String.format("https://www.onnistuu.fi/api/v1/invitation/%s/%s/files/0", applicationSignatures.getStaffInvitationId(), applicationSignatures.getStaffInvitationToken());
                StringBuilder signUpUrl = new StringBuilder();
                signUpUrl.append(requestContext.getRequest().getScheme());
                signUpUrl.append("://");
                signUpUrl.append(requestContext.getRequest().getServerName());
                signUpUrl.append(":");
                signUpUrl.append(requestContext.getRequest().getServerPort());
                signUpUrl.append("/applications/accept.page?application=");
                signUpUrl.append(application.getApplicationId());
                String lineOrganization = ApplicationUtils.isOtaviaLine(application.getLine()) ? "Otavian" : "Otavan Opiston";
                String signerOrganization = ApplicationUtils.isOtaviaLine(application.getLine()) ? "Otavia" : "Otavan Opisto";
                String subject = String.format("Hyväksyminen %s opiskelijaksi", lineOrganization);
                String content = IOUtils.toString(requestContext.getServletContext().getResourceAsStream("/templates/applications/mails/mail-accept-study-place.html"), "UTF-8");
                content = String.format(content, nickname, lineOrganization, line.toLowerCase(), staffDocUrl, staffDocUrl, signUpUrl.toString(), signUpUrl.toString(), staffMember.getFullName(), signerOrganization);
                if (StringUtils.isBlank(guardianMail)) {
                    Mailer.sendMail(Mailer.JNDI_APPLICATION, Mailer.HTML, null, email, subject, content);
                } else {
                    Mailer.sendMail(Mailer.JNDI_APPLICATION, Mailer.HTML, null, email, guardianMail, subject, content);
                }
                // Add notification about sent mail
                ApplicationLogDAO applicationLogDAO = DAOFactory.getInstance().getApplicationLogDAO();
                applicationLogDAO.create(application, ApplicationLogType.HTML, String.format("<p>%s</p><p><b>%s</b></p>%s", "Hakijalle lähetetty ilmoitus opiskelijaksi hyväksymisestä", subject, content), staffMember);
            } else // end of application has been approved logic
            if (applicationState == ApplicationState.TRANSFERRED_AS_STUDENT) {
                // Separate logic for transferring the applicant as student
                // throws exception if multiple persons or is staff
                Student student = ApplicationUtils.createPyramusStudent(application, staffMember);
                PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
                personDAO.updateDefaultUser(student.getPerson(), student);
                String credentialToken = RandomStringUtils.randomAlphanumeric(32).toLowerCase();
                application = applicationDAO.updateApplicationStudentAndCredentialToken(application, student, credentialToken);
                ApplicationUtils.mailCredentialsInfo(requestContext.getRequest(), student, application);
            } else if (applicationState == ApplicationState.REJECTED) {
                if (application.getState() == ApplicationState.REGISTERED_AS_STUDENT) {
                    Student student = application.getStudent();
                    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
                    studentDAO.archive(student);
                }
                // #4226: Applications of rejected Internetix students are removed immediately
                if (StringUtils.equals("aineopiskelu", application.getLine())) {
                    ApplicationUtils.deleteApplication(application);
                    requestContext.setRedirectURL(requestContext.getRequest().getContextPath() + "/applications/browse.page");
                    return;
                }
            } else if (applicationState == ApplicationState.PROCESSING) {
                // #1216: If a signed application is returned to Processing state, remove the
                // previous signatures so that the proper processing order can once again be followed
                ApplicationSignaturesDAO applicationSignaturesDAO = DAOFactory.getInstance().getApplicationSignaturesDAO();
                ApplicationSignatures applicationSignatures = applicationSignaturesDAO.findByApplication(application);
                if (applicationSignatures != null) {
                    applicationSignaturesDAO.delete(applicationSignatures);
                }
            }
            // Update the actual application state
            application = applicationDAO.updateApplicationState(application, applicationState, staffMember);
            if (Boolean.TRUE.equals(lockApplication) && application.getApplicantEditable()) {
                application = applicationDAO.updateApplicantEditable(application, Boolean.FALSE, staffMember);
            }
            if (Boolean.TRUE.equals(setHandler)) {
                application = applicationDAO.updateApplicationHandler(application, staffMember);
            }
            if (Boolean.TRUE.equals(removeHandler)) {
                application = applicationDAO.updateApplicationHandler(application, null);
            }
            // Email notifications and log entries related to state change
            ApplicationUtils.sendNotifications(application, requestContext.getRequest(), staffMember, false, null, true);
        }
        // Response parameters
        requestContext.addResponseParameter("status", "OK");
        requestContext.addResponseParameter("id", application.getId());
        requestContext.addResponseParameter("state", application.getState());
        requestContext.addResponseParameter("stateUi", ApplicationUtils.applicationStateUiValue(application.getState()));
        requestContext.addResponseParameter("applicantEditable", application.getApplicantEditable());
        requestContext.addResponseParameter("handler", application.getHandler() == null ? null : application.getHandler().getFullName());
        requestContext.addResponseParameter("handlerId", application.getHandler() == null ? null : application.getHandler().getId());
        requestContext.addResponseParameter("lastModified", application.getLastModified().getTime());
    } catch (Exception e) {
        requestContext.addResponseParameter("status", "FAIL");
        requestContext.addResponseParameter("reason", e.getMessage());
        logger.log(Level.SEVERE, "Error updating application state", e);
    }
}
Also used : ApplicationLogDAO(fi.otavanopisto.pyramus.dao.application.ApplicationLogDAO) ApplicationState(fi.otavanopisto.pyramus.domainmodel.application.ApplicationState) ApplicationSignatures(fi.otavanopisto.pyramus.domainmodel.application.ApplicationSignatures) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) ApplicationDAO(fi.otavanopisto.pyramus.dao.application.ApplicationDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) JSONObject(net.sf.json.JSONObject) ApplicationSignaturesDAO(fi.otavanopisto.pyramus.dao.application.ApplicationSignaturesDAO) Application(fi.otavanopisto.pyramus.domainmodel.application.Application)

Aggregations

Student (fi.otavanopisto.pyramus.domainmodel.students.Student)199 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)88 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)75 Path (javax.ws.rs.Path)69 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)68 StudentGroupStudent (fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent)59 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)46 Date (java.util.Date)42 Status (javax.ws.rs.core.Response.Status)40 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)38 GET (javax.ws.rs.GET)34 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)31 Person (fi.otavanopisto.pyramus.domainmodel.base.Person)30 User (fi.otavanopisto.pyramus.domainmodel.users.User)30 ArrayList (java.util.ArrayList)27 PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)25 CourseAssessment (fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment)25 HashSet (java.util.HashSet)23 HashMap (java.util.HashMap)21 StudyProgramme (fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme)20