Search in sources :

Example 16 with TransferCredit

use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.

the class AbstractKoskiLukioStudentHandler2019 method findCourseType.

private LukionKurssinTyyppi findCourseType(Student student, CreditStub courseCredit, boolean national, LukionKurssinTyyppi... allowedValues) {
    Set<LukionKurssinTyyppi> resolvedTypes = new HashSet<>();
    for (CreditStubCredit credit : courseCredit.getCredits()) {
        if (credit.getCredit() instanceof CourseAssessment) {
            CourseAssessment courseAssessment = (CourseAssessment) credit.getCredit();
            if (courseAssessment.getCourseStudent() != null && courseAssessment.getCourseStudent().getCourse() != null) {
                Course course = courseAssessment.getCourseStudent().getCourse();
                Set<Long> educationSubTypeIds = course.getCourseEducationTypes().stream().flatMap(educationType -> educationType.getCourseEducationSubtypes().stream().map(subType -> subType.getEducationSubtype().getId())).collect(Collectors.toSet());
                for (Long educationSubTypeId : educationSubTypeIds) {
                    String mappedValue = settings.getCourseTypeMapping2019(educationSubTypeId);
                    if (mappedValue != null && EnumUtils.isValidEnum(LukionKurssinTyyppi.class, mappedValue)) {
                        resolvedTypes.add(LukionKurssinTyyppi.valueOf(mappedValue));
                    }
                }
            } else {
                logger.warning(String.format("CourseAssessment %d has no courseStudent or Course", courseAssessment.getId()));
            }
        } else if (credit.getCredit() instanceof TransferCredit) {
            TransferCredit transferCredit = (TransferCredit) credit.getCredit();
            if (national && transferCredit.getOptionality() == CourseOptionality.MANDATORY) {
                resolvedTypes.add(LukionKurssinTyyppi.pakollinen);
            } else {
                // TODO Is this correct?
                resolvedTypes.add(LukionKurssinTyyppi.syventava);
            }
        } else {
            logger.warning(String.format("Unknown credit type %s", credit.getClass().getSimpleName()));
        }
    }
    Set<LukionKurssinTyyppi> allowedSet = new HashSet<>(Arrays.asList(allowedValues));
    allowedSet.removeIf(element -> !resolvedTypes.contains(element));
    if (allowedSet.size() == 0) {
        logger.warning(String.format("Course %s has no feasible subtypes.", courseCredit.getCourseCode()));
        koskiPersonLogDAO.create(student.getPerson(), student, KoskiPersonState.UNRESOLVABLE_SUBTYPES, new Date(), courseCredit.getCourseCode());
        return allowedValues[0];
    } else if (allowedSet.size() == 1) {
        return allowedSet.iterator().next();
    } else {
        for (LukionKurssinTyyppi type : allowedValues) {
            if (allowedSet.contains(type)) {
                logger.warning(String.format("Course %s has several matching subtypes.", courseCredit.getCourseCode()));
                koskiPersonLogDAO.create(student.getPerson(), student, KoskiPersonState.UNRESOLVABLE_SUBTYPES, new Date(), courseCredit.getCourseCode());
                return type;
            }
        }
    }
    return allowedValues[0];
}
Also used : StudentSubjectSelections(fi.otavanopisto.pyramus.koski.StudentSubjectSelections) SuorituksenTyyppi(fi.otavanopisto.pyramus.koski.koodisto.SuorituksenTyyppi) Arrays(java.util.Arrays) OppiaineMatematiikka(fi.otavanopisto.pyramus.koski.koodisto.OppiaineMatematiikka) KoskiPersonState(fi.otavanopisto.pyramus.domainmodel.koski.KoskiPersonState) Date(java.util.Date) KoskiOppiaineetYleissivistava(fi.otavanopisto.pyramus.koski.koodisto.KoskiOppiaineetYleissivistava) HashMap(java.util.HashMap) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) StringUtils(org.apache.commons.lang3.StringUtils) AbstractKoskiLukioStudentHandler(fi.otavanopisto.pyramus.koski.model.lukio.AbstractKoskiLukioStudentHandler) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) Inject(javax.inject.Inject) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) OpiskelijanOPS(fi.otavanopisto.pyramus.koski.OpiskelijanOPS) LukionMuutOpinnot(fi.otavanopisto.pyramus.koski.koodisto.LukionMuutOpinnot) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CollectionUtils(org.apache.commons.collections.CollectionUtils) EnumUtils(org.apache.commons.lang3.EnumUtils) Map(java.util.Map) Kielivalikoima(fi.otavanopisto.pyramus.koski.koodisto.Kielivalikoima) OppiaineAidinkieliJaKirjallisuus(fi.otavanopisto.pyramus.koski.koodisto.OppiaineAidinkieliJaKirjallisuus) LukionOppiaineenArviointi(fi.otavanopisto.pyramus.koski.model.lukio.LukionOppiaineenArviointi) Laajuus(fi.otavanopisto.pyramus.koski.model.Laajuus) CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) EnumSet(java.util.EnumSet) OpintojenLaajuusYksikko(fi.otavanopisto.pyramus.koski.koodisto.OpintojenLaajuusYksikko) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) CreditStub(fi.otavanopisto.pyramus.koski.CreditStub) Collection(java.util.Collection) Set(java.util.Set) LukionKurssinTyyppi(fi.otavanopisto.pyramus.koski.koodisto.LukionKurssinTyyppi) ModuuliKoodistoLOPS2021(fi.otavanopisto.pyramus.koski.koodisto.ModuuliKoodistoLOPS2021) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) ArviointiasteikkoYleissivistava(fi.otavanopisto.pyramus.koski.koodisto.ArviointiasteikkoYleissivistava) List(java.util.List) PaikallinenKoodi(fi.otavanopisto.pyramus.koski.model.PaikallinenKoodi) CreditStubCredit(fi.otavanopisto.pyramus.koski.CreditStubCredit) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) KurssinArviointi(fi.otavanopisto.pyramus.koski.model.KurssinArviointi) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) OppiaineenSuoritusWithSubject(fi.otavanopisto.pyramus.koski.OppiaineenSuoritusWithSubject) LukionKurssinTyyppi(fi.otavanopisto.pyramus.koski.koodisto.LukionKurssinTyyppi) CreditStubCredit(fi.otavanopisto.pyramus.koski.CreditStubCredit) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) Date(java.util.Date) HashSet(java.util.HashSet)

Example 17 with TransferCredit

use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.

the class KoskiLukioStudentHandler method findCourseType.

private LukionKurssinTyyppi findCourseType(Student student, CreditStub courseCredit, boolean national, LukionKurssinTyyppi... allowedValues) {
    Set<LukionKurssinTyyppi> resolvedTypes = new HashSet<>();
    for (CreditStubCredit credit : courseCredit.getCredits()) {
        if (credit.getCredit() instanceof CourseAssessment) {
            CourseAssessment courseAssessment = (CourseAssessment) credit.getCredit();
            if (courseAssessment.getCourseStudent() != null && courseAssessment.getCourseStudent().getCourse() != null) {
                Course course = courseAssessment.getCourseStudent().getCourse();
                Set<Long> educationSubTypeIds = course.getCourseEducationTypes().stream().flatMap(educationType -> educationType.getCourseEducationSubtypes().stream().map(subType -> subType.getEducationSubtype().getId())).collect(Collectors.toSet());
                for (Long educationSubTypeId : educationSubTypeIds) {
                    String mappedValue = settings.getCourseTypeMapping(educationSubTypeId);
                    if (mappedValue != null && EnumUtils.isValidEnum(LukionKurssinTyyppi.class, mappedValue)) {
                        resolvedTypes.add(LukionKurssinTyyppi.valueOf(mappedValue));
                    }
                }
            } else
                logger.warning(String.format("CourseAssessment %d has no courseStudent or Course", courseAssessment.getId()));
        } else if (credit.getCredit() instanceof TransferCredit) {
            TransferCredit transferCredit = (TransferCredit) credit.getCredit();
            if (national && transferCredit.getOptionality() == CourseOptionality.MANDATORY) {
                resolvedTypes.add(LukionKurssinTyyppi.pakollinen);
            } else {
                resolvedTypes.add(LukionKurssinTyyppi.syventava);
            }
        } else {
            logger.warning(String.format("Unknown credit type %s", credit.getClass().getSimpleName()));
        }
    }
    Set<LukionKurssinTyyppi> allowedSet = new HashSet<>(Arrays.asList(allowedValues));
    allowedSet.removeIf(element -> !resolvedTypes.contains(element));
    if (allowedSet.size() == 0) {
        logger.warning(String.format("Course %s has no feasible subtypes.", courseCredit.getCourseCode()));
        koskiPersonLogDAO.create(student.getPerson(), student, KoskiPersonState.UNRESOLVABLE_SUBTYPES, new Date(), courseCredit.getCourseCode());
        return allowedValues[0];
    } else if (allowedSet.size() == 1) {
        return allowedSet.iterator().next();
    } else {
        for (LukionKurssinTyyppi type : allowedValues) {
            if (allowedSet.contains(type)) {
                logger.warning(String.format("Course %s has several matching subtypes.", courseCredit.getCourseCode()));
                koskiPersonLogDAO.create(student.getPerson(), student, KoskiPersonState.UNRESOLVABLE_SUBTYPES, new Date(), courseCredit.getCourseCode());
                return type;
            }
        }
    }
    return allowedValues[0];
}
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) LukionKurssinTyyppi(fi.otavanopisto.pyramus.koski.koodisto.LukionKurssinTyyppi) CreditStubCredit(fi.otavanopisto.pyramus.koski.CreditStubCredit) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) Date(java.util.Date) HashSet(java.util.HashSet)

Example 18 with TransferCredit

use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.

the class SaveTransferCreditsJSONRequestController method process.

public void process(JSONRequestContext jsonRequestContext) {
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    GradeDAO gradeDAO = DAOFactory.getInstance().getGradeDAO();
    TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
    SubjectDAO subjectDAO = DAOFactory.getInstance().getSubjectDAO();
    CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
    Long studentId = jsonRequestContext.getLong("studentId");
    Student student = studentDAO.findById(studentId);
    int rowCount = jsonRequestContext.getInteger("transferCreditsTable.rowCount");
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "transferCreditsTable." + i;
        Long id = jsonRequestContext.getLong(colPrefix + ".creditId");
        String courseName = jsonRequestContext.getString(colPrefix + ".courseName");
        CourseOptionality courseOptionality = (CourseOptionality) jsonRequestContext.getEnum(colPrefix + ".courseOptionality", CourseOptionality.class);
        Integer courseNumber = jsonRequestContext.getInteger(colPrefix + ".courseNumber");
        Long gradeId = jsonRequestContext.getLong(colPrefix + ".grade");
        Long subjectId = jsonRequestContext.getLong(colPrefix + ".subject");
        Double courseLength = jsonRequestContext.getDouble(colPrefix + ".courseLength");
        Long courseLengthUnitId = jsonRequestContext.getLong(colPrefix + ".courseLengthUnit");
        Long schooId = jsonRequestContext.getLong(colPrefix + ".school");
        Date date = jsonRequestContext.getDate(colPrefix + ".date");
        Long userId = jsonRequestContext.getLong(colPrefix + ".user");
        Long curriculumId = jsonRequestContext.getLong(colPrefix + ".curriculum");
        boolean offCurriculum = new Long(1).equals(jsonRequestContext.getLong(colPrefix + ".offCurriculum"));
        TransferCreditFunding funding = new Long(1).equals(jsonRequestContext.getLong(colPrefix + ".funding")) ? TransferCreditFunding.GOVERNMENT_FUNDING : null;
        Grade grade = gradeDAO.findById(gradeId);
        Subject subject = subjectDAO.findById(subjectId);
        EducationalTimeUnit timeUnit = educationalTimeUnitDAO.findById(courseLengthUnitId);
        School school = schoolDAO.findById(schooId);
        StaffMember staffMember = staffMemberDAO.findById(userId);
        Curriculum curriculum = curriculumId != null ? curriculumDAO.findById(curriculumId) : null;
        TransferCredit transferCredit;
        if (id != null && id >= 0) {
            transferCredit = transferCreditDAO.findById(id);
            transferCreditDAO.update(transferCredit, courseName, courseNumber, courseLength, timeUnit, school, subject, courseOptionality, student, staffMember, grade, date, transferCredit.getVerbalAssessment(), curriculum, offCurriculum, funding);
        } else {
            transferCredit = transferCreditDAO.create(courseName, courseNumber, courseLength, timeUnit, school, subject, courseOptionality, student, staffMember, grade, date, "", curriculum, offCurriculum, funding);
        }
    }
    jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
}
Also used : CourseOptionality(fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality) SubjectDAO(fi.otavanopisto.pyramus.dao.base.SubjectDAO) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) School(fi.otavanopisto.pyramus.domainmodel.base.School) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) TransferCreditDAO(fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO) SchoolDAO(fi.otavanopisto.pyramus.dao.base.SchoolDAO) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) Grade(fi.otavanopisto.pyramus.domainmodel.grading.Grade) GradeDAO(fi.otavanopisto.pyramus.dao.grading.GradeDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Date(java.util.Date) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) TransferCreditFunding(fi.otavanopisto.pyramus.domainmodel.grading.TransferCreditFunding)

Example 19 with TransferCredit

use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.

the class EditStudentProjectViewController 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) {
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    CourseStudentDAO courseStudentDAO = DAOFactory.getInstance().getCourseStudentDAO();
    StudentProjectDAO studentProjectDAO = DAOFactory.getInstance().getStudentProjectDAO();
    StudentProjectModuleDAO studentProjectModuleDAO = DAOFactory.getInstance().getStudentProjectModuleDAO();
    GradingScaleDAO gradingScaleDAO = DAOFactory.getInstance().getGradingScaleDAO();
    ProjectAssessmentDAO projectAssessmentDAO = DAOFactory.getInstance().getProjectAssessmentDAO();
    AcademicTermDAO academicTermDAO = DAOFactory.getInstance().getAcademicTermDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    CreditLinkDAO creditLinkDAO = DAOFactory.getInstance().getCreditLinkDAO();
    CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
    TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
    Long studentProjectId = pageRequestContext.getLong("studentproject");
    List<GradingScale> gradingScales = gradingScaleDAO.listUnarchived();
    StudentProject studentProject = studentProjectDAO.findById(studentProjectId);
    List<StudentProjectModule> studentProjectModules = studentProjectModuleDAO.listByStudentProject(studentProject);
    List<CourseStudent> courseStudents = courseStudentDAO.listByStudent(studentProject.getStudent());
    List<CourseAssessment> allStudentCourseAssessments = courseAssessmentDAO.listByStudent(studentProject.getStudent());
    List<TransferCredit> allStudentTransferCredits = transferCreditDAO.listByStudent(studentProject.getStudent());
    List<CreditLink> allStudentCreditLinks = creditLinkDAO.listByStudent(studentProject.getStudent());
    JSONArray studentProjectModulesJSON = new JSONArray();
    JSONArray courseStudentsJSON = new JSONArray();
    for (CreditLink creditLink : allStudentCreditLinks) {
        switch(creditLink.getCredit().getCreditType()) {
            case CourseAssessment:
                allStudentCourseAssessments.add((CourseAssessment) creditLink.getCredit());
                break;
            case TransferCredit:
                allStudentTransferCredits.add((TransferCredit) creditLink.getCredit());
                break;
        }
    }
    Collections.sort(studentProjectModules, new Comparator<StudentProjectModule>() {

        @Override
        public int compare(StudentProjectModule o1, StudentProjectModule o2) {
            return o1.getModule().getName().compareTo(o2.getModule().getName());
        }
    });
    for (StudentProjectModule studentProjectModule : studentProjectModules) {
        JSONArray moduleCourseStudents = new JSONArray();
        JSONArray moduleCredits = new JSONArray();
        boolean hasPassingGrade = false;
        List<CourseStudent> projectCourseCourseStudents = courseStudentDAO.listByModuleAndStudent(studentProjectModule.getModule(), studentProject.getStudent());
        for (CourseStudent courseStudent : projectCourseCourseStudents) {
            JSONObject courseStudentJson = new JSONObject();
            courseStudentJson.put("courseStudentParticipationType", courseStudent.getParticipationType().getName());
            // courseStudents.remove(courseStudent);
            moduleCourseStudents.add(courseStudentJson);
        }
        for (CourseAssessment assessment : allStudentCourseAssessments) {
            if (assessment.getCourseStudent().getCourse().getModule().getId().equals(studentProjectModule.getModule().getId())) {
                if (assessment.getGrade() != null) {
                    JSONObject courseAssessment = new JSONObject();
                    courseAssessment.put("creditType", assessment.getCreditType().toString());
                    courseAssessment.put("courseName", assessment.getCourseStudent().getCourse().getName());
                    courseAssessment.put("gradeName", assessment.getGrade().getName());
                    moduleCredits.add(courseAssessment);
                    hasPassingGrade = hasPassingGrade || assessment.getGrade().getPassingGrade();
                }
            }
        }
        if ((studentProjectModule.getModule().getCourseNumber() != null) && (studentProjectModule.getModule().getCourseNumber() != -1) && (studentProjectModule.getModule().getSubject() != null)) {
            for (TransferCredit tc : allStudentTransferCredits) {
                if ((tc.getCourseNumber() != null) && (tc.getCourseNumber() != -1) && (tc.getSubject() != null)) {
                    if (tc.getCourseNumber().equals(studentProjectModule.getModule().getCourseNumber()) && tc.getSubject().equals(studentProjectModule.getModule().getSubject())) {
                        if (tc.getGrade() != null) {
                            JSONObject transferCredit = new JSONObject();
                            transferCredit.put("creditType", tc.getCreditType().toString());
                            transferCredit.put("courseName", tc.getCourseName());
                            transferCredit.put("gradeName", tc.getGrade().getName());
                            moduleCredits.add(transferCredit);
                            hasPassingGrade = hasPassingGrade || tc.getGrade().getPassingGrade();
                        }
                    }
                }
            }
        }
        JSONObject obj = new JSONObject();
        obj.put("projectModuleId", studentProjectModule.getId().toString());
        obj.put("projectModuleOptionality", studentProjectModule.getOptionality().toString());
        obj.put("projectModuleAcademicTermId", studentProjectModule.getAcademicTerm() != null ? studentProjectModule.getAcademicTerm().getId().toString() : "");
        obj.put("projectModuleHasPassingGrade", hasPassingGrade ? "1" : "0");
        obj.put("moduleId", studentProjectModule.getModule().getId());
        obj.put("moduleName", studentProjectModule.getModule().getName());
        obj.put("moduleCourseStudents", moduleCourseStudents);
        obj.put("moduleCredits", moduleCredits);
        studentProjectModulesJSON.add(obj);
    }
    List<Student> students = studentDAO.listByPerson(studentProject.getStudent().getPerson());
    Collections.sort(students, new Comparator<Student>() {

        @Override
        public int compare(Student o1, Student o2) {
            /**
             * Ordering study programmes as follows
             *  1. studies that have start date but no end date (ongoing)
             *  2. studies that have no start nor end date
             *  3. studies that have ended
             *  4. studies that are archived
             *  5. other
             */
            int o1class = (o1.getArchived()) ? 4 : (o1.getStudyStartDate() != null && o1.getStudyEndDate() == null) ? 1 : (o1.getStudyStartDate() == null && o1.getStudyEndDate() == null) ? 2 : (o1.getStudyEndDate() != null) ? 3 : 5;
            int o2class = (o2.getArchived()) ? 4 : (o2.getStudyStartDate() != null && o2.getStudyEndDate() == null) ? 1 : (o2.getStudyStartDate() == null && o2.getStudyEndDate() == null) ? 2 : (o2.getStudyEndDate() != null) ? 3 : 5;
            if (o1class == o2class) {
                // classes are the same, we try to do last comparison from the start dates
                return ((o1.getStudyStartDate() != null) && (o2.getStudyStartDate() != null)) ? o2.getStudyStartDate().compareTo(o1.getStudyStartDate()) : 0;
            } else
                return o1class < o2class ? -1 : o1class == o2class ? 0 : 1;
        }
    });
    List<EducationalTimeUnit> educationalTimeUnits = educationalTimeUnitDAO.listUnarchived();
    Collections.sort(educationalTimeUnits, new StringAttributeComparator("getName"));
    List<AcademicTerm> academicTerms = academicTermDAO.listUnarchived();
    Collections.sort(academicTerms, new Comparator<AcademicTerm>() {

        public int compare(AcademicTerm o1, AcademicTerm o2) {
            return o1.getStartDate() == null ? -1 : o2.getStartDate() == null ? 1 : o1.getStartDate().compareTo(o2.getStartDate());
        }
    });
    List<ProjectAssessment> assessments = projectAssessmentDAO.listByProjectAndArchived(studentProject, Boolean.FALSE);
    Collections.sort(assessments, new Comparator<ProjectAssessment>() {

        @Override
        public int compare(ProjectAssessment o1, ProjectAssessment o2) {
            return o2.getDate().compareTo(o1.getDate());
        }
    });
    Collections.sort(courseStudents, new Comparator<CourseStudent>() {

        @Override
        public int compare(CourseStudent o1, CourseStudent o2) {
            return o1.getCourse().getName().compareTo(o2.getCourse().getName());
        }
    });
    for (CourseStudent courseStudent : courseStudents) {
        CourseAssessment courseAssessment = courseAssessmentDAO.findLatestByCourseStudentAndArchived(courseStudent, Boolean.FALSE);
        Grade grade = courseAssessment != null ? courseAssessment.getGrade() : null;
        JSONObject obj = new JSONObject();
        String courseName = courseStudent.getCourse().getName();
        if (!StringUtils.isEmpty(courseStudent.getCourse().getNameExtension()))
            courseName = courseName + " (" + courseStudent.getCourse().getNameExtension() + ")";
        obj.put("courseName", courseName);
        if (courseStudent.getParticipationType() != null) {
            obj.put("participationType", courseStudent.getParticipationType().getName());
        }
        if (courseStudent.getCourse().getBeginDate() != null) {
            obj.put("courseBeginDate", courseStudent.getCourse().getBeginDate().getTime());
        }
        if (courseStudent.getCourse().getEndDate() != null) {
            obj.put("courseEndDate", courseStudent.getCourse().getEndDate().getTime());
        }
        obj.put("gradeName", grade != null ? grade.getName() : "");
        if (courseStudent.getOptionality() != null) {
            obj.put("optionality", courseStudent.getOptionality().toString());
        }
        obj.put("moduleId", courseStudent.getCourse().getModule().getId().toString());
        obj.put("courseId", courseStudent.getCourse().getId().toString());
        obj.put("courseStudentId", courseStudent.getId().toString());
        courseStudentsJSON.add(obj);
    }
    Map<Long, String> verbalAssessments = new HashMap<>();
    for (ProjectAssessment pAss : assessments) {
        // Shortened descriptions
        String description = pAss.getVerbalAssessment();
        if (description != null) {
            description = StringEscapeUtils.unescapeHtml(description.replaceAll("\\<.*?>", ""));
            description = description.replaceAll("\\n", "");
            verbalAssessments.put(pAss.getId(), description);
        }
    }
    /* Tags */
    StringBuilder tagsBuilder = new StringBuilder();
    Iterator<Tag> tagIterator = studentProject.getTags().iterator();
    while (tagIterator.hasNext()) {
        Tag tag = tagIterator.next();
        tagsBuilder.append(tag.getText());
        if (tagIterator.hasNext())
            tagsBuilder.append(' ');
    }
    pageRequestContext.getRequest().setAttribute("projectAssessments", assessments);
    pageRequestContext.getRequest().setAttribute("verbalAssessments", verbalAssessments);
    pageRequestContext.getRequest().setAttribute("studentProject", studentProject);
    pageRequestContext.getRequest().setAttribute("students", students);
    pageRequestContext.getRequest().setAttribute("optionalStudiesLengthTimeUnits", educationalTimeUnits);
    pageRequestContext.getRequest().setAttribute("academicTerms", academicTerms);
    pageRequestContext.getRequest().setAttribute("users", userDAO.listAll());
    pageRequestContext.getRequest().setAttribute("gradingScales", gradingScales);
    pageRequestContext.getRequest().setAttribute("tags", tagsBuilder.toString());
    setJsDataVariable(pageRequestContext, "studentProjectModules", studentProjectModulesJSON.toString());
    setJsDataVariable(pageRequestContext, "courseStudents", courseStudentsJSON.toString());
    pageRequestContext.setIncludeJSP("/templates/projects/editstudentproject.jsp");
}
Also used : GradingScale(fi.otavanopisto.pyramus.domainmodel.grading.GradingScale) GradingScaleDAO(fi.otavanopisto.pyramus.dao.grading.GradingScaleDAO) HashMap(java.util.HashMap) StudentProjectModuleDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectModuleDAO) StudentProjectDAO(fi.otavanopisto.pyramus.dao.projects.StudentProjectDAO) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) CourseAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO) Grade(fi.otavanopisto.pyramus.domainmodel.grading.Grade) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CourseStudentDAO(fi.otavanopisto.pyramus.dao.courses.CourseStudentDAO) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) JSONObject(net.sf.json.JSONObject) StudentProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.StudentProjectModule) ProjectAssessment(fi.otavanopisto.pyramus.domainmodel.grading.ProjectAssessment) ProjectAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.ProjectAssessmentDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) TransferCreditDAO(fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO) AcademicTermDAO(fi.otavanopisto.pyramus.dao.base.AcademicTermDAO) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) JSONArray(net.sf.json.JSONArray) CreditLinkDAO(fi.otavanopisto.pyramus.dao.grading.CreditLinkDAO) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) AcademicTerm(fi.otavanopisto.pyramus.domainmodel.base.AcademicTerm) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentProject(fi.otavanopisto.pyramus.domainmodel.projects.StudentProject)

Example 20 with TransferCredit

use of fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit in project pyramus by otavanopisto.

the class ManageTransferCreditsViewController 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) {
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
    GradingScaleDAO gradingScaleDAO = DAOFactory.getInstance().getGradingScaleDAO();
    TransferCreditTemplateDAO transferCreditTemplateDAO = DAOFactory.getInstance().getTransferCreditTemplateDAO();
    EducationalTimeUnitDAO educationalTimeUnitDAO = DAOFactory.getInstance().getEducationalTimeUnitDAO();
    CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
    Long studentId = pageRequestContext.getLong("studentId");
    Student student = studentDAO.findById(studentId);
    List<TransferCredit> transferCredits = transferCreditDAO.listByStudent(student);
    List<GradingScale> gradingScales = gradingScaleDAO.listUnarchived();
    List<EducationalTimeUnit> timeUnits = educationalTimeUnitDAO.listUnarchived();
    Collections.sort(timeUnits, new StringAttributeComparator("getName"));
    List<TransferCreditTemplate> transferCreditTemplates = transferCreditTemplateDAO.listAll();
    Collections.sort(transferCredits, new StringAttributeComparator("getCourseName", true));
    List<Curriculum> curriculums = curriculumDAO.listUnarchived();
    Collections.sort(curriculums, new StringAttributeComparator("getName"));
    String jsonCurriculums = new JSONArrayExtractor("name", "id").extractString(curriculums);
    setJsDataVariable(pageRequestContext, "curriculums", jsonCurriculums);
    pageRequestContext.getRequest().setAttribute("student", student);
    pageRequestContext.getRequest().setAttribute("transferCredits", transferCredits);
    pageRequestContext.getRequest().setAttribute("gradingScales", gradingScales);
    pageRequestContext.getRequest().setAttribute("timeUnits", timeUnits);
    pageRequestContext.getRequest().setAttribute("transferCreditTemplates", transferCreditTemplates);
    pageRequestContext.setIncludeJSP("/templates/grading/managetransfercredits.jsp");
}
Also used : GradingScale(fi.otavanopisto.pyramus.domainmodel.grading.GradingScale) GradingScaleDAO(fi.otavanopisto.pyramus.dao.grading.GradingScaleDAO) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) EducationalTimeUnitDAO(fi.otavanopisto.pyramus.dao.base.EducationalTimeUnitDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) TransferCreditDAO(fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) TransferCreditTemplate(fi.otavanopisto.pyramus.domainmodel.grading.TransferCreditTemplate) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) TransferCreditTemplateDAO(fi.otavanopisto.pyramus.dao.grading.TransferCreditTemplateDAO) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit)

Aggregations

TransferCredit (fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit)28 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)17 CourseAssessment (fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment)15 TransferCreditDAO (fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO)12 CreditLink (fi.otavanopisto.pyramus.domainmodel.grading.CreditLink)12 Subject (fi.otavanopisto.pyramus.domainmodel.base.Subject)10 ArrayList (java.util.ArrayList)10 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)9 CourseStudent (fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent)9 CourseAssessmentDAO (fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO)8 CreditLinkDAO (fi.otavanopisto.pyramus.dao.grading.CreditLinkDAO)8 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)8 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)8 Date (java.util.Date)8 HashMap (java.util.HashMap)8 CourseOptionality (fi.otavanopisto.pyramus.domainmodel.base.CourseOptionality)7 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)7 List (java.util.List)7 EntityManager (javax.persistence.EntityManager)7 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)6